use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class QueryImpl method executeReadQuery.
/**
* Execute a ReadQuery by assigning the stored parameter values and running
* it in the database
*
* @return the results of the query execution
*/
protected Object executeReadQuery() {
List<Object> parameterValues = processParameters();
// TODO: the following performFlush() call is a temporary workaround for
// bug 4752493:
// CTS: INMEMORY QUERYING IN EJBQUERY BROKEN DUE TO CHANGE TO USE
// REPORTQUERY.
// Ideally we should only flush in case the selectionExpression can't be
// conformed in memory.
// There are two alternative ways to implement that:
// 1. Try running the query with conformInUOW flag first - if it fails
// with
// QueryException.cannotConformExpression then flush and run the query
// again -
// now without conforming.
// 2. Implement a new isComformable method on Expression which would
// determine whether the expression
// could be conformed in memory, flush only in case it returns false.
// Note that doesConform method currently implemented on Expression
// requires object(s) to be confirmed as parameter(s).
// The new isComformable method should not take any objects as
// parameters,
// it should return false if there could be such an object that
// passed to doesConform causes it to throw
// QueryException.cannotConformExpression -
// and true otherwise.
boolean shouldResetConformResultsInUnitOfWork = false;
DatabaseQuery query = getDatabaseQueryInternal();
boolean isObjectLevelReadQuery = query.isObjectLevelReadQuery();
if (isFlushModeAUTO() && (!isObjectLevelReadQuery || !((ObjectLevelReadQuery) query).isReadOnly())) {
performPreQueryFlush();
if (isObjectLevelReadQuery) {
if (((ObjectLevelReadQuery) query).shouldConformResultsInUnitOfWork()) {
cloneSharedQuery();
query = getDatabaseQueryInternal();
((ObjectLevelReadQuery) query).setCacheUsage(ObjectLevelReadQuery.UseDescriptorSetting);
shouldResetConformResultsInUnitOfWork = true;
}
}
}
// Set a pessimistic locking on the query if specified.
if (this.lockMode != null && !this.lockMode.equals(LockModeType.NONE)) {
// We need to throw TransactionRequiredException if there is no
// active transaction
this.entityManager.checkForTransaction(true);
// The lock mode setters and getters validate the query type
// so should be safe to make the casting.
cloneSharedQuery();
query = getDatabaseQueryInternal();
// we were unable to set the lock mode.
if (((ObjectLevelReadQuery) query).setLockModeType(lockMode.name(), (AbstractSession) getActiveSession())) {
throw new PersistenceException(ExceptionLocalization.buildMessage("ejb30-wrong-lock_called_without_version_locking-index", null));
}
}
Session session = getActiveSession();
try {
// in case it's a user-defined query
if (query.isUserDefined()) {
// and there is an active transaction
if (this.entityManager.checkForTransaction(false) != null) {
// verify whether uow has begun early transaction
if (session.isUnitOfWork() && !((UnitOfWorkImpl) session).wasTransactionBegunPrematurely()) {
// uow begins early transaction in case it hasn't
// already begun.
// TODO: This is not good, it means that no SQL queries
// can ever use the cache,
// using isUserDefined to mean an SQL query is also
// wrong.
((UnitOfWorkImpl) session).beginEarlyTransaction();
}
}
}
// Execute the query and return the result.
return session.executeQuery(query, parameterValues);
} catch (DatabaseException e) {
throw getDetailedException(e);
} catch (RuntimeException e) {
setRollbackOnly();
throw e;
} finally {
this.lockMode = null;
if (shouldResetConformResultsInUnitOfWork) {
((ObjectLevelReadQuery) query).conformResultsInUnitOfWork();
}
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class PersistenceContext method setRelationshipInfo.
private void setRelationshipInfo(Object entity) {
if ((entity != null) && (entity instanceof PersistenceWeavedRest)) {
ClassDescriptor descriptor = getServerSession().getClassDescriptor(entity.getClass());
if (descriptor != null) {
((PersistenceWeavedRest) entity)._persistence_setRelationships(new ArrayList<>());
for (DatabaseMapping mapping : descriptor.getMappings()) {
if (mapping.isForeignReferenceMapping()) {
ForeignReferenceMapping frMapping = (ForeignReferenceMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(frMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
} else if (mapping.isEISMapping()) {
if (mapping instanceof EISCompositeCollectionMapping) {
EISCompositeCollectionMapping eisMapping = (EISCompositeCollectionMapping) mapping;
RelationshipInfo info = new RelationshipInfo();
info.setAttributeName(eisMapping.getAttributeName());
info.setOwningEntity(entity);
info.setOwningEntityAlias(descriptor.getAlias());
info.setPersistencePrimaryKey(descriptor.getObjectBuilder().extractPrimaryKeyFromObject(entity, (AbstractSession) getServerSession()));
((PersistenceWeavedRest) entity)._persistence_getRelationships().add(info);
}
}
}
}
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class TransformerFactory method addClassDetailsForMappedSuperClasses.
/**
* INTERNAL:
* Look higher in the hierarchy for the mappings listed in the unMappedAttribute list.
*
* We assume that if a mapping exists, the attribute must either be mapped from the owning
* class or from a superclass.
*/
public void addClassDetailsForMappedSuperClasses(MetadataClass clz, ClassDescriptor initialDescriptor, ClassDetails classDetails, Map<String, ClassDetails> classDetailsMap, List<DatabaseMapping> unMappedAttributes, boolean weaveChangeTracking) {
MetadataClass superClz = clz.getSuperclass();
if (superClz == null || superClz.isObject()) {
return;
}
ClassDescriptor mappedSuperclassDescriptor = ((AbstractSession) session).getMappedSuperclass(superClz.getName());
if (mappedSuperclassDescriptor == null) {
ClassDescriptor descriptor = findDescriptor(session.getProject(), clz.getSuperclass().getName());
if (descriptor != null) {
return;
}
}
// If the superclass declares more mappings than there are unmapped mappings still to process, this superclass has shadowed attributes
if (mappedSuperclassDescriptor != null && unMappedAttributes.size() < mappedSuperclassDescriptor.getMappings().size()) {
List<DatabaseMapping> hiddenMappings = new ArrayList<DatabaseMapping>();
for (DatabaseMapping mapping : mappedSuperclassDescriptor.getMappings()) {
boolean contains = false;
String name = mapping.getAttributeName();
for (DatabaseMapping newmapping : unMappedAttributes) {
if (name.equals(newmapping.getAttributeName())) {
contains = true;
break;
}
}
// If the super has a mapping that wasn't processed by the subclasses, add it to be processed
if (!contains) {
hiddenMappings.add(mapping);
}
}
unMappedAttributes.addAll(hiddenMappings);
}
boolean weaveValueHolders = canWeaveValueHolders(superClz, unMappedAttributes);
List<DatabaseMapping> stillUnMappedMappings = null;
ClassDetails superClassDetails = createClassDetails(superClz, weaveValueHolders, weaveChangeTracking, weaveFetchGroups, weaveInternal, weaveRest);
superClassDetails.setIsMappedSuperClass(true);
if (mappedSuperclassDescriptor != null && !mappedSuperclassDescriptor.usesPropertyAccessForWeaving()) {
superClassDetails.useAttributeAccess();
} else if (!initialDescriptor.usesPropertyAccessForWeaving()) {
superClassDetails.useAttributeAccess();
}
if (!classDetailsMap.containsKey(superClassDetails.getClassName())) {
stillUnMappedMappings = storeAttributeMappings(superClz, superClassDetails, unMappedAttributes, weaveValueHolders);
classDetailsMap.put(superClassDetails.getClassName(), superClassDetails);
addClassDetailsForMappedSuperClasses(superClz, initialDescriptor, classDetails, classDetailsMap, stillUnMappedMappings, weaveChangeTracking);
}
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method addSessionToGlobalSessionManager.
/**
* Put the given session into the session manager so it can be looked up later
*/
protected void addSessionToGlobalSessionManager() {
SessionManager sm = SessionManager.getManager();
ConcurrentMap<String, Session> sessions = sm.getSessions();
AbstractSession oldSession = (AbstractSession) sessions.get(session.getName());
if (oldSession != null) {
throw new PersistenceException(EntityManagerSetupException.attemptedRedeployWithoutClose(session.getName()));
}
sm.addSession(session);
}
use of org.eclipse.persistence.internal.sessions.AbstractSession in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method deployCompositeMembers.
protected void deployCompositeMembers(Map deployProperties, ClassLoader realClassLoader) {
// Don't log these properties - may contain passwords. The properties will be logged by contained persistence units.
Map compositeMemberMapOfProperties = (Map) getConfigProperty(PersistenceUnitProperties.COMPOSITE_UNIT_PROPERTIES, deployProperties);
for (EntityManagerSetupImpl compositeMemberEmSetupImpl : this.compositeMemberEmSetupImpls) {
// the properties guaranteed to be non-null after updateCompositeMemberProperties call
Map compositeMemberProperties = (Map) compositeMemberMapOfProperties.get(compositeMemberEmSetupImpl.getPersistenceUnitInfo().getPersistenceUnitName());
compositeMemberEmSetupImpl.deploy(realClassLoader, compositeMemberProperties);
AbstractSession containedSession = compositeMemberEmSetupImpl.getSession();
((SessionBroker) session).registerSession(containedSession.getName(), containedSession);
}
}
Aggregations