Examples of QualifiedDBIdentifier


Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

    }

    public DBIdentifier getSecondaryTableIdentifier(DBIdentifier tableName) {
        // if no secondary table joins, bad table name, exact match,
        // or an already-qualified table name, nothing to do
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(tableName);
        if (_seconds == null || DBIdentifier.isNull(tableName)
            || _seconds.containsKey(tableName)
            || !DBIdentifier.isNull(path.getSchemaName()))
            return tableName;

        // decide which class-level join table is best match
        DBIdentifier best = tableName;
        int pts = 0;
        DBIdentifier fullJoin = DBIdentifier.NULL;
        DBIdentifier join = DBIdentifier.NULL;
        for (Iterator<DBIdentifier> itr = _seconds.keySet().iterator(); itr.hasNext();) {
            // award a caseless match without schema 2 points
            fullJoin = (DBIdentifier) itr.next();
            QualifiedDBIdentifier joinPath = QualifiedDBIdentifier.getPath(fullJoin);
            if (joinPath.isUnqualifiedObject() && pts < 2 && fullJoin.equalsIgnoreCase(tableName)) {
                best = fullJoin;
                pts = 2;
            } else if (joinPath.isUnqualifiedObject())
                continue;

            // immediately return an exact match with schema
            join = joinPath.getIdentifier();
            if (join.equals(tableName))
                return fullJoin;

            // caseless match with schema worth 1 point
            if (pts < 1 && join.equalsIgnoreCase(tableName)) {
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

        // get the columns for the join with the best match for table name
        List<Column> cols = _seconds.get(getSecondaryTableIdentifier(tableName));
        if (cols == null) {
            // possible that given table has extra info the join table
            // doesn't have; strip it
            QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(tableName);
            if (!DBIdentifier.isNull(path.getSchemaName())) {
                tableName = path.getIdentifier();
                cols = _seconds.get(getSecondaryTableIdentifier(tableName));
            }
        }
        if (cols == null) {
            return Collections.emptyList();
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

        Map<DBIdentifier, Collection<DBIdentifier>> schemas = new HashMap<DBIdentifier, Collection<DBIdentifier>>();
        DBIdentifier schema = DBIdentifier.NULL, table = DBIdentifier.NULL;
        Collection<DBIdentifier> tables = null;
        for (int i = 0; i < args.length; i++) {
            QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(args[i]);
            schema = path.getSchemaName();
            table = path.getIdentifier();

            // if just a schema name, map schema to null
            if (DBIdentifier.isNull(table) && !schemas.containsKey(schema))
                schemas.put(schema, null);
            else if (!DBIdentifier.isNull(table)) {
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

    }

    @Override
    public void addSchema(ClassMapping mapping, SchemaGroup group) {
        // sequence already exists?
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
        if (group.isKnownSequence(path))
            return;

        DBIdentifier schemaName = getSchemaIdentifier();
        if (DBIdentifier.isEmpty(schemaName)) {
            schemaName = path.getSchemaName();
            if (DBIdentifier.isEmpty(schemaName))
                schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
        }

        // create table in this group
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

    /**
     * Creates the sequence object.
     */
    private void buildSequence() {
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
        DBIdentifier seqName = path.getIdentifier();
        // JPA 2 added schema as a configurable attribute on 
        // sequence generator.  OpenJPA <= 1.x allowed this via
        // schema.sequence on the sequence name.  Specifying a schema
        // name on the annotation or in the orm will override the old
        // behavior.
        DBIdentifier schemaName = _schema;
        if (DBIdentifier.isEmpty(schemaName)) {
            schemaName = path.getSchemaName();
            if (DBIdentifier.isEmpty(schemaName))
                schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
        }

        // build the sequence in one of the designated schemas
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

    }

    @Override
    public void addSchema(ClassMapping mapping, SchemaGroup group) {
        // sequence already exists?
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
        if (group.isKnownSequence(path))
            return;

        DBIdentifier schemaName = getSchemaIdentifier();
        if (DBIdentifier.isEmpty(schemaName)) {
            schemaName = path.getSchemaName();
            if (DBIdentifier.isEmpty(schemaName))
                schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
        }

        // create table in this group
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

    /**
     * Creates the sequence object.
     */
    private void buildSequence() {
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_seqName);
        DBIdentifier seqName = path.getIdentifier();
        // JPA 2 added schema as a configurable attribute on 
        // sequence generator.  OpenJPA <= 1.x allowed this via
        // schema.sequence on the sequence name.  Specifying a schema
        // name on the annotation or in the orm will override the old
        // behavior.
        DBIdentifier schemaName = _schema;
        if (DBIdentifier.isEmpty(schemaName)) {
            schemaName = path.getSchemaName();
            if (DBIdentifier.isEmpty(schemaName))
                schemaName = Schemas.getNewTableSchemaIdentifier(_conf);
        }

        // build the sequence in one of the designated schemas
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

            if (schema == null)
                schema = group.addSchema(schemaName);
            given = def.getIdentifier(schema);
        }

        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(given);
        if (DBIdentifier.isNull(path.getSchemaName())) {
            if (!DBIdentifier.isNull(schemaName)) {
                path.setSchemaName(schemaName);
            }
        } else {
            schemaName = path.getSchemaName();
            schema = null;
        }

        // look for named table using full name and findTable, which allows
        // the dynamic schema factory to create the table if needed
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

        // determine the column name based on given info, or template if none;
        // also make sure that if the user gave a column name, he didn't try
        // to put the column in an unexpected table
        if (DBIdentifier.isNull(colName))
            colName = tmplate.getIdentifier();
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(colName);
        if (path.isUnqualifiedColumn()) {
            colName = path.getIdentifier();
        } else if (!DBIdentifier.isNull(path.getObjectTableName())) {
            findTable(context, path.getObjectTableName(), table,
                null, null);
            colName = path.getUnqualifiedName();
        }

        // find existing column
        Column col = table.getColumn(colName);
        if (col == null && !adapt) {
View Full Code Here

Examples of org.apache.openjpa.jdbc.identifier.QualifiedDBIdentifier

        Table local = table;
        Table foreign = rel.getTable();
        boolean fullName = false;
        boolean inverse = false;
        if (!DBIdentifier.isNull(name)) {
            QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(name);
            if (!DBIdentifier.isNull(path.getObjectTableName())) {
                if (DBIdentifier.isEmpty(path.getObjectTableName()))
                    local = foreign;
                else
                    local = findTable(context, path.getObjectTableName(),
                        local, foreign, null);
                fullName = true;
                name = path.getIdentifier().getUnqualifiedName();

                // if inverse join, then swap local and foreign tables
                if (local != table) {
                    foreign = table;
                    inverse = true;
                }
            }
        }
        boolean forceInverse = !fullName && _join == JOIN_INVERSE;
        if (forceInverse) {
            local = foreign;
            foreign = table;
            inverse = true;
        }

        // determine target
        DBIdentifier targetName = given.getTargetIdentifier();
        Object target = null;
        Table ttable = null;
        boolean constant = false;
        boolean fullTarget = false;
        if (DBIdentifier.isNull(targetName) && given.getTargetField() != null) {
            ClassMapping tcls = (inverse) ? cls : rel;
            String fieldName = given.getTargetField();
            String[] names = Normalizer.splitName(fieldName);
            fullTarget = names.length > 1;

            if (names.length > 1 && StringUtils.isEmpty(names[0])) {
                // allow use of '.' without prefix to mean "use expected local
                // cls"; but if we already inversed no need to switch again
                if (!inverse)
                    tcls = cls;
                fieldName = names[1];
            } else if (names.length > 1) {
                // must be class + field name
                tcls = findClassMapping(context, names[0], cls, rel);
                fieldName = names[1];
            }
            if (tcls == null)
                throw new MetaDataException(_loc.get(prefix
                    + "-bad-fktargetcls", context, fieldName, name));

            FieldMapping field = tcls.getFieldMapping(fieldName);
            if (field == null)
                throw new MetaDataException(_loc.get(prefix
                    + "-bad-fktargetfield", new Object[]{ context, fieldName,
                    name, tcls }));
            if (field.getColumns().length != 1)
                throw new MetaDataException(_loc.get(prefix
                    + "-fktargetfield-cols", context, fieldName, name));
            ttable = (field.getJoinForeignKey() != null) ? field.getTable()
                : field.getDefiningMapping().getTable();
            targetName = field.getColumns()[0].getIdentifier();
        } else if (!DBIdentifier.isNull(targetName)) {
            String targetNameStr = targetName.getName();
            if (targetNameStr.charAt(0) == '\'') {
                constant = true;
                target = targetNameStr.substring(1, targetNameStr.length() - 1);
            } else if (targetNameStr.charAt(0) == '-'
                || targetNameStr.charAt(0) == '.'
                || Character.isDigit(targetNameStr.charAt(0))) {
                constant = true;
                try {
                    if (targetNameStr.indexOf('.') == -1)
                        target = new Integer(targetNameStr);
                    else
                        target = new Double(targetNameStr);
                } catch (RuntimeException re) {
                    throw new MetaDataException(_loc.get(prefix
                        + "-bad-fkconst", context, targetName, name));
                }
            } else if ("null".equalsIgnoreCase(targetNameStr))
                constant = true;
            else {
                QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(targetName);
                fullTarget = (!DBIdentifier.isNull(path.getObjectTableName()));
                if (!DBIdentifier.isNull(path.getObjectTableName()) &&
                    DBIdentifier.isEmpty(path.getObjectTableName())) {
                    // allow use of '.' without prefix to mean "use expected
                    // local table", but ignore if we're already inversed
                    if (!inverse)
                        ttable = local;
                    targetName = path.getIdentifier().getUnqualifiedName();
                } else if (!DBIdentifier.isNull(path.getObjectTableName())) {
                    ttable = findTable(context, path.getObjectTableName(), foreign, local, (inverse) ? cls : rel);
                    targetName = path.getIdentifier().getUnqualifiedName();
                }
            }
        }

        // use explicit target table if available
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.