Search in sources :

Example 26 with ConstantPreparedStatementDataProvider

use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method deleteAllParticipantMigrationsOfParticipant.

@Nonnull
public EChange deleteAllParticipantMigrationsOfParticipant(@Nonnull final IParticipantIdentifier aParticipantID) {
    ValueEnforcer.notNull(aParticipantID, "ParticipantID");
    final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_pmigration" + " WHERE pid=?", new ConstantPreparedStatementDataProvider(aParticipantID.getURIEncoded()));
    if (nDeleted == 0) {
        AuditHelper.onAuditDeleteFailure(SMPParticipantMigration.OT, aParticipantID.getURIEncoded(), "no-such-participant-id");
        return EChange.UNCHANGED;
    }
    AuditHelper.onAuditDeleteSuccess(SMPParticipantMigration.OT, aParticipantID.getURIEncoded());
    return EChange.CHANGED;
}
Also used : ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nonnull(javax.annotation.Nonnull)

Example 27 with ConstantPreparedStatementDataProvider

use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method _createParticipantMigration.

@Nullable
private ISMPParticipantMigration _createParticipantMigration(@Nonnull final SMPParticipantMigration aSMPParticipantMigration) {
    ValueEnforcer.notNull(aSMPParticipantMigration, "SMPParticipantMigration");
    final DBExecutor aExecutor = newExecutor();
    final ESuccess eSuccess = aExecutor.performInTransaction(() -> {
        // Create new
        final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_pmigration (id, direction, state, pid, initdt, migkey)" + " VALUES (?, ?, ?, ?, ?, ?)", new ConstantPreparedStatementDataProvider(aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection().getID(), aSMPParticipantMigration.getState().getID(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), DBValueHelper.toTimestamp(aSMPParticipantMigration.getInitiationDateTime()), aSMPParticipantMigration.getMigrationKey()));
        if (nCreated != 1)
            throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
    });
    if (eSuccess.isFailure()) {
        AuditHelper.onAuditCreateFailure(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), "database-error");
        return null;
    }
    AuditHelper.onAuditCreateSuccess(SMPParticipantMigration.OT, aSMPParticipantMigration.getID(), aSMPParticipantMigration.getDirection(), aSMPParticipantMigration.getParticipantIdentifier().getURIEncoded(), aSMPParticipantMigration.getInitiationDateTime(), aSMPParticipantMigration.getMigrationKey());
    return aSMPParticipantMigration;
}
Also used : ESuccess(com.helger.commons.state.ESuccess) DBExecutor(com.helger.db.jdbc.executor.DBExecutor) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nullable(javax.annotation.Nullable)

Example 28 with ConstantPreparedStatementDataProvider

use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method deleteParticipantMigrationOfID.

@Nonnull
public EChange deleteParticipantMigrationOfID(@Nullable final String sParticipantMigrationID) {
    if (StringHelper.hasNoText(sParticipantMigrationID))
        return EChange.UNCHANGED;
    final long nDeleted = newExecutor().insertOrUpdateOrDelete("DELETE FROM smp_pmigration" + " WHERE id=?", new ConstantPreparedStatementDataProvider(sParticipantMigrationID));
    if (nDeleted == 0) {
        AuditHelper.onAuditDeleteFailure(SMPParticipantMigration.OT, sParticipantMigrationID, "no-such-id");
        return EChange.UNCHANGED;
    }
    AuditHelper.onAuditDeleteSuccess(SMPParticipantMigration.OT, sParticipantMigrationID);
    return EChange.CHANGED;
}
Also used : ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nonnull(javax.annotation.Nonnull)

Example 29 with ConstantPreparedStatementDataProvider

use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.

the class SMPParticipantMigrationManagerJDBC method getParticipantMigrationOfParticipantID.

@Nullable
public ISMPParticipantMigration getParticipantMigrationOfParticipantID(@Nonnull final EParticipantMigrationDirection eDirection, @Nonnull final EParticipantMigrationState eState, @Nullable final IParticipantIdentifier aParticipantID) {
    ValueEnforcer.notNull(eDirection, "Direction");
    ValueEnforcer.notNull(eState, "State");
    if (aParticipantID == null)
        return null;
    final Wrapper<DBResultRow> aDBResult = new Wrapper<>();
    newExecutor().querySingle("SELECT id, initdt, migkey FROM smp_pmigration WHERE direction=? AND state=? AND pid=?", new ConstantPreparedStatementDataProvider(eDirection.getID(), eState.getID(), aParticipantID.getURIEncoded()), aDBResult::set);
    if (aDBResult.isNotSet())
        return null;
    final DBResultRow aRow = aDBResult.get();
    return new SMPParticipantMigration(aRow.getAsString(0), eDirection, eState, aParticipantID, aRow.getAsLocalDateTime(1), aRow.getAsString(2));
}
Also used : Wrapper(com.helger.commons.wrapper.Wrapper) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.SMPParticipantMigration) ISMPParticipantMigration(com.helger.phoss.smp.domain.pmigration.ISMPParticipantMigration) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nullable(javax.annotation.Nullable)

Example 30 with ConstantPreparedStatementDataProvider

use of com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider in project phoss-smp by phax.

the class SMPSettingsManagerJDBC method setSettingsValue.

static void setSettingsValue(@Nonnull final DBExecutor aExecutor, @Nonnull @Nonempty final String sKey, @Nullable final String sValue) {
    ValueEnforcer.notNull(aExecutor, "Executor");
    ValueEnforcer.notEmpty(sKey, "Key");
    // update
    final long nUpdated = aExecutor.insertOrUpdateOrDelete("UPDATE smp_settings SET value=? WHERE id=?", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(sValue, 500), DBValueHelper.getTrimmedToLength(sKey, 45)));
    if (nUpdated == 0) {
        // Create
        final long nCreated = aExecutor.insertOrUpdateOrDelete("INSERT INTO smp_settings (id, value) VALUES (?, ?)", new ConstantPreparedStatementDataProvider(DBValueHelper.getTrimmedToLength(sKey, 45), DBValueHelper.getTrimmedToLength(sValue, 500)));
        if (nCreated != 1)
            throw new IllegalStateException("Failed to create new DB entry (" + nCreated + ")");
    }
}
Also used : ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider)

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