Skip to content

Commit

Permalink
fix: initialization synchronization query with volume
Browse files Browse the repository at this point in the history
  • Loading branch information
Nolife999 committed Oct 23, 2023
1 parent e08da9c commit 221dc66
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,27 @@ public static void deleteDataRecordsFoundInIdSource(Connection executorConnectio
* @throws ArcException
*/
public static void keepDataRecordsFoundInIdSourceOnly(Connection executorConnection, String targetDataTable) throws ArcException {


// recreate full table instead of delete as large volume of data may be involved
// this operation occurs once a week

ArcPreparedStatementBuilder query = new ArcPreparedStatementBuilder();
query.build(SQL.DELETE, targetDataTable, SQL.AS, ViewEnum.ALIAS_A);
query.build(SQL.WHERE, SQL.NOT, SQL.EXISTS);
query.build(SQL.DROP, SQL.TABLE, SQL.IF_EXISTS, ViewEnum.T2.getFullName(), SQL.END_QUERY);

query.build(SQL.CREATE, SQL.TEMPORARY, SQL.TABLE, ViewEnum.T2.getFullName(), SQL.AS);
query.build(SQL.SELECT, "*", SQL.FROM, targetDataTable, SQL.AS, ViewEnum.ALIAS_A);
query.build(SQL.WHERE, SQL.EXISTS);
query.build("(");
query.build(SQL.SELECT, SQL.FROM, ViewEnum.T1.getFullName(), SQL.AS, ViewEnum.ALIAS_B);
query.build(SQL.WHERE, ColumnEnum.ID_SOURCE.alias(ViewEnum.ALIAS_A), "=", ColumnEnum.ID_SOURCE.alias(ViewEnum.ALIAS_B));
query.build(")");
query.build(SQL.END_QUERY);

query.build(SQL.TRUNCATE, SQL.TABLE, targetDataTable, SQL.END_QUERY);

query.build(SQL.INSERT_INTO, targetDataTable, SQL.SELECT, "*", SQL.FROM, ViewEnum.T2.getFullName(), SQL.END_QUERY);

UtilitaireDao.get(0).executeImmediate(executorConnection, query);
}

Expand Down
6 changes: 4 additions & 2 deletions arc-utils/src/main/java/fr/insee/arc/utils/dao/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public enum SQL {

LIMIT("LIMIT"), OFFSET("OFFSET"),

CREATE("CREATE"), DROP("DROP"), TEMPORARY("TEMPORARY"), TABLE("TABLE"), IF_NOT_EXISTS("IF NOT EXISTS"), IF_EXISTS("IF EXISTS"), CASCADE("CASCADE"),

CREATE("CREATE"), DROP("DROP"), TRUNCATE("TRUNCATE"),

TEMPORARY("TEMPORARY"), TABLE("TABLE"), IF_NOT_EXISTS("IF NOT EXISTS"), IF_EXISTS("IF EXISTS"), CASCADE("CASCADE"),

LIKE("LIKE"),

IS_NULL("IS NULL"), IS_NOT_NULL("IS NOT NULL"),
Expand Down

0 comments on commit 221dc66

Please sign in to comment.