Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public QueryBuilderBaseFeatureStore(String tableName) {
public String createTableQuery() {
// NOTE: do not use JSONB because we need to keep order to the properties for geoGSON
// see: https://www.postgresql.org/docs/current/datatype-json.html
return "CREATE TABLE " + this.getStoreTableName() +
return "CREATE TABLE IF NOT EXISTS " + this.getStoreTableName() +
" (pkId BIGSERIAL PRIMARY KEY," +
"id bigint," +
" parentId bigint,"+
Expand Down Expand Up @@ -116,27 +116,27 @@ public String removeByTimeRangeQuery(TemporalFilter temporalFilter) {
}

public String createUidUniqueIndexQuery() {
return "CREATE UNIQUE INDEX "+this.getStoreTableName()+"_feature_uid_idx ON "+this.getStoreTableName()+" " +
return "CREATE UNIQUE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_uid_idx ON "+this.getStoreTableName()+" " +
"((data->'properties'->>'uid'), "+VALID_TIME+")";
}
public String createValidTimeIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_valid_time_0_idx ON "+this.getStoreTableName()+ " using GIST (validTime)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_valid_time_0_idx ON "+this.getStoreTableName()+ " using GIST (validTime)";
}

public String createIdIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_id_idx ON "+this.getStoreTableName()+" (id)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_id_idx ON "+this.getStoreTableName()+" (id)";
}

public String createTrigramExtensionQuery() {
return "CREATE EXTENSION IF NOT EXISTS pg_trgm";
}

public String createTrigramDescriptionFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'properties'->>'description') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'properties'->>'description') gin_trgm_ops)";
}

public String createTrigramUidFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_uid_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'properties'->>'uid') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_uid_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'properties'->>'uid') gin_trgm_ops)";
}

public abstract String createSelectEntriesQuery(F filter, Set<VF> fields);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected QueryBuilderCommandStatusStore(String tableName) {

@Override
public String createTableQuery() {
return "CREATE TABLE "+this.getStoreTableName()+
return "CREATE TABLE IF NOT EXISTS "+this.getStoreTableName()+
" (" +
"id BIGSERIAL PRIMARY KEY,"+
COMMAND_ID + " bigint, "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public QueryBuilderCommandStore(String tableName) {


public String createTableQuery() {
return "CREATE TABLE "+this.getStoreTableName()+
return "CREATE TABLE IF NOT EXISTS "+this.getStoreTableName()+
" (" +
"id BIGSERIAL PRIMARY KEY,"+
COMMANDSTREAM_ID +" BIGINT, "+
Expand All @@ -50,23 +50,23 @@ public String createTableQuery() {
}

public String createDataIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_data_idx on "+this.getStoreTableName()+" USING GIN("+PARAMETERS+")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_data_idx on "+this.getStoreTableName()+" USING GIN("+PARAMETERS+")";
}

public String createCommandStreamIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_commandstream_idx on "+this.getStoreTableName()+" ("+COMMANDSTREAM_ID+")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_commandstream_idx on "+this.getStoreTableName()+" ("+COMMANDSTREAM_ID+")";
}

public String createSenderIdIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_senderid_idx on "+this.getStoreTableName()+" ("+SENDER_ID+")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_senderid_idx on "+this.getStoreTableName()+" ("+SENDER_ID+")";
}

public String createFoidIdIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_foidid_idx on "+this.getStoreTableName()+" ("+FOI_ID+")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_foidid_idx on "+this.getStoreTableName()+" ("+FOI_ID+")";
}

public String createIssueTimeIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_issue_time_idx on "+this.getStoreTableName()+" ("+ ISSUE_TIME +")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_issue_time_idx on "+this.getStoreTableName()+" ("+ ISSUE_TIME +")";
}

public String insertCommandQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public QueryBuilderCommandStreamStore(String tableName) {
}

public String createTableQuery() {
return "CREATE TABLE " + this.getStoreTableName() + " (id BIGSERIAL PRIMARY KEY,data JSONB)";
return "CREATE TABLE IF NOT EXISTS " + this.getStoreTableName() + " (id BIGSERIAL PRIMARY KEY,data JSONB)";
}

public String createIndexQuery() {
return "CREATE INDEX " + this.getStoreTableName() + "_data_idx on " + this.getStoreTableName() + " USING GIN(data)";
return "CREATE INDEX IF NOT EXISTS " + this.getStoreTableName() + "_data_idx on " + this.getStoreTableName() + " USING GIN(data)";
}

public String createUniqueIndexQuery() {
return "CREATE UNIQUE INDEX " + this.getStoreTableName() + "_data_output_idx ON " + this.getStoreTableName()
return "CREATE UNIQUE INDEX IF NOT EXISTS " + this.getStoreTableName() + "_data_output_idx ON " + this.getStoreTableName()
+ " USING BTREE((data->>'name'), (data->'system@id'), (data->'validTime'->'begin'))";
}

public String createValidTimeBeginIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_date_range_begin_idx ON "+this.getStoreTableName()+ " USING GIN((data->'validTime'->'begin'))";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_date_range_begin_idx ON "+this.getStoreTableName()+ " USING GIN((data->'validTime'->'begin'))";
}

