use of org.eclipse.persistence.platform.database.OraclePlatform in project eclipselink by eclipse-ee4j.
the class FlashbackTestModel method calculateSystemChangeNumber.
/**
* Find the system change number that reflects the initial fully
* populated state of the database.
* Assumes that when called the database is in its start state.
*/
protected void calculateSystemChangeNumber() throws Exception {
OraclePlatform platform = (OraclePlatform) getSession().getPlatform();
ValueReadQuery scnQuery = platform.getSystemChangeNumberQuery();
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.dontMaintainCache();
int safetyCount = 1400;
boolean validSCN = false;
while ((safetyCount-- > 0) && !validSCN) {
this.systemChangeNumber = (Number) getSession().executeQuery(scnQuery);
// clonedQuery = (ReadAllQuery)query.clone();
// query.setSelectionCriteria(query.getExpressionBuilder().get("salary").greaterThan(safetyCount));
query.setAsOfClause(new AsOfSCNClause(systemChangeNumber));
try {
Vector result = (Vector) getSession().executeQuery(query);
validSCN = true;
} catch (Exception e) {
// keep going...
Thread.sleep(1000 * 30);
}
}
}
use of org.eclipse.persistence.platform.database.OraclePlatform in project eclipselink by eclipse-ee4j.
the class FlashbackTestModel method calculateTimestampHopefully.
/**
* This idea of calculateTimestamp is to get a snapshot at which time
* the database is fully populated.
* Tries going further and further back in time to find one.
* Note if go back too far, or before the last time a table was altered, an
* exception will result.
*/
@SuppressWarnings("deprecation")
public void calculateTimestampHopefully() {
if (getTimestamp() != null) {
return;
}
OraclePlatform platform = (OraclePlatform) getSession().getPlatform();
ValueReadQuery timestampQuery = platform.getTimestampQuery();
ReadObjectQuery query = new ReadObjectQuery(Employee.class);
query.dontMaintainCache();
query.addPartialAttribute("id");
ReadObjectQuery asOfQuery = null;
try {
long asOfTime = ((Timestamp) getSession().executeQuery(timestampQuery)).getTime();
long timeToGoBack = 0;
while (getTimestamp() == null) {
asOfQuery = (ReadObjectQuery) query.clone();
asOfQuery.setAsOfClause(new AsOfClause(new java.sql.Timestamp(asOfTime - timeToGoBack)));
if (getSession().executeQuery(asOfQuery) != null) {
setTimestamp(new Timestamp(asOfTime - timeToGoBack));
} else {
// go back 10 minutes each time.
timeToGoBack += ((timeToGoBack == 0) ? (1000 * 60) : timeToGoBack);
}
}
} catch (Exception e) {
System.out.println("Went too far back, so can't tell this.");
}
}
use of org.eclipse.persistence.platform.database.OraclePlatform in project eclipselink by eclipse-ee4j.
the class FlashbackTestModel method calculateTimestamp.
/**
* By caching the result of this call, it is insured that
* a new timestamp is not calculated after rows are deleted.
* Furthermore, an asof time that maps to a desired snapshot of
* the database must be had.
*/
public void calculateTimestamp() {
if (getTimestamp() == null) {
OraclePlatform platform = (OraclePlatform) getSession().getPlatform();
ValueReadQuery timestampQuery = platform.getTimestampQuery();
ReadAllQuery query = new ReadAllQuery(Employee.class);
query.setSelectionCriteria(query.getExpressionBuilder().get("firstName").notEqual("Eun Kyung"));
ReadAllQuery clonedQuery = null;
int safetyCount = 1400;
while ((safetyCount-- > 0) && (getTimestamp() == null)) {
java.util.Date timestamp = (java.util.Date) getSession().executeQuery(timestampQuery);
clonedQuery = query;
clonedQuery.setAsOfClause(new AsOfClause(timestamp));
Vector result = (Vector) getSession().executeQuery(clonedQuery);
if (result.size() == 12) {
setTimestamp((java.sql.Timestamp) timestamp);
} else {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new TestErrorException("Unable to wait for valid timstamp.", e);
}
}
}
}
}
use of org.eclipse.persistence.platform.database.OraclePlatform in project eclipselink by eclipse-ee4j.
the class DatabaseSessionImpl method setOrDetectDatasource.
/**
* INTERNAL:
* Will set the platform from specified schema generation properties or
* by detecting it through the connection (if one is available).
* Any connection that is open for detection is closed before this method
* returns.
*
* @param throwException - set to true if the caller cares to throw exceptions, false to swallow them.
*/
protected void setOrDetectDatasource(boolean throwException) {
String vendorName = null;
String minorVersion = null;
String majorVersion = null;
String driverName = null;
// attempting a detection.
if (getProperties().containsKey(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME)) {
vendorName = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_PRODUCT_NAME);
minorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MINOR_VERSION);
majorVersion = (String) getProperties().get(PersistenceUnitProperties.SCHEMA_DATABASE_MAJOR_VERSION);
} else {
Connection conn = null;
try {
conn = (Connection) getReadLogin().connectToDatasource(null, this);
DatabaseMetaData dmd = conn.getMetaData();
vendorName = dmd.getDatabaseProductName();
minorVersion = dmd.getDatabaseProductVersion();
majorVersion = Integer.toString(dmd.getDatabaseMajorVersion());
driverName = conn.getMetaData().getDriverName();
} catch (SQLException ex) {
if (throwException) {
DatabaseException dbEx = DatabaseException.errorRetrieveDbMetadataThroughJDBCConnection();
// Typically exception would occur if user did not provide
// correct connection
// parameters. The root cause of exception should be
// propagated up
dbEx.initCause(ex);
throw dbEx;
}
} finally {
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
if (throwException) {
DatabaseException dbEx = DatabaseException.errorRetrieveDbMetadataThroughJDBCConnection();
// Typically exception would occur if user did not
// provide correct connection
// parameters. The root cause of exception should be
// propagated up
dbEx.initCause(ex);
throw dbEx;
}
}
}
}
}
String platformName = null;
try {
// null out the cached platform because the platform on the login
// will be changed by the following line of code
this.platform = null;
platformName = DBPlatformHelper.getDBPlatform(vendorName, minorVersion, majorVersion, getSessionLog());
getLogin().setPlatformClassName(platformName);
} catch (EclipseLinkException classNotFound) {
if (platformName != null && platformName.indexOf("Oracle") != -1) {
try {
// If we are running against Oracle, it is possible that we are
// running in an environment where the extension OracleXPlatform classes can
// not be loaded. Try using the core OracleXPlatform classes
platformName = DBPlatformHelper.getDBPlatform("core." + vendorName, minorVersion, majorVersion, getSessionLog());
getLogin().setPlatformClassName(platformName);
} catch (EclipseLinkException oracleClassNotFound) {
// If we still cannot classload a matching OracleXPlatform class,
// fallback on the base OraclePlatform class
getLogin().setPlatformClassName(OraclePlatform.class.getName());
}
} else {
throw classNotFound;
}
}
if (driverName != null) {
getLogin().getPlatform().setDriverName(driverName);
}
}
use of org.eclipse.persistence.platform.database.OraclePlatform in project eclipselink by eclipse-ee4j.
the class ReadOnlyClassesInSessionBrokerTest method setup.
@Override
public void setup() {
ServerSession serverSession;
Project project = new org.eclipse.persistence.testing.models.readonly.ReadOnlyProject();
DatabaseLogin login = project.getLogin();
login.usePlatform(new OraclePlatform());
login.setDriverClassName("oracle.jdbc.OracleDriver");
login.setConnectionString("jdbc:oracle:thin:@ottvm028.ca.oracle.com:1521:toplink");
login.setUserName("QA6");
login.setPassword("password");
serverSession = (ServerSession) project.createServerSession();
this.sessionBroker = new SessionBroker();
this.sessionBroker.registerSession("broker1", serverSession);
this.sessionBroker.login();
}
Aggregations