1 21 22 package org.opensubsystems.core.persist.db.oracle; 23 24 import java.sql.CallableStatement ; 25 import java.sql.Connection ; 26 import java.sql.PreparedStatement ; 27 import java.sql.SQLException ; 28 import java.sql.Statement ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.logging.Level ; 32 import java.util.logging.Logger ; 33 34 import org.opensubsystems.core.data.BasicDataObject; 35 import org.opensubsystems.core.data.ModifiableDataObject; 36 import org.opensubsystems.core.error.OSSDatabaseAccessException; 37 import org.opensubsystems.core.error.OSSException; 38 import org.opensubsystems.core.persist.db.DatabaseConnectionFactoryImpl; 39 import org.opensubsystems.core.persist.db.DatabaseImpl; 40 import org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl; 41 import org.opensubsystems.core.util.DatabaseUtils; 42 import org.opensubsystems.core.util.Log; 43 44 52 public class OracleDatabaseImpl extends DatabaseImpl 53 { 54 56 59 private static Logger s_logger = Log.getInstance(OracleDatabaseImpl.class); 60 61 63 68 public OracleDatabaseImpl( 69 ) throws OSSException 70 { 71 super(); 72 } 73 74 76 79 protected void createUser( 80 Connection cntAdminDBConnection 81 ) throws OSSException 82 { 83 PreparedStatement pstmQuery = null; 85 try 86 { 87 94 StringBuffer buffer = new StringBuffer (); 95 96 buffer.append("CREATE USER "); 98 buffer.append(DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser()); 99 buffer.append(" PROFILE DEFAULT IDENTIFIED BY "); 100 buffer.append(DatabaseConnectionFactoryImpl.getInstance().getDatabasePassword()); 101 buffer.append(" DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP ACCOUNT UNLOCK "); 102 103 pstmQuery = cntAdminDBConnection.prepareStatement(buffer.toString()); 104 if (pstmQuery.execute()) 105 { 106 pstmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 108 } 109 110 buffer.delete(0, buffer.length()); 112 buffer.append("ALTER USER "); 113 buffer.append(DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser()); 114 buffer.append(" QUOTA UNLIMITED ON USERS"); 115 116 pstmQuery = cntAdminDBConnection.prepareStatement(buffer.toString()); 117 if (pstmQuery.execute()) 118 { 119 pstmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 121 } 122 123 buffer.delete(0, buffer.length()); 125 buffer.append("GRANT CONNECT, CREATE PROCEDURE TO "); 126 buffer.append(DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser()); 127 128 pstmQuery = cntAdminDBConnection.prepareStatement(buffer.toString()); 129 if (pstmQuery.execute()) 130 { 131 pstmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 133 } 134 135 DatabaseTransactionFactoryImpl.getInstance().commitTransaction( 140 cntAdminDBConnection); 141 142 s_logger.log(Level.FINER, "Database user " 143 + DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser() 144 + " with password " 145 + DatabaseConnectionFactoryImpl.getInstance().getDatabasePassword() 146 + " created."); 147 } 148 catch (SQLException sqleExc) 149 { 150 try 151 { 152 DatabaseTransactionFactoryImpl.getInstance().rollbackTransaction( 157 cntAdminDBConnection); 158 } 159 catch (SQLException sqleExc2) 160 { 161 s_logger.log(Level.WARNING, 163 "Failed to rollback changes for creation of user.", 164 sqleExc2); 165 } 166 s_logger.log(Level.SEVERE, 167 "Unable to create default database user.", 168 sqleExc); 169 throw new OSSDatabaseAccessException("Unable to create default database user.", 170 sqleExc); 171 } 172 finally 173 { 174 DatabaseUtils.closeStatement(pstmQuery); 175 } 176 } 177 178 181 public void startDatabaseServer( 182 ) throws OSSException 183 { 184 } 186 187 190 public void createDatabaseInstance( 191 ) throws OSSException 192 { 193 } 195 196 199 public int getDatabaseType() 200 { 201 return DatabaseImpl.ORACLE_DATABASE_TYPE; 202 } 203 204 207 public String getDatabaseTypeIdentifier() 208 { 209 return DatabaseImpl.ORACLE_DATABASE_TYPE_IDENTIFIER; 210 } 211 212 215 public void stop( 216 ) throws OSSException 217 { 218 s_logger.entering(this.getClass().getName(), "stop"); 219 220 super.stop(); 223 224 s_logger.entering(this.getClass().getName(), "stop"); 225 } 226 227 230 public String getCurrentTimestampFunctionCall() 231 { 232 return "SYSTIMESTAMP"; 237 } 238 239 242 public String getSQLCountFunctionCall() 243 { 244 return "count(1)"; 246 } 247 248 251 public boolean preferCountToLast( 252 ) 253 { 254 return true; 259 } 260 261 264 public boolean hasSelectListRangeSupport( 265 ) 266 { 267 return true; 269 } 270 271 274 public Object [] getSQLAnalyzeFunctionCall( 275 Map mapTableNames 276 ) 277 { 278 281 String [] arrReturn = new String [mapTableNames.size()]; 282 StringBuffer buffer = new StringBuffer (); 283 Iterator itItem; 284 int iIndex = 0; 285 286 itItem = mapTableNames.values().iterator(); 287 while (itItem.hasNext()) 288 { 289 buffer.append("analyze table "); 291 buffer.append((String )itItem.next()); 292 buffer.append(" compute statistics"); 293 arrReturn[iIndex++] = buffer.toString(); 295 buffer.delete(0, buffer.length()); 297 } 298 299 return new Object [] {arrReturn, Boolean.TRUE}; 300 } 301 302 305 public boolean isCallableStatement( 306 String strQuery 307 ) 308 { 309 return strQuery.indexOf("{call ") != -1; 310 } 311 312 315 public void insertAndFetchGeneratedValues( 316 Connection dbConnection, 317 PreparedStatement insertStatement, 318 boolean bIsInDomain, 319 String strTableName, 320 int iIndex, 321 BasicDataObject data 322 ) throws SQLException , 323 OSSException 324 { 325 OracleDataUtils.insertAndFetchGeneratedValues((CallableStatement )insertStatement, 326 iIndex, data); 327 } 328 329 332 public void updatedAndFetchGeneratedValues( 333 String strDataName, 334 Connection dbConnection, 335 PreparedStatement updateStatement, 336 boolean bIsInDomain, 337 String strTableName, 338 int iIndex, 339 ModifiableDataObject data 340 ) throws SQLException , 341 OSSException 342 { 343 OracleDataUtils.updateAndFetchGeneratedValues((CallableStatement )updateStatement, 344 iIndex, data); 345 } 346 } 347 | Popular Tags |