Package org.apache.openjpa.jdbc.schema

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


    /**
     * Create a new table from the information in the schema metadata.
     */
    protected Table newTable(ResultSet tableMeta)
        throws SQLException {
        Table t = new Table();
        t.setName(tableMeta.getString("TABLE_NAME"));
        return t;
    }
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

        // class will leave dangling relations; we might be able
        // to issue bulk deletes separately for the joins (possibly
        // using a temporary table to select the primary keys for
        // all the related tables and then issing a delete against those
        // keys), but that logic is not currently implemented
        Table table = getTable(mapping.getFieldMappings(), null);
        if (table == INVALID)
            return false;

        if (subclasses) {
            // if we are including subclasses, we also need to gather
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);
        ForeignKey join = null;
        if (table != null)
            join = _info.getJoin(this, table, adapt);
        if (join == null && joinRequired)
            throw new MetaDataException(_loc.get("join-required", this));
View Full Code Here

    public Unique[] getUniques(ClassMapping cm, boolean adapt) {
        if (_uniques == null || _uniques.isEmpty())
            return new Unique[0];
       
        Iterator uniqueConstraints = _uniques.iterator();
        Table table = cm.getTable();
        Collection result = new ArrayList();
        while (uniqueConstraints.hasNext()) {
            Unique template = (Unique) uniqueConstraints.next();
            Column[] templateColumns = template.getColumns();
            Column[] uniqueColumns = new Column[templateColumns.length];
            boolean missingColumn = true;
            for (int i=0; i<uniqueColumns.length; i++) {
                String columnName = templateColumns[i].getName();
                Column uniqueColumn = table.getColumn(columnName);
                missingColumn = (uniqueColumn == null);
                if (missingColumn) {
                    throw new UserException(_loc.get("missing-unique-column",
                        cm, table, columnName));
                }
View Full Code Here

            schemaName = Schemas.getNewTableSchema(_conf);

        SchemaGroup group = new SchemaGroup();
        Schema schema = group.addSchema(schemaName);

        Table table = schema.addTable(tableName);
        _pkColumn = addPrimaryKeyColumn(table);
        PrimaryKey pk = table.addPrimaryKey();
        pk.addColumn(_pkColumn);

        DBDictionary dict = _conf.getDBDictionaryInstance();
        _seqColumn = table.addColumn(dict.getValidColumnName
            (_seqColumnName, table));
        _seqColumn.setType(dict.getPreferredType(Types.BIGINT));
        _seqColumn.setJavaType(JavaTypes.LONG);
    }
View Full Code Here

    public Table getTable(final FieldMapping field, boolean create,
        boolean adapt) {
        if (_tableName == null && !create)
            return null;

        Table table = field.getDefiningMapping().getTable();
        String schemaName = (table == null) ? null
            : table.getSchema().getName();

        // if we have no join columns defined, there may be class-level join
        // information with a more fully-qualified name for our table
        String tableName = _tableName;
        if (tableName != null && getColumns().isEmpty())
View Full Code Here

        return name;
    }

    public String getTableName(FieldMapping fm, Schema schema) {
        String name = fm.getName();
        Table table = fm.getDefiningMapping().getTable();
        if (table != null) {
            String tableName = table.getName();
            if (tableName.length() > 5)
                tableName = tableName.substring(0, 5);
            name = tableName + "_" + name;
        }
        if (!_defMissing)
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.