Search in sources :

Example 1 with SleeTransaction

use of javax.slee.transaction.SleeTransaction in project smscgateway by RestComm.

the class SchedulerResourceAdaptor method doInjectSms.

private boolean doInjectSms(SmsSet smsSet, boolean callFromSbb) throws NotSupportedException, SystemException, Exception, RollbackException, HeuristicMixedException, HeuristicRollbackException {
    if (!callFromSbb) {
        // If this call is from SBB it comes with Transaction and no need to start one
        SleeTransaction sleeTx = this.sleeTransactionManager.beginSleeTransaction();
    }
    try {
        this.doSetDestCluster(smsSet);
        String eventName = null;
        switch(smsSet.getType()) {
            case SMS_FOR_ESME:
                eventName = EVENT_SMPP_SM;
                break;
            case SMS_FOR_SS7:
                eventName = EVENT_SS7_SM;
                break;
            case SMS_FOR_SIP:
                eventName = EVENT_SIP_SM;
                break;
        }
        final FireableEventType eventTypeId = this.eventIdCache.getEventId(eventName);
        SmsSetEvent event = new SmsSetEvent();
        event.setSmsSet(smsSet);
        SchedulerActivityImpl activity = new SchedulerActivityImpl(this);
        this.sleeEndpoint.startActivityTransacted(activity.getActivityHandle(), activity, ACTIVITY_FLAGS);
        try {
            this.sleeEndpoint.fireEventTransacted(activity.getActivityHandle(), eventTypeId, event, null, null);
        } catch (Exception e) {
            if (this.tracer.isSevereEnabled()) {
                this.tracer.severe("Failed to fire SmsSet event Class=: " + eventTypeId.getEventClassName(), e);
            }
            try {
                this.sleeEndpoint.endActivityTransacted(activity.getActivityHandle());
            } catch (Exception ee) {
            }
        }
        markAsInSystem(smsSet);
    } catch (Exception e) {
        if (!callFromSbb) {
            this.sleeTransactionManager.rollback();
        }
        throw e;
    }
    if (!callFromSbb) {
        // If this call is from SBB it comes with Transaction and no need to commit here
        this.sleeTransactionManager.commit();
    }
    this.incrementActivityCount();
    return true;
}
Also used : SleeTransaction(javax.slee.transaction.SleeTransaction) SmsSetEvent(org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent) FireableEventType(javax.slee.resource.FireableEventType) RollbackException(javax.transaction.RollbackException) PersistenceException(org.mobicents.smsc.cassandra.PersistenceException) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException) InvalidConfigurationException(javax.slee.resource.InvalidConfigurationException) HeuristicMixedException(javax.transaction.HeuristicMixedException)

Example 2 with SleeTransaction

use of javax.slee.transaction.SleeTransaction in project charging-server by RestComm.

the class UpdateUserJdbcTask method executeSimple.

@Override
public Object executeSimple(JdbcTaskContext taskContext) {
    SleeTransaction tx = null;
    try {
        tx = taskContext.getSleeTransactionManager().beginSleeTransaction();
        Connection connection = taskContext.getConnection();
        // static value of query string, since its widely used :)
        PreparedStatement preparedStatement = connection.prepareStatement(DataSourceSchemaInfo._QUERY_INSERT);
        preparedStatement.setString(1, msisdn);
        preparedStatement.setFloat(2, balance);
        preparedStatement.setDate(3, null);
        preparedStatement.setTimestamp(4, null);
        preparedStatement.setString(5, "Active");
        int inserts = preparedStatement.executeUpdate();
        tx.commit();
        tx = null;
        return inserts;
    } catch (Exception e) {
        tracer.severe("Failed to execute jdbc task.", e);
        return null;
    } finally {
        if (tx != null) {
            try {
                tx.rollback();
            } catch (Exception f) {
                tracer.severe("failed to rollback tx", f);
            }
        }
    }
}
Also used : SleeTransaction(javax.slee.transaction.SleeTransaction) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

SleeTransaction (javax.slee.transaction.SleeTransaction)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 FireableEventType (javax.slee.resource.FireableEventType)1 InvalidConfigurationException (javax.slee.resource.InvalidConfigurationException)1 HeuristicMixedException (javax.transaction.HeuristicMixedException)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 NotSupportedException (javax.transaction.NotSupportedException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 PersistenceException (org.mobicents.smsc.cassandra.PersistenceException)1 SmsSetEvent (org.mobicents.smsc.slee.services.smpp.server.events.SmsSetEvent)1