Search in sources :

Example 31 with Database

use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.

the class AbstractDatabasePlatform method createTables.

public void createTables(boolean dropTablesFirst, boolean continueOnError, Table... tables) {
    Database database = new Database();
    database.addTables(tables);
    createDatabase(database, dropTablesFirst, continueOnError);
}
Also used : Database(org.jumpmind.db.model.Database)

Example 32 with Database

use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.

the class AbstractDdlBuilder method alterTable.

public String alterTable(Table currentTable, Table desiredTable, IAlterDatabaseInterceptor... alterDatabaseInterceptors) {
    Database currentModel = new Database();
    currentModel.addTable(currentTable);
    Database desiredModel = new Database();
    desiredModel.addTable(desiredTable);
    return alterDatabase(currentModel, desiredModel, alterDatabaseInterceptors);
}
Also used : Database(org.jumpmind.db.model.Database)

Example 33 with Database

use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.

the class DatabaseXmlAsciiDocBuilder method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("Usage: <input_xml_file> <output_asciidoc_file>");
        System.exit(-1);
    }
    Database db = DatabaseXmlUtil.read(new File(args[0]));
    PrintWriter out = new PrintWriter(new FileWriter(args[1]));
    Table[] tables = db.getTables();
    for (Table table : tables) {
        out.println("=== " + table.getName().toUpperCase());
        out.println();
        if (isNotBlank(table.getDescription())) {
            out.println(table.getDescription());
        }
        out.println();
        out.print(".");
        out.println(table.getName().toUpperCase());
        out.println("[cols=\"3,^1,^1,^1,^1,^1,5\"]");
        out.println("|===");
        out.println();
        out.println("|Name|Type|Size|Default|Keys|Not Null|Description");
        for (Column column : table.getColumns()) {
            out.print("|");
            out.print(column.getName().toUpperCase());
            out.print("|");
            out.print(column.getMappedType());
            out.print("|");
            out.print(isNotBlank(column.getSize()) ? column.getSize() : " ");
            out.print("|");
            out.print(isNotBlank(column.getDefaultValue()) ? column.getDefaultValue() : " ");
            out.print("|");
            if (column.isPrimaryKey()) {
                out.print("PK ");
            }
            ForeignKey[] keys = table.getForeignKeys();
            boolean fk = false;
            for (ForeignKey foreignKey : keys) {
                Reference[] references = foreignKey.getReferences();
                for (Reference reference : references) {
                    if (reference.getLocalColumn().getName().equals(column.getName()) && !fk) {
                        out.print("FK");
                        fk = true;
                    }
                }
            }
            out.print("|");
            if (column.isRequired()) {
                out.print("X");
            }
            out.print("|");
            out.println(column.getDescription());
        }
        out.println("|===");
    }
    out.close();
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) Reference(org.jumpmind.db.model.Reference) FileWriter(java.io.FileWriter) Database(org.jumpmind.db.model.Database) ForeignKey(org.jumpmind.db.model.ForeignKey) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 34 with Database

use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.

the class DatabaseXmlUtilTest method testReadXml.

@Test
public void testReadXml() {
    Database database = DatabaseXmlUtil.read(getClass().getResourceAsStream("/testDatabaseIO.xml"));
    assertNotNull(database);
    assertEquals(2, database.getTableCount());
    assertEquals("test", database.getName());
    Table table = database.getTable(0);
    assertEquals("test_simple_table", table.getName());
    assertEquals(8, table.getColumnCount());
    assertEquals(1, table.getPrimaryKeyColumnCount());
    assertEquals("id", table.getPrimaryKeyColumnNames()[0]);
    Table tableWithAmp = database.getTable(1);
    assertEquals("testColumnWith&", tableWithAmp.getName());
    assertEquals("&Amp", tableWithAmp.getColumn(0).getName());
}
Also used : Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) Test(org.junit.Test)

Example 35 with Database

use of org.jumpmind.db.model.Database in project symmetric-ds by JumpMind.

the class DbExport method getDatabase.

protected Database getDatabase(Table[] tables) {
    Database db = new Database();
    try {
        if (!noCreateInfo) {
            for (Table table : tables) {
                Table newTable = (Table) table.clone();
                if (noIndices) {
                    newTable.removeAllIndices();
                }
                if (noForeignKeys) {
                    newTable.removeAllForeignKeys();
                }
                db.addTable(newTable);
            }
        } else if (addDropTable) {
            for (Table table : tables) {
                Table newTable = (Table) table.clone();
                db.addTable(newTable);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return db;
}
Also used : Table(org.jumpmind.db.model.Table) Database(org.jumpmind.db.model.Database) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

Database (org.jumpmind.db.model.Database)37 Table (org.jumpmind.db.model.Table)21 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)9 Test (org.junit.Test)7 IOException (java.io.IOException)6 IoException (org.jumpmind.exception.IoException)6 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)5 IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)4 SqlException (org.jumpmind.db.sql.SqlException)4 SqlScript (org.jumpmind.db.sql.SqlScript)4 DbExport (org.jumpmind.symmetric.io.data.DbExport)4 DbImport (org.jumpmind.symmetric.io.data.DbImport)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 InputStreamReader (java.io.InputStreamReader)2 LinkedHashMap (java.util.LinkedHashMap)2 AddTableChange (org.jumpmind.db.alter.AddTableChange)2 RemoveTableChange (org.jumpmind.db.alter.RemoveTableChange)2 TableChange (org.jumpmind.db.alter.TableChange)2 Column (org.jumpmind.db.model.Column)2