[jboss-cvs] JBoss Messaging SVN: r4497 - in trunk/src/main/org/jboss/messaging/core/persistence: hb and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 17 05:44:25 EDT 2008
Author: bershath27
Date: 2008-06-17 05:44:25 -0400 (Tue, 17 Jun 2008)
New Revision: 4497
Added:
trunk/src/main/org/jboss/messaging/core/persistence/hb/
trunk/src/main/org/jboss/messaging/core/persistence/hb/JBMMessageManager.java
trunk/src/main/org/jboss/messaging/core/persistence/hb/entity/
trunk/src/main/org/jboss/messaging/core/persistence/hb/entity/JBMMessagePOJO.java
trunk/src/main/org/jboss/messaging/core/persistence/hb/test/
trunk/src/main/org/jboss/messaging/core/persistence/hb/test/impl/
trunk/src/main/org/jboss/messaging/core/persistence/hb/test/impl/JBMMessageManagerImpl.java
trunk/src/main/org/jboss/messaging/core/persistence/hb/util/
trunk/src/main/org/jboss/messaging/core/persistence/hb/util/JBMHBPersistenceUtil.java
Log:
initial checkin for hb drivern persistence manager
Added: trunk/src/main/org/jboss/messaging/core/persistence/hb/JBMMessageManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/hb/JBMMessageManager.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/hb/JBMMessageManager.java 2008-06-17 09:44:25 UTC (rev 4497)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.persistence.hb;
+
+
+import java.math.BigInteger;
+
+import org.jboss.messaging.core.persistence.hb.entity.JBMMessagePOJO;
+/**
+ *
+ * JBMMessageManager Interface
+ *
+ * @author <a href="mailto:tywickra at redhat.com">Tyronne Wickramarathne</a>
+ *
+ */
+public interface JBMMessageManager
+{
+
+ public BigInteger addMessage(JBMMessagePOJO jbmMessagePOJO);
+
+ public BigInteger removeMessage(JBMMessagePOJO jbmMessagePOJO);
+
+ public BigInteger updateMessage(JBMMessagePOJO jbmMessagePOJO);
+
+ public JBMMessagePOJO findMessageById(BigInteger messageId);
+
+ public JBMMessagePOJO findMessage(JBMMessagePOJO jbmMessagePOJO);
+
+}
Added: trunk/src/main/org/jboss/messaging/core/persistence/hb/entity/JBMMessagePOJO.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/hb/entity/JBMMessagePOJO.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/hb/entity/JBMMessagePOJO.java 2008-06-17 09:44:25 UTC (rev 4497)
@@ -0,0 +1,173 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.persistence.hb.entity;
+
+import java.io.Serializable;
+import java.math.BigInteger;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Lob;
+import javax.persistence.Table;
+
+/**
+ *
+ * JBMMessagePOJO Entity
+ *
+ * @author <a href="mailto:tywickra at redhat.com">Tyronne Wickramarathne</a>
+ *
+ */
+ at Entity
+ at Table( name = "JBM_MSG" )
+public class JBMMessagePOJO implements Serializable
+{
+ private static final long serialVersionUID = -4199005333462105317L;
+
+ private BigInteger messageID;
+ private char[] reliable;
+ private BigInteger expiration;
+ private BigInteger timestamp;
+ private int priority;
+ private int type;
+ private BigInteger time;
+ private byte[] headers;
+ private byte[] payload;
+
+
+ public JBMMessagePOJO()
+ {
+
+ }
+
+ @Id
+ @Column( name = "MESSAGE_ID" , nullable = false , precision = 0 )
+ public BigInteger getMessageID()
+ {
+ return messageID;
+ }
+
+ @Lob
+ @Column( name = "RELIABLE" , length = 1 )
+ public char[] getReliable()
+ {
+ return reliable;
+ }
+
+ @Column( name = "EXPIRATION" , length = 20 )
+ public BigInteger getExpiration()
+ {
+ return expiration;
+ }
+
+ @Column( name = "TIMESTAMP", length = 20 )
+ public BigInteger getTimestamp()
+ {
+ return timestamp;
+ }
+
+ @Column( name = "PRIORITY", length = 4 )
+ public int getPriority()
+ {
+ return priority;
+ }
+
+ @Column( name = "TYPE" , length = 4 )
+ public int getType()
+ {
+ return type;
+ }
+
+ @Column( name="INS_TIME", length = 20 )
+ public BigInteger getTime()
+ {
+ return time;
+ }
+
+ @Lob
+ @Column( name="HEADERS")
+ public byte[] getHeaders()
+ {
+ return headers;
+ }
+
+ @Lob
+ @Column( name="PAYLOAD")
+ public byte[] getPayload()
+ {
+ return payload;
+ }
+
+
+ public void setMessageID(BigInteger messageID)
+ {
+ this.messageID = messageID;
+ }
+
+
+ public void setReliable(char[] reliable)
+ {
+ this.reliable = reliable;
+ }
+
+
+ public void setExpiration(BigInteger expiration)
+ {
+ this.expiration = expiration;
+ }
+
+
+ public void setTimestamp(BigInteger timestamp)
+ {
+ this.timestamp = timestamp;
+ }
+
+
+ public void setPriority(int priority)
+ {
+ this.priority = priority;
+ }
+
+
+ public void setType(int type)
+ {
+ this.type = type;
+ }
+
+
+ public void setTime(BigInteger time)
+ {
+ this.time = time;
+ }
+
+
+ public void setHeaders(byte[] headers) {
+ this.headers = headers;
+ }
+
+
+ public void setPayload(byte[] payload) {
+ this.payload = payload;
+ }
+
+
+}
Added: trunk/src/main/org/jboss/messaging/core/persistence/hb/test/impl/JBMMessageManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/hb/test/impl/JBMMessageManagerImpl.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/hb/test/impl/JBMMessageManagerImpl.java 2008-06-17 09:44:25 UTC (rev 4497)
@@ -0,0 +1,236 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.persistence.hb.test.impl;
+
+import java.math.BigInteger;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.persistence.hb.JBMMessageManager;
+import org.jboss.messaging.core.persistence.hb.entity.JBMMessagePOJO;
+import org.jboss.messaging.core.persistence.hb.util.JBMHBPersistenceUtil;
+
+/**
+ *
+ * JBMMessageManagerImpl Implementation
+ *
+ * @author <a href="mailto:tywickra at redhat.com">Tyronne Wickramarathne</a>
+ *
+ */
+public class JBMMessageManagerImpl implements JBMMessageManager
+{
+
+ private static final Logger log = Logger.getLogger(JBMMessageManagerImpl.class);
+
+ private EntityManagerFactory emf;
+ private EntityManager em;
+ private EntityTransaction etx;
+ private boolean etxStatus;
+
+ public JBMMessageManagerImpl()
+ {
+
+ }
+
+
+
+ public BigInteger addMessage(JBMMessagePOJO jbmMessagePOJO)
+ {
+ try
+ {
+ etxStatus = true;
+ emf = JBMHBPersistenceUtil.getEmf();
+ em = emf.createEntityManager();
+ etx = em.getTransaction();
+ etx.begin();
+ log.trace("Transaction begin, to add message "+jbmMessagePOJO.getMessageID());
+ em.persist(jbmMessagePOJO);
+ }
+ catch(Exception exception)
+ {
+ etxStatus = false;
+ log.error("An Exception occured while adding message " + jbmMessagePOJO.getMessageID() );
+ exception.printStackTrace();
+ }
+ finally
+ {
+ if(etxStatus)
+ {
+ log.trace("Preparing to add message " + jbmMessagePOJO.getMessageID() );
+ etx.commit();
+ log.trace("Message successfully added " + jbmMessagePOJO.getMessageID() );
+ }
+ else
+ {
+ log.trace("Preparing to roll back adding message" + jbmMessagePOJO.getMessageID() );
+ etx.rollback();
+ log.trace("Transaction rolled back with the message id " + jbmMessagePOJO.getMessageID() );
+ log.trace("Message didn't persisted " + jbmMessagePOJO.getMessageID() );
+ }
+ if(em != null)
+ em.close();
+ }
+ return jbmMessagePOJO.getMessageID();
+ }
+
+
+
+ public BigInteger removeMessage(JBMMessagePOJO jbmMessagePOJO)
+ {
+ try
+ {
+ etxStatus = true;
+ emf = JBMHBPersistenceUtil.getEmf();
+ em = emf.createEntityManager();
+ etx = em.getTransaction();
+ etx.begin();
+ log.trace("Transaction begin to remove message "+jbmMessagePOJO.getMessageID());
+ em.remove(em.find(JBMMessagePOJO.class, jbmMessagePOJO.getMessageID()));
+ }
+ catch(Exception exception)
+ {
+ etxStatus = false;
+ log.error("An Exception occured while removing message " + jbmMessagePOJO.getMessageID() );
+ exception.printStackTrace();
+ }
+ finally
+ {
+ if(etxStatus)
+ {
+ log.trace("Preparing to remove message " + jbmMessagePOJO.getMessageID() );
+ etx.commit();
+ log.trace("Message successfully removed " + jbmMessagePOJO.getMessageID() );
+ }
+ else
+ {
+ log.trace("Preparing to roll back the transaction with the message id " + jbmMessagePOJO.getMessageID() );
+ etx.rollback();
+ log.trace("Transaction rolled back with the message id " + jbmMessagePOJO.getMessageID() );
+ log.trace("Message didn't persisted " + jbmMessagePOJO.getMessageID() );
+ }
+ if(em != null)
+ em.close();
+ }
+ return jbmMessagePOJO.getMessageID();
+ }
+
+
+
+
+ public BigInteger updateMessage(JBMMessagePOJO jbmMessagePOJO)
+ {
+ try
+ {
+ etxStatus = true;
+ emf = JBMHBPersistenceUtil.getEmf();
+ em = emf.createEntityManager();
+ etx = em.getTransaction();
+ etx.begin();
+
+ JBMMessagePOJO newRecord = em.find(JBMMessagePOJO.class, jbmMessagePOJO.getMessageID());
+ newRecord.setExpiration(jbmMessagePOJO.getExpiration());
+ newRecord.setHeaders(jbmMessagePOJO.getHeaders());
+ newRecord.setPayload(jbmMessagePOJO.getPayload());
+ newRecord.setPriority(jbmMessagePOJO.getPriority());
+ newRecord.setReliable(jbmMessagePOJO.getReliable());
+ newRecord.setTime(jbmMessagePOJO.getTime());
+ newRecord.setTimestamp(jbmMessagePOJO.getTimestamp());
+ newRecord.setType(jbmMessagePOJO.getType());
+ log.trace("Transaction begin to update message " + jbmMessagePOJO.getMessageID());
+ em.persist(newRecord);
+
+ }
+ catch(Exception exception)
+ {
+ etxStatus = false;
+ log.error("An Exception occured while updating message " + jbmMessagePOJO.getMessageID() );
+ exception.printStackTrace();
+ }
+ finally
+ {
+ if(etxStatus)
+ {
+ log.trace("Preparing to update message " + jbmMessagePOJO.getMessageID() );
+ etx.commit();
+ log.trace("Message successfully updated " + jbmMessagePOJO.getMessageID() );
+ }
+ else
+ {
+ log.trace("Preparing to roll back the transaction with the message id " + jbmMessagePOJO.getMessageID() );
+ etx.rollback();
+ log.trace("Transaction rolled back with the message id " + jbmMessagePOJO.getMessageID() );
+ log.trace("Message didn't updated " + jbmMessagePOJO.getMessageID() );
+ }
+ if(em != null)
+ em.close();
+ }
+ return jbmMessagePOJO.getMessageID();
+ }
+
+
+ public JBMMessagePOJO findMessageById(BigInteger messageId)
+ {
+ try
+ {
+ emf = JBMHBPersistenceUtil.getEmf();
+ em = emf.createEntityManager();
+ JBMMessagePOJO jbmMessage = new JBMMessagePOJO();
+ jbmMessage.setMessageID(messageId);
+ return em.find(JBMMessagePOJO.class,jbmMessage.getMessageID());
+ }
+ catch(Exception ex)
+ {
+ log.error("Unable to retrieve message with the id " + messageId );
+ return null;
+ }
+ finally
+ {
+ if(em != null)
+ em.close();
+ }
+ }
+
+
+ public JBMMessagePOJO findMessage(JBMMessagePOJO jbmMessagePOJO)
+ {
+ try
+ {
+ emf = JBMHBPersistenceUtil.getEmf();
+ em = emf.createEntityManager();
+ return em.find(JBMMessagePOJO.class,jbmMessagePOJO);
+ }
+ catch(Exception ex)
+ {
+ log.error("Unable to retrieve message with the id " + jbmMessagePOJO.getMessageID() );
+ return null;
+ }
+ finally
+ {
+ if(em != null)
+ em.close();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/src/main/org/jboss/messaging/core/persistence/hb/util/JBMHBPersistenceUtil.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/persistence/hb/util/JBMHBPersistenceUtil.java (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/persistence/hb/util/JBMHBPersistenceUtil.java 2008-06-17 09:44:25 UTC (rev 4497)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.core.persistence.hb.util;
+
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+
+/**
+ *
+ * JBMHBPersistenceUtil
+ *
+ * @author <a href="mailto:tywickra at redhat.com">Tyronne Wickramarathne</a>
+ *
+ */
+public class JBMHBPersistenceUtil
+{
+ private static EntityManagerFactory emf;
+
+ static
+ {
+ emf = Persistence.createEntityManagerFactory("jbmEntityManager");
+ }
+
+ public static EntityManagerFactory getEmf()
+ {
+ return emf;
+ }
+
+}
More information about the jboss-cvs-commits
mailing list