Search in sources :

Example 11 with ConstantPreparedStatementDataProvider

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

Example 12 with ConstantPreparedStatementDataProvider

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);
        }
    });
}
Also used : DBExecutor(com.helger.db.jdbc.executor.DBExecutor) EDatabaseType(com.helger.phoss.smp.backend.sql.EDatabaseType) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Map(java.util.Map) ICommonsMap(com.helger.commons.collection.impl.ICommonsMap)

Example 13 with ConstantPreparedStatementDataProvider

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;
}
Also used : ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) Nonnull(javax.annotation.Nonnull)

Example 14 with ConstantPreparedStatementDataProvider

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;
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) DBResultRow(com.helger.db.jdbc.executor.DBResultRow) SMPRedirect(com.helger.phoss.smp.domain.redirect.SMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) X509Certificate(java.security.cert.X509Certificate) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 15 with ConstantPreparedStatementDataProvider

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;
}
Also used : IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ConstantPreparedStatementDataProvider(com.helger.db.jdbc.callback.ConstantPreparedStatementDataProvider) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

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