Package org.apache.openjpa.jdbc.schema

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


            // 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) {
                boolean createIndex = true;
                table1 = (inverse) ? fk.getPrimaryKeyTable() : fk.getTable();
                if (correlatedVar != null)
                    createIndex = false// not to create here
                alias1 = _sel.getTableIndex(table1, this, createIndex);
            }

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

            if (createJoin) {
                boolean createIndex = true;
                Table table2 = (inverse) ? fk.getTable()
                    : fk.getPrimaryKeyTable();
                boolean created = false;
                int alias2 = -1;
                if (table2.isAssociation()) {
                    alias2 = _sel.getTableIndex(table2, this, false);
                    if (alias2 == -1)
                        createIndex = true;
                    else
                        created = true;
View Full Code Here


    public void createIndexIfNecessary(Schema schema, DBIdentifier table,
            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

                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

        DBDictionary dict = conf.getDBDictionaryInstance();
        ClassMapping mapping =  (ClassMapping)conf.
            getMetaDataRepositoryInstance().
            getMetaData(EntityVeryLongNames.class,getClass().
                getClassLoader(), true);
        Table table = mapping.getTable();
        assertTrue(table.getName().length() > 0);
        assertTrue(table.getName().length() <= dict.maxTableNameLength);
        validateColumnNames(table, dict);
        mapping =  (ClassMapping)conf.
            getMetaDataRepositoryInstance().
            getMetaData(EntityReservedWords.class,getClass().
                getClassLoader(), true);
        table = mapping.getTable();
        assertTrue(table.getName().length() > 0);
        assertTrue(table.getName().length() <= dict.maxTableNameLength);
        validateColumnNames(table, dict);
    }
View Full Code Here

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

            // 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) {
                boolean createIndex = true;
                table1 = (inverse) ? fk.getPrimaryKeyTable() : fk.getTable();
                if (correlatedVar != null)
                    createIndex = false// not to create here
                alias1 = _sel.getTableIndex(table1, this, createIndex);
            }

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

            if (createJoin) {
                boolean createIndex = true;
                Table table2 = (inverse) ? fk.getTable()
                    : fk.getPrimaryKeyTable();
                boolean created = false;
                int alias2 = -1;
                if (table2.isAssociation()) {
                    alias2 = _sel.getTableIndex(table2, this, false);
                    if (alias2 == -1)
                        createIndex = true;
                    else
                        created = true;
View Full Code Here

            Schema schema = group.getSchema(schemaName);
            if (schema == null) {
                schema = group.addSchema(schemaName);
            }
           
            Table copy = schema.importTable(_pkColumn.getTable());
            // importTable() does not import unique constraints
            Unique[] uniques = _pkColumn.getTable().getUniques();
            for (Unique u : uniques) {
              copy.importUnique(u);
            }
            // we need to reset the table name in the column with the
            // fully qualified name for matching the table name from the
            // Column.
            _pkColumn.resetTableIdentifier(QualifiedDBIdentifier.newPath(schemaName, _pkColumn.getTableIdentifier()));
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.