public String createValidTimeEndIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_date_range_end_idx ON "+this.getStoreTableName()+ " USING GIN((data->'validTime'->'end'))";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_date_range_end_idx ON "+this.getStoreTableName()+ " USING GIN((data->'validTime'->'end'))";
}

public String insertCommandQuery() {
Expand All @@ -68,7 +68,7 @@ public String createTrigramExtensionQuery() {
}

public String createTrigramDescriptionFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'recordSchema'->>'description') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->'recordSchema'->>'description') gin_trgm_ops)";
}

public String createSelectEntriesQuery(CommandStreamFilter filter, Set<ICommandStreamStore.CommandStreamInfoField> fields) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,45 @@ public QueryBuilderDataStreamStore(String tableName) {
}

public String createTableQuery() {
return "CREATE TABLE " + this.getStoreTableName() + " (id BIGSERIAL PRIMARY KEY,data JSONB)";
return "CREATE TABLE IF NOT EXISTS " + this.getStoreTableName() + " (id BIGSERIAL PRIMARY KEY,data JSONB)";
}

public String createIndexQuery() {
return "CREATE INDEX " + this.getStoreTableName() + "_data_idx on " + this.getStoreTableName() + " USING GIN(data)";
return "CREATE INDEX IF NOT EXISTS " + this.getStoreTableName() + "_data_idx on " + this.getStoreTableName() + " USING GIN(data)";
}

public String createUniqueIndexQuery() {
return "CREATE UNIQUE INDEX " + this.getStoreTableName() + "_data_output_idx ON " + this.getStoreTableName()
return "CREATE UNIQUE INDEX IF NOT EXISTS " + this.getStoreTableName() + "_data_output_idx ON " + this.getStoreTableName()
+ " USING BTREE((data->'name'), (data->'system@id'), (data->'validTime'))";
}

public String createDateRangeIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_date_range_idx ON " + this.getStoreTableName() +
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_date_range_idx ON " + this.getStoreTableName() +
" USING gist (int8range( " +
"(data->'validTime'->'begin')::bigint, " +
"(data->'validTime'->'end')::bigint" +
") )";
}

public String createValidTimeBeginIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_date_range_begin_idx ON " + this.getStoreTableName() + " USING GIN((data->'validTime'->'begin'))";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_date_range_begin_idx ON " + this.getStoreTableName() + " USING GIN((data->'validTime'->'begin'))";
}

public String createValidTimeEndIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_date_range_end_idx ON " + this.getStoreTableName() + " USING GIN((data->'validTime'->'end'))";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_date_range_end_idx ON " + this.getStoreTableName() + " USING GIN((data->'validTime'->'end'))";
}

public String createTrigramExtensionQuery() {
return "CREATE EXTENSION IF NOT EXISTS pg_trgm";
}

public String createTrigramDescriptionFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON " + this.getStoreTableName() + " USING GIN ((data->'recordSchema'->>'description') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON " + this.getStoreTableName() + " USING GIN ((data->'recordSchema'->>'description') gin_trgm_ops)";
}

//SELECT * from test_obs_datastreams where to_tsvector(data->'recordStruct'->'description') @@ to_tsquery('video | Air');
public String createDescriptionFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON " + this.getStoreTableName() + " USING " +
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_desc_full_text_datastream_idx ON " + this.getStoreTableName() + " USING " +
"GIN (to_tsvector('english', data->'recordSchema'->'description'))";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String createTableQuery() {
")";
}
public String createDataIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_data_idx on "+this.getStoreTableName()+" USING GIN("+RESULT+")";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_data_idx on "+this.getStoreTableName()+" USING GIN("+RESULT+")";
// return "CREATE INDEX "+this.getStoreTableName()+"_data_idx on "+this.getStoreTableName()+" ("+RESULT+")";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ public String selectLastVersionByUidQuery(String uid, String timestamp) {

@Override
public String createUidUniqueIndexQuery() {
return "CREATE UNIQUE INDEX "+this.getStoreTableName()+"_feature_uid_idx ON "+this.getStoreTableName()+" " +
return "CREATE UNIQUE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_uid_idx ON "+this.getStoreTableName()+" " +
"((data->>'uniqueId'), "+VALID_TIME+")";
}

@Override
public String createTrigramDescriptionFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->>'description') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_desc_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->>'description') gin_trgm_ops)";
}
@Override
public String createTrigramUidFullTextIndexQuery() {
return "CREATE INDEX "+this.getStoreTableName()+"_feature_uid_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->>'uniqueId') gin_trgm_ops)";
return "CREATE INDEX IF NOT EXISTS "+this.getStoreTableName()+"_feature_uid_full_text_datastream_idx ON "+this.getStoreTableName()+" USING GIN ((data->>'uniqueId') gin_trgm_ops)";
}

public String addOrUpdateByIdQuery() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ protected void init(String url, String dbName, String login, String password, St

private void initStore(String[] initScripts) {
try (Connection connection = this.connectionManager.getConnection()) {
if (!PostgisUtils.checkTable(connection, queryBuilder.getStoreTableName())) {
// if (!PostgisUtils.checkTable(connection, queryBuilder.getStoreTableName())) {
// create table
PostgisUtils.executeQueries(connection, initScripts);
}
// }
logger.info("Initialized store '{}'", queryBuilder.getStoreTableName());

} catch (SQLException e) {
Expand Down
Loading