use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addScep.
// method unrevokeCa
void addScep(ScepEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
final String sql = "INSERT INTO SCEP (NAME,CA_ID,ACTIVE,PROFILES,CONTROL,RESPONDER_NAME)" + " VALUES (?,?,?,?,?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
int idx = 1;
ps.setString(idx++, dbEntry.getName());
ps.setInt(idx++, dbEntry.getCaIdent().getId());
setBoolean(ps, idx++, dbEntry.isActive());
ps.setString(idx++, StringUtil.collectionAsStringByComma(dbEntry.getCertProfiles()));
ps.setString(idx++, dbEntry.getControl());
ps.setString(idx++, dbEntry.getResponderName());
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add SCEP " + dbEntry.getName());
}
LOG.info("added SCEP '{}': {}", dbEntry.getName(), dbEntry);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addPublisher.
// method addEnvParam
void addPublisher(PublisherEntry dbEntry) throws CaMgmtException {
ParamUtil.requireNonNull("dbEntry", dbEntry);
final String sql = "INSERT INTO PUBLISHER (ID,NAME,TYPE,CONF) VALUES (?,?,?,?)";
try {
int id = (int) datasource.getMax(null, "PUBLISHER", "ID");
dbEntry.getIdent().setId(id + 1);
} catch (DataAccessException ex) {
throw new CaMgmtException(ex);
}
String name = dbEntry.getIdent().getName();
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
int idx = 1;
ps.setInt(idx++, dbEntry.getIdent().getId());
ps.setString(idx++, name);
ps.setString(idx++, dbEntry.getType());
String conf = dbEntry.getConf();
ps.setString(idx++, conf);
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add publisher " + dbEntry.getIdent());
}
LOG.info("added publisher '{}': {}", dbEntry.getIdent(), dbEntry);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method deleteRows.
// method deleteRowWithName
boolean deleteRows(String table) throws CaMgmtException {
final String sql = "DELETE FROM " + table;
Statement stmt = null;
try {
stmt = createStatement();
return stmt.executeUpdate(sql) > 0;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method createCaHasPublishers.
// method createCaHasProfiles
Set<Integer> createCaHasPublishers(NameId ca) throws CaMgmtException {
final String sql = "SELECT PUBLISHER_ID FROM CA_HAS_PUBLISHER WHERE CA_ID=?";
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = prepareStatement(sql);
stmt.setInt(1, ca.getId());
rs = stmt.executeQuery();
Set<Integer> ret = new HashSet<>();
while (rs.next()) {
int id = rs.getInt("PUBLISHER_ID");
ret.add(id);
}
return ret;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method removeRequestorFromCa.
// method removeCertprofileFromCa
void removeRequestorFromCa(String requestorName, String caName) throws CaMgmtException {
ParamUtil.requireNonBlank("requestorName", requestorName);
ParamUtil.requireNonBlank("caName", caName);
int caId = getNonNullIdForName(sqls.sqlSelectCaId, caName);
int requestorId = getNonNullIdForName(sqls.sqlSelectRequestorId, requestorName);
final String sql = "DELETE FROM CA_HAS_REQUESTOR WHERE CA_ID=? AND REQUESTOR_ID=?";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
ps.setInt(1, caId);
ps.setInt(2, requestorId);
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not remove requestor " + requestorName + " from CA " + caName);
}
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
Aggregations