Search in sources :

Example 1 with CollectDSLContext

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;
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem) Configuration(org.openforis.collect.model.Configuration) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext) OfcConfigRecord(org.openforis.collect.persistence.jooq.tables.records.OfcConfigRecord)

Example 2 with CollectDSLContext

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();
    }
}
Also used : ConfigurationItem(org.openforis.collect.model.Configuration.ConfigurationItem) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext)

Example 3 with CollectDSLContext

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext) DatabaseMetaData(java.sql.DatabaseMetaData)

Example 4 with CollectDSLContext

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();
        }
    }
}
Also used : Field(org.jooq.Field) TableField(org.jooq.TableField) Lookup(org.openforis.collect.persistence.jooq.tables.Lookup) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext) Record(org.jooq.Record) LookupRecord(org.openforis.collect.persistence.jooq.tables.records.LookupRecord)

Example 5 with CollectDSLContext

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);
}
Also used : OfcSurveyRecord(org.openforis.collect.persistence.jooq.tables.records.OfcSurveyRecord) CollectDSLContext(org.openforis.collect.persistence.jooq.CollectDSLContext)

Aggregations

CollectDSLContext (org.openforis.collect.persistence.jooq.CollectDSLContext)11 Record (org.jooq.Record)3 Field (org.jooq.Field)2 ConfigurationItem (org.openforis.collect.model.Configuration.ConfigurationItem)2 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Connection (java.sql.Connection)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 Condition (org.jooq.Condition)1 Name (org.jooq.Name)1 Query (org.jooq.Query)1 TableField (org.jooq.TableField)1 TableLike (org.jooq.TableLike)1 DialectAwareJooqConfiguration (org.jooq.impl.DialectAwareJooqConfiguration)1 Configuration (org.openforis.collect.model.Configuration)1 Lookup (org.openforis.collect.persistence.jooq.tables.Lookup)1 LookupRecord (org.openforis.collect.persistence.jooq.tables.records.LookupRecord)1