use of org.openforis.collect.persistence.jooq.CollectDSLContext in project collect by openforis.
the class ConfigurationDao method load.
public Configuration load() {
Configuration c = new Configuration();
CollectDSLContext dsl = dsl();
Result<OfcConfigRecord> result = dsl.selectFrom(OFC_CONFIG).fetch();
for (OfcConfigRecord record : result) {
String key = record.getValue(OFC_CONFIG.NAME);
String value = record.getValue(OFC_CONFIG.VALUE);
ConfigurationItem configurationItem = ConfigurationItem.fromKey(key);
c.put(configurationItem, value);
}
return c;
}
use of org.openforis.collect.persistence.jooq.CollectDSLContext in project collect by openforis.
the class ConfigurationDao method save.
public void save(Configuration config) {
CollectDSLContext dsl = dsl();
// delete old records
dsl.delete(OFC_CONFIG).execute();
// insert new records
Set<ConfigurationItem> items = config.getProperties();
for (ConfigurationItem item : items) {
String value = config.get(item);
dsl.insertInto(OFC_CONFIG).set(OFC_CONFIG.NAME, item.getKey()).set(OFC_CONFIG.VALUE, value).execute();
}
}
use of org.openforis.collect.persistence.jooq.CollectDSLContext in project collect by openforis.
the class DynamicTableDao method loadTableMetadata.
private TableMetaData loadTableMetadata(Lookup table) {
try {
CollectDSLContext dsl = dsl();
Connection connection = dsl.configuration().connectionProvider().acquire();
DatabaseMetaData metaData = connection.getMetaData();
String schemaName = table.getSchema().getName();
String tableName = table.getName();
return extractTableMetaData(metaData, schemaName, tableName);
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of org.openforis.collect.persistence.jooq.CollectDSLContext in project collect by openforis.
the class DynamicTableDao method visitRows.
public void visitRows(String table, NameValueEntry[] filters, String[] notNullColumns, Visitor<Map<String, String>> visitor) {
Lookup lookupTable = getLookupTable(table);
CollectDSLContext dsl = dsl();
Field<?>[] fields = lookupTable.fields();
SelectJoinStep<Record> select = dsl.select(fields).from(lookupTable);
addFilterConditions(lookupTable, select, filters);
addNotNullConditions(lookupTable, select, notNullColumns);
Cursor<Record> cursor = null;
try {
cursor = select.fetchLazy();
while (cursor.hasNext()) {
Record r = cursor.fetchOne();
Map<String, String> rowMap = parseRecord(r, fields);
visitor.visit(rowMap);
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
use of org.openforis.collect.persistence.jooq.CollectDSLContext in project collect by openforis.
the class SurveyDao method insert.
public void insert(CollectSurvey survey) throws SurveyImportException {
CollectDSLContext dsl = dsl();
// fetch next id
int surveyId = dsl.nextId(OFC_SURVEY.ID, OFC_SURVEY_ID_SEQ);
InsertQuery<OfcSurveyRecord> insert = dsl.insertQuery(OFC_SURVEY);
addNewSurveyValues(insert, survey, surveyId);
insert.execute();
survey.setId(surveyId);
}
Aggregations