Package org.apache.openjpa.jdbc.schema

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


            if (i > 0)
                buf.append(", ");
            buf.append(getDeclareColumnSQL(cols[i], false));
        }

        PrimaryKey pk = table.getPrimaryKey();
        String pkStr;
        if (pk != null) {
            pkStr = getPrimaryKeyConstraintSQL(pk);
            if (!StringUtils.isEmpty(pkStr))
                buf.append(", ").append(pkStr);
View Full Code Here


    /**
     * Return whether the given foreign key is unique.
     */
    public boolean isUnique(ForeignKey fk) {
        PrimaryKey pk = fk.getTable().getPrimaryKey();
        if (pk != null && pk.columnsMatch(fk.getColumns()))
            return true;
        Index[] idx = fk.getTable().getIndexes();
        for (int i = 0; i < idx.length; i++)
            if (idx[i].isUnique() && idx[i].columnsMatch(fk.getColumns()))
                return true;
View Full Code Here

     * If the given table has a single unique foreign key or a foreign
     * key that matches the primary key, return it. Else return null.
     */
    public ForeignKey getUniqueForeignKey(Table table) {
        ForeignKey[] fks = table.getForeignKeys();
        PrimaryKey pk = table.getPrimaryKey();
        ForeignKey unq = null;
        int count = 0;
        for (int i = 0; i < fks.length; i++) {
            if (pk != null && pk.columnsMatch(fks[i].getColumns()))
                return fks[i];
            if (!isUnique(fks[i]))
                continue;

            count++;
View Full Code Here

                mapForeignKey(cls, fks[i], join, outer);

        // map any columns not controlled by foreign keys; also force primary
        // key cols to get mapped to simple fields even if the columns are
        // also foreign key columns
        PrimaryKey pk = (join != null) ? null : table.getPrimaryKey();
        boolean pkcol;
        Column[] cols = table.getColumns();
        for (int i = 0; i < cols.length; i++) {
            pkcol = pk != null && pk.containsColumn(cols[i]);
            if (pkcol && cls.getIdentityType() == ClassMapping.ID_DATASTORE)
                continue;
            if ((cls.getPCSuperclass() == null && pkcol)
                || !isForeignKeyColumn(cols[i]))
                mapColumn(cls, cols[i], join, outer);
View Full Code Here

        }

        // do this before getting the columns so we know how to handle
        // the last comma
        StringBuilder endBuf = new StringBuilder();
        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.setSchemaIdentifier(fromDBName(pkMeta.getString("TABLE_SCHEM"), DBIdentifierType.SCHEMA));
        pk.setTableIdentifier(fromDBName(pkMeta.getString("TABLE_NAME"), DBIdentifierType.TABLE));
        pk.setColumnIdentifier(fromDBName(pkMeta.getString("COLUMN_NAME"), DBIdentifierType.COLUMN));
        pk.setIdentifier(fromDBName(pkMeta.getString("PK_NAME"), DBIdentifierType.CONSTRAINT));
        return pk;
    }
View Full Code Here

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

            List pkList = new ArrayList();
            while (pks != null && pks.next()) {
                PrimaryKey pk = new PrimaryKey();
                pk.setSchemaIdentifier(schemaName);
                pk.setTableIdentifier(tableName);
                pk.setColumnIdentifier(fromDBName(pks.getString("COLUMN_NAME"), DBIdentifierType.COLUMN));
                pkList.add(pk);
            }
            return (PrimaryKey[]) pkList.toArray
                (new PrimaryKey[pkList.size()]);
        } finally {
View Full Code Here

        // add an identity column if we do not already have one
        if (!hasIdentity)
            buf.append(", ").append(identityColumnName).
                append(" NUMERIC IDENTITY UNIQUE");

        PrimaryKey pk = table.getPrimaryKey();
        if (pk != null)
            buf.append(", ").append(getPrimaryKeyConstraintSQL(pk));

        Unique[] unqs = table.getUniques();
        String unqStr;
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.setSchemaIdentifier(fromDBName(getStringFromResultSet(pkMeta, "TABLE_SCHEM", "table_owner"),
            DBIdentifierType.SCHEMA));
        pk.setTableIdentifier(fromDBName(getStringFromResultSet(pkMeta, "TABLE_NAME", "table_name"),
            DBIdentifierType.TABLE));
        pk.setColumnIdentifier(fromDBName(getStringFromResultSet(pkMeta, "COLUMN_NAME", "column_name"),
            DBIdentifierType.COLUMN));
        pk.setIdentifier(fromDBName(getStringFromResultSet(pkMeta, "PK_NAME", "index_name"),
            DBIdentifierType.CONSTRAINT));
        return pk;
    }
View Full Code Here

        }

        // do this before getting the columns so we know how to handle
        // the last comma
        StringBuilder endBuf = new StringBuilder();
        PrimaryKey pk = table.getPrimaryKey();
        String pkStr;
        if (pk != null) {
            pkStr = getPrimaryKeyConstraintSQL(pk);
            if (pkStr != null)
                endBuf.append(pkStr);
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.