use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class RuntimeServices method printClassesInSession.
/**
* This method is used to output those Class Names that have identity Maps in the Session.
* Please note that SubClasses and aggregates will be missing from this list as they do not have
* separate identity maps.
*/
public void printClassesInSession() {
Vector classes = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered();
int index;
if (classes.isEmpty()) {
((AbstractSession) session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_classes_in_session");
return;
}
for (index = 0; index < classes.size(); index++) {
getSession().getSessionLog().log(SessionLog.FINEST, (String) classes.elementAt(index));
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class RuntimeServices method getNumberOfObjectsInAllIdentityMaps.
/**
* This method will SUM and return the number of objects in all Identity Maps in the session.
*/
public Integer getNumberOfObjectsInAllIdentityMaps() {
Vector classesRegistered = getSession().getIdentityMapAccessorInstance().getIdentityMapManager().getClassesRegistered();
String registeredClassName;
int sum = 0;
// Check if there aren't any classes registered
if (classesRegistered.size() == 0) {
((AbstractSession) session).log(SessionLog.INFO, SessionLog.SERVER, "jmx_mbean_runtime_services_no_identity_maps_in_session");
return 0;
}
// get each identity map, and log the size
for (int index = 0; index < classesRegistered.size(); index++) {
registeredClassName = (String) classesRegistered.elementAt(index);
try {
sum += this.getNumberOfObjectsInIdentityMap(registeredClassName);
} catch (ClassNotFoundException classNotFound) {
// we are enumerating registered classes, so this shouldn't happen. Print anyway
classNotFound.printStackTrace();
AbstractSessionLog.getLog().log(SessionLog.SEVERE, "jmx_enabled_platform_mbean_runtime_exception", PLATFORM_NAME, classNotFound);
}
}
return sum;
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class OracleChangeNotificationListener method remove.
/**
* INTERNAL:
* Remove the event listener from the database.
*/
@Override
public void remove(Session session) {
if (this.register == null) {
return;
}
AbstractSession databaseSession = (AbstractSession) session;
Accessor accessor = databaseSession.getAccessor();
accessor.incrementCallCount(databaseSession);
try {
OracleConnection connection = (OracleConnection) databaseSession.getServerPlatform().unwrapConnection(accessor.getConnection());
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_unregister");
try {
connection.unregisterDatabaseChangeNotification(this.register);
} catch (SQLException exception) {
throw DatabaseException.sqlException(exception, databaseSession.getAccessor(), databaseSession, false);
}
} finally {
accessor.decrementCallCount();
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class OracleChangeNotificationListener method register.
/**
* INTERNAL:
* Register the event listener with the database.
*/
@Override
public void register(Session session) {
final AbstractSession databaseSession = (AbstractSession) session;
// Determine which tables should be tracked for change events.
this.descriptorsByTable = new HashMap<DatabaseTable, ClassDescriptor>();
for (ClassDescriptor descriptor : session.getDescriptors().values()) {
if (!descriptor.getTables().isEmpty()) {
if ((descriptor.getCachePolicy().getDatabaseChangeNotificationType() != null) && (descriptor.getCachePolicy().getDatabaseChangeNotificationType() != DatabaseChangeNotificationType.NONE)) {
this.descriptorsByTable.put(descriptor.getTables().get(0), descriptor);
}
}
}
Accessor accessor = databaseSession.getAccessor();
accessor.incrementCallCount(databaseSession);
try {
OracleConnection connection = (OracleConnection) databaseSession.getServerPlatform().unwrapConnection(accessor.getConnection());
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_registering");
Properties properties = new Properties();
properties.setProperty(OracleConnection.DCN_NOTIFY_ROWIDS, "true");
properties.setProperty(OracleConnection.DCN_IGNORE_INSERTOP, "true");
try {
// Register with the database change notification, the connection is not relevant, the events occur after the connection is closed,
// and a different connection can be used to unregister the event listener.
this.register = connection.registerDatabaseChangeNotification(properties);
final List<DatabaseField> fields = new ArrayList<DatabaseField>();
fields.add(new DatabaseField(ROWID));
this.register.addListener(new DatabaseChangeListener() {
@Override
public void onDatabaseChangeNotification(DatabaseChangeEvent changeEvent) {
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_change_event", changeEvent);
if (changeEvent.getTableChangeDescription() != null) {
for (TableChangeDescription tableChange : changeEvent.getTableChangeDescription()) {
ClassDescriptor descriptor = OracleChangeNotificationListener.this.descriptorsByTable.get(new DatabaseTable(tableChange.getTableName()));
if (descriptor != null) {
CacheIndex index = descriptor.getCachePolicy().getCacheIndex(fields);
for (RowChangeDescription rowChange : tableChange.getRowChangeDescription()) {
CacheId id = new CacheId(new Object[] { rowChange.getRowid().stringValue() });
CacheKey key = databaseSession.getIdentityMapAccessorInstance().getIdentityMapManager().getCacheKeyByIndex(index, id, true, descriptor);
if (key != null) {
if ((key.getTransactionId() == null) || !key.getTransactionId().equals(changeEvent.getTransactionId(true))) {
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_invalidate", key.getKey(), descriptor.getJavaClass().getName());
key.setInvalidationState(CacheKey.CACHE_KEY_INVALID);
}
}
}
}
}
}
}
});
// Register each table for database events, this is done by executing a select from the table.
for (DatabaseTable table : this.descriptorsByTable.keySet()) {
OracleStatement statement = (OracleStatement) connection.createStatement();
statement.setDatabaseChangeRegistration(this.register);
try {
statement.executeQuery("SELECT ROWID FROM " + table.getQualifiedName()).close();
databaseSession.log(SessionLog.FINEST, SessionLog.CONNECTION, "dcn_register_table", table.getQualifiedName());
} catch (Exception failed) {
// This will fail if the table does not exist,
// just log the error to allow table creation to work.
databaseSession.logThrowable(SessionLog.WARNING, SessionLog.SQL, failed);
} finally {
statement.close();
}
}
} catch (SQLException exception) {
throw DatabaseException.sqlException(exception, databaseSession.getAccessor(), databaseSession, false);
}
} finally {
accessor.decrementCallCount();
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class JoinedAttributeAdvancedJunitTest method internalEmployeeOuterJoinAddressPhoneProjectsTeamLeaderAddressTeamMembersPhonesOnUOW.
protected void internalEmployeeOuterJoinAddressPhoneProjectsTeamLeaderAddressTeamMembersPhonesOnUOW(boolean noBase) {
ReadAllQuery controlQuery = new ReadAllQuery();
controlQuery.setReferenceClass(Employee.class);
ReadAllQuery queryWithJoins = (ReadAllQuery) controlQuery.clone();
// Note that without the following two lines address and phones are not read not for all Employees:
// once an Employee is built (without Address and Phones)
// it's not going to be rebuilt (get Address and Phones) when it's
// up again either as a teamLeader or teamMember.
// That means that only Employees read first indirectly (either as teamLeaders or
// teamMembers would've got Phones and Addresses).
queryWithJoins.addJoinedAttribute(queryWithJoins.getExpressionBuilder().getAllowingNull("address"));
queryWithJoins.addJoinedAttribute(queryWithJoins.getExpressionBuilder().anyOfAllowingNone("phoneNumbers"));
Expression projects = queryWithJoins.getExpressionBuilder().anyOfAllowingNone("projects");
if (!noBase) {
queryWithJoins.addJoinedAttribute(projects);
}
Expression teamLeader = projects.getAllowingNull("teamLeader");
if (!noBase) {
queryWithJoins.addJoinedAttribute(teamLeader);
}
Expression teamLeaderAddress = teamLeader.getAllowingNull("address");
queryWithJoins.addJoinedAttribute(teamLeaderAddress);
Expression teamMembers = projects.anyOfAllowingNone("teamMembers");
if (!noBase) {
queryWithJoins.addJoinedAttribute(teamMembers);
}
Expression teamMembersPhones = teamMembers.anyOfAllowingNone("phoneNumbers");
queryWithJoins.addJoinedAttribute(teamMembersPhones);
UnitOfWork uow = acquireUnitOfWork();
// loads objects into cache without using joins
uow.commit();
uow.executeQuery(controlQuery);
((UnitOfWorkImpl) uow).setShouldCascadeCloneToJoinedRelationship(true);
Collection results = (Collection) uow.executeQuery(queryWithJoins);
getDbSession().getIdentityMapAccessor().initializeAllIdentityMaps();
Collection controlledResults = (Collection) JoinedAttributeTestHelper.getControlResultsFromControlQuery(controlQuery, queryWithJoins, (AbstractSession) uow);
String errorMsg = JoinedAttributeTestHelper.compareCollections(controlledResults, results, controlQuery.getDescriptor(), (AbstractSession) getDbSession());
if (errorMsg.length() > 0) {
fail(errorMsg);
}
}
Aggregations