Package org.xipki.ca.mgmt.db
Class DbToolBase
- java.lang.Object
-
- org.xipki.ca.mgmt.db.DbToolBase
-
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
DbPorter
public class DbToolBase extends Object implements Closeable
Database tool base.- Since:
- 2.0.0
- Author:
- Lijun Liao (xipki)
-
-
Field Summary
Fields Modifier and Type Field Description protected StringbaseDirprotected Connectionconnectionprotected org.xipki.datasource.DataSourceWrapperdatasourceprotected AtomicBooleanstopMe
-
Constructor Summary
Constructors Constructor Description DbToolBase(org.xipki.datasource.DataSourceWrapper datasource, String baseDir, AtomicBoolean stopMe)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringbuildFilename(String prefix, String suffix, long minIdOfCurrentFile, long maxIdOfCurrentFile, long maxId)voidclose()protected voidcommit(String task)intcount(String table)protected StatementcreateStatement()booleandeleteFromTableWithLargerId(String table, String idColumn, long id, org.slf4j.Logger log)static voiddeleteTmpFiles(String dirName, String prefix)protected voiddisableAutoCommit()static PropertiesgetDbConfProperties(InputStream is)static ZipOutputStreamgetZipOutputStream(File zipFile)longmax(String table, String column)longmax(String table, String column, String condition)longmin(String table, String column)longmin(String table, String column, String condition)protected PreparedStatementprepareStatement(String sql)protected voidrecoverAutoCommit()voidreleaseResources(Statement ps, ResultSet rs)protected voidrollback()protected static voidsetBoolean(PreparedStatement ps, int index, boolean value)protected static voidsetInt(PreparedStatement ps, int index, Integer value)protected static voidsetLong(PreparedStatement ps, int index, Long value)protected SavepointsetSavepoint()booleantableExists(String table)booleantableHasColumn(String table, String column)protected org.xipki.datasource.DataAccessExceptiontranslate(String sql, SQLException ex)protected static voidwriteLine(OutputStream os, String text)
-
-
-
Field Detail
-
stopMe
protected final AtomicBoolean stopMe
-
datasource
protected final org.xipki.datasource.DataSourceWrapper datasource
-
baseDir
protected final String baseDir
-
connection
protected Connection connection
-
-
Constructor Detail
-
DbToolBase
public DbToolBase(org.xipki.datasource.DataSourceWrapper datasource, String baseDir, AtomicBoolean stopMe) throws org.xipki.datasource.DataAccessException- Throws:
org.xipki.datasource.DataAccessException
-
-
Method Detail
-
createStatement
protected Statement createStatement() throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
prepareStatement
protected PreparedStatement prepareStatement(String sql) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
deleteFromTableWithLargerId
public boolean deleteFromTableWithLargerId(String table, String idColumn, long id, org.slf4j.Logger log)
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
min
public long min(String table, String column) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
min
public long min(String table, String column, String condition) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
max
public long max(String table, String column) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
max
public long max(String table, String column, String condition) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
count
public int count(String table) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
tableHasColumn
public boolean tableHasColumn(String table, String column) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
tableExists
public boolean tableExists(String table) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
setSavepoint
protected Savepoint setSavepoint() throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
rollback
protected void rollback() throws org.xipki.datasource.DataAccessException- Throws:
org.xipki.datasource.DataAccessException
-
translate
protected org.xipki.datasource.DataAccessException translate(String sql, SQLException ex)
-
disableAutoCommit
protected void disableAutoCommit() throws org.xipki.datasource.DataAccessException- Throws:
org.xipki.datasource.DataAccessException
-
recoverAutoCommit
protected void recoverAutoCommit()
-
commit
protected void commit(String task) throws org.xipki.datasource.DataAccessException
- Throws:
org.xipki.datasource.DataAccessException
-
setLong
protected static void setLong(PreparedStatement ps, int index, Long value) throws SQLException
- Throws:
SQLException
-
setInt
protected static void setInt(PreparedStatement ps, int index, Integer value) throws SQLException
- Throws:
SQLException
-
setBoolean
protected static void setBoolean(PreparedStatement ps, int index, boolean value) throws SQLException
- Throws:
SQLException
-
getDbConfProperties
public static Properties getDbConfProperties(InputStream is) throws IOException
- Throws:
IOException
-
writeLine
protected static void writeLine(OutputStream os, String text) throws IOException
- Throws:
IOException
-
buildFilename
public static String buildFilename(String prefix, String suffix, long minIdOfCurrentFile, long maxIdOfCurrentFile, long maxId)
-
getZipOutputStream
public static ZipOutputStream getZipOutputStream(File zipFile) throws IOException
- Throws:
IOException
-
-