001    /**
002     * Copyright 2005-2011 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.kew.test;
017    
018    
019    public class TestMessageBean {//implements MessageListener {
020    
021        private static int counter = 0;
022    
023        /*public void onMessage(Message msg) {
024            try {
025                    final String message = "message recieved: \'"+((TextMessage)msg).getText()+"\'";
026                System.out.println(message + ". count=" + ++counter);
027                Transaction transaction = Current.getTransactionManager().getTransaction();
028                System.out.println("what's my threads transaction 1? " + transaction);
029                TransactionTemplate txTemplate = SpringServiceLocator.getTransactionTemplate();
030                txTemplate.execute(new TransactionCallback() {
031                    public Object doInTransaction(TransactionStatus status) {
032                            try{
033                            Transaction transaction = Current.getTransactionManager().getTransaction();
034                        System.out.println("what's my threads transaction 2? " + transaction);
035                            } catch (Exception e) { throw new RuntimeException(e); }
036                            //System.out.println("My datassource? " + SpringServiceLocator.getEdenDataSource());
037                            JdbcTemplate template = new JdbcTemplate(SpringServiceLocator.getEdenDataSource());
038                        return template.execute(new ConnectionCallback() {
039                            public Object doInConnection(Connection connection) throws SQLException {
040                                    String sql = "INSERT INTO ACTIVEMQ_TEST VALUES(?)";
041                                    PreparedStatement preparedStatement = connection.prepareStatement(sql);
042                                    preparedStatement.setString(1, message);
043                                    preparedStatement.executeUpdate();
044                                System.out.println("doing prepared statement.");
045                                    return null;
046                            }
047                        });
048                    }
049                });
050                
051            } catch (Exception e) {
052                e.printStackTrace();
053                throw new RuntimeException("caught exception jmsing");
054            }
055        }*/
056        
057    //    public void onMessage(Message msg) {
058    //        try {
059    //              final String message = "message recieved: \'"+((TextMessage)msg).getText()+"\'";
060    //              JdbcTemplate template = new JdbcTemplate(SpringServiceLocator.getEdenDataSource());
061    //              template.execute(new ConnectionCallback() {
062    //                      public Object doInConnection(Connection connection) throws SQLException {
063    //                              String sql = "INSERT INTO ACTIVEMQ_TEST VALUES(?)";
064    //                              PreparedStatement preparedStatement = connection.prepareStatement(sql);
065    //                              preparedStatement.setString(1, message);
066    //                              preparedStatement.executeUpdate();
067    //                              System.out.println("doing prepared statement.");
068    //                              return null;
069    //                      }
070    //              });
071    //            
072    //        } catch (Exception e) {
073    //            e.printStackTrace();
074    //            throw new RuntimeException("caught exception jmsing");
075    //        }
076    //    }
077    //
078    //    public static boolean isDone() {
079    //        return counter == 1000;
080    //    }
081    }