View Javadoc
1   /***
2    * License Agreement.
3    * 
4    * JSPA (POJO-SP)
5    * 
6    * Copyright (C) 2009 HRX Pty Ltd
7    * 
8    * This file is part of JSPA.
9    * 
10   * JSPA is free software: you can redistribute it and/or modify it under the
11   * terms of the GNU Lesser General Public License version 3 as published by the
12   * Free Software Foundation.
13   * 
14   * JSPA is distributed in the hope that it will be useful, but WITHOUT ANY
15   * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16   * A PARTICULAR PURPOSE. See the Lesser General Public License for more details.
17   * 
18   * You should have received a copy of the GNU Lesser General Public License
19   * along with JSPA. If not, see <http://www.gnu.org/licenses/>.
20   */
21  package com.hrx.rasp.util.dao.operation;
22  
23  import java.sql.CallableStatement;
24  import java.sql.SQLException;
25  import java.util.Collection;
26  
27  import javax.sql.DataSource;
28  
29  import com.hrx.rasp.util.dao.annotations.IN;
30  import com.hrx.rasp.util.dao.exception.StoredProcedureException;
31  import com.hrx.rasp.util.dao.exception.StoredProcedurePrepareException;
32  import com.hrx.rasp.util.dao.exception.StoredProcedureProccessResultException;
33  import com.hrx.rasp.util.dao.exception.StoredProcedureReservedIndexException;
34  import com.hrx.rasp.util.dao.metadata.StoredProcField;
35  
36  /***
37   * @author dan.stoica <dan.stoica@acslink.net.au>
38   * 
39   */
40  public class Delete extends AbstractDAOCommand
41  {
42  	/***
43  	 * Deletes the current record from the database
44  	 * 
45  	 * @param dataSource
46  	 *            The JDBC Data Source
47  	 */
48  
49  	public Delete(DataSource ds)
50  	{
51  		super(ds);
52  	}
53  
54  	/*
55  	 * (non-Javadoc)
56  	 * 
57  	 * @see com.hrx.rasp.util.dao.operation.AbstractDAOCommand#run()
58  	 */
59  	protected Object run() throws StoredProcedureException, SQLException, StoredProcedurePrepareException, StoredProcedureProccessResultException
60  	{
61  		// process the results
62  		checkResultCode(1, 2);
63  		ResponseProcessor.processCallableStatement(getSpBean(), getPkBean(), getCallableStatement(), getMetaData());
64  		return null;
65  	}
66  
67  	@SuppressWarnings("unchecked")
68  	@Override
69  	protected CallableStatement createStatement() throws StoredProcedurePrepareException, StoredProcedureReservedIndexException, SQLException
70  	{
71  		CallableStatement st;
72  		Object pkParameters = getPrimaryKeyParameters();
73  		if (isEmbeddedId())
74  		{
75  			st = StatementBuilder.getDeleteStatement(getConnection(), getStoredProcName(), (Collection<StoredProcField<IN>>)pkParameters, getPkBean());
76  		}else{
77  			st = StatementBuilder.getDeleteStatement(getConnection(), getStoredProcName(), (Collection<StoredProcField<IN>>)pkParameters, getSpBean());			
78  		}
79  		return st;
80  	}
81  
82  }