Search in sources :

Example 6 with RetrieveDescImpl

use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.

the class ClassDesc method getRetrieveDescForFKQuery.

/**
 * Returns a RetrieveDescriptor which represent a SQL query selecting pc
 * instances by the relationship key. The relationship key is taken from
 * the foreign field <code>foreignField</code> and used as query constraint.
 * Please note that the RDs are cached, so the method first checks the cache.
 * If there is no corresponding RetrieveDescriptor in the cache, it creates
 * a new one and stores it in the cache. FetchGroup fields will be added
 * when the query plan is build, see <code>SelectQueryPlan#processFetchGroups</code>.
 *
 * Note, the reason to introduce the RetrieveDesc cache in ClassDesc and not
 * in the store manager is, that we can have the cache per class, where
 * the store manager could only provide one big cache for all pc classes.
 *
 * @param foreignField The relationship field to be retrieved.
 *  Following is true for this field.
 * <ul>
 *  <li> It is part of an independent fetch group with only one field in the fetch group.
 *       <p>Or
 *       <P>Not part of any fetch group.
 *  </li>
 *  <li>It is not mapped to a join table. </li>
 * </ul>
 * @param store The store manager.
 * @return A RetrieveDescriptor selecting pc instance(s) corresponding to
 * the foreign field
 * @see #getRetrieveDescForPKQuery
 */
public RetrieveDesc getRetrieveDescForFKQuery(ForeignFieldDesc foreignField, PersistenceStore store) {
    RetrieveDescImpl rd = null;
    String cacheKey = generateRDCacheKey(foreignField);
    synchronized (foreignRetrieveDescCache) {
        // Cache lookup.
        rd = (RetrieveDescImpl) foreignRetrieveDescCache.get(cacheKey);
        // Generate a new RD if there isn't one be found in the cache.
        if (rd == null) {
            rd = (RetrieveDescImpl) store.getRetrieveDesc(foreignField.foreignConfig.getPersistenceCapableClass());
            addFKConstraints(rd, foreignField);
            // Cache fillup.
            foreignRetrieveDescCache.put(cacheKey, rd);
        }
    }
    return rd;
}
Also used : RetrieveDescImpl(com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)

Example 7 with RetrieveDescImpl

use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.

the class SelectQueryPlan method processForeignFieldConstraint.

/**
 * Joins the current plan with the constraint <code>node</code>. The constraint
 * includes the name of the parent field and the retrieve descriptor for the
 * related class. The plans will be joined with <code>OP_EQUIJOIN</code>.
 * The constraints processed here have been added by
 * {@link RetrieveDesc#addConstraint(String, RetrieveDesc)}.
 *
 * @param node Join constraint.
 */
private void processForeignFieldConstraint(ConstraintForeignFieldName node) {
    RetrieveDescImpl rd = (RetrieveDescImpl) node.desc;
    if (rd == null) {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "sqlstore.constraint.noretrievedesc", node.name, config.getPersistenceCapableClass().getName()));
    }
    SelectQueryPlan fcp = newForeignConstraintPlan(rd, node.name);
    if ((fcp.status & ST_JOINED) == 0) {
        fcp.processParentField(config, node.name);
        // Joins on constraints always join as equijoin
        processJoin(fcp, ActionDesc.OP_EQUIJOIN);
        fcp.appendAndOp = true;
    } else {
        fcp.appendAndOp = false;
    }
}
Also used : RetrieveDescImpl(com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 8 with RetrieveDescImpl

use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.

the class SQLStoreManager method retrieve.

/**
 * The retrieve method builds and executes the SQL query described by
 * the action parameter.
 *
 * @param action
 *     The action parameter holds the RetrieveDesc describing what
 *     should be selected from the database.
 *
 * @param parameters
 *     Query parameters.
 */
public Object retrieve(PersistenceManager pm, RetrieveDesc action, ValueFetcher parameters) {
    if (action == null) {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "core.generic.nullparam", // NOI18N
        "action"));
    }
    if (!(action instanceof RetrieveDescImpl)) {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "core.generic.notinstanceof", action.getClass().getName(), // NOI18N
        "RetrieveDescImpl"));
    }
    RetrieveDescImpl retrieveAction = ((RetrieveDescImpl) action);
    ClassDesc config = retrieveAction.getConfig();
    Concurrency concurrency = config.getConcurrency(pm.isOptimisticTransaction());
    SelectQueryPlan plan = retrieveAction.buildQueryPlan(this, concurrency);
    ArrayList statements = plan.getStatements();
    Object result = null;
    SelectStatement s = (SelectStatement) statements.get(0);
    result = executeQuery(pm, s, concurrency, parameters);
    if ((plan.options & RetrieveDescImpl.OPT_AGGREGATE) == 0) {
        if ((plan.options & RetrieveDescImpl.OPT_DISTINCT) > 0) {
            if (((plan.options & RetrieveDescImpl.OPT_FOR_UPDATE) > 0 && !vendorType.isDistinctSupportedWithUpdateLock())) {
                HashSet hash = new HashSet();
                for (Iterator iter = ((Collection) result).iterator(); iter.hasNext(); ) {
                    Object temp = iter.next();
                    if (!hash.contains(temp)) {
                        hash.add(temp);
                    } else {
                        iter.remove();
                    }
                }
            }
        }
    }
    return result;
}
Also used : RetrieveDescImpl(com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl) Concurrency(com.sun.jdo.spi.persistence.support.sqlstore.sql.concurrency.Concurrency)

Example 9 with RetrieveDescImpl

use of com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl in project Payara by payara.

the class ClassDesc method getRetrieveDescForVerificationQuery.

/**
 * Gets RetrieveDescriptor(rd) for verifying a VC instance. The returned rd
 * is set up to expect constraints for pk followed by constraints for version
 * fields.
 * @param store
 * @return Instance of retrieve Descriptor for verifying a VC instance.
 */
public RetrieveDesc getRetrieveDescForVerificationQuery(PersistenceStore store) {
    assert hasVersionConsistency();
    synchronized (retrieveDescForVerificationSynchObj) {
        if (retrieveDescForVerification == null) {
            RetrieveDescImpl rd = (RetrieveDescImpl) store.getRetrieveDesc(pcClass);
            int index = addPKConstraints(rd);
            rd.addParameterConstraints(versionFields, index);
            rd.setOption(RetrieveDescImpl.OPT_VERIFY);
            retrieveDescForVerification = rd;
        }
    }
    return retrieveDescForVerification;
}
Also used : RetrieveDescImpl(com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)

Aggregations

RetrieveDescImpl (com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)9 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)3 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)2 Concurrency (com.sun.jdo.spi.persistence.support.sqlstore.sql.concurrency.Concurrency)1