Package org.apache.openjpa.jdbc.schema

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


     */
    private Index findIndex(Column[] cols) {
        if (cols == null || cols.length == 0)
            return null;

        Table table = cols[0].getTable();
        Index[] idxs = table.getIndexes();
        for (int i = 0; i < idxs.length; i++)
            if (idxs[i].columnsMatch(cols))
                return idxs[i];
        return null;
    }
View Full Code Here


     */
    private Unique findUnique(Column[] cols) {
        if (cols == null || cols.length == 0)
            return null;

        Table table = cols[0].getTable();
        Unique[] unqs = table.getUniques();
        for (int i = 0; i < unqs.length; i++)
            if (unqs[i].columnsMatch(cols))
                return unqs[i];
        return null;
    }
View Full Code Here

     */
    private void mapSubclasses(Set tables) {
        // loop through tables until either all are mapped or none link to
        // a mapped base class table
        ClassMapping base, sub;
        Table table = null;
        ForeignKey fk = null;
        while (!tables.isEmpty()) {
            // find a table with a foreign key linking to a mapped table
            base = null;
            for (Iterator itr = tables.iterator(); itr.hasNext();) {
                table = (Table) itr.next();
                fk = getUniqueForeignKey(table);
                if (fk == null && table.getForeignKeys().length == 1)
                    fk = table.getForeignKeys()[0];
                else if (fk == null)
                    itr.remove();
                else {
                    base = (ClassMapping) _tables.get(fk.getPrimaryKeyTable());
                    if (base != null) {
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 signal 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

    /**
     * Create a new table from the information in the schema metadata.
     */
    protected Table newTable(ResultSet tableMeta)
        throws SQLException {
        Table t = new Table();
        t.setIdentifier(fromDBName(tableMeta.getString("TABLE_NAME"), DBIdentifierType.TABLE));
        return t;
    }
View Full Code Here

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

    /**
     * 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

    }
    /**
     * Create a forward foreign key to the given target.
     */
    private ForeignKey newForwardForeignKey(ClassMapping target) {
        Table table;
        Column[] cols;
        if (_fk == null) {
            table = _cols[0].getTable();
            cols = _cols;
        } else {
            table = _fk.getTable();
            cols = _fk.getColumns();
        }

        // gather target cols before adding foreign key to table in case
        // there is an error while looking for a target col
        Column[] tcols = new Column[cols.length];
        for (int i = 0; i < cols.length; i++) {
            if (cols[i].getTargetField() != null)
                tcols[i] = getEquivalentColumn(cols[i], target,
                    cols[i].getTargetField());
            else if (_fk != null)
                tcols[i] = getEquivalentColumn(_fk.getPrimaryKeyColumn
                    (cols[i]).getIdentifier(), target, true);
            else if (!DBIdentifier.isNull(cols[i].getTargetIdentifier()))
                tcols[i] = getEquivalentColumn(cols[i].getTargetIdentifier(), target,
                    true);
            else
                tcols[i] = getEquivalentColumn(cols[i].getIdentifier(), target,
                    false);
        }

        ForeignKey newfk = table.addForeignKey();
        newfk.setJoins(cols, tcols);
        if (_fk != null) {
            cols = _fk.getConstantColumns();
            for (int i = 0; i < cols.length; i++)
                newfk.joinConstant(cols[i], _fk.getConstant(cols[i]));
View Full Code Here

        if (_schemaName != null && _schemaName.getType() == DBIdentifierType.NULL){           
            String name = cls.getMappingRepository().getMetaDataFactory().getDefaults().getDefaultSchema();
            _schemaName = (name != null ? DBIdentifier.newSchema(name) : _schemaName);
        }       
       
        Table t = createTable(cls, new TableDefaults() {
            public String get(Schema schema) {
                // delay this so that we don't do schema reflection for unique
                // table name unless necessary
                return cls.getMappingRepository().getMappingDefaults().
                    getTableName(cls, schema);
            }
            public DBIdentifier getIdentifier(Schema schema) {
                return cls.getMappingRepository().getMappingDefaults().
                    getTableIdentifier(cls, schema);
            }
        }, _schemaName, tableName, adapt);
        t.setComment(cls.getTypeAlias() == null
            ? cls.getDescribedType().getName()
            : cls.getTypeAlias());
        return t;
    }
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.