Class Home<T>
- java.lang.Object
-
- net.jextra.fauxjo.Home<T>
-
public class Home<T> extends Object
Base implementation of a data access object.If using a jdbc driver with Statement caching (e.g. PG, Oracle, MySQL) or for fine-grain control over memory use, consider calling setStatementCacheEnabled(false) and closing Connections and their Statements with try-resource or finally. If using HikariCP, set these properties:
- minimumIdle: set to count of services concurrently using this Home X 2.
- maximumPoolSize: set at least 2X larger than minIdleCount or db process count.
- idleTimeout: 600000 (millisec), max time before HikariCP evicts idle connections.
Hikari docs:
It is imperative the app configures driver-level TCP socket timeout. For Postgresql (PG), set socketTimeout to greater of 2-3X the longest query or 30 sec.
PG docs:
If reading from the server takes longer than this value, the connection is closed.
An easy way configure PG socketTimeout when using HikariCP is to use its idleTimeout (in seconds):hikariConf.addDataSourceProperty("socketTimeout", idleTimeout/1000)Hikari recovery notes (after network outage or RDS failover): Recovery time should take the greater of idleTimeout and socket timeout on the driver. During recovery, nobody should call getConnection allowing the pool to evict idle connections. A longer time is more tolerant of long-running queries but also prolongs recovery. See Hikari rapid recovery Hikari rapid recovery 2
- See Also:
setStatementCacheEnabled(boolean)
-
-
Constructor Summary
Constructors Constructor Description Home(String tableName, Class<T> beanClass)Home(Connection conn, String tableName, Class<T> beanClass)Home(Connection conn, Table<T> table, BeanBuilder<T> beanBuilder)Home(Table<T> table, BeanBuilder<T> beanBuilder)
-
Method Summary
-
-
-
Constructor Detail
-
Home
public Home(Connection conn, String tableName, Class<T> beanClass) throws SQLException
- Throws:
SQLException
-
Home
public Home(Table<T> table, BeanBuilder<T> beanBuilder)
-
Home
public Home(Connection conn, Table<T> table, BeanBuilder<T> beanBuilder) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getSupportsGeneratedKeys
public boolean getSupportsGeneratedKeys()
-
getStatementCacheEnabled
public boolean getStatementCacheEnabled()
-
setStatementCacheConfig
public Home<T> setStatementCacheConfig(List<StatementCacheListener> listeners, Integer perConCacheMaxEntries, Long perConCacheMaxAgeMillis)
-
getConnection
public Connection getConnection()
-
setConnection
public boolean setConnection(Connection conn) throws SQLException
- Throws:
SQLException
-
getTable
public Table getTable()
-
getBeanBuilder
public BeanBuilder<T> getBeanBuilder()
-
prepareStatement
public PreparedStatement prepareStatement(String sql) throws SQLException
- Throws:
SQLException
-
getSchemaName
public String getSchemaName()
-
getTableName
public String getTableName()
-
getFullTableName
public String getFullTableName()
-
getQualifiedName
public String getQualifiedName(String name)
This method attaches the schema name to the front of the name passed in.- Returns:
- String that represents the given short name.
-
insert
public int insert(T bean) throws SQLException
- Throws:
SQLException
-
insert
public int insert(Collection<T> beans) throws SQLException
- Throws:
SQLException
-
update
public int update(T bean) throws SQLException
- Throws:
SQLException
-
delete
public boolean delete(T bean) throws SQLException
- Throws:
SQLException
-
getFirst
public T getFirst(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getFirst
public T getFirst(ResultSet rs, boolean errorIfEmpty) throws SQLException
- Throws:
SQLException
-
getUnique
public T getUnique(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getUnique
public T getUnique(ResultSet rs, boolean errorIfEmpty) throws SQLException
- Throws:
SQLException
-
getList
public List<T> getList(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getList
public List<T> getList(ResultSet rs, int maxNumRows) throws SQLException
- Throws:
SQLException
-
getSet
public Set<T> getSet(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getSet
public Set<T> getSet(ResultSet rs, int maxNumRows) throws SQLException
- Throws:
SQLException
-
getIterator
public ResultSetIterator<T> getIterator(ResultSet rs) throws SQLException
- Throws:
SQLException
-
getStatementCacheCsvForPrepStmts
public void getStatementCacheCsvForPrepStmts(StringBuilder sb) throws Exception
- Throws:
Exception
-
getStatementCacheStats
public StringBuilder getStatementCacheStats(StringBuilder strBldrToAppend, DateTimeFormatter optionalDtFormat) throws SQLException
- Throws:
SQLException
-
-