Package org.apache.openjpa.jdbc.schema

Examples of org.apache.openjpa.jdbc.schema.Table


    /**
     * Returns a OpenJPA 3-compatible name for an auto-assign trigger.
     */
    protected String getOpenJPA3GeneratedKeyTriggerName(Column col) {
        Table table = col.getTable();       
        DBIdentifier sName = DBIdentifier.preCombine(table.getIdentifier(), "TRIG");
        return toDBName(getNamingUtil().makeIdentifierValid(sName, table.getSchema().
            getSchemaGroup(), maxTableNameLength, true));
    }
View Full Code Here


    public void createIndexIfNecessary(Schema schema, DBIdentifier table,
            Column pkColumn) {
        if (db2ServerType == db2ZOSV8xOrLater) {
            // 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

        MappingRepository repos = conf.newMappingRepositoryInstance();
        _mapping = repos.getMapping(MappingTest1.class, null, true);
    }

    public void testClassMapping() {
        Table table = _mapping.getTable();
        assertEquals("MAPPINGTEST1", table.getName().toUpperCase());
        assertEquals(1, table.getPrimaryKey().getColumns().length);
        int type = table.getPrimaryKey().getColumns()[0].getType();
        assertEquals(Schemas.getJDBCName(type), Types.INTEGER, type);
    }
View Full Code Here

    public void testMapping() {
        ClassMapping mapping = ((JDBCConfiguration) getConfiguration()).
            getMappingRepositoryInstance().
            getMapping(MappingTest5.class, null, true);

        Table supTable = mapping.getPCSuperclassMapping().getTable();
        assertTrue(mapping.getTable() != supTable);
        FieldMapping field = mapping.getFieldMapping("vertRel");
        ForeignKey fk = field.getForeignKey();
        assertEquals(mapping.getTable(), fk.getTable());
        assertEquals(supTable, fk.getPrimaryKeyTable());
View Full Code Here

        // 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
        String tableName = field.getMappingInfo().getTableName();
        Table table = field.getTypeMapping().getTable();
        ValueMappingInfo vinfo = field.getValueInfo();
        if (tableName != null && table != null
            && (tableName.equalsIgnoreCase(table.getName())
            || tableName.equalsIgnoreCase(table.getFullName()))) {
            vinfo.setJoinDirection(MappingInfo.JOIN_INVERSE);
            vinfo.setColumns(field.getMappingInfo().getColumns());
            field.getMappingInfo().setTableName(null);
            field.getMappingInfo().setColumns(null);
        }
View Full Code Here

            // get first table alias before updating path; if there is a from
            // select then we shouldn't actually create a join object, since
            // the joins will all be done in the from select
            boolean createJoin = _sel._from == null;
            Table table1 = null;
            int alias1 = -1;
            if (createJoin) {
                table1 = (inverse) ? fk.getPrimaryKeyTable() : fk.getTable();
                alias1 = _sel.getTableIndex(table1, this, true);
            }

            // update the path with the relation name before getting pk alias
            this.append(name);
            this.append(var);
            if (toMany) {
                _sel._flags |= IMPLICIT_DISTINCT;
                _sel._flags |= TO_MANY;
            }
            _outer = outer;

            if (createJoin) {
                Table table2 = (inverse) ? fk.getTable()
                    : fk.getPrimaryKeyTable();
                int alias2 = _sel.getTableIndex(table2, this, true);
                Join j = new Join(table1, alias1, table2, alias2, fk, inverse);
                j.setType((outer) ? Join.TYPE_OUTER : Join.TYPE_INNER);
View Full Code Here

    public void createIndexIfNecessary(Schema schema, String table,
            Column pkColumn) {
        if (isDB2ZOSV8xOrLater()) {
            // build the index for the sequence tables
            // the index name will the fully qualified table name + _IDX
            Table tab = schema.getTable(table);
            Index idx = tab.addIndex(tab.getFullName() + "_IDX");
            idx.setUnique(true);
            idx.addColumn(pkColumn);
        }
    }
View Full Code Here

    /**
     * Returns a OpenJPA 3-compatible name for an auto-assign sequence.
     */
    protected String getOpenJPA3GeneratedKeySequenceName(Column col) {
        Table table = col.getTable();
        return makeNameValid("SEQ_" + table.getName(), table.getSchema().
            getSchemaGroup(), maxTableNameLength, NAME_ANY);
    }
View Full Code Here

    /**
     * Returns a OpenJPA 3-compatible name for an auto-assign trigger.
     */
    protected String getOpenJPA3GeneratedKeyTriggerName(Column col) {
        Table table = col.getTable();
        return makeNameValid("TRIG_" + table.getName(), table.getSchema().
            getSchemaGroup(), maxTableNameLength, NAME_ANY);
    }
View Full Code Here

                sql.append(where);
            }
            return sql;
        }

        Table table = mapping.getTable();
        String tableName = getFullName(table, false);

        // only use a  subselect if the where is not empty; otherwise
        // an unqualified delete or update will work
        if (sel.getWhere() == null || sel.getWhere().isEmpty()) {
            sql.append(tableName);
            appendUpdates(sel, store, sql, params, updateParams, false);
            return sql;
        }

        // we need to use a subselect if we are to bulk delete where
        // the select includes multiple tables; if the database
        // doesn't support it, then we need to sigal this by returning null
        if (!supportsSubselect || !supportsCorrelatedSubselect)
            return null;

        Column[] pks = mapping.getPrimaryKeyColumns();
        sel.clearSelects();
        sel.setDistinct(true);

        // if we have only a single PK, we can use a non-correlated
        // subquery (using an IN statement), which is much faster than
        // a correlated subquery (since a correlated subquery needs
        // to be executed once for each row in the table)
        if (pks.length == 1) {
            sel.select(pks[0]);
            sql.append(tableName);
            appendUpdates(sel, store, sql, params, updateParams, false);
            sql.append(" WHERE ").
                append(pks[0]).append(" IN (").
                append(sel.toSelect(false, null)).append(")");
        } else {
            sel.clearSelects();
            sel.setDistinct(false);

            // since the select is using a correlated subquery, we
            // only need to select a bogus virtual column
            sel.select("1", null);

            // add in the joins to the table
            Column[] cols = table.getPrimaryKey().getColumns();
            SQLBuffer buf = new SQLBuffer(this);
            buf.append("(");
            for (int i = 0; i < cols.length; i++) {
                if (i > 0)
                    buf.append(" AND ");
View Full Code Here

TOP

Related Classes of org.apache.openjpa.jdbc.schema.Table

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.