1 /**
2 * Copyright 2005-2014 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.kew.test;
17
18
19 public class TestMessageBean {//implements MessageListener {
20
21 private static int counter = 0;
22
23 /*public void onMessage(Message msg) {
24 try {
25 final String message = "message recieved: \'"+((TextMessage)msg).getText()+"\'";
26 System.out.println(message + ". count=" + ++counter);
27 Transaction transaction = Current.getTransactionManager().getTransaction();
28 System.out.println("what's my threads transaction 1? " + transaction);
29 TransactionTemplate txTemplate = SpringServiceLocator.getTransactionTemplate();
30 txTemplate.execute(new TransactionCallback() {
31 public Object doInTransaction(TransactionStatus status) {
32 try{
33 Transaction transaction = Current.getTransactionManager().getTransaction();
34 System.out.println("what's my threads transaction 2? " + transaction);
35 } catch (Exception e) { throw new RuntimeException(e); }
36 //System.out.println("My datassource? " + SpringServiceLocator.getEdenDataSource());
37 JdbcTemplate template = new JdbcTemplate(SpringServiceLocator.getEdenDataSource());
38 return template.execute(new ConnectionCallback() {
39 public Object doInConnection(Connection connection) throws SQLException {
40 String sql = "INSERT INTO ACTIVEMQ_TEST VALUES(?)";
41 PreparedStatement preparedStatement = connection.prepareStatement(sql);
42 preparedStatement.setString(1, message);
43 preparedStatement.executeUpdate();
44 System.out.println("doing prepared statement.");
45 return null;
46 }
47 });
48 }
49 });
50
51 } catch (Exception e) {
52 e.printStackTrace();
53 throw new RuntimeException("caught exception jmsing");
54 }
55 }*/
56
57 // public void onMessage(Message msg) {
58 // try {
59 // final String message = "message recieved: \'"+((TextMessage)msg).getText()+"\'";
60 // JdbcTemplate template = new JdbcTemplate(SpringServiceLocator.getEdenDataSource());
61 // template.execute(new ConnectionCallback() {
62 // public Object doInConnection(Connection connection) throws SQLException {
63 // String sql = "INSERT INTO ACTIVEMQ_TEST VALUES(?)";
64 // PreparedStatement preparedStatement = connection.prepareStatement(sql);
65 // preparedStatement.setString(1, message);
66 // preparedStatement.executeUpdate();
67 // System.out.println("doing prepared statement.");
68 // return null;
69 // }
70 // });
71 //
72 // } catch (Exception e) {
73 // e.printStackTrace();
74 // throw new RuntimeException("caught exception jmsing");
75 // }
76 // }
77 //
78 // public static boolean isDone() {
79 // return counter == 1000;
80 // }
81 }