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);
}
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);
}
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();
}
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());
}
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;
}
Aggregations