Search in sources :

Example 6 with JDOFatalInternalException

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

the class SelectQueryPlan method addCorrelatedInQuery.

/**
 * Creates and builds a correlated "In" subquery.
 * Merges tables from the subquery plan to the current plan and adds
 * the local fields corresponding to the subquery to the constaints.
 * The subquery is added to the constraint stack.
 *
 * @param node subquery constraint.
 */
private void addCorrelatedInQuery(ConstraintFieldNameSubQuery node) {
    FieldDesc field = config.getField(node.fieldName);
    RetrieveDescImpl rd = (RetrieveDescImpl) node.desc;
    if (field != null && field instanceof ForeignFieldDesc) {
        ForeignFieldDesc ff = (ForeignFieldDesc) field;
        if (ff.getComponentType() != rd.getPersistenceCapableClass()) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.constraint.unknownfield", node.fieldName, rd.getPersistenceCapableClass().getName()));
        }
        SelectQueryPlan subqueryPlan = new CorrelatedInSelectPlan(rd, store, ff, this);
        subqueryPlan.build();
        // Make the tables involved in the subquery known to the parent query.
        addQueryTables(subqueryPlan.tables);
        // Push a new subquery constraint on the stack
        ConstraintSubquery subqueryConstraint = new ConstraintSubquery();
        subqueryConstraint.plan = subqueryPlan;
        constraint.stack.add(subqueryConstraint);
        ArrayList localFields = ff.getLocalFields();
        // Add the local fields corresponding to the subquery to the stack.
        for (int i = 0; i < localFields.size(); i++) {
            constraint.addField((LocalFieldDesc) localFields.get(i), this);
        }
    } else {
        // or the field is not present in the config.
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
        "core.constraint.unknownfield", node.fieldName, rd.getPersistenceCapableClass().getName()));
    }
}
Also used : RetrieveDescImpl(com.sun.jdo.spi.persistence.support.sqlstore.sql.RetrieveDescImpl) 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)

Example 7 with JDOFatalInternalException

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

the class SelectQueryPlan method processParentField.

/**
 * Sets the plan's parent field and adds the tables for the join columns
 * to the table list. The parent field is identified by <code>fieldName</code>
 * and defined in the model information of the parent class
 * <code>parentConfig</code>.
 *
 * @see ClassDesc
 */
private void processParentField(ClassDesc parentConfig, String fieldName) {
    if (parentField == null) {
        // The plan has not been processed before
        FieldDesc f = parentConfig.getField(fieldName);
        if (f == null || !(f instanceof ForeignFieldDesc)) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.constraint.unknownfield", fieldName, parentConfig.getPersistenceCapableClass().getName()));
        }
        parentField = (ForeignFieldDesc) f;
        // Add the join table, if neccessary.
        if (parentField.useJoinTable()) {
            // 
            for (int i = 0; i < parentField.assocLocalColumns.size(); i++) {
                ColumnElement col = (ColumnElement) parentField.assocLocalColumns.get(i);
                addQueryTable(col.getDeclaringTable(), config);
            }
        }
        // The side-effect for this is to create statements with no columns.
        for (int i = 0; i < parentField.foreignColumns.size(); i++) {
            ColumnElement col = (ColumnElement) parentField.foreignColumns.get(i);
            addQueryTable(col.getDeclaringTable(), config);
        }
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) ColumnElement(org.netbeans.modules.dbschema.ColumnElement) com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)

Example 8 with JDOFatalInternalException

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

the class SelectStatement method processRootConstraint.

/**
 * Processes Order By constraints and calls the super class
 * method for all other constrains.
 */
protected void processRootConstraint(ConstraintOperation opNode, List stack, StringBuffer whereText) {
    int op = opNode.operation;
    int opInfo = operationFormat(op);
    if ((opInfo & OP_ORDERBY_MASK) > 0) {
        stack.remove(stack.size() - 1);
        ConstraintNode node = (ConstraintNode) stack.get(stack.size() - 1);
        if (!(node instanceof ConstraintField)) {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.constraint.needfieldnode"));
        } else {
            processOrderByField((ConstraintFieldDesc) node, op);
            stack.remove(stack.size() - 1);
        }
    } else {
        super.processRootConstraint(opNode, stack, whereText);
    }
}
Also used : JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException) ConstraintNode(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.ConstraintNode) ConstraintField(com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint.ConstraintField)

Example 9 with JDOFatalInternalException

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

the class Statement method processRootConstraint.

protected void processRootConstraint(ConstraintOperation opNode, List stack, StringBuffer whereText) {
    int op = opNode.operation;
    int opInfo = operationFormat(op);
    if ((opInfo & OP_WHERE_MASK) > 0) {
        String constraint = getWhereText(stack);
        if (whereText.length() > 0 && constraint.length() > 0) {
            // This is neccessary, if the constraint stack is "un-balanced",
            // see OrderingTest#ordering006 for an example.
            whereText.append(" and ");
        }
        whereText.append(constraint);
    } else {
        throw new JDOFatalInternalException(I18NHelper.getMessage(messages, "sqlstore.sql.generator.statement.unexpectedconstraint", // NOI18N
        op));
    }
}
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)

Example 10 with JDOFatalInternalException

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

the class Statement method processNullOperation.

private void processNullOperation(int opCode, List stack, StringBuffer result) {
    String nullComparisionFunctionName = vendorType.getNullComparisonFunctionName();
    if (nullComparisionFunctionName.length() != 0) {
        // Null comparision for LOB type fields is
        // through function for this DB
        Object nextNode = stack.get(stack.size() - 1);
        if (nextNode != null) {
            if (nextNode instanceof ConstraintFieldName) {
                ConstraintFieldName fieldNode = (ConstraintFieldName) nextNode;
                QueryPlan originalPlan = getQueryPlan();
                if (fieldNode.originalPlan != null) {
                    originalPlan = fieldNode.originalPlan;
                }
                LocalFieldDesc desc = (LocalFieldDesc) originalPlan.config.getField(fieldNode.name);
                if (desc.isMappedToLob()) {
                    // Add a dummy ConstraintOperation Node corresponding
                    // to null comparision func.
                    stack.add(new ConstraintOperation(ActionDesc.OP_NULL_COMPARISION_FUNCTION));
                }
            }
        } else {
            throw new JDOFatalInternalException(I18NHelper.getMessage(messages, // NOI18N
            "core.constraint.stackempty"));
        }
    }
    result.append(getWhereText(stack));
    String str = (opCode == ActionDesc.OP_NULL) ? vendorType.getIsNull() : vendorType.getIsNotNull();
    result.append(str);
}
Also used : LocalFieldDesc(com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc) JDOFatalInternalException(com.sun.jdo.api.persistence.support.JDOFatalInternalException)

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