use of org.whole.lang.rdb.model.Database in project whole by wholeplatform.
the class ImportSchemaExample method importSchema.
protected void importSchema() throws Exception {
// create a connection to a local database
Class.forName("org.h2.Driver");
Connection connection = DriverManager.getConnection("jdbc:h2:mem:" + DBNAME);
// reverse engineer
DBSchemaTemplateFactory dbSchemaTemplateFactory = new DBSchemaTemplateFactory(connection, DBNAME, null);
Database database = dbSchemaTemplateFactory.create();
// pretty print the obtained model
PrettyPrinterOperation.prettyPrint(database);
connection.close();
}
use of org.whole.lang.rdb.model.Database in project whole by wholeplatform.
the class DBSchemaTemplateFactoryTest method testRDBSchemaTemplateFactory.
@Test
public void testRDBSchemaTemplateFactory() throws Exception {
IBindingManager bm = BindingManagerFactory.instance.createArguments();
bm.wDefValue("connection", connection);
bm.wDefValue("generateDropStatements", false);
Database template = new CycleModel().create();
Database database = EntityUtils.clone(template);
Matcher.removeVars(database, true);
InterpreterOperation.interpret(database, bm);
DBSchemaTemplateFactory dbSchemaTemplateFactory = new DBSchemaTemplateFactory(connection, null, "PUBLIC");
Database generatedDatabase = dbSchemaTemplateFactory.create();
HashMap<EntityDescriptor<?>, Comparator<IEntity>> comparatorsMap = new HashMap<EntityDescriptor<?>, Comparator<IEntity>>();
comparatorsMap.put(RDBEntityDescriptorEnum.Tables, new OrderedMatcher.SimpleFeatureComparator(RDBFeatureDescriptorEnum.name));
Assert.assertTrue(OrderedMatcher.match(template, generatedDatabase, comparatorsMap));
}
use of org.whole.lang.rdb.model.Database in project whole by wholeplatform.
the class SQLInterpreterTest method testMapAuthorsQuery2.
@Test
public void testMapAuthorsQuery2() {
IBindingManager bm = BindingManagerFactory.instance.createArguments();
bm.wDefValue("connection", connection);
bm.wDefValue("generateDropStatements", false);
Database database = new SampleDatabase().create();
InterpreterOperation.interpret(database, bm);
IEntity e = DBMappingTemplateManager.instance().create("populateDB");
InterpreterOperation.interpret(e, bm);
IEntity map = DBMappingTemplateManager.instance().create("mapAuthorsQuery2");
IEntity results = DBMappingTemplateManager.instance().create("mapAuthorsResults");
int index = 0;
for (IEntity result : DynamicCompilerOperation.compile(map, bm).getResultIterator()) {
IEntity expectedResult = results.wGet(index++).wGet(0);
assertTrue(Matcher.match(expectedResult, result));
}
assertEquals(results.wSize(), index);
}
use of org.whole.lang.rdb.model.Database in project whole by wholeplatform.
the class DatabasePart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
Database entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(3);
list.add(entity.getUri());
list.add(entity.getNamespace());
list.add(entity.getSchemas());
return list;
}
Aggregations