Package org.apache.openjpa.jdbc.schema

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


        field.setColumnIO(vinfo.getColumnIO());
        field.mapConstraints(field.getName(), adapt);

        // add primary key columns to table pk if logical
        field.mapPrimaryKey(adapt);
        PrimaryKey pk = field.getTable().getPrimaryKey();
        if (field.isPrimaryKey() && pk != null && (adapt || pk.isLogical()))
            pk.addColumn(cols[0]);

        // set joinable
        field.getDefiningMapping().setJoinable(field.getColumns()[0], this);
    }
View Full Code Here


            cls.setColumnIO(info.getColumnIO());
        }
        cls.setTable(table);

        // add a primary key if we don't have one already
        PrimaryKey pk = table.getPrimaryKey();
        if (pk == null) {
            String pkname = null;
            if (adapt)
                pkname = cls.getMappingRepository().getMappingDefaults().
                    getPrimaryKeyName(cls, table);
            pk = table.addPrimaryKey(pkname);
            pk.setLogical(!adapt);
            if (pkCols != null)
                pk.setColumns(pkCols);
        }

        // set joinable
        if (cls.getIdentityType() == ClassMapping.ID_DATASTORE)
            cls.setJoinable(cls.getPrimaryKeyColumns()[0],
View Full Code Here

        return col;
    }

    public PrimaryKey newPrimaryKey(ResultSet pkMeta)
        throws SQLException {
        PrimaryKey pk = super.newPrimaryKey(pkMeta);
        if (swapSchemaAndCatalog)
            pk.setSchemaName(pkMeta.getString("TABLE_CAT"));
        return pk;
    }
View Full Code Here

    }

    public boolean needsToCreateIndex(Index idx, Table table) {
       // Informix will automatically create a unique index for the
       // primary key, so don't create another index again
       PrimaryKey pk = table.getPrimaryKey();
       if (pk != null && idx.columnsMatch(pk.getColumns()))
           return false;
       return true;
    }
View Full Code Here

        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));
View Full Code Here

        }

        // do this before getting the columns so we know how to handle
        // the last comma
        StringBuffer endBuf = new StringBuffer();
        PrimaryKey pk = table.getPrimaryKey();
        String pkStr;
        if (pk != null) {
            pkStr = getPrimaryKeyConstraintSQL(pk);
            if (pkStr != null)
                endBuf.append(pkStr);
View Full Code Here

    /**
     * Create a new primary key from the information in the schema metadata.
     */
    protected PrimaryKey newPrimaryKey(ResultSet pkMeta)
        throws SQLException {
        PrimaryKey pk = new PrimaryKey();
        pk.setSchemaName(pkMeta.getString("TABLE_SCHEM"));
        pk.setTableName(pkMeta.getString("TABLE_NAME"));
        pk.setColumnName(pkMeta.getString("COLUMN_NAME"));
        pk.setName(pkMeta.getString("PK_NAME"));
        return pk;
    }
View Full Code Here

            pks = meta.getBestRowIdentifier(catalog, schemaName,
                tableName, 0, false);

            List pkList = new ArrayList();
            while (pks != null && pks.next()) {
                PrimaryKey pk = new PrimaryKey();
                pk.setSchemaName(schemaName);
                pk.setTableName(tableName);
                pk.setColumnName(pks.getString("COLUMN_NAME"));
                pkList.add(pk);
            }
            return (PrimaryKey[]) pkList.toArray
                (new PrimaryKey[pkList.size()]);
        } finally {
View Full Code Here

                + "-no-fkcol-name-adapt", context));

        if (name == null && targetName == null) {
            // if no name or target is provided and there's more than one likely
            // join possibility, too ambiguous
            PrimaryKey pk = foreign.getPrimaryKey();
            if (joins.length != 1 || pk == null || pk.getColumns().length != 1)
                throw new MetaDataException(_loc.get(prefix
                    + "-no-fkcol-name-adapt", context));

            // assume target is pk column
            targetName = pk.getColumns()[0].getName();
        } else if (name != null && targetName == null) {
            // if one primary key column use it for target; if multiple joins
            // look for a foreign column with same name as local column
            PrimaryKey pk = foreign.getPrimaryKey();
            if (joins.length == 1 && pk != null && pk.getColumns().length == 1)
                targetName = pk.getColumns()[0].getName();
            else if (foreign.getColumn(name) != null)
                targetName = name;
            else
                throw new MetaDataException(_loc.get(prefix
                    + "-no-fkcol-target-adapt", context, name));
View Full Code Here

        if (col.getName().equals(targetCol.getName()))
            return true;
        if (num > 1)
            return false;

        PrimaryKey pk = targetCol.getTable().getPrimaryKey();
        if (pk == null || pk.getColumns().length != 1)
            return false;
        return targetCol == pk.getColumns()[0];
    }
View Full Code Here

TOP

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

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.