use of org.xipki.ca.dbtool.xmlio.ocsp.OcspCertsReader in project xipki by xipki.
the class OcspCertStoreDbImporter method importCert0.
// method importCert
private long importCert0(PreparedStatement psCert, String certsZipFile, long minId, File processLogFile, ProcessLog processLog, int numProcessedInLastProcess) throws Exception {
ZipFile zipFile = new ZipFile(new File(certsZipFile));
ZipEntry certsXmlEntry = zipFile.getEntry("certs.xml");
OcspCertsReader certs;
try {
certs = new OcspCertsReader(zipFile.getInputStream(certsXmlEntry));
} catch (Exception ex) {
try {
zipFile.close();
} catch (Exception e2) {
LOG.error("could not close ZIP file {}: {}", certsZipFile, e2.getMessage());
LOG.debug("could not close ZIP file " + certsZipFile, e2);
}
throw ex;
}
disableAutoCommit();
try {
int numEntriesInBatch = 0;
long lastSuccessfulCertId = 0;
while (certs.hasNext()) {
if (stopMe.get()) {
throw new InterruptedException("interrupted by the user");
}
OcspCertType cert = (OcspCertType) certs.next();
long id = cert.getId();
if (id < minId) {
continue;
}
numEntriesInBatch++;
// cert
try {
int idx = 1;
psCert.setLong(idx++, id);
psCert.setInt(idx++, cert.getIid());
psCert.setString(idx++, cert.getSn());
psCert.setLong(idx++, cert.getUpdate());
psCert.setLong(idx++, cert.getNbefore());
psCert.setLong(idx++, cert.getNafter());
setBoolean(psCert, idx++, cert.getRev().booleanValue());
setInt(psCert, idx++, cert.getRr());
setLong(psCert, idx++, cert.getRt());
setLong(psCert, idx++, cert.getRit());
psCert.setString(idx++, cert.getProfile());
psCert.setString(idx++, cert.getHash());
psCert.setString(idx++, cert.getSubject());
psCert.addBatch();
} catch (SQLException ex) {
throw translate(SQL_ADD_CERT, ex);
}
boolean isLastBlock = !certs.hasNext();
if (numEntriesInBatch > 0 && (numEntriesInBatch % this.numCertsPerCommit == 0 || isLastBlock)) {
if (evaulateOnly) {
psCert.clearBatch();
} else {
try {
psCert.executeBatch();
commit("(commit import cert to OCSP)");
} catch (Throwable th) {
rollback();
deleteCertGreatherThan(lastSuccessfulCertId, LOG);
if (th instanceof SQLException) {
throw translate(SQL_ADD_CERT, (SQLException) th);
} else if (th instanceof Exception) {
throw (Exception) th;
} else {
throw new Exception(th);
}
}
}
lastSuccessfulCertId = id;
processLog.addNumProcessed(numEntriesInBatch);
numEntriesInBatch = 0;
echoToFile((numProcessedInLastProcess + processLog.numProcessed()) + ":" + lastSuccessfulCertId, processLogFile);
processLog.printStatus();
}
}
return lastSuccessfulCertId;
} finally {
recoverAutoCommit();
zipFile.close();
}
}
Aggregations