[jboss-svn-commits] JBL Code SVN: r13058 - in labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format: hibernate and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 3 19:09:38 EDT 2007


Author: bernard.tison
Date: 2007-07-03 19:09:38 -0400 (Tue, 03 Jul 2007)
New Revision: 13058

Added:
   labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/
   labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/HibernateMessageStoreImpl.java
   labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.hbm.xml
   labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.java
Log:
Hibernate implementation for MessageStore

Added: labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/HibernateMessageStoreImpl.java
===================================================================
--- labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/HibernateMessageStoreImpl.java	                        (rev 0)
+++ labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/HibernateMessageStoreImpl.java	2007-07-03 23:09:38 UTC (rev 13058)
@@ -0,0 +1,240 @@
+/*
+ * 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.hibernate;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.hibernate.HibernateException;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.Configuration;
+import org.jboss.internal.soa.esb.message.urigen.DefaultMessageURIGenerator;
+import org.jboss.internal.soa.esb.thirdparty.Base64;
+import org.jboss.soa.esb.message.Message;
+import org.jboss.soa.esb.message.urigen.MessageURIGenerator;
+import org.jboss.soa.esb.services.persistence.MessageStore;
+import org.jboss.soa.esb.services.persistence.MessageStoreException;
+import org.jboss.soa.esb.util.Util;
+
+public class HibernateMessageStoreImpl implements MessageStore
+{
+	private static Logger logger = Logger.getLogger(HibernateMessageStoreImpl.class);
+	
+	protected SessionFactory sessionFactory;
+
+	protected MessageURIGenerator uriGenerator = new DefaultMessageURIGenerator();
+
+	public HibernateMessageStoreImpl() {}
+	
+	// TODO: possible enhancement: sessionfactory in JNDI tree
+	public synchronized SessionFactory getSessionFactory() {
+		if (sessionFactory==null) {
+			logger.debug("building hibernate session factory");			
+			Configuration configuration = new Configuration();
+			configuration.configure();
+			sessionFactory = configuration.buildSessionFactory();
+		}
+		return sessionFactory;
+	}
+
+
+	/* (non-Javadoc)
+	 * @see org.jboss.soa.esb.services.persistence.MessageStore#getMessageURIGenerator()
+	 */
+	public MessageURIGenerator getMessageURIGenerator() {
+		return uriGenerator;
+	}
+
+	/**
+	 * add's a @Message to the database persistence store
+	 * will set the 'delivered' flag to TRUE by default - assuming that the @Message has been delivered
+	 */
+	public synchronized URI addMessage (Message message, String classification) throws MessageStoreException
+	{
+		
+		URI uuid;
+		try {
+			Session session = getSessionFactory().getCurrentSession();
+			session.beginTransaction();
+			PersistentMessage msg = new PersistentMessage();
+			uuid = uriGenerator.generateMessageURI(message);
+			String messageString = Base64.encodeObject(Util.serialize(message));
+			msg.setUuid(uuid.toString());
+			msg.setType(message.getType().toString());
+			msg.setMessage(messageString);
+			msg.setDelivered("TRUE");
+			msg.setClassification(classification);
+			session.save(msg);
+			session.getTransaction().commit();
+		} catch (Exception e) {
+			logger.error(e.getMessage(),e);
+			getSessionFactory().getCurrentSession().getTransaction().rollback();
+			throw new MessageStoreException(e);
+		} finally {
+			
+		}
+		
+		
+		
+		
+		
+//		// String messageString = null;
+//		URI uid = null;
+//		try{
+//			conn = mgr.getConnection();
+//
+//			uid = uriGenerator.generateMessageURI(message);
+//
+//			String messageString = Base64.encodeObject(Util.serialize(message));
+//
+//			// insert into the database
+//			String sql = "insert into message(uuid, type, message, delivered, classification) values(?,?,?,?,?)";
+//            PreparedStatement ps = conn.prepareStatement(sql);
+//			ps.setString(1, uid.toString());
+//			ps.setString(2, message.getType().toString());
+//			ps.setString(3, messageString);
+//			ps.setString(4, "TRUE");
+//            ps.setString(5, classification);
+//			ps.execute();
+//            ps.close();
+//
+//		}
+//		catch (Exception e)
+//		{
+//			logger.error(e);
+//			throw new MessageStoreException(e);
+//		} 
+//		finally
+//		{
+//			release();
+//		}
+
+		return uuid;
+	}
+
+	/**
+	 * return a @Message based on the passed in key in the form of a JBoss ESB @URI
+	 * format for URI: "urn:jboss/esb/message/UID#" + UUID.randomUUID()" - see the method in this class @addMessage
+	 */
+	public synchronized Message getMessage (URI uid) throws MessageStoreException
+	{
+		
+		PersistentMessage msg = null;
+		try {
+			Session session = getSessionFactory().getCurrentSession();
+			session.beginTransaction();
+			msg = (PersistentMessage)session.get(PersistentMessage.class,uid.toString());
+			session.getTransaction().commit();
+		} catch (HibernateException e) {
+			logger.error(e);
+			throw new MessageStoreException(e);
+		}
+		
+		if (msg == null) {
+			throw new MessageStoreException("Non existing Message for UUID: " + uid);
+		}
+		
+		Message message;
+		try {
+			message = Util.deserialize((Serializable)Base64.decodeToObject(msg.getMessage()));
+		} catch (Exception e) {
+			logger.error(e);
+			throw new MessageStoreException(e);
+		} 
+	    return message;
+		
+		
+//		
+//		
+//		String sql = "select uuid,type,message from message where uuid=?";
+//		Message message = null;
+//
+//		try
+//		{
+//			conn = mgr.getConnection();
+//            PreparedStatement ps = conn.prepareStatement(sql);
+//			ps.setString(1, uid.toString());
+//
+//			ResultSet rs = ps.executeQuery();
+//			if (!rs.next())
+//				throw new MessageStoreException("Non existing Message for UUID: " + uid);
+//
+//			message = Util.deserialize((Serializable) Base64.decodeToObject(rs
+//					.getString(3)));
+//
+//		}
+//		catch (SQLException e)
+//		{
+//			throw new MessageStoreException(e);
+//		}
+//		catch (Exception e)
+//		{
+//			logger.error(e);
+//			throw new MessageStoreException(e);
+//		} 
+//		finally
+//		{
+//			release();
+//		}
+//
+//		return message;
+
+	}
+	
+	/**
+	 * 
+	 * @param uid - key for message to set undelivered flag on
+	 * @throws MessageStoreException
+	 */
+	public void setUndelivered(URI uid) throws MessageStoreException{
+		throw new UnsupportedOperationException();
+	}
+	
+	public void setDelivered(URI uid) throws MessageStoreException{
+		throw new UnsupportedOperationException();		
+	}
+	
+	/**
+	 * This method can be used to retrieve a collection of all the undelivered (delivered=FALSE) from the message-store
+	 * You should test for 'null' on the return type to see if any messages exist in the collection
+	 * @return Map<URI, Message> - a collection of all the undelivered messages in the message-store
+	 * @throws MessageStoreException
+	 */
+	public Map<URI, Message> getUndeliveredMessages(String classification) throws MessageStoreException {
+		throw new UnsupportedOperationException();		
+	}
+    
+    /**
+     * This method can be used to retrieve a collection of all from the message-store
+     * You should test for 'null' on the return type to see if any messages exist in the collection
+     * @return Map<URI, Message> - a collection of all the undelivered messages in the message-store
+     * @throws MessageStoreException
+     */
+    public Map<URI, Message> getAllMessages(String classification) throws MessageStoreException {
+    	throw new UnsupportedOperationException();
+        
+    }
+
+}

