[jboss-svn-commits] JBL Code SVN: r7235 - in labs/jbossesb/trunk/product: core/services/src/org/jboss/internal/soa/esb/persistence/format/db install/conf install/message-store/sql/hsqldb install/message-store/sql/postgresql samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 30 12:19:35 EST 2006
Author: daniel.brum at jboss.com
Date: 2006-10-30 12:19:28 -0500 (Mon, 30 Oct 2006)
New Revision: 7235
Added:
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java
labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/HsqldbUtil.java
labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/TestUtil.java
Removed:
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java
Modified:
labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStorePlugin.java
labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
labs/jbossesb/trunk/product/install/message-store/sql/hsqldb/create_database.sql
labs/jbossesb/trunk/product/install/message-store/sql/postgresql/create_database.sql
Log:
Copied: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java (from rev 7230, labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java)
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java 2006-10-30 13:39:12 UTC (rev 7230)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStoreImpl.java 2006-10-30 17:19:28 UTC (rev 7235)
@@ -0,0 +1,127 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author daniel.brum at jboss.com
+ */
+
+package org.jboss.internal.soa.esb.persistence.format.db;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.util.Util;
+
+
+public class DBMessageStoreImpl implements MessageStore {
+
+
+ protected DBConnectionManager mgr = null;
+ protected Connection conn = null;
+ protected ResultSet rs = null;
+ protected PreparedStatement ps = null;
+
+ public DBMessageStoreImpl() {
+ mgr = DBConnectionManager.getInstance();
+ }
+
+ public synchronized URI addMessage(Message message){
+
+// String messageString = null;
+ URI uid = null;
+
+
+ try {
+ conn = mgr.getConnection();
+
+ uid = new URI("urn:jboss:esb:message:UID:" + UUID.randomUUID().toString());
+
+ String messageString = Base64.encodeObject(Util.serialize(message));
+
+ //insert into the database
+ String sql = "insert into message(uuid, type, message) values(?,?,?)";
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, uid.toString());
+ ps.setString(2, message.getType().toString());
+ ps.setString(3, messageString);
+ ps.execute();
+
+ } catch (Exception e) { e.printStackTrace(); }
+ finally { release(); }
+
+ return uid;
+ }
+
+ public synchronized Message getMessage(URI uid) throws Exception{
+
+ String sql = "select uuid,type,message from message where uid=?";
+ Message message = null;
+
+ try {
+ conn = mgr.getConnection();
+ ps = conn.prepareStatement(sql);
+ ps.setString(1, uid.toString());
+
+ rs = ps.executeQuery();
+ if (! rs.next()) throw new Exception("Non existing Message for UUID: " + uid);
+
+ message = Util.deserialize((Serializable)Base64.decodeToObject(rs.getString(3)));
+
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ return null;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }finally { release(); }
+
+ return message;
+
+ }
+
+ private void release() {
+
+ if (conn != null) {
+ if (rs != null) {
+ try{
+ rs.close();
+ }catch (Exception e) {}
+ }
+ try{
+ ps.close();
+ }catch (Exception e1){}
+ try{
+ conn.close();
+ }catch(Exception e2){}
+ }
+ }
+
+
+
+
+
+
+}
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStorePlugin.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStorePlugin.java 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/DBMessageStorePlugin.java 2006-10-30 17:19:28 UTC (rev 7235)
@@ -35,7 +35,7 @@
public MessageStore getMessageStore() {
- return new MessageStoreImpl();
+ return new DBMessageStoreImpl();
}
Deleted: labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/internal/soa/esb/persistence/format/db/MessageStoreImpl.java 2006-10-30 17:19:28 UTC (rev 7235)
@@ -1,162 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2006, JBoss Inc., and others contributors as indicated
- * by the @authors tag. All rights reserved.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- *
- * (C) 2005-2006,
- * @author daniel.brum at jboss.com
- */
-
-package org.jboss.internal.soa.esb.persistence.format.db;
-
-import java.io.Serializable;
-import java.net.URI;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.UUID;
-
-import org.jboss.internal.soa.esb.thirdparty.Base64;
-import org.jboss.soa.esb.message.Message;
-import org.jboss.soa.esb.services.persistence.MessageStore;
-import org.jboss.soa.esb.util.Util;
-
-
-public class MessageStoreImpl implements MessageStore {
-
-
- protected DBConnectionManager mgr = null;
- protected Connection conn = null;
- protected ResultSet rs = null;
- protected PreparedStatement ps = null;
-
- public MessageStoreImpl() {
- mgr = DBConnectionManager.getInstance();
- }
-
- public synchronized URI addMessage(Message message){
-
-// String messageString = null;
- URI uid = null;
-
-
- try {
- conn = mgr.getConnection();
-
- uid = new URI("urn:jboss:esb:message:UID:" + UUID.randomUUID().toString());
-
- String messageString = Base64.encodeObject(Util.serialize(message));
-
-// if (message.getType().equals(MessageType.JBOSS_XML) ) {
-// Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-// ((org.jboss.internal.soa.esb.message.format.xml.MessageImpl)message).toXML(doc);
-// StringWriter sWriter = new StringWriter();
-// OutputFormat format = new OutputFormat();
-// format.setIndenting(true);
-// XMLSerializer xmlS = new XMLSerializer(sWriter, format);
-// xmlS.asDOMSerializer();
-// xmlS.serialize(doc);
-// messageString = sWriter.toString();
-// }
-//
-// if (message.getType().equals(MessageType.JAVA_SERIALIZED) ) {
-// messageString = Base64.encodeObject((Serializable)message);
-// }
-
- //insert into the database
- String sql = "insert into message(uid, type, message) values(?,?,?)";
- ps = conn.prepareStatement(sql);
- ps.setString(1, uid.toString());
- ps.setString(2, message.getType().toString());
- ps.setString(3, messageString);
- ps.execute();
-
- } catch (Exception e) { e.printStackTrace(); }
- finally { release(); }
-
- return uid;
- }
-
- public synchronized Message getMessage(URI uid) throws Exception{
-
- String sql = "select uid,type,message from message where uid=?";
- Message message = null;
-
- try {
- conn = mgr.getConnection();
- ps = conn.prepareStatement(sql);
- ps.setString(1, uid.toString());
-
- rs = ps.executeQuery();
- if (! rs.next()) throw new Exception("Non existing Message for UID: " + uid);
-// URI type= URI.create(rs.getString(2));
- message = Util.deserialize((Serializable)Base64.decodeToObject(rs.getString(3)));
-
-
-// if (type.equals(MessageType.JBOSS_XML)) {
-//
-// InputStream inStream = new ByteArrayInputStream(msg.getBytes());
-// DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-// DocumentBuilder builder = factory.newDocumentBuilder();
-// Document doc = builder.parse(inStream);
-//
-// org.jboss.internal.soa.esb.message.format.xml.MessageImpl xmlMessage =
-// new org.jboss.internal.soa.esb.message.format.xml.MessageImpl();
-// xmlMessage.fromXML(doc);
-// message=xmlMessage;
-//
-// }
-// if (type.equals(MessageType.JAVA_SERIALIZED)) {
-//
-// Object byteMessage = Base64.decodeToObject(msg);
-// message = (org.jboss.internal.soa.esb.message.format.serialized.MessageImpl)byteMessage;
-// }
-
- } catch (SQLException e) {
- e.printStackTrace();
- return null;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }finally { release(); }
-
- return message;
-
- }
-
- private void release() {
-
- if (conn != null) {
- if (rs != null) {
- try{
- rs.close();
- }catch (Exception e) {}
- }
- try{
- ps.close();
- }catch (Exception e1){}
- try{
- conn.close();
- }catch(Exception e2){}
- }
- }
-
-
-
-
-
-
-}
Modified: labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml
===================================================================
--- labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/install/conf/jbossesb-properties.xml 2006-10-30 17:19:28 UTC (rev 7235)
@@ -58,12 +58,10 @@
<property name="abandoned-connection-time-interval" value="30000"/>
</properties>
<properties name="dbstore">
- <property name="org.jboss.soa.esb.persistence.db.connection.url" value="jdbc:postgresql://localhost:5432/jbossesb"/>
- <!-- Hypersonic: value="jdbc:hsqldb:hsql://localhost:1701" -->
- <property name="org.jboss.soa.esb.persistence.db.jdbc.driver" value="org.postgresql.Driver"/>
- <!-- Hypersonic: value="org.hsqldb.jdbcDriver" -->
- <property name="org.jboss.soa.esb.persistence.db.user" value="postgres"/>
- <property name="org.jboss.soa.esb.persistence.db.pwd" value="postgres"/>
+ <property name="org.jboss.soa.esb.persistence.db.connection.url" value="jdbc:hsqldb:hsql://localhost:9001/jbossesb"/>
+ <property name="org.jboss.soa.esb.persistence.db.jdbc.driver" value="org.hsqldb.jdbcDriver"/>
+ <property name="org.jboss.soa.esb.persistence.db.user" value="sa"/>
+ <property name="org.jboss.soa.esb.persistence.db.pwd" value=""/>
<property name="org.jboss.soa.esb.persistence.db.pool.initial.size" value="2"/>
<property name="org.jboss.soa.esb.persistence.db.pool.min.size" value="2"/>
<property name="org.jboss.soa.esb.persistence.db.pool.max.size" value="5"/>
Modified: labs/jbossesb/trunk/product/install/message-store/sql/hsqldb/create_database.sql
===================================================================
--- labs/jbossesb/trunk/product/install/message-store/sql/hsqldb/create_database.sql 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/install/message-store/sql/hsqldb/create_database.sql 2006-10-30 17:19:28 UTC (rev 7235)
@@ -5,8 +5,8 @@
CREATE TABLE message
(
- uid VARCHAR NOT NULL,
+ uuid VARCHAR NOT NULL,
type VARCHAR NOT NULL,
message VARCHAR NOT NULL,
- CONSTRAINT pk_uid PRIMARY KEY (uid)
+ CONSTRAINT pk_uid PRIMARY KEY (uuid)
);
Modified: labs/jbossesb/trunk/product/install/message-store/sql/postgresql/create_database.sql
===================================================================
--- labs/jbossesb/trunk/product/install/message-store/sql/postgresql/create_database.sql 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/install/message-store/sql/postgresql/create_database.sql 2006-10-30 17:19:28 UTC (rev 7235)
@@ -10,10 +10,8 @@
CREATE TABLE message
(
- uid text NOT NULL,
+ uuid text NOT NULL,
"type" text NOT NULL,
message text NOT NULL,
- CONSTRAINT pk_uid PRIMARY KEY (uid)
+ CONSTRAINT pk_uid PRIMARY KEY (uuid)
);
-
-insert into message(uid,type,message) values(1,"init setup","init setup");
Added: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/HsqldbUtil.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/HsqldbUtil.java 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/HsqldbUtil.java 2006-10-30 17:19:28 UTC (rev 7235)
@@ -0,0 +1,66 @@
+package org.jboss.soa.esb.samples.trailblazer.mockup;
+
+import java.sql.DriverManager;
+import java.sql.Statement;
+
+import org.hsqldb.Server;
+/**
+ * Utility to start and stop a hsql Database.
+ *
+ * @author <a href="mailto:kurt.stam at jboss.com">Kurt Stam</a>
+ *
+ */
+public class HsqldbUtil
+{
+ final private static String THREAD_NAME = "hypersonic-unittest";
+ /**
+ * Starts the hsql database in it's own thread.
+ * Don't forget to shut it down when you're done.
+ *
+ * @param databaseFile - i.e. build/hsqltestdb
+ * @param databaseName - i.e. jbossesb
+ * @throws Exception
+ */
+ public static void startHsqldb(final String databaseFile,
+ final String databaseName) throws Exception
+ {
+ // Start DB in new thread, or else it will block us
+ Thread serverThread = new Thread(THREAD_NAME) {
+ public void run() {
+ try {
+ // Create startup arguments
+ String[] args = new String[4];
+ args[0] = "-database.0";
+ args[1] = databaseFile;
+ args[2] = "-dbname.0";
+ args[3] = databaseName;
+
+ System.out.println("creating db from this script: " + databaseFile);
+
+ // Start server
+ Server.main(args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+// log.error("Failed to start database", e);
+ }
+ };
+ serverThread.run();
+ }
+ /**
+ *
+ * @param url
+ * @param username
+ * @param password
+ * @throws Exception
+ */
+ public static void stopHsqldb(String url, String username, String password) throws Exception {
+ java.sql.Connection connection = DriverManager.getConnection(
+ url, username, password);
+ Statement statement = connection.createStatement();
+ String shutdownCommand = "SHUTDOWN COMPACT";
+ statement.executeQuery(shutdownCommand);
+ }
+
+
+}
Added: labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/TestUtil.java
===================================================================
--- labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/TestUtil.java 2006-10-30 16:09:21 UTC (rev 7234)
+++ labs/jbossesb/trunk/product/samples/trailblazer2/esb/src/org/jboss/soa/esb/samples/trailblazer/mockup/TestUtil.java 2006-10-30 17:19:28 UTC (rev 7235)
@@ -0,0 +1,54 @@
+package org.jboss.soa.esb.samples.trailblazer.mockup;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+
+public class TestUtil
+{
+ private static Logger log = Logger.getLogger(TestUtil.class);
+ private static String _prefix=null;
+ /**
+ * When performing file system interaction, the user.dir may differ (i.e. running the
+ * tests from within eclipse).
+ */
+ public static String getPrefix()
+ {
+ if (_prefix==null) {
+ _prefix="";
+ String baseDir = System.getProperty("user.dir");
+ log.log(Priority.INFO, baseDir);
+ if (!baseDir.endsWith("product")) {
+ _prefix = "product/";
+ }
+ }
+ return _prefix;
+ }
+ /**
+ * Sets the jbossesb-properties.xml to use for test
+ */
+ public static void setESBPropertiesFileToUse()
+ {
+
+// String jbossesbPropertiesFile = getPrefix() + "etc/test/resources/jbossesb-unittest-properties.xml";
+ String jbossesbPropertiesFile = "jbossesb-unittest-properties.xml";
+ System.setProperty("org.jboss.soa.esb.propertyFile", jbossesbPropertiesFile);
+ }
+
+ public static String readTextFile(File file) throws IOException
+ {
+ StringBuffer sb = new StringBuffer(1024);
+ BufferedReader reader = new BufferedReader(new FileReader(file.getPath()));
+ char[] chars = new char[1];
+ while( (reader.read(chars)) > -1){
+ sb.append(String.valueOf(chars));
+ chars = new char[1];
+ }
+ reader.close();
+ return sb.toString();
+ }
+}
More information about the jboss-svn-commits
mailing list