-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #3437 fixed issues using Citus
Signed-off-by: Robin Arnold <robin.arnold@ibm.com>
- Loading branch information
1 parent
246897f
commit 24bb883
Showing
19 changed files
with
400 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...base-utils/src/main/java/com/ibm/fhir/database/utils/citus/CitusDistributionCheckDAO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.database.utils.citus; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.util.logging.Logger; | ||
|
||
import com.ibm.fhir.database.utils.api.IDatabaseSupplier; | ||
import com.ibm.fhir.database.utils.api.IDatabaseTranslator; | ||
import com.ibm.fhir.database.utils.common.DataDefinitionUtil; | ||
|
||
/** | ||
* DAO to check if the table is already distributed | ||
*/ | ||
public class CitusDistributionCheckDAO implements IDatabaseSupplier<Boolean> { | ||
private static final Logger logger = Logger.getLogger(CitusDistributionCheckDAO.class.getName()); | ||
|
||
private final String schemaName; | ||
private final String tableName; | ||
|
||
/** | ||
* Public constructor | ||
* | ||
* @param schemaName | ||
* @param tableName | ||
*/ | ||
public CitusDistributionCheckDAO(String schemaName, String tableName) { | ||
DataDefinitionUtil.assertValidName(schemaName); | ||
DataDefinitionUtil.assertValidName(tableName); | ||
this.schemaName = schemaName.toLowerCase(); | ||
this.tableName = tableName.toLowerCase(); | ||
} | ||
|
||
@Override | ||
public Boolean run(IDatabaseTranslator translator, Connection c) { | ||
Boolean result = Boolean.FALSE; | ||
|
||
final String relname = DataDefinitionUtil.getQualifiedName(schemaName, this.tableName); | ||
final String SQL = "SELECT 1 FROM pg_dist_partition WHERE logicalrelid = ?::regclass"; | ||
|
||
try (PreparedStatement ps = c.prepareStatement(SQL)) { | ||
ps.setString(1, relname); | ||
ResultSet rs = ps.executeQuery(); | ||
if (rs.next()) { | ||
result = Boolean.TRUE; | ||
} | ||
} catch (SQLException x) { | ||
// Translate the exception into something a little more meaningful | ||
// for this database type and application | ||
logger.severe("select failed: " + SQL + " for logicalrelid = '" + relname + "'"); | ||
throw translator.translate(x); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.