Added: labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.hbm.xml
===================================================================
--- labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.hbm.xml	                        (rev 0)
+++ labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.hbm.xml	2007-07-03 23:09:38 UTC (rev 13058)
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+<!-- Generated Jun 22, 2007 12:24:43 AM by Hibernate Tools 3.2.0.b9 -->
+<hibernate-mapping>
+    <class name="org.jboss.internal.soa.esb.persistence.format.hibernate.PersistentMessage" table="message" catalog="jbossesb">
+        <comment></comment>
+        <id name="uuid" type="string">
+            <column name="uuid" length="128" />
+            <generator class="assigned" />
+        </id>
+        <property name="type" type="string">
+            <column name="type" length="128" not-null="true">
+                <comment></comment>
+            </column>
+        </property>
+        <property name="message" type="string">
+            <column name="message" length="65535" not-null="true">
+                <comment></comment>
+            </column>
+        </property>
+        <property name="delivered" type="string">
+            <column name="delivered" length="10" not-null="true">
+                <comment></comment>
+            </column>
+        </property>
+        <property name="classification" type="string">
+            <column name="classification" length="10">
+                <comment></comment>
+            </column>
+        </property>
+    </class>
+</hibernate-mapping>

Added: labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.java
===================================================================
--- labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.java	                        (rev 0)
+++ labs/jbossesb/workspace/btison/trunk/product/services/jbossesb/src/main/java/org/jboss/internal/soa/esb/persistence/format/hibernate/PersistentMessage.java	2007-07-03 23:09:38 UTC (rev 13058)
@@ -0,0 +1,79 @@
+package org.jboss.internal.soa.esb.persistence.format.hibernate;
+
+// Generated Jun 22, 2007 10:09:47 AM by Hibernate Tools 3.2.0.b9
+
+/**
+ * Message generated by hbm2java
+ */
+public class PersistentMessage implements java.io.Serializable {
+
+	private String uuid;
+
+	private String type;
+
+	private String message;
+
+	private String delivered;
+
+	private String classification;
+
+	public PersistentMessage() {
+	}
+
+	public PersistentMessage(String uuid, String type, String message, String delivered) {
+		this.uuid = uuid;
+		this.type = type;
+		this.message = message;
+		this.delivered = delivered;
+	}
+
+	public PersistentMessage(String uuid, String type, String message, String delivered,
+			String classification) {
+		this.uuid = uuid;
+		this.type = type;
+		this.message = message;
+		this.delivered = delivered;
+		this.classification = classification;
+	}
+
+	public String getUuid() {
+		return this.uuid;
+	}
+
+	public void setUuid(String uuid) {
+		this.uuid = uuid;
+	}
+
+	public String getType() {
+		return this.type;
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public String getMessage() {
+		return this.message;
+	}
+
+	public void setMessage(String message) {
+		this.message = message;
+	}
+
+	public String getDelivered() {
+		return this.delivered;
+	}
+
+	public void setDelivered(String delivered) {
+		this.delivered = delivered;
+	}
+
+	public String getClassification() {
+		return this.classification;
+	}
+
+	public void setClassification(String classification) {
+		this.classification = classification;
+	}
+
+}




More information about the jboss-svn-commits mailing list