Package org.apache.openjpa.jdbc.schema

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


    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

    /**
     * Return the alias for the give column
     */
    public String getColumnAlias(Column col, Object path) {
        Table table = col.getTable();
        String tableAlias = null;
        Iterator itr = getJoinIterator();
        while (itr.hasNext()) {
            Join join = (Join) itr.next();
            if (join != null) {
                if (join.getTable1() == table)
                    tableAlias = join.getAlias1();
                else if (join.getTable2() == table)
                    tableAlias = join.getAlias2();
                if (tableAlias != null)
                    return new StringBuilder(tableAlias).append(".").
                        append(_dict.getNamingUtil().toDBName(col.getIdentifier())).toString();
            }
        }
        throw new InternalException("Can not resolve alias for field: " +
            path.toString() + " mapped to column: " + col.getIdentifier().getName() +
            " table: "+table.getIdentifier().getName());
    }
View Full Code Here

    /**
     * Map this field to its table, optionally requiring that it be
     * in another table. Utility method for use by mapping strategies.
     */
    public void mapJoin(boolean adapt, boolean joinRequired) {
        Table table = _info.getTable(this, joinRequired, adapt);

        if(table != null && table.equals(getDefiningMapping().getTable())) {
            // Don't create a join if the field's table is the same as the
            // class's table.
            table = null;
        }

        ForeignKey join = null;
        if (table != null)
            join = _info.getJoin(this, table, adapt);
        if (join == null && joinRequired)
            throw new MetaDataException(_loc.get("join-required", this));

        if (join == null) {
            _info.assertNoJoin(this, true);
            _info.assertNoForeignKey(this, !adapt);
            _info.assertNoUnique(this, !adapt);
            _info.assertNoIndex(this, !adapt);
        } else {
            _fk = join;
            _io = _info.getColumnIO();
            _outer = _info.isJoinOuter();
            _unq = _info.getJoinUnique(this, false, adapt);
            _joinTableUniques = _info.getJoinTableUniques(this, false, adapt);
            _idx = _info.getJoinIndex(this, adapt);
            table.setAssociation();
        }
    }
View Full Code Here

        cls = mapping.getFieldMapping("toBlob").getHandler().getClass();
        assertTrue(cls.getName(),
            BlobValueHandler.class.isAssignableFrom(cls));

        SchemaGroup schema = repos.getSchemaGroup();
        Table table = schema.getSchemas()[0].getTables()[0];
        Column[] cols = table.getColumns();
        for (int i = 0; i < cols.length; i++) {
            if (cols[i].getName().equalsIgnoreCase("id")
                || cols[i].getName().equalsIgnoreCase("versn")
                || cols[i].getName().equalsIgnoreCase("typ"))
                continue;
View Full Code Here

       
        DBDictionary dict = new DBDictionary();
        dict.setConfiguration(mockConfiguration);
        dict.maxTableNameLength = 10;

        Table table = new Table();
        table.setIdentifier(DBIdentifier.newTable("NameIsTooLong"));
       
        try {
            dict.getCreateTableSQL(table);
            fail("Expected a UserException");
        } catch (UserException ue) {
View Full Code Here

       
        DBDictionary dict = new DBDictionary();
        dict.setConfiguration(mockConfiguration);
        dict.maxTableNameLength = 10;

        Table table = new Table();
        table.setIdentifier(DBIdentifier.newTable("NameIsTooLong"));
        table.setSchemaIdentifier(DBIdentifier.newSchema("IAmASchema"));
       
        try {
            dict.getCreateTableSQL(table);
            fail("Expected a UserException");
        } catch (UserException ue) {
View Full Code Here

       
        DBDictionary dict = new DBDictionary();
        dict.setConfiguration(mockConfiguration);
        dict.maxTableNameLength = 12;

        Table table = new Table();
        table.setIdentifier(DBIdentifier.newTable("NameIsRight"));
        table.setSchemaIdentifier(DBIdentifier.newSchema("IAmASchema"));
       
        String[] sqls = dict.getCreateTableSQL(table);
        assertEquals(1, sqls.length);
        assertTrue(sqls[0].contains("NameIsRight"));
        assertTrue(sqls[0].contains("IAmASchema"));
View Full Code Here

        DBDictionary dict = new DBDictionary();
        dict.setConfiguration(mockConfiguration);
        dict.tableLengthIncludesSchema=true;
        dict.maxTableNameLength = 12;

        Table table = new Table();
        table.setIdentifier(DBIdentifier.newTable("NameIsTooLong"));
        table.setSchemaIdentifier(DBIdentifier.newSchema("IAmASchema"));
       
        try {
            dict.getCreateTableSQL(table);
            fail("Expected a UserException");
        } catch (UserException ue) {
View Full Code Here

        DBDictionary dict = new DBDictionary();
        dict.setConfiguration(mockConfiguration);
        dict.tableLengthIncludesSchema=true;
        dict.maxTableNameLength = 18;

        Table table = new Table();
        table.setIdentifier(DBIdentifier.newTable("NameIsRight"));
        table.setSchemaIdentifier(DBIdentifier.newSchema("schema"));
       
        String[] sqls = dict.getCreateTableSQL(table);
        assertEquals(1, sqls.length);
        assertTrue(sqls[0].contains("NameIsRight"));
        assertTrue(sqls[0].contains("schema"));
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.