Example usage for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult

List of usage examples for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult

Introduction

In this page you can find the example usage for org.springframework.transaction.support TransactionCallbackWithoutResult TransactionCallbackWithoutResult.

Prototype

TransactionCallbackWithoutResult

Source Link

Usage

From source file:org.apache.camel.component.jdbc.aggregationrepository.JdbcAggregationRepository.java

public void remove(final CamelContext camelContext, final String correlationId, final Exchange exchange) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            final String key = correlationId;
            final String confirmKey = exchange.getExchangeId();
            try {
                final byte[] data = codec.marshallExchange(camelContext, exchange);

                if (LOG.isDebugEnabled()) {
                    LOG.debug("Removing key [" + key + "]");
                }/*from w  w  w. jav  a 2 s .com*/

                jdbcTemplate.update("DELETE FROM " + getRepositoryName() + " WHERE " + ID + " = ?",
                        new Object[] { key });

                jdbcTemplate.execute(
                        "INSERT INTO " + getRepositoryNameCompleted() + " (" + EXCHANGE + ", " + ID
                                + ") VALUES (?, ?)",
                        new AbstractLobCreatingPreparedStatementCallback(getLobHandler()) {
                            @Override
                            protected void setValues(PreparedStatement ps, LobCreator lobCreator)
                                    throws SQLException {
                                lobCreator.setBlobAsBytes(ps, 1, data);
                                ps.setString(2, confirmKey);
                            }
                        });
            } catch (IOException e) {
                throw new RuntimeException("Error removing key " + key + " from repository " + repositoryName,
                        e);
            }
        }
    });
}

From source file:org.apache.camel.component.jdbc.aggregationrepository.JdbcAggregationRepository.java

public void confirm(final CamelContext camelContext, final String exchangeId) {
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Confirming exchangeId [" + exchangeId + "]");
            }//from ww  w. j a v a2 s  .  c  o m
            final String confirmKey = exchangeId;

            jdbcTemplate.update("DELETE FROM " + getRepositoryNameCompleted() + " WHERE " + ID + " = ?",
                    new Object[] { confirmKey });

        }
    });
}

From source file:org.apereo.portal.jdbc.DatabaseMetaDataImpl.java

/**
 * Test the database to see if it really supports outer joins.
 * @param conn The connection to use./*from  www  .  j  ava 2  s .c  o  m*/
 */
private void testOuterJoins(final JdbcTemplate jdbcTemplate) {
    if (this.dbmdSupportsOuterJoins) {
        for (final JoinQueryString joinQueryString : joinTests) {
            final String joinTestQuery = "SELECT COUNT(UP_USER.USER_ID) " + "FROM "
                    + joinQueryString.getTestJoin() + " UP_USER.USER_ID=0";

            try {
                transactionTemplate.execute(new TransactionCallbackWithoutResult() {
                    @Override
                    public void doInTransactionWithoutResult(TransactionStatus status) {
                        jdbcTemplate.execute(joinTestQuery);
                    }
                });

                this.joinTest = joinQueryString;
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Using join test: " + this.joinTest.getClass().getName());
                }
                break;
            } catch (Exception e) {
                final String logMessage = "Join test failed: " + joinQueryString.getClass().getName()
                        + " on statement: '" + joinTestQuery + "':";

                if (LOG.isDebugEnabled()) {
                    LOG.debug(logMessage, e);
                }
            }
        }
    }
}

From source file:org.apereo.portal.RDBMUserIdentityStore.java

