import java.sql.Date;
import org.cacert.gigi.GigiApiException;
+import org.cacert.gigi.database.DBEnum;
import org.cacert.gigi.database.GigiPreparedStatement;
import org.cacert.gigi.database.GigiResultSet;
import org.cacert.gigi.output.CertificateValiditySelector;
this.id = id;
}
- public static enum JobType {
+ public static enum JobType implements DBEnum {
SIGN("sign"), REVOKE("revoke");
private final String name;
this.name = name;
}
- public String getName() {
+ @Override
+ public String getDBName() {
return name;
}
}
CertificateValiditySelector.checkValidityLength(period);
try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `jobs` SET targetId=?, task=?::`jobType`, executeFrom=?, executeTo=?")) {
ps.setInt(1, targetId.getId());
- ps.setString(2, JobType.SIGN.getName());
+ ps.setEnum(2, JobType.SIGN);
ps.setDate(3, start);
ps.setString(4, period);
ps.execute();
try (GigiPreparedStatement ps = new GigiPreparedStatement("INSERT INTO `jobs` SET targetId=?, task=?::`jobType`")) {
ps.setInt(1, targetId.getId());
- ps.setString(2, JobType.REVOKE.getName());
+ ps.setEnum(2, JobType.REVOKE);
ps.execute();
return cache.put(new Job(ps.lastInsertId()));
}
}
- public synchronized boolean waitFor(int max) throws InterruptedException {
+ public synchronized boolean waitFor(int max) {
long start = System.currentTimeMillis();
try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `jobs` WHERE id=? AND state='open'")) {
ps.setInt(1, id);
if (max != 0 && System.currentTimeMillis() - start > max) {
return false;
}
- Thread.sleep((long) (2000 + Math.random() * 2000));
+ try {
+ this.wait((long) (2000 + Math.random() * 2000));
+ } catch (InterruptedException ie) {
+ // Ignore the interruption
+ ie.printStackTrace();
+ }
rs = ps.executeQuery();
}
}
if (i != null) {
return i;
}
- try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `jobs` WHERE id=?'")) {
+ try (GigiPreparedStatement ps = new GigiPreparedStatement("SELECT 1 FROM `jobs` WHERE id=?")) {
ps.setInt(1, id);
GigiResultSet rs = ps.executeQuery();
if (rs.next()) {