Search in sources :

Example 16 with DBExecutor

use of com.helger.db.jdbc.executor.DBExecutor 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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) ISMPTransportProfile(com.helger.peppol.smp.ISMPTransportProfile) SMPTransportProfile(com.helger.peppol.smp.SMPTransportProfile) Nullable(javax.annotation.Nullable)

Aggregations

DBExecutor (com.helger.db.jdbc.executor.DBExecutor)16 ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)14 ESuccess (com.helger.commons.state.ESuccess)13 Nonnull (javax.annotation.Nonnull)10 MutableBoolean (com.helger.commons.mutable.MutableBoolean)7 Wrapper (com.helger.commons.wrapper.Wrapper)6 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)6 Nullable (javax.annotation.Nullable)5 EChange (com.helger.commons.state.EChange)4 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)4 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)4 ICommonsMap (com.helger.commons.collection.impl.ICommonsMap)3 MutableLong (com.helger.commons.mutable.MutableLong)3 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)3 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)3 Map (java.util.Map)3 ValueEnforcer (com.helger.commons.ValueEnforcer)2 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)2 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)2 CallbackList (com.helger.commons.callback.CallbackList)2