@Override
public void removePortalUID(final String userName) {
    this.transactionOperations.execute(new TransactionCallbackWithoutResult() {
        @Override//from   w ww  .  jav a 2 s .c o m
        protected void doInTransactionWithoutResult(TransactionStatus arg0) {
            if (PersonFactory.GUEST_USERNAMES.contains(userName)) {
                throw new IllegalArgumentException("CANNOT RESET LAYOUT FOR A GUEST USER");
            }

            final int userId = jdbcOperations.queryForObject("SELECT USER_ID FROM UP_USER WHERE USER_NAME=?",
                    Integer.class, userName);

            final int type = jdbcOperations.queryForObject(
                    "SELECT ENTITY_TYPE_ID FROM UP_ENTITY_TYPE WHERE ENTITY_TYPE_NAME = ?", Integer.class,
                    IPerson.class.getName());

            jdbcOperations.update("DELETE FROM UP_PERMISSION WHERE PRINCIPAL_KEY=? AND PRINCIPAL_TYPE=?",
                    userName, type);

            final List<Integer> groupIds = jdbcOperations.queryForList(
                    "SELECT M.GROUP_ID " + "FROM UP_GROUP_MEMBERSHIP M, UP_GROUP G, UP_ENTITY_TYPE E "
                            + "WHERE M.GROUP_ID = G.GROUP_ID " + "  AND G.ENTITY_TYPE_ID = E.ENTITY_TYPE_ID "
                            + "  AND  E.ENTITY_TYPE_NAME = 'org.apereo.portal.security.IPerson'"
                            + "  AND  M.MEMBER_KEY =? AND  M.MEMBER_IS_GROUP = 'F'",
                    Integer.class, userName);

            // Remove from local group
            // Delete from DeleteUser.java and place here
            // must be made before delete user in UP_USER
            for (final Integer groupId : groupIds) {
                // GROUP_ID is a VARCHAR
                String gid = groupId.toString();
                jdbcOperations.update("DELETE FROM UP_GROUP_MEMBERSHIP WHERE MEMBER_KEY=? AND GROUP_ID=?",
                        userName, gid);
            }

            jdbcOperations.update("DELETE FROM UP_USER            WHERE USER_ID = ?", userId);
            jdbcOperations.update("DELETE FROM UP_USER_LAYOUT     WHERE USER_ID = ?", userId);
            jdbcOperations.update("DELETE FROM UP_USER_PROFILE    WHERE USER_ID = ?", userId);
            jdbcOperations.update("DELETE FROM UP_LAYOUT_PARAM    WHERE USER_ID = ?", userId);
            jdbcOperations.update("DELETE FROM UP_LAYOUT_STRUCT   WHERE USER_ID = ?", userId);
            jdbcOperations.update("DELETE FROM UP_USER_LOCALE     WHERE USER_ID = ?", userId);

            //Purge all portlet entity data
            final Set<IPortletEntity> portletEntities = portletEntityDao.getPortletEntitiesForUser(userId);
            for (final IPortletEntity portletEntity : portletEntities) {
                portletEntityDao.deletePortletEntity(portletEntity);
            }

            //Purge all stylesheet preference data
            final List<? extends IStylesheetUserPreferences> stylesheetUserPreferences = stylesheetUserPreferencesDao
                    .getStylesheetUserPreferencesForUser(userId);
            for (final IStylesheetUserPreferences stylesheetUserPreference : stylesheetUserPreferences) {
                stylesheetUserPreferencesDao.deleteStylesheetUserPreferences(stylesheetUserPreference);
            }

            final ILocalAccountPerson person = localAccountDao.getPerson(userName);
            if (person != null) {
                localAccountDao.deleteAccount(person);
            }
        }
    });
}

From source file:org.apereo.portal.RDBMUserIdentityStore.java

/**
 *
 * removeuPortalUID//from w w  w.  java 2s  .  c o  m
 * @param   uPortalUID integer key to uPortal data for a user
 * @throws SQLException exception if a sql error is encountered
 */
@Override
public void removePortalUID(final int uPortalUID) {

    this.transactionOperations.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus arg0) {
            final String name = jdbcOperations.queryForObject("SELECT USER_NAME FROM UP_USER WHERE USER_ID=?",
                    String.class, uPortalUID);
            if (name == null) {
                log.warn("No user exists for id " + uPortalUID + " Nothing will be deleted");
                return;
            }

            removePortalUID(name);
        }
    });
}

From source file:org.apereo.portal.tools.dbloader.DataXmlHandler.java

protected final void doInsert() {
    if (this.rowData.size() == 0) {
        this.logger
                .warn("Found a row with no data for table " + this.currentTable + ", the row will be ignored");
        return;/*from w  w  w  . j a  v a 2s .  c o m*/
    }

    final Map<String, Integer> columnInfo = this.tableColumnInfo.get(this.currentTable);

    final StringBuilder columns = new StringBuilder();
    final StringBuilder parameters = new StringBuilder();
    final Object[] values = new Object[this.rowData.size()];
    final int[] types = new int[this.rowData.size()];

    int index = 0;
    for (final Iterator<Entry<String, String>> rowIterator = this.rowData.entrySet().iterator(); rowIterator
            .hasNext();) {
        final Entry<String, String> row = rowIterator.next();
        final String columnName = row.getKey();
        columns.append(columnName);
        parameters.append("?");

        values[index] = row.getValue();
        types[index] = columnInfo.get(columnName);

        if (rowIterator.hasNext()) {
            columns.append(", ");
            parameters.append(", ");
        }

        index++;
    }

    final String sql = "INSERT INTO " + this.currentTable + " (" + columns + ") VALUES (" + parameters + ")";
    if (this.logger.isInfoEnabled()) {
        this.logger.info(sql + "\t" + Arrays.asList(values) + "\t" + Arrays.asList(ArrayUtils.toObject(types)));
    }

    this.transactionOperations.execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            jdbcOperations.update(sql, values, types);
        }
    });
}

