use of com.google.api.ads.admanager.jaxws.v202205.Row in project molgenis-emx2 by molgenis.
the class SqlTable method getWhereConditionForBatchDelete.
private Condition getWhereConditionForBatchDelete(Collection<Row> rows) {
List<Condition> conditions = new ArrayList<>();
for (Row r : rows) {
List<Condition> rowCondition = new ArrayList<>();
if (getMetadata().getPrimaryKeys().isEmpty()) {
// when no key, use all columns as id
for (Column keyPart : getMetadata().getStoredColumns()) {
rowCondition.add(getColumnCondition(r, keyPart));
}
} else {
for (Column keyPart : getMetadata().getPrimaryKeyColumns()) {
rowCondition.add(getColumnCondition(r, keyPart));
}
}
conditions.add(and(rowCondition));
}
return or(conditions);
}
use of com.google.api.ads.admanager.jaxws.v202205.Row in project molgenis-emx2 by molgenis.
the class SqlTable method insertBatch.
private static int insertBatch(SqlTable table, List<Row> rows, boolean updateOnConflict, Set<String> updateColumns) {
boolean inherit = table.getMetadata().getInherit() != null;
if (inherit) {
SqlTable inheritedTable = table.getInheritedTable();
inheritedTable.insertBatch(inheritedTable, rows, updateOnConflict, updateColumns);
}
// get metadata
Set<Column> columns = table.getColumnsToBeUpdated(updateColumns);
// check that columns exist for validation
checkForMissingVariablesColumns(columns);
List<Column> allColumns = table.getMetadata().getMutationColumns();
List<Field> insertFields = columns.stream().map(c -> c.getJooqField()).collect(Collectors.toList());
if (!inherit) {
insertFields.add(field(name(MG_INSERTEDBY)));
insertFields.add(field(name(MG_INSERTEDON)));
insertFields.add(field(name(MG_UPDATEDBY)));
insertFields.add(field(name(MG_UPDATEDON)));
}
// define the insert step
InsertValuesStepN<org.jooq.Record> step = table.getJooq().insertInto(table.getJooqTable(), insertFields.toArray(new Field[0]));
// add all the rows as steps
String user = table.getSchema().getDatabase().getActiveUser();
if (user == null) {
user = ADMIN_USER;
}
LocalDateTime now = LocalDateTime.now();
for (Row row : rows) {
// get values
Map values = SqlTypeUtils.getValuesAsMap(row, columns);
if (!inherit) {
values.put(MG_INSERTEDBY, user);
values.put(MG_INSERTEDON, now);
values.put(MG_UPDATEDBY, user);
values.put(MG_UPDATEDON, now);
}
// when insert, we should include all columns, not only 'updateColumns'
if (!row.isDraft()) {
checkRequired(row, allColumns);
checkValidation(values, columns);
}
step.values(values.values());
}
// optionally, add conflict clause
if (updateOnConflict) {
InsertOnDuplicateSetStep<org.jooq.Record> step2 = step.onConflict(table.getMetadata().getPrimaryKeyFields().toArray(new Field[0])).doUpdate();
for (Column column : columns) {
step2.set(column.getJooqField(), (Object) field(unquotedName("excluded.\"" + column.getName() + "\"")));
}
if (!inherit) {
step2.set(field(name(MG_UPDATEDBY)), user);
step2.set(field(name(MG_UPDATEDON)), now);
}
}
return step.execute();
}
use of com.google.api.ads.admanager.jaxws.v202205.Row in project molgenis-emx2 by molgenis.
the class TestReadWriteStores method executeTest.
public static void executeTest(TableStore store) throws IOException, MolgenisException {
List<Row> rows = new ArrayList<>();
int count = 10;
for (int i = 1; i <= count; i++) {
rows.add(new Row().setString("stringCol", "test" + i).setInt("intCol", i).setDecimal("decimalCol", Double.valueOf(i / 2)).setUuid("uuidCol", UUID.randomUUID()).setDate("dateCol", LocalDate.of(2019, 12, 12)).setDateTime("datetimeCol", LocalDateTime.now()).setBool("boolCol", true).setStringArray("stringarrayCol", new String[] { "a", "b,including comma," }).setIntArray("intarrayCol", new Integer[] { 1, 2 }).setDecimalArray("doubleArrayCol", new Double[] { 1.0, 2.0 }).setDecimalArray("doubleArrayCol", new Double[] { 1.0, 2.0 }).setDateArray("dateArray", new LocalDate[] { LocalDate.of(2019, 12, 12), LocalDate.of(2019, 12, 12) }).setDateTimeArray("datetimeArrayCol", new LocalDateTime[] { LocalDateTime.now(), LocalDateTime.now() }).setBoolArray("booleanArrayCol", new Boolean[] { true, false }));
}
StopWatch.start("created some rows");
// write them
store.writeTable("test", List.of(), rows);
store.writeTable("test2", List.of(), rows);
StopWatch.print("wrote them to " + store.getClass().getSimpleName(), count);
List<Row> rows2 = StreamSupport.stream(store.readTable("test2").spliterator(), false).collect(Collectors.toList());
// for (Row r : rows2) System.out.println(r);
StopWatch.print("fromReader them back from " + store.getClass().getSimpleName(), count);
// compare
CompareTools.assertEquals(rows, rows2);
// write another one
store.writeTable("test3", List.of(), rows);
StopWatch.print("wrote them to " + store.getClass().getSimpleName(), count);
rows2 = StreamSupport.stream(store.readTable("test3").spliterator(), false).collect(Collectors.toList());
// for (Row r : rows2) System.out.println(r);
StopWatch.print("fromReader them back from " + store.getClass().getSimpleName(), count);
// compare
CompareTools.assertEquals(rows, rows2);
StopWatch.print("compared succesfully");
// write empty
store.writeTable("test4", List.of("empty"), new ArrayList<>());
// test that reading store that doesn't exist errors properly
try {
store.readTable("fake");
fail("should have failed");
} catch (MolgenisException me) {
System.out.println("errored correctly:" + me);
}
}
use of com.google.api.ads.admanager.jaxws.v202205.Row in project molgenis-emx2 by molgenis.
the class TestTypesImport method testTsvTypeCast.
@Test
public void testTsvTypeCast() {
ClassLoader classLoader = getClass().getClassLoader();
Path path = new File(classLoader.getResource("TypeTest.tsv").getFile()).toPath();
TableStore store = new TableStoreForCsvFile(path);
for (Row r : store.readTable("Sheet1")) {
assertEquals("1", r.getString("column1"));
assertEquals("2", r.getString("column2"));
}
}
use of com.google.api.ads.admanager.jaxws.v202205.Row 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());
}
Aggregations