1 21 22 package org.opensubsystems.core.persist.db; 23 24 import java.sql.Connection ; 25 import java.sql.SQLException ; 26 import java.sql.Statement ; 27 import java.util.List ; 28 import java.util.Properties ; 29 import java.util.logging.Level ; 30 import java.util.logging.Logger ; 31 32 import org.opensubsystems.core.error.OSSDatabaseAccessException; 33 import org.opensubsystems.core.error.OSSException; 34 import org.opensubsystems.core.util.Config; 35 import org.opensubsystems.core.util.DatabaseUtils; 36 import org.opensubsystems.core.util.GlobalConstants; 37 import org.opensubsystems.core.util.Log; 38 39 49 public abstract class DatabaseSchemaImpl implements DatabaseSchema, 50 DatabaseOperations 51 { 52 54 58 public static final String DATABASE_SCHEMA_PREFIX = "oss.dbschema.prefix"; 59 60 62 65 public static final String DATABASE_SCHEMA_PREFIX_DEFAULT = "BF_"; 66 67 73 public static final String NL = "\n"; 74 75 77 80 private static String s_strSchemaPrefix; 81 82 85 protected DatabaseSchema[] m_arrDependentSchemas; 86 87 90 protected String m_strSchemaName; 91 92 95 protected int m_iSchemaVersion; 96 97 100 protected boolean m_bIsInDomain; 101 102 104 107 private static Logger s_logger = Log.getInstance(DatabaseSchemaImpl.class); 108 109 111 114 static 115 { 116 Properties prpSettings; 117 118 prpSettings = Config.getInstance().getPropertiesSafely(); 119 s_strSchemaPrefix = Config.getStringProperty(prpSettings, 120 DATABASE_SCHEMA_PREFIX, 121 DATABASE_SCHEMA_PREFIX_DEFAULT, 122 "Defaut database table prefix", 123 false); 124 if (s_strSchemaPrefix.length() > DATABASE_SCHEMA_PREFIX_DEFAULT.length()) 125 { 126 s_logger.config("Length of " + DATABASE_SCHEMA_PREFIX + " value is" + 127 " longer than the default value " + 128 DATABASE_SCHEMA_PREFIX_DEFAULT + ". This may cause" + 129 " issues for some databases."); 130 } 131 } 132 133 144 public DatabaseSchemaImpl( 145 DatabaseSchema[] arrDependentSchemas, 146 String strSchemaName, 147 int iSchemaVersion, 148 boolean bIsInDomain 149 ) throws OSSException 150 { 151 super(); 152 153 m_arrDependentSchemas = arrDependentSchemas; 154 m_strSchemaName = strSchemaName; 155 m_iSchemaVersion = iSchemaVersion; 156 m_bIsInDomain = bIsInDomain; 157 } 158 159 161 164 public void upgrade( 165 Connection cntDBConnection, 166 String strUserName, 167 int iOriginalVersion 168 ) throws SQLException  169 { 170 } 174 175 189 public String [] getJoinFromWhere( 190 List conditions, 191 int[] columns 192 ) 193 { 194 return null; 195 } 196 197 208 public boolean isExistingIndex( 209 String strIndexName 210 ) 211 { 212 return false; 213 } 214 215 220 public static String getSchemaPrefix( 221 ) 222 { 223 return s_strSchemaPrefix; 224 } 225 226 228 240 protected void upgradeView( 241 Connection cntDBConnection, 242 String strUserName, 243 int iOriginalVersion, 244 String strViewName 245 ) throws SQLException , OSSException 246 { 247 Statement stmQuery = null; 249 try 250 { 251 int iVersion = iOriginalVersion; 252 253 stmQuery = cntDBConnection.createStatement(); 254 255 if (iVersion < getVersion()) 256 { 257 if (stmQuery.execute("drop view " + strViewName)) 258 { 259 stmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 261 } 262 s_logger.log(Level.FINEST, "View " + strViewName + " deleted."); 263 264 create(cntDBConnection, strUserName); 266 } 267 } 268 catch (SQLException sqleExc) 269 { 270 s_logger.log(Level.WARNING, "Failed to upgrade schema" + getName() + 271 " from version " + iOriginalVersion + " to version " + getVersion(), 272 sqleExc); 273 throw sqleExc; 274 } 275 finally 276 { 277 DatabaseUtils.closeStatement(stmQuery); 278 } 279 } 280 281 289 protected final String [] getOwnerColumnNames() 291 { 292 return null; 293 } 294 295 298 public boolean isInDomain() 299 { 300 return m_bIsInDomain; 301 } 302 303 306 public DatabaseSchema[] getDependentSchemas( 307 ) throws OSSException 308 { 309 return m_arrDependentSchemas; 310 } 311 312 315 public String getName( 316 ) 317 { 318 return m_strSchemaName; 319 } 320 321 324 public int getVersion( 325 ) 326 { 327 return m_iSchemaVersion; 328 } 329 330 333 public void handleSQLException( 334 SQLException exc, 335 Connection dbConnection, 336 int iOperationType, 337 int iDataType, 338 Object data 339 ) throws OSSException 340 { 341 switch (iOperationType) 342 { 343 case (DBOP_SELECT) : 344 { 345 throw new OSSDatabaseAccessException( 346 "Failed to read data from the database.", exc); 347 } 348 default: 349 { 350 if (GlobalConstants.ERROR_CHECKING) 351 { 352 assert false : "Unknown update operation type " + iOperationType; 353 } 354 } 355 } 356 } 357 } 358
| Popular Tags
|