Package org.jpox.store.rdbms.key

Examples of org.jpox.store.rdbms.key.PrimaryKey


     * to add on any specification of PK name in the metadata.
     * @return The primary key.
     */
    public PrimaryKey getPrimaryKey()
    {
        PrimaryKey pk = super.getPrimaryKey();
        if (joinMetaData == null)
        {
            // TODO Localise this message
            throw new JPOXUserException("A relationship to a secondary table requires a <join> specification. " +
                "The secondary table is " + this.getDatastoreIdentifierFullyQualified() +
                " and the primary table is " + this.getPrimaryDatastoreContainerObject() +
                ". The fields mapped to this secondary table are: " + fieldMappingsMap.keySet().toString());
        }
        PrimaryKeyMetaData pkmd = joinMetaData.getPrimaryKeyMetaData();
        if (pkmd != null && pkmd.getName() != null)
        {
            pk.setName(pkmd.getName());
        }

        return pk;
    }
View Full Code Here


     * to add on any specification of PK name in the &lt;join&gt; metadata.
     * @return The primary key.
     */
    public PrimaryKey getPrimaryKey()
    {
        PrimaryKey pk = super.getPrimaryKey();
        if (fmd.getJoinMetaData() != null)
        {
            PrimaryKeyMetaData pkmd = fmd.getJoinMetaData().getPrimaryKeyMetaData();
            if (pkmd != null && pkmd.getName() != null)
            {
                pk.setName(pkmd.getName());
            }
        }

        return pk;
    }
View Full Code Here

        }

        // PRIMARY KEY(col[,col])
        if (supportsPrimaryKeyInCreateStatements())
        {
            PrimaryKey pk = table.getPrimaryKey();
            if (pk != null && pk.size() > 0)
            {
                createStmt.append(",").append(getContinuationString());
                createStmt.append("    ").append(pk.toString());
            }
        }

        // UNIQUE( col [,col] )
        if (supportsUniqueConstraintsInEndCreateStatements())
View Full Code Here

     * the pk.size() will be 0.
     * @return The primary key.
     */
    public PrimaryKey getPrimaryKey()
    {
        PrimaryKey pk = new PrimaryKey(this);
        Iterator i = columns.iterator();
        while (i.hasNext())
        {
            Column col = (Column) i.next();
            if (col.isPrimaryKey())
            {
                pk.addDatastoreField(col);
            }
        }

        return pk;
    }
View Full Code Here

     */
    protected boolean validatePrimaryKey(Connection conn)
    throws SQLException
    {
        Map actualPKs = getExistingPrimaryKeys(conn);
        PrimaryKey expectedPK = getPrimaryKey();
        if (expectedPK.size() == 0)
        {
            if (!actualPKs.isEmpty())
            {
                throw new WrongPrimaryKeyException(this.toString(), expectedPK.toString(), StringUtils.collectionToString(actualPKs.values()));
            }
        }
        else
        {
            if (actualPKs.size() != 1 ||
                !actualPKs.values().contains(expectedPK))
            {
                throw new WrongPrimaryKeyException(this.toString(), expectedPK.toString(), StringUtils.collectionToString(actualPKs.values()));
            }
        }

        return true;
    }
View Full Code Here

         * equal to the primary key (then they are indexed anyway).
         * Ensure that we have separate indices for foreign key columns
         * if the primary key is the combination of foreign keys, e.g. in join tables.
         * This greatly decreases deadlock probability e.g. on Oracle.
         */
        PrimaryKey pk = getPrimaryKey();
        Iterator i = getExpectedForeignKeys(clr).iterator();
        while (i.hasNext())
        {
            ForeignKey fk = (ForeignKey) i.next();
            if (!pk.getColumnList().equals(fk.getColumnList()))
            {
                indices.add(new Index(fk));
            }
        }

View Full Code Here

                }
                else
                {
                    pkName = idFactory.newIdentifier(IdentifierFactory.COLUMN, s);
                }
                PrimaryKey pk = (PrimaryKey) primaryKeysByName.get(pkName);
                if (pk == null)
                {
                    pk = new PrimaryKey(this);
                    pk.setName(pkName.getIdentifier());
                    primaryKeysByName.put(pkName, pk);
                }

                int keySeq = rs.getInt(5) - 1;
                DatastoreIdentifier colName = idFactory.newIdentifier(IdentifierFactory.COLUMN, rs.getString(4));
                Column col = (Column) columnsByName.get(colName);

                if (col == null)
                {
                    throw new UnexpectedColumnException(this.toString(), colName.getIdentifier(), this.getSchemaName(), this.getCatalogName());
                }
                pk.setDatastoreField(keySeq, col);
            }
        }
        finally
        {
            if (rs.getStatement() != null)
View Full Code Here

        assertIsInitialized();

        ArrayList stmts = new ArrayList();
        stmts.add(dba.getCreateTableStatement(this, (Column[]) columns.toArray(new Column[columns.size()]), props));

        PrimaryKey pk = getPrimaryKey();
        if (pk.size() > 0)
        {
            // Some databases define the primary key on the create table
            // statement so we don't have a Statement for the primary key here.
            String pkStmt = dba.getAddPrimaryKeyStatement(pk, storeMgr.getIdentifierFactory());
            if (pkStmt != null)
View Full Code Here

            // TODO Go to the datastore and query for this table to get the columns of the PK
            JPOXLogger.DATASTORE_SCHEMA.warn(LOCALISER.msg("058106", acmd.getFullClassName(),
                fkmd.getTable()));
            return null;
        }
        PrimaryKey pk = refTable.getPrimaryKey();
        List targetCols = pk.getColumns();

        // Generate the columns for the source of the foreign-key
        List sourceCols = new ArrayList();
        ColumnMetaData[] colmds = fkmd.getColumnMetaData();
        AbstractMemberMetaData[] fmds = fkmd.getMemberMetaData();
View Full Code Here

     * to add on any specification of PK name in the metadata.
     * @return The primary key.
     */
    public PrimaryKey getPrimaryKey()
    {
        PrimaryKey pk = super.getPrimaryKey();
        PrimaryKeyMetaData pkmd = cmd.getPrimaryKeyMetaData();
        if (pkmd != null && pkmd.getName() != null)
        {
            pk.setName(pkmd.getName());
        }

        return pk;
    }
View Full Code Here

TOP

Related Classes of org.jpox.store.rdbms.key.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.