Package org.jboss.dna.common.jdbc.model.api

Examples of org.jboss.dna.common.jdbc.model.api.PrimaryKey


        // check
        assertSame("Unable to find column", column, bean.findColumnByName(COLUMN_NAME));
    }

    public void testSetPrimaryKey() {
        PrimaryKey primaryKey = factory.createPrimaryKey();
        // set
        bean.setPrimaryKey(primaryKey);
        // check
        assertSame("Unable to set primary key", primaryKey, bean.getPrimaryKey());
    }
View Full Code Here


        assertSame("Unable to set source table", sourceTable, bean.getSourceTable());
    }

    public void testSetSourcePrimaryKey() {
        // create
        PrimaryKey primaryKey = new DefaultModelFactory().createPrimaryKey();
        // set
        bean.setSourcePrimaryKey(primaryKey);
        // check
        assertSame("Unable to set source primary key", primaryKey, bean.getSourcePrimaryKey());
    }
View Full Code Here

        String tableName = table.getName();
        // pk name
        String primaryKeyName = null; // initially null

        // create table's primary key
        PrimaryKey pk = factory.createPrimaryKey();

        // ***************************
        // *** DatabaseNamedObject ***
        // ***************************

        // set name
        // pk.setName (primaryKeyName); // it will be overriden later in this code
        // set remarks
        // pk.setRemarks (remarks); // N/A

        // TODO set extra properties
        // table.addExtraProperty (String key, Object value);

        // ********************
        // *** SchemaObject ***
        // ********************

        // set catalog
        pk.setCatalog(table.getCatalog());
        // set schema
        pk.setSchema(table.getSchema());

        // process all columns included into primary key
        while (resultSet.next()) {
            // get PK name
            if (primaryKeyName == null) {
                primaryKeyName = getString(resultSet, "PK_NAME", false);
                // set name
                pk.setName(primaryKeyName);
            }

            // column name
            String columnName = getString(resultSet, "COLUMN_NAME", false);
            // sequence number within primary key
            Integer ordinalPosition = getInteger(resultSet, "KEY_SEQ", false);

            // trying to find table column with specified name
            TableColumn tableColumn = table.findColumnByName(columnName);

            String errMessage = null;
            // warn if null
            if (tableColumn == null) {
                errMessage = String.format("[Database %s] Unable to find table column '%5$s' for the table %s (schema %s, catalog %s)",
                                           database.getName(),
                                           tableName,
                                           schemaName,
                                           catalogName,
                                           columnName);
                traceLog.debug(errMessage);
            }
            // if fail is enabled
            if (failOnError && (tableColumn == null)) {
                throw new DatabaseMetaDataMethodException(errMessage, "populatePrimaryKey");
            }

            // create PK column
            PrimaryKeyColumn pkColumn = factory.createPrimaryKeyColumn();
            // check if we found the original table column
            if (tableColumn != null) {
                // mark original table column as part of PK
                tableColumn.setPrimaryKeyColumn(Boolean.TRUE);
                // clone properties from original table column to the pkcolumn
                PropertyUtils.copyProperties(pkColumn, tableColumn);
            } else { // recovery if table column is not found but we still want to create pk column
                // set name at least
                pkColumn.setName(columnName);
            }
            // modify ordinal position that correspond to the position in PK
            pkColumn.setOrdinalPosition(ordinalPosition);

            // add PK column to the primary key
            pk.addColumn(pkColumn);
        }

        // set table primary key
        table.setPrimaryKey(pk);

View Full Code Here

                // check for PK table and corresponding PK column
                Table pkTable = database.findTableByName(pkTableCatalogName, pkTableSchemaName, pkTableName);
                // sets the scope table of a foreign key.
                fk.setSourceTable(pkTable);
                // find PK
                PrimaryKey pk = (pkTable == null) ? null : pkTable.getPrimaryKey();
                // set
                fk.setSourcePrimaryKey(pk);

                // What happens to a foreign key when the primary key is updated
                fk.setUpdateRule(getKeyModifyRuleType(updateRule));
View Full Code Here

TOP

Related Classes of org.jboss.dna.common.jdbc.model.api.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.