[jboss-svn-commits] JBL Code SVN: r5561 - labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Aug 7 11:53:39 EDT 2006
Author: tfennelly
Date: 2006-08-07 11:53:34 -0400 (Mon, 07 Aug 2006)
New Revision: 5561
Added:
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java
Log:
moved from the EJB folder
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+import javax.ejb.CreateException;
+
+/**
+ * @author kstam
+ */
+public interface BatchHandler
+{
+ public void create() throws CreateException;
+ public void finish() throws Exception;
+ public void commitBatch(BobjStdDTO p_oDto ) throws Exception;
+ public long newBatch() throws Exception;
+ public int addToBatch(String p_s) throws Exception;
+ public void remove();
+}
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandler.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,326 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.bizclasses.BatchProcess;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.internal.core.objectstore.BobjStore;
+import org.jboss.soa.esb.internal.core.objectstore.DaoBatchTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoIndexTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoSnapTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoUidTable;
+import org.jboss.soa.esb.internal.core.objectstore.RowBatch;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.Util;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.PostActivate;
+import javax.ejb.PrePassivate;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateful;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+/**
+ * @author Esteban
+ */
+ at Remote(BatchHandler.class)
+ at Local(BatchHandler.class)
+ at TransactionManagement(TransactionManagementType.BEAN)
+public @Stateful class BatchHandlerBean implements BatchHandler
+{
+ private static final long serialVersionUID = 1L;
+ SessionContext m_oSessCtx;
+
+ public void setSessionContext(SessionContext p_oSessCtx)
+ { this.m_oSessCtx = p_oSessCtx; }
+
+ private Logger m_oLogger;
+ private JdbcCleanConn m_oUidConn;
+ private JdbcCleanConn m_oDataConn;
+
+ private DaoUidTable m_oDaoUid;
+ private DaoBatchTable m_oDaoBatch;
+ private DaoIndexTable m_oDaoIndex;
+ private DaoSnapTable m_oDaoSnap;
+
+ private long m_lBatchNum = -1;
+ private int m_iSeq;
+
+/**
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws CreateException
+ {
+ try
+ { getResources();
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("Failed to Create : <"+e.getMessage()+">");
+ throw new CreateException(e.getMessage());
+ }
+ } //__________________________________
+
+ @PostActivate
+ public void ejbActivate()
+ { try
+ { getResources();
+ m_oLogger.info("EJB Activated");
+ }
+ catch (Exception e)
+ { m_oLogger.error("Failed to Activate : <"+e.getMessage()+">");
+ }
+ } //__________________________________
+
+ @PrePassivate
+ public void ejbPassivate()
+ { m_oLogger.info("EJB Passivated");
+ releaseResources();
+ m_oLogger = null;
+ m_oUidConn = null;
+ m_oDataConn = null;
+ } //__________________________________
+
+ @Remove
+ public void remove()
+ {
+ releaseResources();
+ m_oLogger.info("EJB Removed");
+ } //__________________________________
+
+ private void getResources() throws Exception
+ { Context oCtx = new InitialContext();
+ m_oLogger = Util.getDefaultLogger(this.getClass());
+ m_oUidConn = new JdbcCleanConn ((DataSource)oCtx.lookup("java:JbossEsbDS"));
+ m_oDataConn = new JdbcCleanConn ((DataSource)oCtx.lookup("java:JbossEsbDS"));
+ } //__________________________________
+
+ private void releaseResources()
+ { if (null != m_oDataConn) m_oDataConn.release();
+ if (null != m_oUidConn) m_oUidConn.release();
+ m_oDaoBatch = null;
+ m_oDaoUid = null;
+ m_oDaoIndex = null;
+ m_oDaoSnap = null;
+ } //__________________________________
+
+// Utility Methods
+
+ private DaoUidTable getDaoUid() throws Exception
+ { if (null==m_oDaoUid)
+ m_oDaoUid = new DaoUidTable(m_oUidConn, BobjStore.getUidTableName());
+ return m_oDaoUid;
+ } //__________________________________
+
+ private DaoBatchTable getDaoBatch(String p_sTbl) throws Exception
+ { if (null==m_oDaoBatch)
+ m_oDaoBatch = new DaoBatchTable(m_oDataConn,p_sTbl);
+ return m_oDaoBatch;
+ } //__________________________________
+
+ private DaoIndexTable getDaoIndex(String p_sTbl) throws Exception
+ { if (null==m_oDaoIndex)
+ m_oDaoIndex = new DaoIndexTable(m_oDataConn,p_sTbl);
+ return m_oDaoIndex;
+ } //__________________________________
+
+ private DaoSnapTable getDaoSnap(BobjStore p_o) throws Exception
+ { if (null==m_oDaoSnap)
+ m_oDaoSnap = new DaoSnapTable(m_oDataConn,p_o);
+ return m_oDaoSnap;
+ } //__________________________________
+
+ private void doCommitBatch(BatchProcess p_oBP) throws Exception
+ { String sPrevClass = null;
+ BobjStore oStore = null;
+
+ PreparedStatement PSbatch = getDaoBatch(BobjStore.getBatchTableName())
+ .getPS(DaoBatchTable.PS_GET_BATCH_ROWS);
+ PSbatch.setLong(1,p_oBP.getBatchNum());
+
+ long lNow = System.currentTimeMillis();
+ String sSnapDt = new SimpleDateFormat("yyyyMMdd").format(new Date(lNow));
+
+ // Get all Batch rows
+ ResultSet RS = m_oDataConn.execQueryWait(PSbatch,10);
+ while (RS.next())
+ { String sXml = RS.getString(1+DaoBatchTable.STR_DATA);
+ BobjStdDTO oDto = BobjStdDTO.getFromXml(sXml);
+ // Get proper Dao's for Index and Snap table
+ String sNewClass = oDto.fullClassName();
+ if (! sNewClass.equals(sPrevClass))
+ { oStore = BobjStore.getStore(sNewClass);
+ sPrevClass = sNewClass;
+ m_oDaoIndex = null;
+ m_oDaoSnap = null;
+ }
+ // Set batch number to current batch
+ oDto.setBatch (p_oBP.getBatchNum());
+ oDto.setStamp (lNow);
+ oDto.setSnapDate(sSnapDt);
+
+ // Insert Snap row
+ PreparedStatement PSins = getDaoSnap(oStore).getPS(DaoSnapTable.PS_INS_SNAP);
+ m_oDaoSnap.setInsValues(PSins,oDto);
+ try { m_oDataConn.execUpdWait(PSins,10); }
+ catch (Exception e) { m_oLogger.error(e.getMessage()); }
+
+ // Insert row in all index tables
+ String[][] saa = oDto.getLocators();
+ for (int i1=0; i1<saa.length; i1++)
+ { m_oDaoIndex = getDaoIndex(oStore.getLocatorTable(i1));
+ PSins = m_oDaoIndex.getPS(DaoIndexTable.PS_INS_INDEX);
+ m_oDaoIndex.setInsValues(PSins,oDto,i1);
+ try { m_oDataConn.execUpdWait(PSins,10); }
+ catch (Exception e) { m_oLogger.error(e.getMessage()); }
+ }
+ }
+ PSbatch.close();
+
+ // Delete batch rows we just used
+ PreparedStatement PSdel = getDaoBatch(BobjStore.getBatchTableName())
+ .getPS(DaoBatchTable.PS_DELETE_BATCH);
+ PSdel.setLong(1,p_oBP.getBatchNum());
+ m_oDataConn.execUpdWait(PSdel,10);
+
+ p_oBP.setField (BatchProcess.ATTRIB.commitStamp,Long.toString(lNow));
+ p_oBP.setStamp (lNow);
+ p_oBP.setSnapDate(sSnapDt);
+
+ oStore = BobjStore.getStore(BatchProcess.class.getName());
+
+ // Update snap table with proper timestamp
+ m_oDaoSnap = null;
+ PreparedStatement PSupd = getDaoSnap(oStore).getPS(DaoSnapTable.PS_UPD_SNAP);
+ getDaoSnap(oStore).setUpdValues(PSupd,p_oBP);
+ m_oDataConn.execUpdWait(PSupd,10);
+
+ // Update index table with proper timestamp
+ m_oDaoIndex = null;
+ PSupd = getDaoIndex(oStore.getLocatorTable()).getPS(DaoIndexTable.PS_UPD_INDEX);
+ getDaoIndex(oStore.getLocatorTable()).setUpdValues(PSupd,p_oBP);
+ m_oDataConn.execUpdWait(PSupd,10);
+
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local and remote interface methods
+/**
+ */
+ public long newBatch() throws Exception
+ { if (m_lBatchNum > 0) throw
+ new Exception ("Must finish with previous batch before opening new");
+ m_iSeq = 0;
+ try
+ { return m_lBatchNum = getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_BATCH, 1);
+ }
+ catch (Exception e)
+ { m_oLogger.error("BatchHandlerBean.newBatch() FAILED "+ e.getMessage());
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+/**
+ * @return
+ */
+ public long getBatchNum()
+ { return m_lBatchNum;
+ } //__________________________________
+
+/**
+ * @param p_s
+ * @return
+ * @throws Exception
+ */
+ public int addToBatch(String p_s) throws Exception
+ { if (null==p_s) throw
+ new Exception ("Tryng to add a null String to a batch");
+ if (m_lBatchNum < 1) throw
+ new Exception ("Must request batch number before adding objects");
+ try
+ { RowBatch oRow = new RowBatch(m_lBatchNum,++m_iSeq,0,p_s);
+ getDaoBatch(BobjStore.getBatchTableName());
+ PreparedStatement PS = m_oDaoBatch.getPS(DaoBatchTable.PS_INS_BATCHROW);
+ m_oDaoBatch.setInsValues(PS,oRow);
+ m_oDataConn.execUpdWait(PS,1);
+ m_oDataConn.commit();
+ return m_iSeq;
+ }
+ catch (Exception e)
+ { if (null != m_oDataConn) m_oDataConn.rollback();
+ m_oLogger.error("addToBatch() failed",e);
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+/**
+ * @throws Exception
+ */
+ public void finish() throws Exception
+ { if (m_lBatchNum < 1) return;
+ m_lBatchNum = -1;
+ m_iSeq = 0;
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local interface methods
+///** KS: I'm commenting this out since we are now using the
+// same interface for local and remote calls. If all
+// works this code can be deleted.
+// */
+// public void commitBatch(BatchProcess p_oBO) throws Exception
+// { try { doCommitBatch(p_oBO); m_oDataConn.commit(); }
+// catch (Exception e)
+// { if (null != m_oDataConn) m_oDataConn.rollback();
+// m_oLogger.error("commitBatch(BatchProcess) FAILED ",e);
+// throw e;
+// }
+// finally { releaseResources(); }
+// } //__________________________________
+
+//______________________________________________________________________________
+// Public remote interface methods
+/**
+ */
+ public void commitBatch(BobjStdDTO p_oDto) throws Exception
+ {
+ commitBatch (new BatchProcess(p_oDto).toDTO());
+ }
+
+} //____________________________________________________________________________
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/BatchHandlerBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,34 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import java.io.Serializable;
+
+/**
+ * Business interface for NotificationHandler.
+ * @author kstam
+ */
+public interface NotificationHandler
+{
+ public void create() throws Exception;
+ public void sendNotifications( String p_sParams, Serializable p_oMsg ) throws Exception;
+}
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandler.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,123 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.DomElement;
+import org.jboss.soa.esb.notification.NotificationList;
+import org.jboss.soa.esb.util.Util;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionAttribute;
+import javax.ejb.TransactionAttributeType;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.naming.InitialContext;
+import java.io.Serializable;
+/**
+ * @author Esteban
+ */
+ at Remote(NotificationHandler.class)
+ at Local(NotificationHandler.class)
+ at TransactionManagement(TransactionManagementType.CONTAINER)
+ at TransactionAttribute(TransactionAttributeType.REQUIRED)
+
+public @Stateless class NotificationHandlerBean implements NotificationHandler
+{
+ private static final long serialVersionUID = 1L;
+ private Logger m_oLogger;
+ SessionContext m_ctxSess;
+
+ public void setSessionContext(SessionContext sessionContext)
+ { m_ctxSess = sessionContext; }
+/**
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws Exception
+ { try
+ { m_oLogger = Util.getDefaultLogger(this.getClass());
+// Context oCtxInit =
+ new InitialContext();
+
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("EJB Create Failed <"+e.getMessage()+">");
+ throw new Exception(e.getMessage());
+ }
+ } //__________________________________
+
+ @Remove
+ public void ejbRemove()
+ { m_oLogger.info(this.toString()+" Removed");
+ } //__________________________________
+
+// Utility Methods
+
+ protected void releaseResources()
+ {
+ } //__________________________________
+
+//______________________________________________________________________________
+// Public local and remote interface methods
+
+ private static final String s_sDfltList =
+ "<NotificationList type=\"Error\" >"
+ +" <target"
+ +" class = \"NotifyEmail\""
+ +" from = \"JbossEsbDefault at myOrg.com\""
+ +" sendTo = \"\""
+ +" subject = \"Default JBoss ESB Notification\""
+ +" message = \" Message from JBoss ESB :\""
+ +" />"
+ +" </NotificationList>"
+ ;
+ private static NotificationList s_dfltList;
+ static
+ { try
+ { s_dfltList = new NotificationList(DomElement.fromXml(s_sDfltList)); }
+ catch (Exception e) { e.printStackTrace(System.out); }
+ }
+/**
+ * @param p_sParams
+ * @param p_sMsg
+ * @throws Exception
+ */
+ public void sendNotifications(String p_sParams, Serializable p_oMsg)
+ throws Exception
+ {
+ DomElement oP = (null==p_sParams)?null:DomElement.fromXml(p_sParams);
+ NotificationList m_oL = (null==oP) ? s_dfltList : new NotificationList(oP);
+ m_oL.sendNotification(p_oMsg);
+ } //__________________________________
+
+} //____________________________________________________________________________
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/NotificationHandlerBean.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,43 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import org.jboss.soa.esb.util.BobjStdDTO;
+
+/**
+ * @author kstam
+ */
+public interface PersistHandler
+{
+ public void create() throws Exception;
+
+ public long getUidChunk( int p_iQ ) throws Exception;
+
+ public void rmvObject( String p_sClassName,long p_lUid ) throws Exception;
+
+ public long addDTO( BobjStdDTO p_oDto ) throws Exception;
+
+ public BobjStdDTO getDTO( String p_sClassName,long p_lUid ) throws Exception;
+
+ public void rplDTO( BobjStdDTO p_oDto ) throws Exception;
+
+}
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandler.java
___________________________________________________________________
Name: svn:executable
+ *
Added: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java 2006-08-07 15:50:46 UTC (rev 5560)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java 2006-08-07 15:53:34 UTC (rev 5561)
@@ -0,0 +1,368 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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.soa.esb.services.beans;
+
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.helpers.persist.JdbcCleanConn;
+import org.jboss.soa.esb.internal.core.objectstore.BobjStore;
+import org.jboss.soa.esb.internal.core.objectstore.DaoIndexTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoSnapTable;
+import org.jboss.soa.esb.internal.core.objectstore.DaoUidTable;
+import org.jboss.soa.esb.util.BobjStdDTO;
+import org.jboss.soa.esb.util.ObjLocator;
+import org.jboss.soa.esb.util.Util;
+
+import javax.ejb.CreateException;
+import javax.ejb.Init;
+import javax.ejb.Local;
+import javax.ejb.Remote;
+import javax.ejb.Remove;
+import javax.ejb.SessionContext;
+import javax.ejb.Stateless;
+import javax.ejb.TransactionManagement;
+import javax.ejb.TransactionManagementType;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.sql.DataSource;
+import java.io.ObjectStreamClass;
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.text.SimpleDateFormat;
+
+/**
+ * @author Esteban
+ */
+ at Remote(PersistHandler.class)
+ at Local(PersistHandler.class)
+ at TransactionManagement(TransactionManagementType.BEAN)
+public @Stateless class PersistHandlerBean implements PersistHandler
+{
+ private static final long serialVersionUID = 1L;
+ private Logger m_oLogger;
+ SessionContext m_ctxSess;
+
+ private JdbcCleanConn m_oUidConn;
+ private JdbcCleanConn m_oDataConn;
+
+ private static final int s_iChunkSize=100;
+ private long m_lUid;
+ private int m_iChunkLeft=0;
+
+ private DaoUidTable m_oDaoUid;
+ private DaoSnapTable m_oDaoSnap;
+ private DaoIndexTable[] m_oaDaoIndex;
+
+ public void setSessionContext(SessionContext sessionContext)
+ { m_ctxSess = sessionContext; }
+/**
+ * Create method. Should get called to initialize this class.
+ * @throws CreateException
+ */
+ @Init
+ public void create() throws Exception
+ { try
+ { m_oLogger = Util.getDefaultLogger(this.getClass());
+ Context oCtxInit = new InitialContext();
+ String sDSjndiName = BobjStore.getDataSourceJndi();
+ DataSource oDS = (DataSource)oCtxInit.lookup(sDSjndiName);
+ m_oUidConn = new JdbcCleanConn(oDS);
+ m_oDataConn = new JdbcCleanConn(oDS);
+
+ Class oCls = Class.forName("org.jboss.soa.esb.util.BobjStdDTO");
+ ObjectStreamClass XX = ObjectStreamClass.lookup(oCls);
+ System.out.println(XX.getSerialVersionUID());
+ System.out.println(oCls.getProtectionDomain().getCodeSource().getLocation());
+
+ m_oLogger.info(this.toString()+" Created");
+ }
+ catch (Exception e)
+ { m_oLogger.error("EJB Create Failed <"+e.getMessage()+">");
+ throw new Exception(e.getMessage());
+ }
+ } //__________________________________
+
+ @Remove
+ public void remove()
+ { m_oLogger.info(this.toString()+" Removed");
+ } //__________________________________
+
+
+ /**
+ * @param p_sClassName - String Fully qualified name of class to be retrieved
+ * @param p_lUid
+ * @return
+ * @throws Exception
+ */
+ public BobjStdDTO getDTO (String p_sClassName, long p_lUid) throws Exception
+ { try { return doGetSnapshot(BobjStore.getStore(p_sClassName), p_lUid);}
+ catch (Exception e) { throw e; }
+ finally { releaseResources(); }
+ } //__________________________________
+ /**
+ *
+ * @param p_oDto BobjStdDTO - Serialized BaseBusinessObject that has to be replaced
+ * @throws Exception
+ */
+ public void rplDTO(BobjStdDTO p_oDto) throws Exception
+ { try
+ { doRplSnapshot(p_oDto);
+ m_oDataConn.commit();
+ }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+// ______________________________________________________________________________
+// Public local and remote interface methods
+ /**
+ */
+ public long getUidChunk (int p_iQ) throws Exception
+ { try { return getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_OBJ,p_iQ); }
+ catch (Exception e) { throw e;}
+ finally { releaseResources(); }
+ } //__________________________________
+ /**
+ * @param p_sClassName
+ * @param p_lUid
+ * @throws Exception
+ */
+ public void rmvObject(String p_sClassName, long p_lUid) throws Exception
+ { try { doRmvSnapshot(BobjStore.getStore(p_sClassName), p_lUid); m_oDataConn.commit(); }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+ /**
+ */
+ public long addDTO(BobjStdDTO p_oDto) throws Exception
+ { try
+ { long lRet = doAddSnapshot(p_oDto);
+ m_oDataConn.commit();
+ return lRet;
+ }
+ catch (Exception e)
+ { try { if (null != m_oDataConn) m_oDataConn.rollback(); }
+ catch (Exception eRoll) {}
+ throw e;
+ }
+ finally { releaseResources(); }
+ } //__________________________________
+
+
+// Utility Methods
+
+ private DaoUidTable getDaoUid() throws Exception
+ { if (null==m_oDaoUid) m_oDaoUid
+ = new DaoUidTable(m_oUidConn,BobjStore.getUidTableName());
+ return m_oDaoUid;
+ } //__________________________________
+
+ private DaoSnapTable getDaoSnap(BobjStore p_oSt) throws Exception
+ { if (null==m_oDaoSnap)
+ m_oDaoSnap = new DaoSnapTable(m_oDataConn,p_oSt);
+ return m_oDaoSnap;
+ } //__________________________________
+
+ private DaoIndexTable getDaoIndex(BobjStore p_oSt,int p_i) throws Exception
+ { if (null==m_oaDaoIndex)
+ m_oaDaoIndex = new DaoIndexTable[p_oSt.allLocatorTables().length];
+ if (null==m_oaDaoIndex[p_i])
+ m_oaDaoIndex[p_i] = new DaoIndexTable(m_oDataConn,p_oSt.getLocatorTable(p_i));
+ return m_oaDaoIndex[p_i];
+ } //__________________________________
+
+ protected ObjLocator[] doAddLocators(BobjStore pStore,BobjStdDTO p_oDto) throws Exception
+ { long lUid = p_oDto.getUid();
+ if (lUid < 1)
+ { lUid = doAssignUid();
+ p_oDto.setUid(lUid);
+ p_oDto.setSnap(lUid);
+ }
+ long lStamp = p_oDto.getStamp();
+ if (lStamp < 1)
+ p_oDto.setStamp(lStamp = System.currentTimeMillis());
+
+ String[][] saa = p_oDto.getLocators();
+ ObjLocator[]oaRet = new ObjLocator[saa.length];
+ int iCurr = 0;
+ for (int i1=0; i1<saa.length; i1++)
+ { String[] saCurr = saa[i1];
+ ObjLocator oLoc = new ObjLocator(lUid,saCurr);
+ oaRet[iCurr] = oLoc;
+ String sTbl = pStore.getLocatorTable(iCurr++);
+ if (null == sTbl)
+ continue;
+
+ DaoIndexTable oDao = new DaoIndexTable(m_oDataConn,sTbl);
+ PreparedStatement PS = oDao.getPS(DaoIndexTable.PS_INS_INDEX);
+
+ PS.setLong (DaoIndexTable.OBJECT_UID,lUid);
+ PS.setLong (DaoIndexTable.TIMESTAMP,lStamp);
+ PS.setLong (DaoIndexTable.UID_SNAP,p_oDto.getSnap());
+ PS.setString (DaoIndexTable.SNAP_DATE,s_oY4md.format(new Date(lStamp)));
+
+ int iFld = DaoIndexTable.FIRST_FIELD;
+ for (int i2=0; i2<saCurr.length; i2++)
+ { String sFldVal = saCurr[i2];
+ PS.setString(iFld++,(null == sFldVal)?"":sFldVal);
+ }
+ m_oDataConn.execUpdWait(PS,1);
+ }
+
+ return oaRet;
+ } //__________________________________
+
+ private void doDelLocators (BobjStore p_oSt, long p_lUid)
+ { if (p_lUid < 1) return;
+ int iQlocs = p_oSt.allLocatorTables().length;
+ for (int i1=0; i1<iQlocs; i1++)
+ try
+ { PreparedStatement PS = getDaoIndex(p_oSt,i1).getPS(DaoIndexTable.PS_RMV_INDEX);
+ PS.setLong(1,p_lUid);
+ m_oDataConn.execQueryWait(PS,5);
+ }
+ catch (Exception e)
+ { m_oLogger.warn("doDelLocator() FAILED <"+e.getMessage()+">");
+ }
+ } //__________________________________
+
+ private void doDelOneSnap (BobjStore p_oSt,long p_lUid) throws Exception
+ { if (p_lUid < 1) return;
+ PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_RMV_SNAP);
+ PS.setLong(1,p_lUid);
+ m_oDataConn.execQueryWait(PS,5);
+ } //__________________________________
+
+ private void doRmvSnapshot (BobjStore p_oSt,long p_lUid) throws Exception
+ {
+ PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_SEL_4UPD);
+ PS.setLong(1,p_lUid);
+ ResultSet rs = m_oDataConn.execQueryWait(PS,30);
+ if (! rs.next()) throw new Exception("Non existing Snapshot");
+ long lObjUid = rs.getLong(DaoSnapTable.OBJECT_UID);
+
+ doDelOneSnap(p_oSt,p_lUid);
+ doDelLocators(p_oSt,lObjUid);
+
+ } //__________________________________
+
+ private void doRplSnapshot(BobjStdDTO p_oDto)
+ throws Exception
+ { long lSnapUid = p_oDto.getSnap();
+ BobjStore oSt = BobjStore.getStore(p_oDto);
+ doDelOneSnap(oSt,lSnapUid);
+ doDelLocators(oSt,p_oDto.getUid());
+ doAddSnapshot(p_oDto,false);
+ } //__________________________________
+
+ private long doAddSnapshot(BobjStdDTO p_oDto)
+ throws Exception
+ { return doAddSnapshot(p_oDto,true);
+ } //__________________________________
+
+ SimpleDateFormat s_oY4md = new SimpleDateFormat("yyyyMMdd");
+ private long doAddSnapshot(BobjStdDTO p_oDto, boolean p_bNewVrs)
+ throws Exception
+ { long lObjUid = p_oDto.getUid();
+ if (lObjUid < 1) p_oDto.setUid(lObjUid=doAssignUid());
+ p_oDto.setSnap(lObjUid);
+
+ // Set Timestamp
+ long lNow = System.currentTimeMillis();
+ p_oDto.setStamp(lNow);
+ p_oDto.setSnapDate(s_oY4md.format(new Date(lNow)));
+
+ BobjStore oSt = BobjStore.getStore(p_oDto);
+ PreparedStatement PS = getDaoSnap(oSt).getPS(DaoSnapTable.PS_INS_SNAP);
+ getDaoSnap(oSt).setInsValues(PS,p_oDto);
+
+ m_oDataConn.execUpdWait(PS,1);
+
+ int iQlocs = oSt.allLocatorTables().length;
+ for (int i1=0; i1<iQlocs; i1++)
+ { DaoIndexTable oDao = getDaoIndex(oSt,i1);
+ PS = oDao.getPS(DaoIndexTable.PS_INS_INDEX);
+ oDao.setInsValues(PS,p_oDto);
+ try { m_oDataConn.execUpdWait(PS,1); }
+ catch (Exception e)
+ { PS = oDao.getPS(DaoIndexTable.PS_UPD_INDEX);
+ oDao.setUpdValues(PS,p_oDto);
+ m_oDataConn.execUpdWait(PS,10);
+ }
+ }
+
+ return lObjUid;
+ } //__________________________________
+
+ protected void updateLocTbl(BobjStdDTO p_oDto, int p_iNum)
+ throws Exception
+ { BobjStore oSt = BobjStore.getStore(p_oDto);
+ String sTbl = oSt.getLocatorTable(p_iNum);
+ if (null==sTbl) return;
+ DaoIndexTable oDao = getDaoIndex(oSt,p_iNum);
+ PreparedStatement PSupd = oDao.getPS(DaoIndexTable.PS_UPD_INDEX);
+ oDao.setUpdValues(PSupd, p_oDto);
+
+ m_oDataConn.execUpdWait(PSupd,10);
+ } //__________________________________
+
+ private BobjStdDTO doGetSnapshot (BobjStore p_oSt,long p_lUid) throws Exception
+ { PreparedStatement PS = getDaoSnap(p_oSt).getPS(DaoSnapTable.PS_SEL_SNAP);
+ PS.setLong(1,p_lUid);
+ ResultSet rs = m_oDataConn.execQueryWait(PS,30);
+ if (! rs.next()) throw new Exception("Non existing Snapshot");
+ BobjStdDTO oRet = (BobjStdDTO)getDaoSnap(p_oSt).getFromRS(rs);
+ return oRet;
+ } //__________________________________
+
+ private void releaseResources()
+ { if (null!=m_oaDaoIndex)
+ for (int i1=0; i1<m_oaDaoIndex.length; i1++)
+ m_oaDaoIndex[i1] = null;
+ m_oaDaoIndex = null;
+ m_oDaoSnap = null;
+ m_oDaoUid = null;
+ if (null != m_oDataConn) m_oDataConn.release();
+ if (null != m_oUidConn) m_oUidConn.release();
+ } //__________________________________
+
+ private long doAssignUid() throws Exception
+ { if (m_iChunkLeft < 1)
+ { m_lUid = getDaoUid().getUidChunk(DaoUidTable.SEQUENCE_OBJ, s_iChunkSize);
+ m_iChunkLeft = s_iChunkSize;
+ }
+ m_iChunkLeft--;
+ return ++m_lUid;
+ } //__________________________________
+
+
+
+} //____________________________________________________________________________
Property changes on: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/beans/PersistHandlerBean.java
___________________________________________________________________
Name: svn:executable
+ *
More information about the jboss-svn-commits
mailing list