Package liquibase.structure.core

Examples of liquibase.structure.core.PrimaryKey


public class PrimaryKeyTest  {

    @Test
    public void setColumn_singlePKColumn() {
        PrimaryKey pk = new PrimaryKey();
        pk.addColumn(0, new Column("id"));

        assertEquals(1, pk.getColumnNamesAsList().size());
    }
View Full Code Here


        assertEquals(1, pk.getColumnNamesAsList().size());
    }

    @Test
    public void setColumn_outOfOrder() {
        PrimaryKey pk = new PrimaryKey();
        pk.addColumn(1, new Column("id2"));
        pk.addColumn(0, new Column("id1"));

        assertEquals(2, pk.getColumnNamesAsList().size());
        assertEquals("id1", pk.getColumnNamesAsList().get(0));
        assertEquals("id2", pk.getColumnNamesAsList().get(1));
    }
View Full Code Here

        assertEquals("id2", pk.getColumnNamesAsList().get(1));
    }

    @Test
    public void setColumn_inOrder() {
        PrimaryKey pk = new PrimaryKey();
        pk.addColumn(0, new Column("id1"));
        pk.addColumn(1, new Column("id2"));

        assertEquals(2, pk.getColumnNamesAsList().size());
        assertEquals("id1", pk.getColumnNamesAsList().get(0));
        assertEquals("id2", pk.getColumnNamesAsList().get(1));
    }
View Full Code Here

                new UnparsedSql(sql, getAffectedPrimaryKey(statement))
        };
    }

    protected PrimaryKey getAffectedPrimaryKey(DropPrimaryKeyStatement statement) {
        return new PrimaryKey().setName(statement.getConstraintName()).setTable((Table) new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName()));
    }
View Full Code Here

                setAutoIncrement(false);
            }


            Table table = (Table) columnSnapshot.getRelation();
            PrimaryKey primaryKey = table.getPrimaryKey();
            if (primaryKey != null && primaryKey.getColumnNamesAsList().contains(columnSnapshot.getName())) {
                constraints.setPrimaryKey(true);
                constraints.setPrimaryKeyName(primaryKey.getName());
                constraints.setPrimaryKeyTablespace(primaryKey.getTablespace());
                nonDefaultConstraints = true;
            }

            List<UniqueConstraint> uniqueConstraints = table.getUniqueConstraints();
            if (uniqueConstraints != null) {
View Full Code Here

                    status.assertCorrect(columnSnapshot != null, "Column "+columnConfig.getName()+" is missing");
                    if (columnSnapshot != null) {
                        ConstraintsConfig constraints = columnConfig.getConstraints();
                        if (constraints != null) {
                            if (constraints.isPrimaryKey() != null && constraints.isPrimaryKey()) {
                                PrimaryKey tablePk = tableSnapshot.getPrimaryKey();
                                status.assertCorrect(tablePk != null && tablePk.getColumnNamesAsList().contains(columnConfig.getName()), "Column "+columnConfig.getName()+" is not part of the primary key");
                            }
                            if (constraints.isNullable() != null) {
                                if (constraints.isNullable()) {
                                    status.assertCorrect(columnSnapshot.isNullable() == null || columnSnapshot.isNullable(), "Column "+columnConfig.getName()+" nullability does not match");
                                } else {
View Full Code Here

    }


    @Override
    public String[] hash(DatabaseObject databaseObject, Database accordingTo, DatabaseObjectComparatorChain chain) {
        PrimaryKey pk = (PrimaryKey) databaseObject;
        if (databaseObject.getName() == null) {
            return DatabaseObjectComparatorFactory.getInstance().hash(pk.getTable(), accordingTo);
        } else {
            if (pk.getTable() == null || pk.getTable().getName() == null) {
                return new String[] {pk.getName().toLowerCase() };
            } else {
                return new String[] {pk.getName().toLowerCase(), pk.getTable().getName().toLowerCase()};
            }
        }
    }
View Full Code Here

    public boolean isSameObject(DatabaseObject databaseObject1, DatabaseObject databaseObject2, Database accordingTo, DatabaseObjectComparatorChain chain) {
        if (!(databaseObject1 instanceof PrimaryKey && databaseObject2 instanceof PrimaryKey)) {
            return false;
        }

        PrimaryKey thisPrimaryKey = (PrimaryKey) databaseObject1;
        PrimaryKey otherPrimaryKey = (PrimaryKey) databaseObject2;

        if (thisPrimaryKey.getTable() != null && thisPrimaryKey.getTable().getName() != null && otherPrimaryKey.getTable() != null && otherPrimaryKey.getTable().getName() != null) {
            return DatabaseObjectComparatorFactory.getInstance().isSameObject(thisPrimaryKey.getTable(), otherPrimaryKey.getTable(), accordingTo);
        } else {
            return StringUtils.trimToEmpty(thisPrimaryKey.getName()).equalsIgnoreCase(otherPrimaryKey.getName());
        }
    }
View Full Code Here

        return new Change[] {createTableChange };
    }

    @Override
    public void checkDiffResult(DiffResult diffResult, DropPrimaryKeyChange change) {
        assertNotNull(diffResult.getMissingObject(new PrimaryKey(change.getConstraintName(), change.getCatalogName(), change.getSchemaName(), change.getTableName())));
    }
View Full Code Here

                new UnparsedSql(sql, getAffectedPrimaryKey(statement))
        };
    }

    protected PrimaryKey getAffectedPrimaryKey(AddPrimaryKeyStatement statement) {
        return new PrimaryKey().setTable((Table) new Table().setName(statement.getTableName()).setSchema(statement.getCatalogName(), statement.getSchemaName()));
    }
View Full Code Here

TOP

Related Classes of liquibase.structure.core.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.