Added SNAPSHOT and historic year to initialization
This commit is contained in:
parent
e86bb3296a
commit
8da417ff85
|
@ -165,9 +165,22 @@ public class PerformanceManagerImpl implements PerformanceManager{
|
|||
String createStmt=t.createStatement();
|
||||
log.debug("Creating Table with stmt {} ",createStmt);
|
||||
stmt.execute(createStmt);
|
||||
|
||||
for(String sql:t.updateSchemaStatement()) {
|
||||
try {
|
||||
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();
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ public class SchemaDefinition {
|
|||
return toReportLabels;
|
||||
}
|
||||
|
||||
public SchemaDefinition(AnalysisType relatedAnalysis, Properties props) {
|
||||
public SchemaDefinition(AnalysisType relatedAnalysis, Properties props) throws Exception {
|
||||
super();
|
||||
this.relatedDescription = props.getProperty(DESCRIPTION);
|
||||
this.relatedAnalysis = relatedAnalysis;
|
||||
|
@ -106,6 +106,9 @@ public class SchemaDefinition {
|
|||
this.snapshotFieldName=props.getProperty(SNAPSHOT);
|
||||
this.historicYearFieldName=props.getProperty(HISTORIC);
|
||||
this.routineIdFieldName=props.getProperty(ROUTINE_ID);
|
||||
if(!((snapshotFieldName==null)==(historicYearFieldName==null)))
|
||||
throw new Exception(SNAPSHOT+" and "+HISTORIC+" fields need to be specified together");
|
||||
|
||||
|
||||
this.analysisEnabled=Boolean.parseBoolean(props.getProperty(ENABLE_ANALYSIS, "false"));
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ import java.sql.SQLException;
|
|||
import java.sql.Statement;
|
||||
import java.sql.Types;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
|
@ -106,6 +108,17 @@ public class ImportedTable {
|
|||
return new DBField(Types.BIGINT,schema.getRoutineIdFieldName());
|
||||
}
|
||||
|
||||
private DBField getSNAPSHOTField() {
|
||||
return new DBField(Types.BOOLEAN,schema.getSnapshotFieldName());
|
||||
}
|
||||
|
||||
private DBField getHistoricYearField() {
|
||||
return new DBField(Types.BIGINT,schema.getHistoricYearFieldName());
|
||||
}
|
||||
|
||||
private boolean hasSNAPSHOT() {
|
||||
return schema.getSnapshotFieldName()==null;
|
||||
}
|
||||
|
||||
private Query prepareInsertionQuery() {
|
||||
|
||||
|
@ -150,10 +163,26 @@ public class ImportedTable {
|
|||
String.format( "%1$s bigint,"
|
||||
+ "FOREIGN KEY (%1$s) REFERENCES "+ImportRoutine.TABLE+"("+ImportRoutine.ID+")",getRoutineIdField().getFieldName());
|
||||
|
||||
if(hasSNAPSHOT())
|
||||
standardDefinitions=
|
||||
String.format( "%1$s bigint, %2$s boolean DEFAULT FALSE, %3$s int DEFAULT 0,"
|
||||
+ "FOREIGN KEY (%1$s) REFERENCES "+ImportRoutine.TABLE+"("+ImportRoutine.ID+")",
|
||||
getRoutineIdField().getFieldName(),
|
||||
getSNAPSHOTField().getFieldName(),
|
||||
getHistoricYearField().getFieldName());
|
||||
|
||||
|
||||
return String.format("CREATE TABLE IF NOT EXISTS %1$s (%2$s, %3$s)",
|
||||
tablename,fieldDefinitions.substring(0,fieldDefinitions.lastIndexOf(",")),standardDefinitions);
|
||||
}
|
||||
|
||||
|
||||
public List<String> updateSchemaStatement() {
|
||||
ArrayList<String> toReturn=new ArrayList<>();
|
||||
if(hasSNAPSHOT()) toReturn.addAll(Arrays.asList(String.format("ALTER TABLE %1$s ADD %2$s boolean DEFAULT FALSE",getTableName(),getSNAPSHOTField().getFieldName()),
|
||||
String.format("ALTER TABLE %1$s ADD %2$s int DEFAULT 0",getTableName(),getSNAPSHOTField().getFieldName())));
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if passed set of labels is
|
||||
|
|
Loading…
Reference in New Issue