use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method deleteAllParticipantMigrationsOfParticipant.
@Nonnull
public EChange deleteAllParticipantMigrationsOfParticipant(@Nonnull final IParticipantIdentifier aParticipantID) {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_pmigration" + " WHERE pid=?", new ConstantPreparedStatementDataProvider(aParticipantID.getURIEncoded()));
if (nDeleted == 0) {
AuditHelper.onAuditDeleteFailure(SMPParticipantMigration.OT, aParticipantID.getURIEncoded(), "no-such-participant-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditDeleteSuccess(SMPParticipantMigration.OT, aParticipantID.getURIEncoded());
return EChange.CHANGED;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method _createParticipantMigration.
@Nullable
private ISMPParticipantMigration _createParticipantMigration(@Nonnull final SMPParticipantMigration aSMPParticipantMigration) {
ValueEnforcer.notNull(aSMPParticipantMigration, "SMPParticipantMigration");
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Create new
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_pmigration (id, direction, state, pid, initdt, migkey)" + " VALUES (?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection().getID(), aSMPParticipantMigration.getState().getID(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), DBValueHelper.toTimestamp(aSMPParticipantMigration.getInitiationDateTime()), aSMPParticipantMigration.getMigrationKey()));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
});
if (eSuccess.isFailure()) {
AuditHelper.onAuditCreateFailure(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), "database-error");
return null;
}
AuditHelper.onAuditCreateSuccess(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), aSMPParticipantMigration.getInitiationDateTime(), aSMPParticipantMigration.getMigrationKey());
return aSMPParticipantMigration;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method deleteParticipantMigrationOfID.
@Nonnull
public EChange deleteParticipantMigrationOfID(@Nullable final String sParticipantMigrationID) {
if (StringHelper.hasNoText(sParticipantMigrationID))
return EChange.UNCHANGED;
final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_pmigration" + " WHERE id=?", new ConstantPreparedStatementDataProvider(sParticipantMigrationID));
if (nDeleted == 0) {
AuditHelper.onAuditDeleteFailure(SMPParticipantMigration.OT, sParticipantMigrationID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditDeleteSuccess(SMPParticipantMigration.OT, sParticipantMigrationID);
return EChange.CHANGED;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method getParticipantMigrationOfParticipantID.
@Nullable
public ISMPParticipantMigration getParticipantMigrationOfParticipantID(@Nonnull final EParticipantMigrationDirection eDirection, @Nonnull final EParticipantMigrationState eState, @Nullable final IParticipantIdentifier aParticipantID) {
ValueEnforcer.notNull(eDirection, "Direction");
ValueEnforcer.notNull(eState, "State");
if (aParticipantID == null)
return null;
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
newExecutor().querySingle("SELECT id, initdt, migkey FROM smp_pmigration WHERE direction=? AND state=? AND pid=?", new ConstantPreparedStatementDataProvider(eDirection.getID(), eState.getID(), aParticipantID.getURIEncoded()), aDBResult::set);
if (aDBResult.isNotSet())
return null;
final DBResultRow aRow = aDBResult.get();
return new SMPParticipantMigration(aRow.getAsString(0), eDirection, eState, aParticipantID, aRow.getAsLocalDateTime(1), aRow.getAsString(2));
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPSettingsManagerJDBC method setSettingsValue.
static void setSettingsValue(@Nonnull final DBExecutor aExecutor, @Nonnull @Nonempty final String sKey, @Nullable final String sValue) {
ValueEnforcer.notNull(aExecutor, "Executor");
ValueEnforcer.notEmpty(sKey, "Key");
// update
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_settings SET value=? WHERE id=?", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(sValue, 500), DBValueHelper.getTrimmedToLength(sKey, 45)));
if (nUpdated == 0) {
// Create
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_settings (id, value) VALUES (?, ?)", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(sKey, 45), DBValueHelper.getTrimmedToLength(sValue, 500)));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
}
}
Aggregations