01: /*
02: * Copyright 2005-2007 The Kuali Foundation.
03: *
04: *
05: * Licensed under the Educational Community License, Version 1.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.opensource.org/licenses/ecl1.php
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package edu.iu.uis.eden.test;
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: }
|