use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.
the class TestSettingsAndMembersLoading method testExcelTypesCast.
@Test
public void testExcelTypesCast() {
Database database = TestDatabaseFactory.getTestDatabase();
Schema schema = database.dropCreateSchema(TestSettingsAndMembersLoading.class.getSimpleName());
ClassLoader classLoader = getClass().getClassLoader();
Path path = new File(classLoader.getResource("settings_and_members.xlsx").getFile()).toPath();
new ImportExcelTask(path, schema, true).run();
assertEquals("key1", schema.getTable("table1").getMetadata().getSettings().get(0).key());
assertEquals("value1", schema.getTable("table1").getMetadata().getSettings().get(0).value());
assertEquals("key2", schema.getMetadata().getSettings().get(0).key());
assertEquals("value2", schema.getMetadata().getSettings().get(0).value());
assertEquals(1, schema.getMembers().size());
assertEquals("anonymous", schema.getMembers().get(0).getUser());
assertEquals("Viewer", schema.getMembers().get(0).getRole());
database.dropSchema(schema.getName());
}
use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.
the class MolgenisSessionManager method createSessionListener.
/**
* takes care of creating and destroying session attributes when Jetty creates/destroys sessions
*/
private EventListener createSessionListener() {
MolgenisSessionManager _this = this;
return new HttpSessionListener() {
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
logger.info("Initializing session");
// create private database wrapper to session
Database database = new SqlDatabase(false);
// set default use to "anonymous"
database.setActiveUser("anonymous");
// create session and add to sessions lists so we can also access all active
// sessions
MolgenisSession molgenisSession = new MolgenisSession(database);
sessions.put(httpSessionEvent.getSession().getId(), molgenisSession);
logger.info("session created: " + httpSessionEvent.getSession().getId());
// create listener
database.setListener(new MolgenisSessionManagerDatabaseListener(_this, molgenisSession));
}
public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
// remove from session pool
sessions.remove(httpSessionEvent.getSession().getId());
logger.info("session destroyed: " + httpSessionEvent.getSession().getId());
}
};
}
use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.
the class InitTestDatabaseAndRunNonParallelTests method createDatabase.
@BeforeClass
public static void createDatabase() {
// we want this run only once and NOT parallel for total test suite
// AND we want run all other tests in parallel
// so tests are in molgenis-emx2-sql-it ('integration test')
// and 'init' only happence once, here
Database db = new SqlDatabase(true);
assertTrue(db.getDatabaseVersion() > 0);
}
use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.
the class RunWebApi method main.
public static void main(String[] args) throws IOException {
// create data source
HikariDataSource dataSource = new HikariDataSource();
String url = "jdbc:postgresql:molgenis";
dataSource.setJdbcUrl(url);
dataSource.setUsername("molgenis");
dataSource.setPassword("molgenis");
dataSource.setPassword("molgenis");
// setup
Database db = TestDatabaseFactory.getTestDatabase();
Schema schema = db.dropCreateSchema("pet store");
PetStoreExample.create(schema.getMetadata());
PetStoreExample.populate(schema);
MolgenisWebservice.start(8080);
}
use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.
the class TestTruncate method testTruncate.
@Test
public void testTruncate() {
Database db = TestDatabaseFactory.getTestDatabase();
Schema schema = db.dropCreateSchema(TestTruncate.class.getSimpleName());
// create simple table, add data, and truncate
Table table1 = schema.create(table("Table1", column("name").setPkey()));
table1.insert(row("name", "a"));
Assert.assertEquals(1, table1.retrieveRows().size());
table1.truncate();
Assert.assertEquals(0, table1.retrieveRows().size());
// create with subclass
Table table2 = schema.create(table("Table2").setInherit("Table1").add(column("col1")));
table1.insert(row("name", "a"));
table2.insert(row("name", "b", "col1", "checkb"));
Assert.assertEquals(2, table1.retrieveRows().size());
Assert.assertEquals(1, table2.retrieveRows().size());
table1.truncate();
Assert.assertEquals(1, table1.retrieveRows().size());
Assert.assertEquals(1, table2.retrieveRows().size());
table2.truncate();
Assert.assertEquals(0, table1.retrieveRows().size());
Assert.assertEquals(0, table2.retrieveRows().size());
// create with subclass of a subclass
Table table3 = schema.create(table("Table3").setInherit("Table2").add(column("col2")));
table1.insert(row("name", "a"));
table2.insert(row("name", "b", "col1", "checkb"));
table3.insert(row("name", "c", "col1", "checkc", "col2", "checkc"));
Assert.assertEquals(3, table1.retrieveRows().size());
Assert.assertEquals(2, table2.retrieveRows().size());
Assert.assertEquals(1, table3.retrieveRows().size());
// leaves subclass?!!! is this expected behavior?
table2.truncate();
Assert.assertEquals(2, table1.retrieveRows().size());
// !!!
Assert.assertEquals(1, table2.retrieveRows().size());
Assert.assertEquals(1, table3.retrieveRows().size());
table3.truncate();
Assert.assertEquals(1, table1.retrieveRows().size());
Assert.assertEquals(0, table2.retrieveRows().size());
Assert.assertEquals(0, table3.retrieveRows().size());
table1.truncate();
Assert.assertEquals(0, table1.retrieveRows().size());
Assert.assertEquals(0, table2.retrieveRows().size());
Assert.assertEquals(0, table3.retrieveRows().size());
}
Aggregations