Search in sources :

Example 1 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class DumpMapping method printMappingFieldElements.

public static void printMappingFieldElements(int tabs, ArrayList fields) {
    final int count = ((fields != null) ? fields.size() : 0);
    if (count > 0) {
        // NOI18N
        println(tabs, "--> fields ");
        for (int i = 0; i < count; i++) {
            MappingFieldElementImpl mfe = (MappingFieldElementImpl) fields.get(i);
            // NOI18N
            println(tabs, "[" + i + "] " + mfe.getClass());
            // NOI18N
            println(tabs + 1, "name            = " + mfe.getName());
            // NOI18N
            println(tabs + 1, "fetchGroup      = " + mfe.getFetchGroup());
            // NOI18N
            println(tabs + 1, "columns         = " + mfe.getColumns());
            if (!(mfe instanceof MappingRelationshipElement)) {
                // NOI18N
                println(tabs + 1, "columnObjects	 = " + mfe.getColumnObjects());
            } else {
                MappingRelationshipElementImpl mre = (MappingRelationshipElementImpl) mfe;
                ArrayList columnObjects = mre.getColumnObjects();
                int colCount = ((columnObjects != null) ? columnObjects.size() : 0);
                if (colCount > 0) {
                    // NOI18N
                    println(tabs + 1, "--> columnsObjects ");
                    for (int j = 0; j < colCount; j++) {
                        ColumnPairElement fce = (ColumnPairElement) columnObjects.get(j);
                        ColumnElement rce = (fce != null) ? fce.getReferencedColumn() : null;
                        // NOI18N
                        println(tabs + 1, "[" + j + "] " + fce + " -> " + rce);
                    }
                    // NOI18N
                    println(tabs + 1, "<-- columnsObjects ");
                }
                // NOI18N
                println(tabs + 1, "associatedColumns = " + mre.getAssociatedColumns());
                ArrayList associatedColumnObjects = mre.getAssociatedColumnObjects();
                colCount = ((associatedColumnObjects != null) ? associatedColumnObjects.size() : 0);
                if (colCount > 0) {
                    // NOI18N
                    println(tabs + 1, "--> associatedColumnObjects ");
                    for (int j = 0; j < colCount; j++) {
                        ColumnPairElement fce = (ColumnPairElement) associatedColumnObjects.get(j);
                        ColumnElement rce = (fce != null) ? fce.getReferencedColumn() : null;
                        // NOI18N
                        println(tabs + 1, "[" + j + "] " + fce + " -> " + rce);
                    }
                    // NOI18N
                    println(tabs + 1, "<-- associatedColumnObjects ");
                }
            }
        }
        // NOI18N
        println(tabs, "<-- fields ");
    }
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement) ColumnPairElement(org.netbeans.modules.dbschema.ColumnPairElement)

Example 2 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement 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 3 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class SelectStatement method generateAnsiJoin.

/**
 * Generates an ANSI compliant join. The columns for the join
 * condition end up in the from clause. The joined tables
 * are added indirectly to the member variable tableList by
 * being added to {@link QueryTable#nextTable} associated with
 * the "from-" table.
 *
 * @param jnode Join constraint.
 * @param opCode Join operation.
 * @see #processFromClause
 */
private void generateAnsiJoin(ConstraintJoin jnode, int opCode) {
    for (int i = 0; i < jnode.fromColumns.size(); i++) {
        ColumnElement fromColumn = (ColumnElement) jnode.fromColumns.get(i);
        ColumnElement toColumn = (ColumnElement) jnode.toColumns.get(i);
        QueryTable fromTable = findQueryTable(jnode.fromPlan, fromColumn);
        QueryTable toTable = findQueryTable(jnode.toPlan, toColumn);
        // Process the from clause
        processFromClause(fromTable, toTable);
        // Process the on clause.
        if (toTable.onClause == null) {
            toTable.onClause = new StringBuffer();
        }
        // NOI18N
        appendJoinCondition(toTable.onClause, fromTable, toTable, fromColumn, toColumn, "=");
        fromTable.joinOp = opCode;
    }
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Example 4 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class ClassDesc method getLocalFieldDesc.

LocalFieldDesc getLocalFieldDesc(ColumnElement column) {
    LocalFieldDesc result;
    for (int i = 0; i < 2; i++) {
        ArrayList theFields = null;
        if (i == 0) {
            theFields = fields;
        } else {
            theFields = hiddenFields;
        }
        if (theFields != null) {
            for (int j = 0; j < theFields.size(); j++) {
                FieldDesc f = (FieldDesc) theFields.get(j);
                if (f instanceof LocalFieldDesc) {
                    result = (LocalFieldDesc) f;
                    for (int k = 0; k < result.columnDescs.size(); k++) {
                        ColumnElement c = (ColumnElement) result.columnDescs.get(k);
                        // if (c.equals(column))
                        if (c.getName().getFullName().compareTo(column.getName().getFullName()) == 0) {
                            // searching.
                            if ((f.getTrackedFields() != null) && ((f.sqlProperties & FieldDesc.PROP_PRIMARY_TRACKED_FIELD) == 0)) {
                                continue;
                            }
                            return result;
                        }
                    }
                }
            }
        }
    }
    // If we didn't find the field associated with the column, we need to
    // create a hidden field and add it to the hiddenFields list.
    result = createLocalHiddenField(column);
    return result;
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement)

Example 5 with ColumnElement

use of org.netbeans.modules.dbschema.ColumnElement in project Payara by payara.

the class ClassDesc method initializeJoinTables.

private void initializeJoinTables() {
    Iterator iter = foreignFields.iterator();
    while (iter.hasNext()) {
        ForeignFieldDesc ff = (ForeignFieldDesc) iter.next();
        if (ff.useJoinTable()) {
            TableElement joinTable = ((ColumnElement) ff.assocLocalColumns.get(0)).getDeclaringTable();
            TableDesc joinTableDesc = findTableDesc(joinTable);
            if (joinTableDesc == null) {
                joinTableDesc = new TableDesc(joinTable);
                // Mark this table as a join table
                joinTableDesc.setJoinTable(true);
                addTableDesc(joinTableDesc);
            }
        }
    }
}
Also used : ColumnElement(org.netbeans.modules.dbschema.ColumnElement) TableElement(org.netbeans.modules.dbschema.TableElement)

Aggregations

ColumnElement (org.netbeans.modules.dbschema.ColumnElement)24 JDOFatalInternalException (com.sun.jdo.api.persistence.support.JDOFatalInternalException)4 Iterator (java.util.Iterator)4 LocalFieldDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.LocalFieldDesc)3 ArrayList (java.util.ArrayList)3 TableElement (org.netbeans.modules.dbschema.TableElement)3 ColumnPairElement (org.netbeans.modules.dbschema.ColumnPairElement)2 JDOFatalDataStoreException (com.sun.jdo.api.persistence.support.JDOFatalDataStoreException)1 TableDesc (com.sun.jdo.spi.persistence.support.sqlstore.model.TableDesc)1 ResultDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.ResultDesc)1 UpdateJoinTableDesc (com.sun.jdo.spi.persistence.support.sqlstore.sql.UpdateJoinTableDesc)1 com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint (com.sun.jdo.spi.persistence.support.sqlstore.sql.constraint)1 Collection (java.util.Collection)1