use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPTransportProfileManagerJDBC method getSMPTransportProfileOfID.
@Nullable
public ISMPTransportProfile getSMPTransportProfileOfID(@Nullable final String sID) {
if (StringHelper.hasNoText(sID))
return null;
final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
newExecutor().querySingle("SELECT name, deprecated FROM smp_tprofile WHERE id=?", new ConstantPreparedStatementDataProvider(sID), aDBResult::set);
if (aDBResult.isNotSet())
return null;
final DBResultRow aRow = aDBResult.get();
return new SMPTransportProfile(sID, aRow.getAsString(0), aRow.getAsBoolean(1, SMPTransportProfile.DEFAULT_DEPRECATED));
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPUserManagerJDBC method updateOwnershipsAndKillUsers.
public void updateOwnershipsAndKillUsers(@Nonnull final ICommonsMap<String, String> aOldToNewUserNameMap) {
ValueEnforcer.notNull(aOldToNewUserNameMap, "OldToNewUserNameMap");
final DBExecutor aExecutor = newExecutor();
aExecutor.performInTransaction(() -> {
// Drop the Foreign Key Constraint - do this all the time
try {
final EDatabaseType eDBType = SMPDataSourceSingleton.getDatabaseType();
switch(eDBType) {
case MYSQL:
aExecutor.executeStatement("ALTER TABLE smp_ownership DROP FOREIGN KEY FK_smp_ownership_username;");
break;
case POSTGRESQL:
aExecutor.executeStatement("ALTER TABLE smp_ownership DROP CONSTRAINT FK_smp_ownership_username;");
break;
case ORACLE:
case DB2:
// No such constraint
break;
default:
throw new IllegalStateException("The migration code for DB type " + eDBType + " is missing");
}
} catch (final RuntimeException ex) {
LOGGER.warn("Error in droping constraints", ex);
}
// Update user names
for (final Map.Entry<String, String> aEntry : aOldToNewUserNameMap.entrySet()) {
final String sOld = aEntry.getKey();
final String sNew = aEntry.getValue();
aExecutor.insertOrUpdateOrDelete("UPDATE smp_ownership SET username=? WHERE username=?", new ConstantPreparedStatementDataProvider(sNew, sOld));
}
try {
aExecutor.executeStatement("DROP TABLE smp_user;");
} catch (final RuntimeException ex) {
LOGGER.warn("Error in droping table smp_user", ex);
}
});
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPBusinessCardManagerJDBC method deleteSMPBusinessCard.
@Nonnull
public EChange deleteSMPBusinessCard(@Nullable final ISMPBusinessCard aSMPBusinessCard) {
if (aSMPBusinessCard == null)
return EChange.UNCHANGED;
if (LOGGER.isDebugEnabled())
LOGGER.debug("deleteSMPBusinessCard (" + aSMPBusinessCard.getID() + ")");
final long nCount = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_bce" + " WHERE pid=?", new ConstantPreparedStatementDataProvider(aSMPBusinessCard.getID()));
if (nCount <= 0) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Finished deleteSMPBusinessCard. Change=false");
AuditHelper.onAuditDeleteFailure(SMPBusinessCard.OT, aSMPBusinessCard.getID(), "no-such-id");
return EChange.UNCHANGED;
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("Finished deleteSMPBusinessCard. Change=true");
AuditHelper.onAuditDeleteSuccess(SMPBusinessCard.OT, aSMPBusinessCard.getID(), Integer.valueOf(aSMPBusinessCard.getEntityCount()));
// Invoke generic callbacks
m_aCBs.forEach(x -> x.onSMPBusinessCardDeleted(aSMPBusinessCard));
return EChange.CHANGED;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method getAllSMPRedirectsOfServiceGroup.
@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPRedirect> getAllSMPRedirectsOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
final ICommonsList<ISMPRedirect> ret = new CommonsArrayList<>();
if (aServiceGroup != null) {
final IParticipantIdentifier aParticipantID = aServiceGroup.getParticipantIdentifier();
final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT documentIdentifierScheme, documentIdentifier, redirectionUrl, certificateUID, certificate, extension" + " FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue()));
if (aDBResult != null)
for (final DBResultRow aRow : aDBResult) {
final X509Certificate aCertificate = CertificateHelper.convertStringToCertficateOrNull(aRow.getAsString(4));
ret.add(new SMPRedirect(aServiceGroup, new SimpleDocumentTypeIdentifier(aRow.getAsString(0), aRow.getAsString(1)), aRow.getAsString(2), aRow.getAsString(3), aCertificate, aRow.getAsString(5)));
}
}
return ret;
}
use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.
the class SMPRedirectManagerJDBC method deleteSMPRedirect.
@Nonnull
public EChange deleteSMPRedirect(@Nullable final ISMPRedirect aSMPRedirect) {
if (aSMPRedirect == null)
return EChange.UNCHANGED;
final IParticipantIdentifier aParticipantID = aSMPRedirect.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPRedirect.getDocumentTypeIdentifier();
final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_service_metadata_red" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? and documentIdentifier=?", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
if (nDeleted == 0) {
AuditHelper.onAuditDeleteFailure(SMPRedirect.OT, aSMPRedirect.getID(), "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditDeleteSuccess(SMPRedirect.OT, aSMPRedirect.getID(), aSMPRedirect.getServiceGroupID(), aSMPRedirect.getDocumentTypeIdentifier().getURIEncoded());
m_aCallbacks.forEach(x -> x.onSMPRedirectDeleted(aSMPRedirect));
return EChange.CHANGED;
}
Aggregations