From source file:org.axonframework.eventhandling.scheduling.quartz.QuartzTableMaker.java

@Transactional
@PostConstruct/*  ww w.  j  a v  a  2 s  . c om*/
public void createTables() {
    new TransactionTemplate(transactionManager).execute(new TransactionCallbackWithoutResult() {
        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            executeCreateSQL();
        }
    });
}

From source file:org.bremersee.pagebuilder.example.service.PersonServiceImpl.java

@PostConstruct
public void init() {
    TransactionTemplate tt = new TransactionTemplate(transactionManager);
    tt.execute(new TransactionCallbackWithoutResult() {

        @Override/*ww w.  j ava  2s .  c  om*/
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            personRepository
                    .save(new Person("Heinrich", "Heine", new Address("Rue de Chanson", "Paris", "12345")));
            personRepository.save(
                    new Person("Virginia", "Woolf", new Address("Mrs Dalloway Street", "London", "1882")));
            personRepository
                    .save(new Person("Thomas", "Mann", new Address("Buddenbrooks Str. 3", "Lbeck", "23552")));
            personRepository.save(new Person("Malcomlm", "Lowry",
                    new Address("Under the Popocatpetl", "Quauhnhuac", "1947")));
            personRepository.save(new Person("Annete von", "Droste-Hlshoff",
                    new Address("Im Grase 8", "Gievenbeck", "1848")));
            personRepository.save(
                    new Person("Wilhelm", "Raabe", new Address("Sperlingsgasse 33", "Braunschweig", "38102")));
            personRepository.save(
                    new Person("Klaus", "Mann", new Address("Mephistopheles Linje 2", "Hamburg", "6789")));
            personRepository.save(new Person("Guillermo Cabrera", "Infante",
                    new Address("Nachtigallengasse 18", "Havanna", "1958")));
            personRepository
                    .save(new Person("James", "Joyce", new Address("Eccles Street No. 7", "Dublin", "1606")));
            personRepository
                    .save(new Person("Heinrich", "Mann", new Address("Unter dem Tan 66", "Lbeck", "23552")));
        }
    });
}

From source file:org.cleverbus.core.common.asynch.queue.MessagePollExecutorTest.java

@Before
public void prepareData() {
    // set failed limit
    setPrivateField(messagesPool, "partlyFailedInterval", 0);
    setPrivateField(messagesPool, "postponedInterval", 0);
    setPrivateField(messagePollExecutor, "targetURI", "mock:test");
    setPrivateField(messagePollExecutor, "postponedIntervalWhenFailed", 0);

    // firstly commit messages to DB (we can commit because we have embedded DB for tests only)
    TransactionTemplate txTemplate = new TransactionTemplate(jpaTransactionManager);
    txTemplate.execute(new TransactionCallbackWithoutResult() {
        @Override// ww w. j a va 2s  . co m
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            insertNewMessage("1234_4567", MsgStateEnum.POSTPONED, false);
            insertNewMessage("1234_4567_8", MsgStateEnum.PARTLY_FAILED, false, FUNNEL_VALUE);
            insertNewMessage("1234_4567_9", MsgStateEnum.PARTLY_FAILED, false, "somethingElse");
        }
    });
}

From source file:org.fcrepo.camel.FcrepoProducer.java

/**
 * Define how message exchanges are processed.
 *
 * @param exchange the InOut message exchange
 * @throws FcrepoOperationFailedException when the underlying HTTP request results in an error
 *///from w w w  . ja v a 2  s . co  m
@Override
public void process(final Exchange exchange) throws FcrepoOperationFailedException {
    if (exchange.isTransacted()) {
        transactionTemplate.execute(new TransactionCallbackWithoutResult() {
            @Override
            protected void doInTransactionWithoutResult(final TransactionStatus status) {
                final DefaultTransactionStatus st = (DefaultTransactionStatus) status;
                final FcrepoTransactionObject tx = (FcrepoTransactionObject) st.getTransaction();
                try {
                    doRequest(exchange, tx.getSessionId());
                } catch (final FcrepoOperationFailedException ex) {
                    throw new TransactionSystemException("Error executing fcrepo request in transaction: ", ex);
                }
            }
        });
    } else {
        doRequest(exchange, null);
    }
}