1 21 22 package org.opensubsystems.core.persist.db; 23 24 import java.sql.Connection ; 25 import java.sql.PreparedStatement ; 26 import java.sql.SQLException ; 27 28 import org.opensubsystems.core.error.OSSDataNotFoundException; 29 import org.opensubsystems.core.error.OSSException; 30 import org.opensubsystems.core.error.OSSInconsistentDataException; 31 32 42 public class DatabaseDeleteSingleDataObjectOperation extends DatabaseUpdateOperation 43 { 44 46 49 private ModifiableDatabaseSchema m_schema; 50 51 54 private int m_iDataType; 55 56 59 private int m_iId; 60 61 64 private int m_iDomainId; 65 66 68 77 public DatabaseDeleteSingleDataObjectOperation( 78 DatabaseFactoryImpl factory, 79 String strQuery, 80 ModifiableDatabaseSchema schema, 81 int iId, 82 int iDomainId 83 ) 84 { 85 super(factory, strQuery, schema, DatabaseUpdateOperation.DBOP_DELETE, null); 86 87 m_schema = schema; 88 m_iDataType = factory.getDataType(); 89 m_iId = iId; 90 m_iDomainId = iDomainId; 91 } 92 93 96 protected void performOperation( 97 DatabaseFactoryImpl dbfactory, 98 Connection cntConnection, 99 PreparedStatement pstmQuery 100 ) throws OSSException, SQLException  101 { 102 m_schema.deleteRelatedData(cntConnection, m_iDataType, m_iId); 103 104 int iDeleted; 105 106 pstmQuery.setInt(1, m_iId); 107 if (m_schema.isInDomain()) 108 { 109 pstmQuery.setInt(2, m_iDomainId); 111 } 112 iDeleted = pstmQuery.executeUpdate(); 113 114 if (iDeleted == 0) 115 { 116 throw new OSSDataNotFoundException( 117 "Data to delete cannot be found in the database"); 118 } 119 else if (iDeleted != 1) 120 { 121 throw new OSSInconsistentDataException( 122 "Inconsistent database contains multiple (" 123 + iDeleted + ") data object with the same ID"); 124 } 125 } 126 } 127
| Popular Tags
|