/** * INTERNAL: * Extract value from the row and set the attribute to the value in the object. * @since EclipseLink 2.6.0 */ @Override public Object readFromRowIntoObject(XMLRecord row, Object object, AbstractSession executionSession, boolean isTargetProtected) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setSession(executionSession); return readFromRowIntoObject(row, null, object, null, query, executionSession, isTargetProtected); }
/** * PUBLIC: * Refresh the attributes of the object and of all of its private parts from the database. * The object will be pessimisticly locked on the database for the duration of the transaction. * <p>Lock Modes: ObjectBuildingQuery.NO_LOCK, LOCK, LOCK_NOWAIT */ public Object refreshAndLockObject(Object object, short lockMode) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setSelectionObject(object); query.refreshIdentityMapResult(); query.cascadePrivateParts(); query.setLockMode(lockMode); query.setIsExecutionClone(true); return executeQuery(query); }
/** * INTERNAL * Return true if the refresh should refresh on this mapping or not. */ protected ReadObjectQuery buildCascadeQuery(MergeManager mergeManager) { ReadObjectQuery cascadeQuery = new ReadObjectQuery(); if (mergeManager.shouldCascadeAllParts()) { cascadeQuery.cascadeAllParts(); cascadeQuery.refreshIdentityMapResult(); } if (mergeManager.shouldCascadePrivateParts() && getForeignReferenceMapping().isPrivateOwned()) { cascadeQuery.cascadePrivateParts(); cascadeQuery.refreshIdentityMapResult(); } return cascadeQuery; }
/** * PUBLIC: * Use the example object to consruct a read object query by the objects primary key. * This will read the object from the database with the same primary key as the object * or null if no object is found. */ public Object readObject(Object object) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setSelectionObject(object); query.setIsExecutionClone(true); return executeQuery(query); }
/** * PUBLIC: * Read the first instance of the class from the database matching the given expression. * This operation can be customized through using a ReadObjectQuery. * * @see ReadObjectQuery */ public Object readObject(Class domainClass, Expression expression) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(domainClass); query.setSelectionCriteria(expression); query.setIsExecutionClone(true); return executeQuery(query); }
/** * INTERNAL: * Set the properties needed to be cascaded into the custom query inlucding the translation row. */ protected void prepareCustomQuery(DatabaseQuery customQuery) { ReadObjectQuery customReadQuery = (ReadObjectQuery)customQuery; customReadQuery.setShouldRefreshIdentityMapResult(shouldRefreshIdentityMapResult()); customReadQuery.setCascadePolicy(getCascadePolicy()); customReadQuery.setShouldMaintainCache(shouldMaintainCache()); customReadQuery.setShouldUseWrapperPolicy(shouldUseWrapperPolicy()); // CR... was missing some values, execution could cause infinite loop. customReadQuery.setQueryId(getQueryId()); customReadQuery.setExecutionTime(getExecutionTime()); customReadQuery.setShouldLoadResultIntoSelectionObject(shouldLoadResultIntoSelectionObject()); AbstractRecord primaryKeyRow; if (getSelectionObject() != null) { // CR#... Must also set the selection object as may be loading into the object (refresh) customReadQuery.setSelectionObject(getSelectionObject()); // The translation/primary key row will be set in prepareForExecution. } else if (getSelectionKey() != null) { customReadQuery.setSelectionKey(getSelectionKey()); } else { // The primary key row must be used. primaryKeyRow = customQuery.getDescriptor().getObjectBuilder().extractPrimaryKeyRowFromExpression(getSelectionCriteria(), customQuery.getTranslationRow(), customReadQuery.getSession()); customReadQuery.setTranslationRow(primaryKeyRow); } }
checkDescriptor(session); if (isCustomQueryUsed() == null) { if (!isUserDefined()) { if (!isCallQuery()) { DescriptorQueryManager descriptorQueryManager = this.descriptor.getQueryManager(); if ((!hasJoining() || !getJoinedAttributeManager().hasJoinedAttributeExpressions()) && (!hasPartialAttributeExpressions()) && (!hasAsOfClause()) && (!hasNonDefaultFetchGroup()) && (getHintString() == null) && wasDefaultLockMode() && shouldIgnoreBindAllParameters() && (!hasFetchGroup()) && (getFetchGroupName() == null) && shouldUseDefaultFetchGroup()) { if ((getSelectionKey() != null) || (getSelectionObject() != null)) {// Must be primary key. setIsCustomQueryUsed(true); } else { if (getSelectionCriteria() != null) { AbstractRecord primaryKeyRow = this.descriptor.getObjectBuilder().extractPrimaryKeyRowFromExpression(getSelectionCriteria(), translationRow, session); setIsCustomQueryUsed(true); if (isCustomQueryUsed() == null) { setIsCustomQueryUsed(false); if (isCustomQueryUsed().booleanValue()) { return this.descriptor.getQueryManager().getReadObjectQuery(); } else {
boolean shouldSetRowsForJoins = hasJoining() && this.joinedAttributeManager.isToManyJoin(); AbstractSession session = getSession(); Object result = null; AbstractRecord row = null; Object sopObject = getTranslationRow().getSopObject(); boolean useOptimization = false; if (sopObject == null) { useOptimization = usesResultSetAccessOptimization(); boolean exceptionOccured = false; ResultSet resultSet = call.getResult(); DatabaseAccessor dbAccessor = (DatabaseAccessor)getAccessor(); try { if (resultSet.next()) { boolean optimizeData = platform.shouldOptimizeDataConversion(); if (useSimple) { row = new SimpleResultSetRecord(call.getFields(), call.getFieldsArray(), resultSet, metaData, dbAccessor, getExecutionSession(), platform, optimizeData); if (this.descriptor.isDescriptorTypeAggregate()) { row = new ResultSetRecord(call.getFields(), call.getFieldsArray(), resultSet, metaData, dbAccessor, getExecutionSession(), platform, optimizeData); result = registerResultInUnitOfWork(row, (UnitOfWorkImpl)session, this.translationRow, true); } else { result = buildObject(row); throw DatabaseException.sqlException(exception, call, getAccessor(), session, false); } finally {
setExecutionTime(System.currentTimeMillis()); return returnValue; AbstractSession session = getSession(); if (hasJoining() && getJoinedAttributeManager().isToManyJoin()) { List rows = getQueryMechanism().selectAllRows(); if (rows.size() > 0) { row = (AbstractRecord)rows.get(0); getJoinedAttributeManager().setDataResults(rows, session); } else { row = getQueryMechanism().selectOneRow(); setExecutionTime(System.currentTimeMillis()); Object result = null; result = registerResultInUnitOfWork(row, (UnitOfWorkImpl)session, getTranslationRow(), true); } else { if (row != null) { result = buildObject(row); if ((result == null) && shouldRefreshIdentityMapResult()) { if (getSelectionKey() != null) { session.getParentIdentityMapSession(this, true, true).getIdentityMapAccessor().invalidateObject(getSelectionKey(), getReferenceClass()); } else if (getSelectionObject() != null) { session.getParentIdentityMapSession(this, true, true).getIdentityMapAccessor().invalidateObject(getSelectionObject());
checkDescriptor(session); if (useCustomQuery == null) { if (!isCallQuery() if ((!hasJoining() || !this.joinedAttributeManager.hasJoinedAttributeExpressions()) && (!hasPartialAttributeExpressions()) && (redirector == null) && !doNotRedirect && (!hasAsOfClause()) && (!hasNonDefaultFetchGroup()) && (this.shouldUseSerializedObjectPolicy == shouldUseSerializedObjectPolicyDefault) && this.wasDefaultLockMode && (shouldBindAllParameters == null) && (this.hintString == null) && !hasBatchReadAttributes() useCustomQuery = Boolean.TRUE; } else { Expression selectionCriteria = getSelectionCriteria(); if (selectionCriteria != null) { AbstractRecord primaryKeyRow = this.descriptor.getObjectBuilder().extractPrimaryKeyRowFromExpression(selectionCriteria, translationRow, session); ReadObjectQuery customQuery = this.descriptor.getQueryManager().getReadObjectQuery(); if (this.accessors != null) { customQuery = (ReadObjectQuery) customQuery.clone(); customQuery.setIsExecutionClone(true); customQuery.setAccessors(this.accessors);
protected Object remoteExecute() { // Do a cache lookup. checkDescriptor(session); // As the selection object is transient, compute the key. if (getSelectionObject() != null) { // Must be checked separately as the expression and row is not yet set. setSelectionKey(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getSelectionObject(), session)); } Object cacheHit = checkEarlyReturn(getSession(), getTranslationRow()); if ((cacheHit != null) || shouldCheckCacheOnly()) { return cacheHit; } return super.remoteExecute(); }
protected Object remoteExecute() { // Do a cache lookup. checkDescriptor(session); // As the selection object is transient, compute the key. if (getSelectionObject() != null) { // Must be checked separately as the expression and row is not yet set. setSelectionId(getDescriptor().getObjectBuilder().extractPrimaryKeyFromObject(getSelectionObject(), session)); } Object cacheHit = checkEarlyReturn(getSession(), getTranslationRow()); if ((cacheHit != null) || shouldCheckCacheOnly()) { if (cacheHit == InvalidObject.instance) { return null; } return cacheHit; } return super.remoteExecute(); }
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (!isNestedUnitOfWork() && (cacheKey.getObject() != null)) { CacheInvalidationPolicy cachePolicy = descriptor.getCacheInvalidationPolicy(); // BUG#6671556 refresh invalid objects when accessed in the unit of work. if (cachePolicy.shouldRefreshInvalidObjectsInUnitOfWork() && cachePolicy.isInvalidated(cacheKey)) { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionKey(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); parent.executeQuery(query); } } }
return null; if (shouldConformResultsInUnitOfWork() || this.descriptor.shouldAlwaysConformResultsInUnitOfWork()) { return conformResult(result, unitOfWork, arguments, buildDirectlyFromRows); clone = buildObject((AbstractRecord)result); } else { clone = registerIndividualResult(result, unitOfWork, null); if (shouldUseWrapperPolicy()) { clone = this.descriptor.getObjectBuilder().wrapObject(clone, unitOfWork);
clone = buildObject((AbstractRecord)result); } else { clone = registerIndividualResult( this.descriptor.getObjectBuilder().unwrapObject(result, unitOfWork.getParent()), null, unitOfWork, null, null); Expression selectionCriteria = getSelectionCriteria(); if ((selectionCriteria != null) && (this.selectionId == null) && (this.selectionObject == null)) { ExpressionBuilder builder = selectionCriteria.getBuilder(); builder.setSession(unitOfWork.getRootSession(null)); builder.setQueryClass(getReferenceClass()); clone = conformIndividualResult(clone, unitOfWork, databaseRow, selectionCriteria, null); if (clone == null) { return clone; if (shouldUseWrapperPolicy()) { return this.descriptor.getObjectBuilder().wrapObject(clone, unitOfWork); } else {
/** * PUBLIC: * Read the first instance of the class from the database returned through execution the Call string. * The Call can be an SQLCall or JPQLCall. * * example: session.readObject(Employee.class, new SQLCall("SELECT * FROM EMPLOYEE")); * @see SQLCall * @see JPQLCall */ public Object readObject(Class domainClass, Call aCall) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(domainClass); query.setCall(aCall); query.setIsExecutionClone(true); return executeQuery(query); }
/** * PUBLIC: * Read the first instance of the class from the database return through execution the SQL string. * The SQL string must be a valid SQL select statement or selecting stored procedure call. * This operation can be customized through using a ReadObjectQuery. * Warning: Allowing an unverified SQL string to be passed into this * method makes your application vulnerable to SQL injection attacks. * * @see ReadObjectQuery */ public Object readObject(Class domainClass, String sqlString) throws DatabaseException { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(domainClass); query.setSQLString(sqlString); query.setIsExecutionClone(true); return executeQuery(query); }
/** * INTERNAL: * This method is used to load a relationship from a list of PKs. * This list may be available if the relationship has been cached. */ @Override public Object valueFromPKList(Object[] pks, AbstractRecord foreignKeys, AbstractSession session) { if (pks.length == 0 || pks[0] == null) return null; ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(getReferenceClass()); query.setSelectionId(pks[0]); query.setIsExecutionClone(true); query.setSession(session); return session.executeQuery(query); }
/** * INTERNAL: * Check if the object is invalid and refresh it. * This is used to ensure that no invalid objects are registered. */ public void checkAndRefreshInvalidObject(Object object, CacheKey cacheKey, ClassDescriptor descriptor) { if (isConsideredInvalid(object, cacheKey, descriptor)) { ReadObjectQuery query = new ReadObjectQuery(); query.setReferenceClass(object.getClass()); query.setSelectionId(cacheKey.getKey()); query.refreshIdentityMapResult(); query.setIsExecutionClone(true); this.executeQuery(query); } }
/** * INTERNAL: */ protected ReadObjectQuery getQuery() { if (m_query == null) { m_query = new ReadObjectQuery(m_parentClass); Expression selectionCriteria = null; Iterator keys = m_queryKeyFields.keySet().iterator(); ExpressionBuilder builder = new ExpressionBuilder(); while (keys.hasNext()) { String keyField = ((DatabaseField) keys.next()).getQualifiedName(); if (selectionCriteria == null) { selectionCriteria = builder.getField(keyField).equal(builder.getParameter(keyField)); } else { selectionCriteria.and(builder.getField(keyField).equal(builder.getParameter(keyField))); } m_query.addArgument(keyField); } m_query.setSelectionCriteria(selectionCriteria); m_query.setShouldUseWrapperPolicy(false); } return m_query; }