Search in sources :

Example 1 with JDOQueryException

use of com.sun.jdo.api.persistence.support.JDOQueryException in project Payara by payara.

the class ErrorMsg method error.

/**
 * Indicates an error situation.
 * @param line line number
 * @param col column number
 * @param msg error message
 */
public void error(int line, int col, String msg) throws JDOQueryException {
    JDOQueryException ex;
    if (line > 1) {
        // include line and column info
        Object[] args = { context, new Integer(line), new Integer(col), msg };
        ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msglinecolumn", // NOI18N
        args));
    } else if (col > 0) {
        // include column info
        Object[] args = { context, new Integer(col), msg };
        ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msgcolumn", // NOI18N
        args));
    } else {
        Object[] args = { context, msg };
        ex = new JDOQueryException(I18NHelper.getMessage(messages, "jqlc.errormsg.generic.msg", // NOI18N
        args));
    }
    logger.throwing("jqlc.ErrorMsg", "error", ex);
    throw ex;
}
Also used : JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Example 2 with JDOQueryException

use of com.sun.jdo.api.persistence.support.JDOQueryException in project Payara by payara.

the class JQLC method setClass.

/**
 */
public void setClass(Class candidateClass) {
    // check valid candidate class definition
    if (candidateClass == null) {
        JDOQueryException ex = new JDOQueryException(I18NHelper.getMessage(messages, // NOI18N
        "jqlc.jqlc.generic.nocandidateclass"));
        // NOI18N
        logger.throwing("jqlc.JQLC", "setClass", ex);
        throw ex;
    }
    this.candidateClass = candidateClass;
}
Also used : JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Example 3 with JDOQueryException

use of com.sun.jdo.api.persistence.support.JDOQueryException 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 4 with JDOQueryException

use of com.sun.jdo.api.persistence.support.JDOQueryException in project Payara by payara.

the class ParameterTable method defineValueByName.

/**
 */
private void defineValueByName(String name, Object value) {
    int index = names.indexOf(name);
    if (index == -1)
        throw new JDOQueryException(// NOI18N
        I18NHelper.getMessage(messages, "jqlc.parametertable.definevaluebyname.undefinedparam", name));
    defineValueByIndex(index, value);
}
Also used : JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Example 5 with JDOQueryException

use of com.sun.jdo.api.persistence.support.JDOQueryException in project Payara by payara.

the class ParameterTable method defineValueByIndex.

/**
 */
private void defineValueByIndex(int index, Object value) {
    // index < 0 => implementation error
    if (index < 0)
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "jqlc.parametertable.definevaluebyindex.wrongindex", String.valueOf(index)));
    // index > type.size => too many actual parameters
    if (index >= types.size())
        throw new JDOQueryException(// NOI18N
        I18NHelper.getMessage(messages, "jqlc.parametertable.definevaluebyindex.wrongnumberofargs"));
    // check type compatibility of actual and formal parameter
    Class formalType = ((Type) types.get(index)).getJavaClass();
    if (!isCompatibleValue(formalType, value)) {
        String actualTypeName = ((value == null) ? "<type of null>" : value.getClass().getName());
        throw new JDOQueryException(// NOI18N
        I18NHelper.getMessage(// NOI18N
        messages, // NOI18N
        "jqlc.parametertable.definevaluebyindex.typemismatch", actualTypeName, formalType.getName()));
    }
    // everything is ok => set the actual parameters's value
    values.set(index, value);
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) Type(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.Type) WrapperClassType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.WrapperClassType) DateType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType) StringType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.StringType) MathType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.MathType) PrimitiveType(com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.PrimitiveType) JDOQueryException(com.sun.jdo.api.persistence.support.JDOQueryException)

Aggregations

JDOQueryException (com.sun.jdo.api.persistence.support.JDOQueryException)5 JDOException (com.sun.jdo.api.persistence.support.JDOException)1 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)1 RetrieveDesc (com.sun.jdo.spi.persistence.support.sqlstore.RetrieveDesc)1 DateType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType)1 MathType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.MathType)1 PrimitiveType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.PrimitiveType)1 StringType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.StringType)1 Type (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.Type)1 WrapperClassType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.WrapperClassType)1 ArrayList (java.util.ArrayList)1