Fixed SNAPSHOT labels management

This commit is contained in:
Fabio Sinibaldi 2020-01-29 12:26:53 +01:00
parent e4e0eae0b7
commit c9f455ee4c
3 changed files with 31 additions and 12 deletions

View File

@ -165,12 +165,16 @@ public class PerformanceManagerImpl implements PerformanceManager{
String createStmt=t.createStatement();
log.debug("Creating Table with stmt {} ",createStmt);
stmt.execute(createStmt);
if(Boolean.parseBoolean(LocalConfiguration.getProperty(LocalConfiguration.COMMIT_SCHEMA)))
conn.commit();
for(String sql:t.updateSchemaStatement()) {
try {
stmt.execute(sql);
stmt.execute(sql);
}catch(SQLException e) {
log.warn("Error while trying to update schema. Depending on DBMS it can mean the update was already in place.",e);
if(Boolean.parseBoolean(LocalConfiguration.getProperty(LocalConfiguration.COMMIT_SCHEMA)))
conn.commit();
}
}
@ -178,13 +182,15 @@ public class PerformanceManagerImpl implements PerformanceManager{
}
if(Boolean.parseBoolean(LocalConfiguration.getProperty(LocalConfiguration.COMMIT_SCHEMA)))
conn.commit();
}
public static void importSchema(SchemaDefinition schema,String csvBasePath) throws IOException, SQLException, InternalException {
log.info("Loading schema {} ",schema);

View File

@ -78,12 +78,14 @@ public class ImportedTable {
csvFields=new ArrayList<>();
labels=new HashMap<>();
for(DBField field:csvFieldsDefinition) {
String escaped=escapeString(field.getFieldName());
csvFields.add(field.getFieldName());
labels.put(field.getFieldName(), new DBField(field.getType(),escaped));
for(DBField field:csvFieldsDefinition)
addLabelledField(field,true);
if(hasSNAPSHOT()) {
addLabelledField(new DBField(Types.BOOLEAN,schema.getSnapshotFieldName()),false);
addLabelledField(new DBField(Types.BIGINT,schema.getHistoricYearFieldName()),false);
}
check(schema.getAssociationUUIDField());
check(schema.getBatchUUIDField());
check(schema.getCompanyUUIDField());
@ -100,6 +102,15 @@ public class ImportedTable {
}
private void addLabelledField(DBField field,boolean escape) {
if(escape) {
String escaped=escapeString(field.getFieldName());
csvFields.add(field.getFieldName());
labels.put(field.getFieldName(), new DBField(field.getType(),escaped));
}else labels.put(field.getFieldName(), field);
}
private void check(String field) throws InternalException {
if(field!=null)
if(!labels.containsKey(field)) throw new InternalException("Incoherent schema definition for table "+tablename+". Field "+field+" not found in csv.");
@ -110,15 +121,15 @@ public class ImportedTable {
}
private DBField getSNAPSHOTField() {
return new DBField(Types.BOOLEAN,schema.getSnapshotFieldName());
return labels.get(schema.getSnapshotFieldName());
}
private DBField getHistoricYearField() {
return new DBField(Types.BIGINT,schema.getHistoricYearFieldName());
return labels.get(schema.getHistoricYearFieldName());
}
private boolean hasSNAPSHOT() {
return schema.getSnapshotFieldName()==null;
return !(schema.getSnapshotFieldName()==null);
}
private Query prepareInsertionQuery() {

View File

@ -7,6 +7,8 @@ species=species
quarter=quarter
area=area
routine=internal_routine_id
snapshot=internal_snapshot
history_year=internal_historic_year
csv=csv/GROW_OUT_AGGREGATED.csv
enable_analysis=true
report_fields=aggregated_batch_id,farm_id,area