use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPSettingsManagerJDBC method getSettingsValue.
@Nullable
public static String getSettingsValue(@Nonnull final DBExecutor aExecutor, @Nullable final String sKey) {
if (StringHelper.hasNoText(sKey))
return null;
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
aExecutor.querySingle("SELECT value FROM smp_settings WHERE id=?", new ConstantPreparedStatementDataProvider(sKey), aDBResult::set);
if (aDBResult.isNotSet())
return null;
return aDBResult.get().getAsString(0);
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method updateSMPTransportProfile.
@Nonnull
public EChange updateSMPTransportProfile(@Nullable final String sSMPTransportProfileID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final MutableLong aUpdated = new MutableLong(-1);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_tprofile SET name=?, deprecated=? WHERE id=?", new ConstantPreparedStatementDataProvider(sName, Boolean.valueOf(bIsDeprecated), sSMPTransportProfileID));
aUpdated.set(nUpdated);
});
if (eSuccess.isFailure()) {
// DB error
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "database-error");
return EChange.UNCHANGED;
}
if (aUpdated.is0()) {
// No such transport profile ID
AuditHelper.onAuditModifyFailure(SMPTransportProfile.OT, "update", sSMPTransportProfileID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditModifySuccess(SMPTransportProfile.OT, "update", sSMPTransportProfileID, sName, Boolean.valueOf(bIsDeprecated));
return EChange.CHANGED;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method createSMPTransportProfile.
@Nullable
public ISMPTransportProfile createSMPTransportProfile(@Nonnull @Nonempty final String sID, @Nonnull @Nonempty final String sName, final boolean bIsDeprecated) {
final ISMPTransportProfile ret = new SMPTransportProfile(sID, sName, bIsDeprecated);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Create new
final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_tprofile (id, name, deprecated) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(ret.getID(), 45), ret.getName(), Boolean.valueOf(ret.isDeprecated())));
if (nCreated != 1)
throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
});
if (eSuccess.isFailure()) {
AuditHelper.onAuditCreateFailure(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated), "database-error");
return null;
}
AuditHelper.onAuditCreateSuccess(SMPTransportProfile.OT, sID, sName, Boolean.valueOf(bIsDeprecated));
return ret;
}
Aggregations