Search in sources :

Example 6 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DifferenceTest method describeRefOnly.

@Test
public void describeRefOnly() {
    DbProperty refDbProp = mock(DbProperty.class);
    when(refDbProp.getPath()).thenReturn("alfresco.some_table.some_column");
    when(refDbProp.getDbObject()).thenReturn(new Column("some_column"));
    Difference diff = new Difference(Where.ONLY_IN_REFERENCE, refDbProp, null);
    assertEquals("Difference: missing column from database, expected at path: alfresco.some_table.some_column", diff.describe());
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) Test(org.junit.Test)

Example 7 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class MySQLDialectExportTester method checkOtherTable.

private void checkOtherTable(Schema schema, Table otherTable) {
    assertNotNull("Couldn't find table export_test_other", otherTable);
    assertSame("Incorrect parent or no parent set", schema, otherTable.getParent());
    Iterator<Column> colIt = otherTable.getColumns().iterator();
    Column col = colIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
    assertEquals("id", col.getName());
    assertEquals("bigint", col.getType());
    assertEquals(false, col.isNullable());
    assertEquals(1, col.getOrder());
    assertEquals(false, col.isAutoIncrement());
    col = colIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
    assertEquals("version", col.getName());
    assertEquals("bigint", col.getType());
    assertEquals(false, col.isNullable());
    assertEquals(2, col.getOrder());
    col = colIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
    assertEquals("ex_id", col.getName());
    assertEquals("bigint", col.getType());
    assertEquals(false, col.isNullable());
    assertEquals(3, col.getOrder());
    col = colIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
    assertSame("Incorrect parent or no parent set", otherTable, col.getParent());
    assertEquals("local_name", col.getName());
    assertEquals("varchar(200)", col.getType());
    assertEquals(false, col.isNullable());
    assertEquals(4, col.getOrder());
    assertEquals(2, otherTable.getIndexes().size());
    Iterator<Index> indexIt = otherTable.getIndexes().iterator();
    Index index = indexIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, index.getParent());
    assertEquals("export_test_idx_other_1", index.getName());
    assertEquals(true, index.isUnique());
    assertEquals(2, index.getColumnNames().size());
    assertEquals("ex_id", index.getColumnNames().get(0));
    assertEquals("local_name", index.getColumnNames().get(1));
    index = indexIt.next();
    assertSame("Incorrect parent or no parent set", otherTable, index.getParent());
    assertEquals("export_test_idx_other_2", index.getName());
    assertEquals(1, index.getColumnNames().size());
    assertEquals("ex_id", index.getColumnNames().get(0));
    PrimaryKey pk = otherTable.getPrimaryKey();
    assertSame("Incorrect parent or no parent set", otherTable, pk.getParent());
    assertEquals("id", pk.getColumnNames().get(0));
    assertEquals(1, pk.getColumnOrders().get(0).intValue());
    assertEquals(1, otherTable.getForeignKeys().size());
    ForeignKey fk = otherTable.getForeignKeys().get(0);
    assertSame("Incorrect parent or no parent set", otherTable, fk.getParent());
    assertEquals("export_test_fk_example", fk.getName());
    assertEquals("ex_id", fk.getLocalColumn());
    assertEquals("export_test_example", fk.getTargetTable());
    assertEquals("id", fk.getTargetColumn());
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) PrimaryKey(org.alfresco.util.schemacomp.model.PrimaryKey) Index(org.alfresco.util.schemacomp.model.Index) ForeignKey(org.alfresco.util.schemacomp.model.ForeignKey)

Example 8 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class XMLToSchema method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (qName.equals(XML.EL_TABLE)) {
        Table table = (Table) stack.pop();
        schema.add(table);
    } else if (qName.equals(XML.EL_COLUMN)) {
        Column column = (Column) stack.pop();
        Table table = (Table) stack.peek();
        column.setParent(table);
        table.getColumns().add(column);
    } else if (qName.equals(XML.EL_PRIMARY_KEY)) {
        PrimaryKey pk = (PrimaryKey) stack.pop();
        Table table = (Table) stack.peek();
        table.setPrimaryKey(pk);
    } else if (qName.equals(XML.EL_FOREIGN_KEY)) {
        ForeignKey fk = (ForeignKey) stack.pop();
        Table table = (Table) stack.peek();
        fk.setParent(table);
        table.getForeignKeys().add(fk);
    } else if (qName.equals(XML.EL_INDEX)) {
        Index index = (Index) stack.pop();
        Table table = (Table) stack.peek();
        index.setParent(table);
        table.getIndexes().add(index);
    } else if (qName.equals(XML.EL_SEQUENCE)) {
        Sequence seq = (Sequence) stack.pop();
        seq.setParent(schema);
        schema.add(seq);
    } else if (qName.equals(XML.EL_VALIDATOR)) {
        DbValidator validator = (DbValidator) stack.pop();
        DbObject dbo = (DbObject) stack.peek();
        dbo.getValidators().add(validator);
    }
    // Deal with elements that contain text.
    if (lastText.length() != 0) {
        if (qName.equals(XML.EL_TYPE)) {
            Column column = (Column) stack.peek();
            column.setType(lastText.toString());
        } else if (qName.equals(XML.EL_NULLABLE)) {
            Column column = (Column) stack.peek();
            column.setNullable(Boolean.parseBoolean(lastText.toString()));
        } else if (qName.equals(XML.EL_AUTOINCREMENT)) {
            Column column = (Column) stack.peek();
            column.setAutoIncrement(Boolean.parseBoolean(lastText.toString()));
        } else if (qName.equals(XML.EL_COLUMN_NAME)) {
            if (stack.peek() instanceof PrimaryKey) {
                PrimaryKey pk = (PrimaryKey) stack.peek();
                pk.getColumnNames().add(lastText.toString());
            } else if (stack.peek() instanceof Index) {
                Index index = (Index) stack.peek();
                index.getColumnNames().add(lastText.toString());
            }
        } else if (qName.equals(XML.EL_LOCAL_COLUMN)) {
            ForeignKey fk = (ForeignKey) stack.peek();
            fk.setLocalColumn(lastText.toString());
        } else if (qName.equals(XML.EL_TARGET_TABLE)) {
            ForeignKey fk = (ForeignKey) stack.peek();
            fk.setTargetTable(lastText.toString());
        } else if (qName.equals(XML.EL_TARGET_COLUMN)) {
            ForeignKey fk = (ForeignKey) stack.peek();
            fk.setTargetColumn(lastText.toString());
        } else if (qName.equals(XML.EL_PROPERTY)) {
            String propValue = lastText.toString();
            String propName = (String) stack.pop();
            if (stack.peek() instanceof DbValidator) {
                @SuppressWarnings("unchecked") DbValidator validator = (DbValidator) stack.peek();
                validator.setProperty(propName, propValue);
            }
        }
    }
}
Also used : Table(org.alfresco.util.schemacomp.model.Table) Column(org.alfresco.util.schemacomp.model.Column) DbObject(org.alfresco.util.schemacomp.model.DbObject) PrimaryKey(org.alfresco.util.schemacomp.model.PrimaryKey) Index(org.alfresco.util.schemacomp.model.Index) Sequence(org.alfresco.util.schemacomp.model.Sequence) ForeignKey(org.alfresco.util.schemacomp.model.ForeignKey) DbValidator(org.alfresco.util.schemacomp.validator.DbValidator)

