Search in sources :

Example 31 with ConstantPreparedStatementDataProvider

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);
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nullable(javax.annotation.Nullable)

Example 32 with ConstantPreparedStatementDataProvider

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;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) MutableLong(com.helger.commons.mutable.MutableLong) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nonnull(javax.annotation.Nonnull)

Example 33 with ConstantPreparedStatementDataProvider

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;
}
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

ConstantPreparedStatementDataProvider (com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)33 Nonnull (javax.annotation.Nonnull)20 DBExecutor (com.helger.db.jdbc.executor.DBExecutor)16 ESuccess (com.helger.commons.state.ESuccess)15 Nullable (javax.annotation.Nullable)15 Wrapper (com.helger.commons.wrapper.Wrapper)14 DBResultRow (com.helger.db.jdbc.executor.DBResultRow)14 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)14 MutableBoolean (com.helger.commons.mutable.MutableBoolean)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)8 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)8 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)8 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)7 EChange (com.helger.commons.state.EChange)6 ISMPTransportProfile (com.helger.peppol.smp.ISMPTransportProfile)5 IProcessIdentifier (com.helger.peppolid.IProcessIdentifier)5 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)5 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)5 ValueEnforcer (com.helger.commons.ValueEnforcer)4 ReturnsMutableObject (com.helger.commons.annotation.ReturnsMutableObject)4