1 21 22 package org.opensubsystems.core.persist.db; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import org.opensubsystems.core.data.DataConstant; 30 import org.opensubsystems.core.data.ModifiableDataObject; 31 import org.opensubsystems.core.error.OSSDataCreateException; 32 import org.opensubsystems.core.error.OSSDataDeleteException; 33 import org.opensubsystems.core.error.OSSDataSaveException; 34 import org.opensubsystems.core.error.OSSException; 35 36 45 public abstract class ModifiableDatabaseSchemaImpl extends DatabaseSchemaImpl 46 implements ModifiableDatabaseSchema 47 { 48 50 56 protected Map m_mapModifiableTableNames; 57 58 60 75 public ModifiableDatabaseSchemaImpl( 76 DatabaseSchema[] arrDependentSchemas, 77 String strSchemaName, 78 int iSchemaVersion, 79 boolean bIsInDomain, 80 Map mapModifiableTableNames 81 ) throws OSSException 82 { 83 super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain); 84 85 m_mapModifiableTableNames = mapModifiableTableNames; 86 } 87 88 104 public ModifiableDatabaseSchemaImpl( 105 DatabaseSchema[] arrDependentSchemas, 106 String strSchemaName, 107 int iSchemaVersion, 108 boolean bIsInDomain, 109 Integer iModifiableDataType, 110 String strModifiableTableName 111 ) throws OSSException 112 { 113 super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain); 114 115 if ((strModifiableTableName != null) && (strModifiableTableName.length() > 0)) 116 { 117 m_mapModifiableTableNames = new HashMap (1); 118 m_mapModifiableTableNames.put(iModifiableDataType, strModifiableTableName); 119 } 120 } 121 122 124 136 public int deleteRelatedData( 137 Connection cntDBConnection, 138 int iDataType, 139 int iId 140 ) throws OSSException, 141 SQLException  142 { 143 return 0; 145 } 146 147 149 152 public Map getModifiableTableNames( 153 ) 154 { 155 return m_mapModifiableTableNames; 156 } 157 158 161 public void handleSQLException( 162 SQLException exc, 163 Connection dbConnection, 164 int iOperationType, 165 int iDataType, 166 Object data 167 ) throws OSSException 168 { 169 switch (iOperationType) 170 { 171 case (DBOP_INSERT) : 172 { 173 throw new OSSDataCreateException( 174 "Failed to create data in the database.", exc); 175 } 176 case (DBOP_UPDATE) : 177 { 178 if ((exc.getMessage().indexOf("[100]") > -1) 182 && (data instanceof ModifiableDataObject)) 183 { 184 Integer iDataTypeCode = new Integer (iDataType); 185 186 DatabaseDataUtils.checkUpdateError( 187 dbConnection, 188 DataConstant.getDataTypeName(iDataTypeCode), 189 (String )getModifiableTableNames().get(iDataTypeCode), 190 ((ModifiableDataObject)data).getId(), 191 ((ModifiableDataObject)data).getModificationTimestamp()); 192 } 193 throw new OSSDataSaveException( 195 "Failed to update data in the database.", exc); 196 } 197 case (DBOP_DELETE) : 198 { 199 throw new OSSDataDeleteException( 200 "Failed to delete data from the database.", exc); 201 } 202 default: 203 { 204 super.handleSQLException(exc, dbConnection, iOperationType, 205 iDataType, data); 206 } 207 } 208 } 209 } 210
| Popular Tags
|