Example 9 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DbObjectXMLTransformer method transformTable.

private void transformTable(Table table) throws SAXException {
    // Output columns
    simpleStartTag(XML.EL_COLUMNS);
    for (Column column : table.getColumns()) {
        output(column);
    }
    simpleEndTag(XML.EL_COLUMNS);
    // Output primary key
    if (table.hasPrimaryKey()) {
        output(table.getPrimaryKey());
    }
    // Output foreign keys
    simpleStartTag(XML.EL_FOREIGN_KEYS);
    for (ForeignKey fk : table.getForeignKeys()) {
        output(fk);
    }
    simpleEndTag(XML.EL_FOREIGN_KEYS);
    // Output indexes
    simpleStartTag(XML.EL_INDEXES);
    for (Index index : table.getIndexes()) {
        output(index);
    }
    simpleEndTag(XML.EL_INDEXES);
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) Index(org.alfresco.util.schemacomp.model.Index) ForeignKey(org.alfresco.util.schemacomp.model.ForeignKey)

Example 10 with Column

use of org.alfresco.util.schemacomp.model.Column in project alfresco-repository by Alfresco.

the class DbObjectXMLTransformer method addAttributes.

/**
 * Add class-specific attributes.
 *
 * @param dbObject DbObject
 * @param attribs AttributesImpl
 */
private void addAttributes(DbObject dbObject, AttributesImpl attribs) {
    if (dbObject instanceof Schema) {
        Schema schema = (Schema) dbObject;
        attribs.addAttribute("", "", XML.ATTR_DB_PREFIX, "CDATA", schema.getDbPrefix());
        attribs.addAttribute("", "", XML.ATTR_VERSION, "CDATA", Integer.toString(schema.getVersion()));
        attribs.addAttribute("", "", XML.ATTR_TABLE_COLUMN_ORDER, "CDATA", Boolean.toString(schema.isCheckTableColumnOrder()));
    } else if (dbObject instanceof Index) {
        Index index = (Index) dbObject;
        attribs.addAttribute("", "", XML.ATTR_UNIQUE, "CDATA", Boolean.toString(index.isUnique()));
    } else if (dbObject instanceof Column) {
        Column column = (Column) dbObject;
        attribs.addAttribute("", "", XML.ATTR_ORDER, "CDATA", Integer.toString(column.getOrder()));
    }
}
Also used : Column(org.alfresco.util.schemacomp.model.Column) Schema(org.alfresco.util.schemacomp.model.Schema) Index(org.alfresco.util.schemacomp.model.Index)

Aggregations

Column (org.alfresco.util.schemacomp.model.Column)19 Index (org.alfresco.util.schemacomp.model.Index)11 PrimaryKey (org.alfresco.util.schemacomp.model.PrimaryKey)11 ForeignKey (org.alfresco.util.schemacomp.model.ForeignKey)10 Test (org.junit.Test)8 Table (org.alfresco.util.schemacomp.model.Table)7 BufferedReader (java.io.BufferedReader)5 StringReader (java.io.StringReader)5 Sequence (org.alfresco.util.schemacomp.model.Sequence)5 DbValidator (org.alfresco.util.schemacomp.validator.DbValidator)5 Schema (org.alfresco.util.schemacomp.model.Schema)4 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DbProperty (org.alfresco.util.schemacomp.DbProperty)1 ValidationResult (org.alfresco.util.schemacomp.ValidationResult)1 DbObject (org.alfresco.util.schemacomp.model.DbObject)1 NameValidator (org.alfresco.util.schemacomp.validator.NameValidator)1