1 21 22 package org.opensubsystems.core.persist.db.db2; 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.Map ; 30 import java.util.logging.Level ; 31 import java.util.logging.Logger ; 32 33 import org.opensubsystems.core.data.BasicDataObject; 34 import org.opensubsystems.core.data.ModifiableDataObject; 35 import org.opensubsystems.core.error.OSSDatabaseAccessException; 36 import org.opensubsystems.core.error.OSSException; 37 import org.opensubsystems.core.persist.db.DatabaseConnectionFactoryImpl; 38 import org.opensubsystems.core.persist.db.DatabaseImpl; 39 import org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl; 40 import org.opensubsystems.core.util.DatabaseUtils; 41 import org.opensubsystems.core.util.Log; 42 43 51 public class DB2DatabaseImpl extends DatabaseImpl 52 { 53 55 58 private static Logger s_logger = Log.getInstance(DB2DatabaseImpl.class); 59 60 62 67 public DB2DatabaseImpl( 68 ) throws OSSException 69 { 70 super(); 71 } 72 73 75 80 protected void createUser( 81 Connection cntAdminDBConnection 82 ) throws OSSException 83 { 84 PreparedStatement pstmQuery = null; 87 try 88 { 89 StringBuffer buffer = new StringBuffer (); 90 91 buffer.append("GRANT CONNECT, CREATETAB ON DATABASE TO USER "); 92 buffer.append(DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser()); 93 94 pstmQuery = cntAdminDBConnection.prepareStatement(buffer.toString()); 95 if (pstmQuery.execute()) 96 { 97 pstmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS); 99 } 100 101 DatabaseTransactionFactoryImpl.getInstance().commitTransaction( 106 cntAdminDBConnection); 107 108 s_logger.log(Level.FINER, "Database user " 109 + DatabaseConnectionFactoryImpl.getInstance().getDatabaseUser() 110 + " with password " 111 + DatabaseConnectionFactoryImpl.getInstance().getDatabasePassword() 112 + " created."); 113 } 114 catch (SQLException sqleExc) 115 { 116 try 117 { 118 DatabaseTransactionFactoryImpl.getInstance().rollbackTransaction( 123 cntAdminDBConnection); 124 } 125 catch (SQLException sqleExc2) 126 { 127 s_logger.log(Level.WARNING, 129 "Failed to rollback changes for creation of user.", 130 sqleExc2); 131 } 132 s_logger.log(Level.SEVERE, 133 "Unable to create default database user.", 134 sqleExc); 135 throw new OSSDatabaseAccessException("Unable to create default database user.", 136 sqleExc); 137 } 138 finally 139 { 140 DatabaseUtils.closeStatement(pstmQuery); 141 } 142 } 143 144 147 public void startDatabaseServer() throws OSSException 148 { 149 } 151 152 155 public void createDatabaseInstance() throws OSSException 156 { 157 } 159 160 163 public void stop( 164 ) throws OSSException 165 { 166 s_logger.entering(this.getClass().getName(), "stop"); 167 168 super.stop(); 171 172 s_logger.entering(this.getClass().getName(), "stop"); 173 } 174 175 178 public int getDatabaseType() 179 { 180 return DatabaseImpl.DB2_DATABASE_TYPE; 181 } 182 183 186 public String getDatabaseTypeIdentifier() 187 { 188 return DatabaseImpl.DB2_DATABASE_TYPE_IDENTIFIER; 189 } 190 191 194 public String getCurrentTimestampFunctionCall() 195 { 196 return "CURRENT TIMESTAMP"; 198 } 199 200 203 public String getSQLCountFunctionCall() 204 { 205 return "count(*)"; 207 } 208 209 212 public boolean preferCountToLast( 213 ) 214 { 215 return true; 220 } 221 222 225 public boolean hasSelectListRangeSupport( 226 ) 227 { 228 return true; 230 } 231 232 235 public Object [] getSQLAnalyzeFunctionCall( 236 Map mapTableNames 237 ) 238 { 239 259 return null; 260 } 261 262 265 public boolean isCallableStatement( 266 String strQuery 267 ) 268 { 269 return strQuery.indexOf("call ") != -1; 270 } 271 272 275 public void insertAndFetchGeneratedValues( 276 Connection dbConnection, 277 PreparedStatement insertStatement, 278 boolean bIsInDomain, 279 String strTableName, 280 int iIndex, 281 BasicDataObject data 282 ) throws SQLException , 283 OSSException 284 { 285 DB2DataUtils.insertAndFetchGeneratedValues((CallableStatement )insertStatement, 286 iIndex, data); 287 } 288 289 292 public void updatedAndFetchGeneratedValues( 293 String strDataName, 294 Connection dbConnection, 295 PreparedStatement updateStatement, 296 boolean bIsInDomain, 297 String strTableName, 298 int iIndex, 299 ModifiableDataObject data 300 ) throws SQLException , 301 OSSException 302 { 303 DB2DataUtils.updateAndFetchGeneratedValues((CallableStatement )updateStatement, 304 iIndex, data); 305 } 306 } 307 | Popular Tags |