Search in sources :

Example 6 with Database

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();
}
Also used : DBSchemaTemplateFactory(org.whole.lang.rdb.codebase.DBSchemaTemplateFactory) Connection(java.sql.Connection) Database(org.whole.lang.rdb.model.Database)

Example 7 with Database

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));
}
Also used : EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) HashMap(java.util.HashMap) IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) Comparator(java.util.Comparator) Test(org.junit.Test)

Example 8 with Database

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);
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) Database(org.whole.lang.rdb.model.Database) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) SampleDatabase(org.whole.lang.rdb.codebase.SampleDatabase) Test(org.junit.Test)

Example 9 with Database

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;
}
Also used : IEntity(org.whole.lang.model.IEntity) Database(org.whole.lang.rdb.model.Database) ArrayList(java.util.ArrayList)

Aggregations

Database (org.whole.lang.rdb.model.Database)9 IEntity (org.whole.lang.model.IEntity)8 Test (org.junit.Test)7 IBindingManager (org.whole.lang.bindings.IBindingManager)7 SampleDatabase (org.whole.lang.rdb.codebase.SampleDatabase)5 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 EntityDescriptor (org.whole.lang.reflect.EntityDescriptor)2 Connection (java.sql.Connection)1 ArrayList (java.util.ArrayList)1 Category (org.junit.experimental.categories.Category)1 DBSchemaTemplateFactory (org.whole.lang.rdb.codebase.DBSchemaTemplateFactory)1