Search in sources :

Example 16 with JDOFatalInternalException

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

the class RetrieveDescImpl method buildQueryPlan.

/**
 * Builds the internal query plan and initializes the select statements.
 * Projections on collection fields will not be resolved until the actual
 * retrieval in {@link SQLStoreManager#retrieve(
 * com.sun.jdo.spi.persistence.support.sqlstore.PersistenceManager,
 *       RetrieveDesc, com.sun.jdo.spi.persistence.support.sqlstore.ValueFetcher)}.
 */
public synchronized SelectQueryPlan buildQueryPlan(SQLStoreManager store, Concurrency concurrency) {
    if (plan == null) {
        handleProjection();
        plan = SelectQueryPlan.newInstance(this, store, concurrency);
        plan.build();
        // Generate the text for the select statements.
        ArrayList statements = plan.getStatements();
        // Sanity check.
        if (statements.size() > 1) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "sqlstore.retrievedesc.stmntsnotjoined"));
        }
    }
    return plan;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) ArrayList(java.util.ArrayList)

Example 17 with JDOFatalInternalException

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

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

the class Statement method processConstraintField.

private void processConstraintField(ConstraintField fieldNode, StringBuffer result) {
    LocalFieldDesc desc = null;
    QueryPlan thePlan = getOriginalPlan(fieldNode);
    if (fieldNode instanceof ConstraintFieldDesc) {
        desc = ((ConstraintFieldDesc) fieldNode).desc;
    } else if (fieldNode instanceof ConstraintFieldName) {
        desc = thePlan.config.getLocalFieldDesc(((ConstraintFieldName) fieldNode).name);
    } else {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "core.generic.notinstanceof", fieldNode.getClass().getName(), // NOI18N
        "ConstraintFieldDesc/ConstraintFieldName"));
    }
    generateColumnText(desc, thePlan, result);
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

Example 19 with JDOFatalInternalException

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

the class Statement method processConstraints.

/**
 * Processes the constraint stack and adds it to the query.
 * This means turning the constraint stack into SQL text and
 * adding it to the where clause.
 *
 * @return Where clause based on the constraint stack.
 */
public StringBuffer processConstraints() {
    StringBuffer whereText = new StringBuffer();
    List stack = constraint.getConstraints();
    while (stack.size() > 0) {
        ConstraintNode node = (ConstraintNode) stack.get(stack.size() - 1);
        if (!(node instanceof ConstraintOperation)) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.generic.notinstanceof", node.getClass().getName(), // NOI18N
            "ConstraintOperation"));
        }
        processRootConstraint((ConstraintOperation) node, stack, whereText);
    }
    return whereText;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 20 with JDOFatalInternalException

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

the class Statement method operationFormat.

protected int operationFormat(int operation) {
    int format = 0;
    switch(operation) {
        // Binary operators
        case ActionDesc.OP_EQ:
        case ActionDesc.OP_NE:
        case ActionDesc.OP_GT:
        case ActionDesc.OP_GE:
        case ActionDesc.OP_LT:
        case ActionDesc.OP_LE:
        case ActionDesc.OP_AND:
        case ActionDesc.OP_MUL:
        case ActionDesc.OP_LIKE:
            format = OP_BINOP_MASK;
            break;
        // Binary operators that require Parenthesis
        case ActionDesc.OP_ADD:
        case ActionDesc.OP_SUB:
        case ActionDesc.OP_DIV:
        case ActionDesc.OP_OR:
            format = OP_BINOP_MASK | OP_PAREN_MASK;
            break;
        // Functions
        case ActionDesc.OP_ABS:
        case ActionDesc.OP_SQRT:
        case ActionDesc.OP_LENGTH:
        case ActionDesc.OP_LTRIM:
        case ActionDesc.OP_NOT:
        case ActionDesc.OP_NULL_COMPARISION_FUNCTION:
            format = OP_FUNC_MASK;
            break;
        // Irregular operators
        case ActionDesc.OP_BETWEEN:
        case ActionDesc.OP_LIKE_ESCAPE:
        case ActionDesc.OP_IN:
        case ActionDesc.OP_NOTIN:
        case ActionDesc.OP_NULL:
        case ActionDesc.OP_NOTNULL:
        case ActionDesc.OP_MAYBE_NULL:
        case ActionDesc.OP_CONCAT:
        case ActionDesc.OP_EQUIJOIN:
            format = OP_IRREGULAR_MASK | OP_WHERE_MASK;
            break;
        // Hence they do not have OP_WHERE_MASK set.
        case ActionDesc.OP_SUBSTRING:
        case ActionDesc.OP_POSITION:
        case ActionDesc.OP_POSITION_START:
            format = OP_IRREGULAR_MASK;
            break;
        case ActionDesc.OP_NOTEXISTS:
        case ActionDesc.OP_EXISTS:
            format = OP_IRREGULAR_MASK | OP_WHERE_MASK | OP_PREFIX_MASK;
            break;
        case ActionDesc.OP_MOD:
            format = vendorType.isModOperationUsingFunction() ? OP_IRREGULAR_MASK : OP_BINOP_MASK | OP_PAREN_MASK;
            break;
        case ActionDesc.OP_DISTINCT:
            format = OP_OTHER_MASK;
            break;
        case ActionDesc.OP_ORDERBY:
        case ActionDesc.OP_ORDERBY_DESC:
            format = OP_ORDERBY_MASK;
            break;
        case ActionDesc.OP_RTRIM:
        case ActionDesc.OP_RTRIMFIXED:
            if (vendorType.isAnsiTrim()) {
                format = OP_WHERE_MASK | OP_PREFIX_MASK | OP_POSTFIX_MASK | OP_PARAM_MASK;
            } else {
                format = OP_FUNC_MASK;
            }
            break;
        // TODO: Check how can this masks be optimized
        case ActionDesc.OP_LEFTJOIN:
            format = OP_IRREGULAR_MASK | OP_WHERE_MASK | OP_INFIX_MASK;
            format = format | OP_POSTFIX_MASK;
            break;
        case ActionDesc.OP_RIGHTJOIN:
            format = OP_IRREGULAR_MASK | OP_WHERE_MASK | OP_INFIX_MASK;
            format = format | OP_PREFIX_MASK;
            break;
        default:
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.constraint.illegalop", // NOI18N
            "" + operation));
    }
    return format;
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)

Aggregations

JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)26 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)4 ColumnElement (org.netbeans.modules.dbschema.ColumnElement)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)3 ArrayList (java.util.ArrayList)3 JDODataStoreException (com.sun.jdo.api.persistence.support.JDODataStoreException)2 JDOException (com.sun.jdo.api.persistence.support.JDOException)2 JDOUnsupportedOptionException (com.sun.jdo.api.persistence.support.JDOUnsupportedOptionException)2 JDOUserException (com.sun.jdo.api.persistence.support.JDOUserException)2 RetrieveDescImpl (com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl)2 Field (java.lang.reflect.Field)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2 TableElement (org.netbeans.modules.dbschema.TableElement)2 JDOQueryException (com.sun.jdo.api.persistence.support.JDOQueryException)1 ClassDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ClassDesc)1 FieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.FieldDesc)1 ForeignFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.ForeignFieldDesc)1 TableDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc)1 DateType (com.sun.jdo.spi.persistence.support.sqlstore.query.util.type.DateType)1