use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class ExcelApi method getExcelTable.
static String getExcelTable(Request request, Response response) throws IOException {
Table table = getTable(request);
if (table == null)
throw new MolgenisException("Table " + request.params(TABLE) + " unknown");
Path tempDir = Files.createTempDirectory(MolgenisWebservice.TEMPFILES_DELETE_ON_EXIT);
tempDir.toFile().deleteOnExit();
try (OutputStream outputStream = response.raw().getOutputStream()) {
Path excelFile = tempDir.resolve("download.xlsx");
MolgenisIO.toExcelFile(excelFile, table);
response.type("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.header("Content-Disposition", "attachment; filename=" + table.getSchema().getMetadata().getName() + "_" + table.getName() + System.currentTimeMillis() + ".xlsx");
outputStream.write(Files.readAllBytes(excelFile));
return "Export success";
}
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class LinkedDataFragmentsApi method ttlTable.
private static String ttlTable(Request request, Response response) {
Table table = getTable(request);
StringWriter sw = new StringWriter();
LinkedDataService.getTtlForTable(table, new PrintWriter(sw));
return sw.getBuffer().toString();
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class CatalogueSiteMapTest method buildSiteMap.
@Test
public void buildSiteMap() {
Schema schema = mock(Schema.class);
Table table = mock(Table.class);
Query query = mock(Query.class);
List<Row> row = Collections.singletonList(new Row("pid", "my-cohort-pid"));
when(schema.getTable("Cohorts")).thenReturn(table);
when(table.select(any())).thenReturn(query);
when(query.retrieveRows()).thenReturn(row);
CatalogueSiteMap catalogueSiteMap = new CatalogueSiteMap(schema, "https://my/base/url");
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\" >\n" + " <url>\n" + " <loc>https://my/base/url/ssr-catalogue/Cohorts/my-cohort-pid</loc>\n" + " </url>\n" + "</urlset>";
assertEquals(expected, catalogueSiteMap.buildSiteMap());
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class Benchmark method testCopyInAndOut.
public void testCopyInAndOut() {
Database database = TestDatabaseFactory.getTestDatabase();
Schema schema = database.dropCreateSchema(Benchmark.class.getSimpleName());
int aSize = 50;
int bSize = 100000;
Table a = schema.create(table("TableA").add(column("ID").setPkey()));
List<String> values = new ArrayList<>();
Table b = schema.create(table("TableB").add(column("ID").setPkey()).add(column("ref").setType(REF_ARRAY).setRefTable("TableA")));
// Table c =
// schema.create(
// table("TableC")
// .add(column("ID").setPkey())
// .add(column("ref").setType(MREF).setRefTable("TableA")));
StopWatch.start("benchmark started");
List<Row> aRows = new ArrayList<>();
for (int i = 0; i < aSize; i++) {
aRows.add(new Row().set("ID", "row" + i));
values.add("row" + i);
}
StopWatch.start("benchmark1");
a.insert(aRows);
StopWatch.print("inserted primary", aSize);
aRows.clear();
List<Row> bRows = new ArrayList<>();
for (int i = 0; i < bSize; i++) {
bRows.add(new Row().set("ID", "row" + i).set("ref", values));
}
StopWatch.start("benchmark2 started");
b.insert(bRows);
StopWatch.print("inserted ref_array", bSize);
bRows.clear();
// List<Row> cRows = new ArrayList<>();
// for (int i = 0; i < bSize; i++) {
// cRows.add(new Row().set("ID", "row" + i).set("ref", values));
// }
// StopWatch.start("benchmark3 started");
// c.insert(cRows);
// StopWatch.print("inserted mref", bSize);
// cRows.clear();
// StopWatch.print("inserted mref", bSize);
// ref_array
}
use of org.jaxdb.www.ddlx_0_5.xLygluGCXAA.$Table in project molgenis-emx2 by molgenis.
the class TestCompositeForeignKeys method testCompositeRef.
@Test
public void testCompositeRef() {
Schema schema = database.dropCreateSchema(TestCompositeForeignKeys.class.getSimpleName() + "Ref");
schema.create(table("Person", column("firstName").setPkey(), column("lastName").setPkey(), column("uncle", REF).setRefTable("Person")));
Table p = schema.getTable("Person");
p.insert(new Row().setString("firstName", "Donald").setString("lastName", "Duck"));
try {
p.insert(new Row().setString("firstName", "Kwik").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "MISSING"));
fail("should have failed on missing foreign key");
} catch (Exception e) {
System.out.println("errored correctly: " + e);
}
p.insert(new Row().setString("firstName", "Kwik").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
p.insert(new Row().setString("firstName", "Kwek").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
p.insert(new Row().setString("firstName", "Kwak").setString("lastName", "Duck").setString("uncle.firstName", "Donald").setString("uncle.lastName", "Duck"));
try {
p.delete(new Row().setString("firstName", "Donald").setString("lastName", "Duck"));
fail("should have failed on foreign key (Donald is used in foreign key)");
} catch (Exception e) {
System.out.println("errored correctly: " + e);
}
schema.create(table("Student").setInherit("Person"));
Table s = schema.getTable("Student");
s.insert(new Row().setString("firstName", "Mickey").setString("lastName", "Mouse").setString("uncle.firstName", "Kwik").setString("uncle.lastName", "Duck"));
String result = schema.query("Student", s("firstName"), s("lastName"), s("uncle", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).retrieveJSON();
System.out.println(result);
result = schema.query("Student").select(s("firstName"), s("lastName")).where(or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse")))).retrieveJSON();
System.out.println(result);
assertTrue(result.contains("Mouse"));
assertFalse(result.contains("Duck"));
result = schema.query("Person").select(s("firstName"), s("lastName")).where(or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse")))).retrieveJSON();
System.out.println(result);
assertTrue(result.contains("Mouse"));
assertTrue(result.contains("Duck"));
// composite key filter
result = schema.query("Person").select(s("firstName"), s("lastName")).where(f("uncle", or(and(f("firstName", EQUALS, "Donald"), f("lastName", EQUALS, "Duck")), and(f("firstName", EQUALS, "Mickey"), f("lastName", EQUALS, "Mouse"))))).retrieveJSON();
System.out.println(result);
assertTrue(result.contains("Kwik"));
assertFalse(result.contains("Mouse"));
// refback
schema.getTable("Person").getMetadata().add(column("nephew").setType(REFBACK).setRefTable("Person").setRefBack("uncle"));
s.insert(new Row().setString("firstName", "Katrien").setString("lastName", "Duck").setString("nephew.firstName", "Kwik").setString("nephew.lastName", // I know, not true
"Duck"));
assertTrue(List.of(s.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Katrien")).retrieveRows().get(0).getStringArray("nephew-firstName")).contains("Kwik"));
assertTrue(List.of(p.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).where(f("firstName", EQUALS, "Kwik")).retrieveRows().get(0).getStringArray("uncle-firstName")).contains("Katrien"));
// test order by for refback
p.query().select(s("firstName"), s("lastName"), s("nephew", s("firstName"), s("lastName")), s("uncle", s("firstName"), s("lastName"))).orderBy("nephew").retrieveJSON();
}
Aggregations