use of com.helger.db.jdbc.executor.DBExecutor in project phoss-smp by phax.
the class SMPParticipantMigrationManagerJDBC method setParticipantMigrationState.
@Nonnull
public EChange setParticipantMigrationState(@Nullable final String sParticipantMigrationID, @Nonnull final EParticipantMigrationState eNewState) {
ValueEnforcer.notNull(eNewState, "NewState");
final MutableLong aUpdated = new MutableLong(-1);
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Update existing
final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_pmigration SET state=? WHERE id=?", new ConstantPreparedStatementDataProvider(eNewState.getID(), sParticipantMigrationID));
aUpdated.set(nUpdated);
});
if (eSuccess.isFailure()) {
// DB error
AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState, "database-error");
return EChange.UNCHANGED;
}
if (aUpdated.is0()) {
// No such participant migration ID
AuditHelper.onAuditModifyFailure(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, "no-such-id");
return EChange.UNCHANGED;
}
AuditHelper.onAuditModifySuccess(SMPParticipantMigration.OT, "set-migration-state", sParticipantMigrationID, eNewState);
return EChange.CHANGED;
}
use of com.helger.db.jdbc.executor.DBExecutor in project phoss-smp by phax.
the class SMPServiceGroupManagerJDBC method createSMPServiceGroup.
@Nonnull
public SMPServiceGroup createSMPServiceGroup(@Nonnull @Nonempty final String sOwnerID, @Nonnull final IParticipantIdentifier aParticipantID, @Nullable final String sExtension, final boolean bCreateInSML) throws SMPServerException {
ValueEnforcer.notEmpty(sOwnerID, "OwnerID");
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup (" + sOwnerID + ", " + aParticipantID.getURIEncoded() + ", " + (StringHelper.hasText(sExtension) ? "with extension" : "without extension") + ", " + bCreateInSML + ")");
final MutableBoolean aCreatedSGHook = new MutableBoolean(false);
final MutableBoolean aCreatedSGDB = new MutableBoolean(false);
final IRegistrationHook aHook = RegistrationHookFactory.getInstance();
final Wrapper<Exception> aCaughtException = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// Check if the passed service group ID is already in use
final SMPServiceGroup aDBServiceGroup = getSMPServiceGroupOfID(aParticipantID);
if (aDBServiceGroup != null)
throw new IllegalStateException("The service group with ID " + aParticipantID.getURIEncoded() + " already exists!");
if (bCreateInSML) {
// It's a new service group - Create in SML and remember that
// Throws exception in case of an error
aHook.createServiceGroup(aParticipantID);
aCreatedSGHook.set(true);
}
// Did not exist. Create it.
if (aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_service_group (businessIdentifierScheme, businessIdentifier, extension) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sExtension)) > 0) {
aCreatedSGDB.set(true);
aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_ownership (businessIdentifierScheme, businessIdentifier, username) VALUES (?, ?, ?)", new ConstantPreparedStatementDataProvider(aParticipantID.getScheme(), aParticipantID.getValue(), sOwnerID));
}
}, aCaughtException::set);
if (aCreatedSGHook.booleanValue() && !aCreatedSGDB.booleanValue()) {
// Undo creation in SML again
try {
aHook.undoCreateServiceGroup(aParticipantID);
} catch (final RegistrationHookException ex) {
LOGGER.error("Failed to undoCreateServiceGroup (" + aParticipantID.getURIEncoded() + ")", ex);
}
}
if (eSuccess.isFailure() || aCaughtException.isSet() || !aCreatedSGDB.booleanValue()) {
AuditHelper.onAuditCreateFailure(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
// Propagate contained exception
final Exception ex = aCaughtException.get();
if (ex instanceof SMPServerException)
throw (SMPServerException) ex;
if (ex instanceof RegistrationHookException)
throw new SMPSMLException("Failed to create '" + aParticipantID.getURIEncoded() + "' in SML", ex);
throw new SMPInternalErrorException("Error creating ServiceGroup '" + aParticipantID.getURIEncoded() + "'", ex);
}
if (LOGGER.isDebugEnabled())
LOGGER.debug("createSMPServiceGroup succeeded");
AuditHelper.onAuditCreateSuccess(SMPServiceGroup.OT, aParticipantID.getURIEncoded(), sOwnerID, sExtension, Boolean.valueOf(bCreateInSML));
final SMPServiceGroup aServiceGroup = new SMPServiceGroup(sOwnerID, aParticipantID, sExtension);
if (m_aCache != null)
m_aCache.put(aParticipantID.getURIEncoded(), aServiceGroup);
m_aCBs.forEach(x -> x.onSMPServiceGroupCreated(aServiceGroup, bCreateInSML));
return aServiceGroup;
}
use of com.helger.db.jdbc.executor.DBExecutor in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteSMPProcess.
@Nonnull
public EChange deleteSMPProcess(@Nullable final ISMPServiceInformation aSMPServiceInformation, @Nullable final ISMPProcess aProcess) {
if (aSMPServiceInformation == null || aProcess == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
final IProcessIdentifier aProcessID = aProcess.getProcessIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=? AND processIdentifierType=? AND processIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue(), aProcessID.getScheme(), aProcessID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc));
});
if (eSuccess.isFailure())
return EChange.UNCHANGED;
return EChange.valueOf(ret.get().longValue() > 0);
}
use of com.helger.db.jdbc.executor.DBExecutor in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method _deleteSMPServiceInformationNoCallback.
@Nonnull
private EChange _deleteSMPServiceInformationNoCallback(@Nonnull final ISMPServiceInformation aSMPServiceInformation) {
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(-1));
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
final IParticipantIdentifier aPID = aSMPServiceInformation.getServiceGroup().getParticipantIdentifier();
final IDocumentTypeIdentifier aDocTypeID = aSMPServiceInformation.getDocumentTypeIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=? AND documentIdentifierScheme=? AND documentIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue(), aDocTypeID.getScheme(), aDocTypeID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
});
if (eSuccess.isFailure())
return EChange.UNCHANGED;
return EChange.valueOf(ret.get().longValue() > 0);
}
use of com.helger.db.jdbc.executor.DBExecutor in project phoss-smp by phax.
the class SMPServiceInformationManagerJDBC method deleteAllSMPServiceInformationOfServiceGroup.
@Nonnull
public EChange deleteAllSMPServiceInformationOfServiceGroup(@Nullable final ISMPServiceGroup aServiceGroup) {
if (aServiceGroup == null)
return EChange.UNCHANGED;
final Wrapper<Long> ret = new Wrapper<>(Long.valueOf(0));
final Wrapper<ICommonsList<ISMPServiceInformation>> aAllDeleted = new Wrapper<>();
final DBExecutor aExecutor = newExecutor();
final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
// get the old ones first
aAllDeleted.set(getAllSMPServiceInformationOfServiceGroup(aServiceGroup));
final IParticipantIdentifier aPID = aServiceGroup.getParticipantIdentifier();
final long nCountEP = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_endpoint" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountProc = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_process" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
final long nCountSM = aExecutor.insertOrUpdateOrDelete("DELETE FROM smp_service_metadata" + " WHERE businessIdentifierScheme=? AND businessIdentifier=?", new ConstantPreparedStatementDataProvider(aPID.getScheme(), aPID.getValue()));
ret.set(Long.valueOf(nCountEP + nCountProc + nCountSM));
});
if (eSuccess.isFailure() || ret.get().longValue() <= 0) {
AuditHelper.onAuditDeleteFailure(SMPServiceInformation.OT, "no-such-id", aServiceGroup.getID());
return EChange.UNCHANGED;
}
// Callback outside of transaction
if (aAllDeleted.isSet())
for (final ISMPServiceInformation aSMPServiceInformation : aAllDeleted.get()) {
AuditHelper.onAuditDeleteSuccess(SMPServiceInformation.OT, aSMPServiceInformation.getID());
m_aCBs.forEach(x -> x.onSMPServiceInformationDeleted(aSMPServiceInformation));
}
return EChange.CHANGED;
}
Aggregations