Package org.apache.openjpa.jdbc.identifier

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


    private void mergeJoinColumn(MetaDataContext context, String prefix,
        Column given, Object[][] joins, int idx, Table table, ClassMapping cls,
        ClassMapping rel, ForeignKeyDefaults def, boolean inversable,
        boolean adapt, boolean fill) {
        // default to the primary key column name if this is a pk join
        DBIdentifier name = given.getIdentifier();
        if (DBIdentifier.isNull(name) && given.getFlag(Column.FLAG_PK_JOIN) && cls != null) {
            Column[] pks = cls.getPrimaryKeyColumns();
            if (pks.length == 1)
                name = pks[0].getIdentifier();
        }

        // if we can't adapt, then the user must at least give a column name
        if (DBIdentifier.isNull(name) && !adapt && !fill)
            throw new MetaDataException(_loc.get(prefix + "-no-fkcol-name",
                context));

        // check to see if the column isn't in the expected table; it might
        // be an inverse join or a join to a base class of the target type
        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) == '.'
View Full Code Here


        t0.setDummy(false);
        em.getTransaction().begin();
        em.persist(t0);
        em.getTransaction().commit();
        Column boolCol = getMapping(EntityBool.class).getTable().getColumn("dummy");
        DBIdentifier boolColId = boolCol.getIdentifier();
        Query q =
            em.createNativeQuery("Select "
                    + ((JDBCConfiguration) emf.getConfiguration())
                        .getDBDictionaryInstance().getPlaceholderValueString(
                            boolCol)
                    + " FROM EntityBool a UNION ALL Select a." + boolColId.getName()  + " " +
                        "FROM EntityBool a");
        q.getResultList();
        em.close();
    }
View Full Code Here

    /**
     * Creates the object-level representation of the sequence table.
     */
    private void buildTable() {
        QualifiedDBIdentifier path = QualifiedDBIdentifier.getPath(_table);
        DBIdentifier tableName = path.getIdentifier();
        DBIdentifier schemaName = path.getSchemaName();
        if (DBIdentifier.isEmpty(schemaName))
            schemaName = Schemas.getNewTableSchemaIdentifier(_conf);

        // build the table in one of the designated schemas
        SchemaGroup group = new SchemaGroup();
View Full Code Here

    public String getTableName(FieldMapping fm, Schema schema) {
        return getTableIdentifier(fm, schema).getName();
    }

    public DBIdentifier getTableIdentifier(FieldMapping fm, Schema schema) {
        DBIdentifier sName = DBIdentifier.newTable(fm.getName());
        Table table = fm.getDefiningMapping().getTable();
        if (table != null) {
            DBIdentifier tableName = DBIdentifier.truncate(table.getIdentifier(),5);
            sName = DBIdentifier.append(tableName, fm.getName());
        }
        if (!_defMissing)
            sName = dict.getValidTableName(sName, schema);
        return sName;
View Full Code Here

        //
        if(!dict.supportsLockingWithMultipleTables) {
            // look for columns mapped to secondary tables which need to be locked
            FieldMapping fms[] = mapping.getFieldMappings();
            for( FieldMapping fm : fms) {
                DBIdentifier secTableName = fm.getMappingInfo().getTableIdentifier();
                if (!DBIdentifier.isNull(secTableName)) {
                    // select only the PK columns, since we just want to lock
                    Select select = factory.newSelect();
                    select.select(fm.getColumns());
                    select.whereForeignKey(fm.getJoinForeignKey(), id, mapping, _store);
View Full Code Here

     * Correct the given column's name.
     */
    protected void correctName(Table table, Column col) {
        if (!_defMissing || _removeHungarianNotation)
        {
            DBIdentifier name = col.getIdentifier();
            if (_removeHungarianNotation)
                name = DBIdentifier.removeHungarianNotation(name);
            DBIdentifier correctedName = dict.getValidColumnName(name, table);
            col.setIdentifier(correctedName);
            table.addCorrectedColumnName(correctedName, true);
        }
    }
View Full Code Here

    }

    protected DBIdentifier getIndexName(DBIdentifier name, Table table, Column[] cols) {
        // always use dict for index names because no spec mandates them
        // based on defaults
        DBIdentifier sName = name;
        if (DBIdentifier.isNull(sName))
            sName = cols[0].getIdentifier();

        if (_removeHungarianNotation)
            sName = DBIdentifier.removeHungarianNotation(sName);
View Full Code Here

        // this is necessary to support openjpa 3 mappings, which didn't
        // differentiate between secondary table joins and relations built
        // around an inverse key: check to see if we're mapped as a secondary
        // table join but we're in the table of the related type, and if so
        // switch our join mapping info to our value mapping info
        DBIdentifier tableName = field.getMappingInfo().getTableIdentifier();
        Table table = field.getTypeMapping().getTable();
        ValueMappingInfo vinfo = field.getValueInfo();
        if (!DBIdentifier.isNull(tableName) && table != null
            && (tableName.equals(table.getIdentifier())
            || tableName.equals(table.getFullIdentifier()))) {
            vinfo.setJoinDirection(MappingInfo.JOIN_INVERSE);
            vinfo.setColumns(field.getMappingInfo().getColumns());
            field.getMappingInfo().setTableIdentifier(DBIdentifier.NULL);
            field.getMappingInfo().setColumns(null);
        }
View Full Code Here

            Column pkColumn) {
        if (isDB2ZOSV8xOrLater()) {
            // build the index for the sequence tables
            // the index name will be the fully qualified table name + _IDX
            Table tab = schema.getTable(table);
            DBIdentifier fullIdxId = tab.getFullIdentifier().clone();
            DBIdentifier unQualifiedName = DBIdentifier.append(fullIdxId.getUnqualifiedName(), "IDX");
            fullIdxId.setName(getValidIndexName(unQualifiedName, tab));
            Index idx = tab.addIndex(fullIdxId);
            idx.setUnique(true);
            idx.addColumn(pkColumn);
        }
View Full Code Here

        StringBuilder buf = new StringBuilder();
        buf.append("CREATE ");
        if (index.isUnique())
            buf.append("UNIQUE ");
       
        DBIdentifier fullIdxName = index.getIdentifier();
        DBIdentifier unQualifiedName = fullIdxName.getUnqualifiedName();
        checkNameLength(toDBName(unQualifiedName), maxIndexNameLength,
                "long-index-name");
        String indexName = toDBName(fullIdxName);
        
        buf.append("INDEX ").append(indexName);
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.identifier.DBIdentifier

Copyright © 2018 www.massapicom. 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.