use of org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor in project eclipselink by eclipse-ee4j.
the class TransactionIsolationLevelSwitchListener method postAcquireConnection.
@Override
public void postAcquireConnection(SessionEvent event) {
Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
Statement stmt1 = null;
String isolationLevel = "";
try {
int i = conn.getTransactionIsolation();
switch(i) {
case 1:
isolationLevel = "READ UNCOMMITTED";
break;
case 2:
isolationLevel = "READ COMMITTED";
break;
case 4:
isolationLevel = "REPEATABLE READ";
break;
case 8:
isolationLevel = "SERIALIZABLE";
break;
}
if (i > 0) {
// If conn1 began transaction and updated the row (but hasn't
// committed the transaction yet),
// then conn2 should be able to read the original (not updated)
// state of the row.
// Without this conn2 reading the row hangs on Symfoware.
stmt1 = conn.createStatement();
stmt1.execute(statement + "READ UNCOMMITTED");
connections.put(conn, isolationLevel);
}
} catch (SQLException sqlException) {
throw new TestProblemException("postAcquireConnection failed. ", sqlException);
} finally {
if (stmt1 != null) {
try {
stmt1.close();
} catch (SQLException ex) {
// Ignore
}
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor in project eclipselink by eclipse-ee4j.
the class SybaseTransactionIsolationListener method isDatabaseVersionSupported.
// verify that it's version 15 or higher - this doesn't work with version 12.5
public static boolean isDatabaseVersionSupported(ServerSession serverSession) {
DatabaseAccessor accessor = (DatabaseAccessor) serverSession.allocateReadConnection();
int version;
try {
String strVersion = accessor.getConnectionMetaData().getDatabaseProductVersion();
int iStart = strVersion.indexOf("/") + 1;
int iEnd = strVersion.indexOf(".");
String strIntVersion = strVersion.substring(iStart, iEnd);
version = Integer.parseInt(strIntVersion);
} catch (SQLException ex) {
throw new TestProblemException("failed to obtain database version number", ex);
}
return version >= requiredVersion;
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor in project eclipselink by eclipse-ee4j.
the class SybaseTransactionIsolationListener method postAcquireConnection.
@Override
public void postAcquireConnection(SessionEvent event) {
Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
Statement stmt1 = null;
Statement stmt2 = null;
ResultSet result = null;
Integer isolationLevel;
try {
stmt1 = conn.createStatement();
result = stmt1.executeQuery("select @@isolation");
result.next();
isolationLevel = result.getInt(1);
if (isolationLevel > 0) {
// If conn1 began transaction and updated the row (but hasn't committed the transaction yet),
// then conn2 should be able to read the original (not updated) state of the row.
// Without this conn2 reading the row hangs on Sybase.
stmt2 = conn.createStatement();
stmt2.execute("set transaction isolation level 0");
stmt2.close();
connections.put(conn, isolationLevel);
}
} catch (SQLException sqlException) {
throw new TestProblemException("postAcquireConnection failed. ", sqlException);
} finally {
if (result != null) {
try {
result.close();
} catch (SQLException ex) {
// Ignore
}
}
if (stmt1 != null) {
try {
stmt1.close();
} catch (SQLException ex) {
// Ignore
}
}
if (stmt2 != null) {
try {
stmt2.close();
} catch (SQLException ex) {
// Ignore
}
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor in project eclipselink by eclipse-ee4j.
the class SybaseTransactionIsolationListener method preReleaseConnection.
@Override
public void preReleaseConnection(SessionEvent event) {
Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
Statement stmt = null;
try {
Integer isolationLevel = connections.remove(conn);
if (isolationLevel != null) {
// reset the original transaction isolation.
stmt = conn.createStatement();
stmt.execute("set transaction isolation level " + isolationLevel);
stmt.close();
}
} catch (SQLException sqlException) {
throw new TestProblemException("preReleaseConnection failed. ", sqlException);
} finally {
if (stmt != null) {
try {
stmt.close();
} catch (SQLException ex) {
// Ignore
}
}
}
}
use of org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor in project eclipselink by eclipse-ee4j.
the class ReadAllQuery method registerResultSetInUnitOfWork.
/**
* INTERNAL:
* Version of the previous method for ResultSet optimization.
*
* @return the final (conformed, refreshed, wrapped) UnitOfWork query result
*/
public Object registerResultSetInUnitOfWork(ResultSet resultSet, Vector fields, DatabaseField[] fieldsArray, UnitOfWorkImpl unitOfWork, AbstractRecord arguments) throws SQLException {
// TODO: add support for Conforming results in UOW - currently conforming in uow is not compatible with ResultSet optimization.
ContainerPolicy cp = this.containerPolicy;
Object clones = cp.containerInstance();
ResultSetMetaData metaData = resultSet.getMetaData();
boolean hasNext = resultSet.next();
if (hasNext) {
// TODO: possibly add support for SortedListContainerPolicy (cp.shouldAddAll() == true) - this policy currently is not compatible with ResultSet optimization
boolean quickAdd = (clones instanceof Collection) && !this.descriptor.getObjectBuilder().hasWrapperPolicy();
DatabaseAccessor dbAccessor = (DatabaseAccessor) getAccessor();
boolean useSimple = this.descriptor.getObjectBuilder().isSimple();
AbstractSession executionSession = getExecutionSession();
DatabasePlatform platform = dbAccessor.getPlatform();
boolean optimizeData = platform.shouldOptimizeDataConversion();
if (useSimple) {
// None of the fields are relational - the row could be reused, just clear all the values.
SimpleResultSetRecord row = new SimpleResultSetRecord(fields, fieldsArray, resultSet, metaData, dbAccessor, executionSession, platform, optimizeData);
if (this.descriptor.isDescriptorTypeAggregate()) {
// Aggregate Collection may have an unmapped primary key referencing the owner, the corresponding field will not be used when the object is populated and therefore may not be cleared.
row.setShouldKeepValues(true);
}
while (hasNext) {
Object clone = buildObject(row);
if (quickAdd) {
((Collection) clones).add(clone);
} else {
// TODO: investigate is it possible to support MappedKeyMapPolicy - this policy currently is not compatible with ResultSet optimization
cp.addInto(clone, clones, unitOfWork);
}
row.reset();
hasNext = resultSet.next();
}
} else {
boolean shouldKeepRow = this.descriptor.getObjectBuilder().shouldKeepRow();
while (hasNext) {
ResultSetRecord row = new ResultSetRecord(fields, fieldsArray, resultSet, metaData, dbAccessor, executionSession, platform, optimizeData);
Object clone = buildObject(row);
if (quickAdd) {
((Collection) clones).add(clone);
} else {
// TODO: investigate is it possible to support MappedKeyMapPolicy - this policy currently is not compatible with ResultSet optimization
cp.addInto(clone, clones, unitOfWork);
}
if (shouldKeepRow) {
if (row.hasResultSet()) {
// ResultSet has not been fully triggered - that means the cached object was used.
// Yet the row still may be cached in a value holder (see loadBatchReadAttributes and loadJoinedAttributes methods).
// Remove ResultSet to avoid attempt to trigger it (already closed) when pk or fk values (already extracted) accessed when the value holder is instantiated.
row.removeResultSet();
} else {
row.removeNonIndirectionValues();
}
}
hasNext = resultSet.next();
}
}
}
return clones;
}
Aggregations