use of org.xipki.datasource.DataAccessException in project xipki by xipki.
the class OcspCertPublisher method initialize.
@Override
public void initialize(String conf, PasswordResolver passwordResolver, Map<String, DataSourceWrapper> datasources) throws CertPublisherException {
ParamUtil.requireNonNull("conf", conf);
ParamUtil.requireNonEmpty("datasources", datasources);
ConfPairs pairs = new ConfPairs(conf);
String str = pairs.value("publish.goodcerts");
this.publishsGoodCert = (str == null) ? true : Boolean.parseBoolean(str);
str = pairs.value("asyn");
this.asyn = (str == null) ? false : Boolean.parseBoolean(str);
ConfPairs confPairs = new ConfPairs(conf);
String datasourceName = confPairs.value("datasource");
DataSourceWrapper datasource = null;
if (datasourceName != null) {
datasource = datasources.get(datasourceName);
}
if (datasource == null) {
throw new CertPublisherException("no datasource named '" + datasourceName + "' is specified");
}
try {
queryExecutor = new OcspStoreQueryExecutor(datasource, this.publishsGoodCert);
} catch (NoSuchAlgorithmException | DataAccessException ex) {
throw new CertPublisherException(ex.getMessage(), ex);
}
}
use of org.xipki.datasource.DataAccessException in project xipki by xipki.
the class OcspStoreQueryExecutor method borrowPreparedStatement.
// method addIssuer
/**
* TODO.
* @param sqlQuery the SQL query
* @return the next idle preparedStatement, {@code null} will be returned if no PreparedStament
* can be created within 5 seconds.
*/
private PreparedStatement borrowPreparedStatement(String sqlQuery) throws DataAccessException {
PreparedStatement ps = null;
Connection col = datasource.getConnection();
if (col != null) {
ps = datasource.prepareStatement(col, sqlQuery);
}
if (ps == null) {
throw new DataAccessException("could not create prepared statement for " + sqlQuery);
}
return ps;
}
use of org.xipki.datasource.DataAccessException in project xipki by xipki.
the class CertStoreQueryExecutor method borrowPreparedStatement.
// method borrowPreparedStatements
private PreparedStatement borrowPreparedStatement(String sqlQuery) throws DataAccessException {
PreparedStatement ps = null;
Connection conn = datasource.getConnection();
if (conn != null) {
ps = datasource.prepareStatement(conn, sqlQuery);
}
if (ps != null) {
return ps;
}
throw new DataAccessException("could not create prepared statement for " + sqlQuery);
}
use of org.xipki.datasource.DataAccessException in project xipki by xipki.
the class CertStoreQueryExecutor method borrowPreparedStatements.
private PreparedStatement[] borrowPreparedStatements(String... sqlQueries) throws DataAccessException {
Connection conn = datasource.getConnection();
if (conn == null) {
throw new DataAccessException("could not get connection");
}
final int n = sqlQueries.length;
PreparedStatement[] pss = new PreparedStatement[n];
for (int i = 0; i < n; i++) {
pss[i] = datasource.prepareStatement(conn, sqlQueries[i]);
if (pss[i] != null) {
continue;
}
// destroy all already initialized statements
for (int j = 0; j < i; j++) {
try {
pss[j].close();
} catch (Throwable th) {
LOG.warn("could not close preparedStatement", th);
}
}
try {
conn.close();
} catch (Throwable th) {
LOG.warn("could not close connection", th);
}
throw new DataAccessException("could not create prepared statement for " + sqlQueries[i]);
}
return pss;
}
use of org.xipki.datasource.DataAccessException in project xipki by xipki.
the class DbGoodCertSerialIterator method readNextNumber.
private BigInteger readNextNumber() {
BigInteger firstSerial = nextSerials.pollFirst();
if (firstSerial != null) {
return firstSerial;
}
if (noUnrevokedCerts) {
return null;
}
String sql = sqlNextSerials;
PreparedStatement stmt = null;
ResultSet rs = null;
int idx = 0;
try {
stmt = caDataSource.getConnection().prepareStatement(sql);
stmt.setInt(1, caId);
stmt.setLong(2, nextStartId);
rs = stmt.executeQuery();
while (rs.next()) {
idx++;
long id = rs.getLong("ID");
if (id + 1 > nextStartId) {
nextStartId = id + 1;
}
String serialStr = rs.getString("SN");
BigInteger serial = new BigInteger(serialStr, 16);
if (!caSerial.equals(serial)) {
nextSerials.addLast(serial);
}
}
} catch (SQLException ex) {
DataAccessException daex = caDataSource.translate(sql, ex);
throw new NoSuchElementException(daex.getMessage());
} catch (DataAccessException ex) {
throw new NoSuchElementException(ex.getMessage());
} finally {
caDataSource.releaseResources(stmt, rs);
}
if (idx < numSqlEntries) {
noUnrevokedCerts = true;
}
return nextSerials.pollFirst();
}
Aggregations