-
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 remote index support for profile, tags and security
Signed-off-by: Robin Arnold <robin.arnold@ibm.com>
- Loading branch information
1 parent
0752bbb
commit 6343ab9
Showing
49 changed files
with
2,022 additions
and
225 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
...abase-utils/src/main/java/com/ibm/fhir/database/utils/common/PreparedStatementHelper.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,126 @@ | ||
/* | ||
* (C) Copyright IBM Corp. 2022 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.ibm.fhir.database.utils.common; | ||
|
||
import java.sql.PreparedStatement; | ||
import java.sql.SQLException; | ||
import java.sql.Timestamp; | ||
import java.sql.Types; | ||
import java.util.Calendar; | ||
|
||
/** | ||
* Collection of utility functions to simply setting values on a PreparedStatement | ||
*/ | ||
public class PreparedStatementHelper { | ||
// The PreparedStatement we delegate everything to | ||
private final Calendar UTC = CalendarHelper.getCalendarForUTC(); | ||
private final PreparedStatement ps; | ||
private int index = 1; | ||
|
||
/** | ||
* Public constructor | ||
* @param ps | ||
*/ | ||
public PreparedStatementHelper(PreparedStatement ps) { | ||
this.ps = ps; | ||
} | ||
|
||
/** | ||
* Set the (possibly null) int value at the current position | ||
* and increment the position by 1 | ||
* @param value | ||
* @return this instance | ||
* @throws SQLException | ||
*/ | ||
public PreparedStatementHelper setInt(Integer value) throws SQLException { | ||
if (value != null) { | ||
ps.setInt(index, value); | ||
} else { | ||
ps.setNull(index, Types.INTEGER); | ||
} | ||
index++; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the (possibly null) long value at the current position | ||
* and increment the position by 1 | ||
* @param value | ||
* @return this instance | ||
* @throws SQLException | ||
*/ | ||
public PreparedStatementHelper setLong(Long value) throws SQLException { | ||
if (value != null) { | ||
ps.setLong(index, value); | ||
} else { | ||
ps.setNull(index, Types.BIGINT); | ||
} | ||
index++; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the (possibly null) long value at the current position | ||
* and increment the position by 1 | ||
* @param value | ||
* @return this instance | ||
* @throws SQLException | ||
*/ | ||
public PreparedStatementHelper setShort(Short value) throws SQLException { | ||
if (value != null) { | ||
ps.setShort(index, value); | ||
} else { | ||
ps.setNull(index, Types.SMALLINT); | ||
} | ||
index++; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the (possibly null) String value at the current position | ||
* and increment the position by 1 | ||
* @param value | ||
* @return this instance | ||
* @throws SQLException | ||
*/ | ||
public PreparedStatementHelper setString(String value) throws SQLException { | ||
if (value != null) { | ||
ps.setString(index, value); | ||
} else { | ||
ps.setNull(index, Types.VARCHAR); | ||
} | ||
index++; | ||
return this; | ||
} | ||
|
||
/** | ||
* Set the (possibly null) int value at the current position | ||
* and increment the position by 1 | ||
* @param value | ||
* @return this instance | ||
* @throws SQLException | ||
*/ | ||
public PreparedStatementHelper setTimestamp(Timestamp value) throws SQLException { | ||
if (value != null) { | ||
ps.setTimestamp(index, value, UTC); | ||
} else { | ||
ps.setNull(index, Types.TIMESTAMP); | ||
} | ||
index++; | ||
return this; | ||
} | ||
|
||
/** | ||
* Add a new batch entry based on the current state of the {@link PreparedStatement}. | ||
* Note that we don't return this on purpose...because addBatch should be last in | ||
* any sequence of setXX(...) calls. | ||
* @throws SQLException | ||
*/ | ||
public void addBatch() throws SQLException { | ||
ps.addBatch(); | ||
} | ||
} |
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.