Search in sources :

Example 1 with RetrieveDesc

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

the class JQLC method codeGen.

/**
 */
public RetrieveDesc codeGen(PersistenceManager pm, ParameterTable paramtab) {
    boolean finer = logger.isLoggable(Logger.FINER);
    boolean finest = logger.isLoggable(Logger.FINEST);
    RetrieveDesc rd = null;
    // check if a RetrieveDescriptor for the actual parameter constellation
    // is already available in the cache
    String key = paramtab.getKeyForRetrieveDescCache();
    synchronized (retrieveDescCache) {
        if (key != null)
            rd = (RetrieveDesc) retrieveDescCache.get(key);
        if (rd == null) {
            Optimizer optimizer = new Optimizer();
            optimizer.init(typetab, paramtab, errorMsg);
            optimizer.setASTFactory(JQLAST.Factory.getInstance());
            CodeGeneration codeGen = new CodeGeneration();
            codeGen.init(pm, typetab, paramtab, errorMsg, prefetchEnabled);
            codeGen.setASTFactory(JQLAST.Factory.getInstance());
            try {
                JQLAST ast = queryAST;
                // NOI18N
                if (finer)
                    logger.finer("LOG_JQLCStartPass", "optimizer");
                optimizer.query(ast);
                // Do not store the optimizer result in the instance variable queryAST,
                // it cannot be reused by the next execution of this query. The next execute
                // might have different query parameter values, so the optimized AST is different.
                ast = (JQLAST) optimizer.getAST();
                // NOI18N
                if (finest)
                    logger.finest("LOG_JQLCDumpTree", ast.getTreeRepr("(optimized AST)"));
                // NOI18N
                if (finer)
                    logger.finer("LOG_JQLCStartPass", "code generation");
                codeGen.query(ast);
                rd = codeGen.getRetrieveDesc();
                // if the key is not null
                if (key != null)
                    retrieveDescCache.put(key, rd);
            } catch (ANTLRException ex) {
                // NOI18N
                errorMsg.fatal("JQLC.codeGen unexpected exception", ex);
            }
        } else {
            // NOI18N
            if (finer)
                logger.finest("LOG_JQLCReuseRetrieveDesc");
        }
    }
    return rd;
}
Also used : ANTLRException(antlr.ANTLRException) RetrieveDesc(com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc)

Example 2 with RetrieveDesc

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

the class QueryImpl method doExecute.

/**
 * Internal method called by execute, executeWithArray, executeWithMap.
 * - calls the code generation of the query compiler
 * - flushes updates
 * - executes the RetrieveDesc returned by the code generation
 * - resets the compiler
 */
private Object doExecute(ParameterTable params) {
    Object result = null;
    RetrieveDesc rd = null;
    try {
        // We need to make sure that no parallel thread closes the pm =>
        // try to get a shared lock for the pm. Today, the pm impl does
        // not allow to promote a shared lock into a exclusive lock. Thus
        // we need to get an exclusive lock here. Otherwise pm.internalFlush
        // runs into a deadlock, because it tries to get a exclusive lock.
        // This code need to be changed to get a ahared lock as soon as
        // The next line might result in a NPE, if pm is closed or if the
        // query instance was deserialized. Please note, I cannot check the
        // pm and then get the lock, because the pm might be closed in
        // parallel. Then subsequent uses of pm in doexecute would fail.
        pm.acquireExclusiveLock();
    } catch (NullPointerException npe) {
        // NPE means pm is closed or query instance was serialized.
        String key = (createdBySerialization ? // NOI18N
        "query.queryimpl.doexecute.notboundtopm" : // NOI18N
        "query.queryimpl.doexecute.pmclosed");
        JDOException ex = new JDOQueryException(I18NHelper.getMessage(messages, key));
        // NOI18N
        logger.throwing("query.QueryImpl", "compile", ex);
        throw ex;
    }
    try {
        checkCandidates();
        // call the code generation
        rd = jqlc.codeGen(pm, params);
        // flush changes (inserts, updates, deletes) to the datastore
        flush();
        if (logger.isLoggable(Logger.FINER))
            // NOI18N
            logger.finer("LOG_ExecuteQuery", this, params.getValues());
        // Note, the RetrieveDesc returned by the code generation is null
        // in the case of a query having a false filter =>
        // do not go to the datastore, but return an emtpy collection
        result = (rd != null) ? pm.retrieve(rd, params.getValueFetcher()) : new ArrayList();
    } finally {
        // Note, the following stmt needs to be replaced by
        // pm.releaseSharedLock, as soon as the pm supports promoting a
        // shared lock into an exclusive lock.
        pm.releaseExclusiveLock();
    }
    return result;
}
Also used : RetrieveDesc(com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc) ArrayList(java.util.ArrayList) JDOException(com.sun.jdo.api.persistence.support.JDOException) JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Example 3 with RetrieveDesc

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

the class JQLAST method toString.

/**
 * Returns a string representation of this JQLAST w/o child nodes.
 * @return a string representation of the object.
 */
public String toString() {
    StringBuffer repr = new StringBuffer();
    Object jqlType = getJQLType();
    RetrieveDesc rd = getRetrieveDesc();
    // token text
    // NOI18N
    repr.append((getText() == null ? "null" : getText()));
    // NOI18N
    repr.append(" [");
    // token type
    repr.append(getType());
    // line/column info
    // NOI18N
    repr.append(", (");
    // NOI18N
    repr.append(getLine() + "/" + getColumn());
    // NOI18N
    repr.append(")");
    // type info
    // NOI18N
    repr.append(", ");
    repr.append(jqlType);
    // RetrieveDesc info
    // NOI18N
    repr.append(", ");
    repr.append(getRetrieveDescRepr(rd));
    // NOI18N
    repr.append("]");
    return repr.toString();
}
Also used : RetrieveDesc(com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc)

Aggregations

RetrieveDesc (com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc)3 ANTLRException (antlr.ANTLRException)1 JDOException (com.sun.jdo.api.persistence.support.JDOException)1 JDOQueryException (com.sun.jdo.api.persistence.support.JDOQueryException)1 ArrayList (java.util.ArrayList)1