You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by mr...@apache.org on 2009/01/24 00:53:21 UTC
svn commit: r737256 [10/12] - in /ode/branches/APACHE_ODE_1.X:
bpel-test/src/test/resources/
bpel-test/src/test/resources/bpel/2.0/TestAlarm/
bpel-test/src/test/resources/bpel/2.0/TestAssignComplex/
bpel-test/src/test/resources/bpel/2.0/TestAssignDate/...
Modified: ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/java/org/apache/ode/dao/jpa/test/SelectObjectTest.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/java/org/apache/ode/dao/jpa/test/SelectObjectTest.java?rev=737256&r1=737255&r2=737256&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/java/org/apache/ode/dao/jpa/test/SelectObjectTest.java (original)
+++ ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/java/org/apache/ode/dao/jpa/test/SelectObjectTest.java Fri Jan 23 23:53:17 2009
@@ -1,300 +1,300 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ode.dao.jpa.test;
-
-import junit.framework.TestCase;
-import org.apache.ode.bpel.common.CorrelationKey;
-import org.apache.ode.bpel.common.CorrelationKeySet;
-import org.apache.ode.bpel.dao.ActivityRecoveryDAO;
-import org.apache.ode.bpel.dao.BpelDAOConnection;
-import org.apache.ode.bpel.dao.CorrelationSetDAO;
-import org.apache.ode.bpel.dao.CorrelatorDAO;
-import org.apache.ode.bpel.dao.FaultDAO;
-import org.apache.ode.bpel.dao.MessageDAO;
-import org.apache.ode.bpel.dao.MessageExchangeDAO;
-import org.apache.ode.bpel.dao.MessageRouteDAO;
-import org.apache.ode.bpel.dao.PartnerLinkDAO;
-import org.apache.ode.bpel.dao.ProcessDAO;
-import org.apache.ode.bpel.dao.ProcessInstanceDAO;
-import org.apache.ode.bpel.dao.ScopeDAO;
-import org.apache.ode.bpel.dao.ScopeStateEnum;
-import org.apache.ode.bpel.dao.XmlDataDAO;
-import org.apache.ode.dao.jpa.BPELDAOConnectionFactoryImpl;
-import org.apache.ode.il.EmbeddedGeronimoFactory;
-import org.apache.ode.utils.GUID;
-import org.hsqldb.jdbc.jdbcDataSource;
-
-import javax.persistence.EntityManager;
-import javax.sql.DataSource;
-import javax.transaction.TransactionManager;
-import javax.xml.namespace.QName;
-import java.util.Collection;
-import java.util.Properties;
-import java.util.List;
-
-public class SelectObjectTest extends TestCase {
-
- private EntityManager em;
- private static final String TEST_NS = "http://org.apache.ode.jpa.test";
- private String[] correlationKeys = { "key1", "key2" };
- private String[] actions = { "action1","action2" };
- private CorrelationKey key1 = new CorrelationKey("key1",correlationKeys);
- private static final String CORRELATOR_ID1 = "testCorrelator1";
- private static final String CORRELATOR_ID2 = "testCorrelator2";
-
- TransactionManager _txm;
- DataSource _ds;
- BPELDAOConnectionFactoryImpl factory;
-
- @Override
- protected void setUp() throws Exception {
- jdbcDataSource hsqlds = new jdbcDataSource();
- hsqlds.setDatabase("jdbc:hsqldb:mem:" + new GUID().toString());
- hsqlds.setUser("sa");
- hsqlds.setPassword("");
- _ds = hsqlds;
-
- _txm = new EmbeddedGeronimoFactory().getTransactionManager();
-
- factory = new BPELDAOConnectionFactoryImpl();
- factory.setDataSource(_ds);
- factory.setTransactionManager(_txm);
- Properties props = new Properties();
- props.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)");
- factory.init(props);
-
- _txm.begin();
- }
-
- public void testGetObject() throws Exception {
- new InsertObjectTest().createStuff(factory);
-
- _txm.commit();
- _txm.begin();
-
- BpelDAOConnection conn = factory.getConnection();
-
- // Assert the ProcessDAO
- ProcessDAO p = conn.getProcess(new QName(TEST_NS,"testPID1"));
- assertNotNull( p );
- Collection<ProcessInstanceDAO> insts = p.findInstance(key1);
- assertNotNull( insts );
- assertTrue( insts.size() > 0 );
- assertNotNull(p.getType());
- assertNotNull(p.getProcessId());
- assertEquals( p.getVersion() , 1 );
-
- // Assert the CorrelatorDAO
- CorrelatorDAO corr = p.getCorrelator(CORRELATOR_ID1);
- assertNotNull( corr );
- assertEquals(corr.getCorrelatorId(),CORRELATOR_ID1);
-
- // Assert the MessageRouteDAO
- List<MessageRouteDAO> routes = corr.findRoute(new CorrelationKeySet().add(key1));
- MessageRouteDAO route = null;
- if (routes != null && routes.size() > 0) {
- route = routes.get(0);
- }
- assertNotNull( route );
- assertEquals(route.getGroupId(),"testRoute" );
- assertEquals(route.getIndex() , 1 );
- assertNotNull(route.getTargetInstance() );
-
- // Assert the ProcessInstanceDAO
- for ( ProcessInstanceDAO inst : insts ) {
- Long id = inst.getInstanceId();
- assertNotNull( id );
-
- ProcessInstanceDAO inst2 = conn.getInstance(id);
- assertSame(inst2,inst);
-
- ProcessInstanceDAO inst3 = p.getInstance(id);
- assertSame( inst3 , inst );
-
- Long mon = inst.genMonotonic();
- assertEquals(inst.getActivityFailureCount() , 2);
- assertNotNull(inst.getActivityFailureDateTime() );
- assertNotNull(inst.getCreateTime() );
- assertTrue(inst.getExecutionState().length > 0 );
- assertNotNull(inst.getLastActiveTime() );
- assertSame(inst.getProcess() , p );
- assertEquals(inst.getPreviousState() , 0);
- assertEquals(inst.getState() , 1);
-
- // Assert the Root ScopeDAO
- ScopeDAO rs = inst.getRootScope();
- assertNotNull( rs );
- assertNotNull(rs.getChildScopes());
- ScopeDAO child1 = null;
- for ( ScopeDAO childItr : rs.getChildScopes()){
- child1 = childItr;
- break;
- }
- assertNotNull(child1);
- assertNotNull(rs.getCorrelationSets());
- assertEquals(rs.getCorrelationSets().size() , 0 );
- assertEquals(rs.getModelId(),1);
- assertEquals(rs.getName(),"Root");
- assertTrue(rs.getParentScope() == null);
- assertNotNull(rs.getPartnerLinks());
- assertEquals(rs.getPartnerLinks().size() ,0);
- assertSame(rs.getProcessInstance(),inst);
- assertNotNull(rs.getScopeInstanceId());
- assertEquals(rs.getState(),ScopeStateEnum.ACTIVE);
- assertNotNull(rs.getVariables());
- assertEquals(rs.getVariables().size(),0);
-
-
- // Assert the ActivityRecoveryDAO
- assertNotNull(inst.getActivityRecoveries());
- ActivityRecoveryDAO rec1 = null;
- for (ActivityRecoveryDAO recItr : inst.getActivityRecoveries()) {
- if (recItr.getActivityId() == 3) {
- rec1 = recItr;break;
- }
- }
- assertNotNull(rec1);
- String tmpAct = rec1.getActions();
-// assertEquals(rec1.getActionsList(),actions);
- assertEquals(rec1.getActivityId(),3);
- assertEquals(rec1.getChannel(),"testChannel1");
- assertNotNull(rec1.getDateTime());
-// assertNotNull(rec1.getDetails());
- assertEquals(rec1.getReason(),"testReason1");
- assertEquals(rec1.getRetries(),2);
-
- // Assert the CorrelationSetDAO
- //assertNotNull(inst.getCorrelationSets());
- //CorrelationSetDAO cs1 = null;
- //for ( CorrelationSetDAO csItr : inst.getCorrelationSets() ) {
- // cs1 = csItr;
- // break;
- //}
- //assertNotNull(cs1);
-
- // Assert the FaultDAO
- FaultDAO fault = inst.getFault();
- assertNotNull(fault);
- assertEquals(fault.getActivityId(),1);
- assertNotNull(fault.getData());
- assertEquals(fault.getExplanation(),"testExplanation");
- assertEquals(fault.getLineNo(),1);
- assertEquals(fault.getName(),new QName(TEST_NS,"testFault"));
-
- // Assert MessageExchangeDAO
- CorrelatorDAO ic = inst.getInstantiatingCorrelator();
- assertNotNull(ic);
- assertEquals(ic.getCorrelatorId(),CORRELATOR_ID1);
- // The message is dequeued but not persisted
- MessageExchangeDAO me = ic.dequeueMessage(new CorrelationKeySet().add(key1));
- assertNotNull(me);
- assertEquals(me.getCallee(),new QName(TEST_NS,"testCallee"));
- assertEquals(me.getPropagateTransactionFlag(),false);
- assertEquals(me.getChannel(),"testChannel");
- assertEquals(me.getCorrelationId(),"testCorrelationId");
- //assertNotNull(me.getCreateTime());
- assertEquals(me.getDirection(),'0');
- assertNotNull(me.getEPR());
- assertEquals(me.getFault().toString(),"testFault");
- assertEquals(me.getFaultExplanation(),"testFaultExplanation");
- assertSame(me.getInstance(),inst);
- assertEquals(me.getOperation(),"testOperation");
- assertNotNull(me.getPartnerLink());
- assertEquals(me.getPartnerLinkModelId(),1);
- assertEquals(me.getPattern(),"testPattern");
- assertEquals(me.getPortType(),new QName(TEST_NS,"testPortType"));
- assertSame(me.getProcess(),p);
- assertEquals(me.getProperty("testProp1Key"),"testProp1");
- assertNotNull(me.getRequest());
- assertNotNull(me.getResponse());
- assertEquals(me.getStatus(),"testStatus");
-
- // Assert MessageDAO
- MessageDAO m = me.getRequest();
- assertNotNull(m.getData());
- assertSame(m.getMessageExchange(),me);
- assertEquals(m.getType(),new QName(TEST_NS,"testRequest"));
-
-
- //Assert Child ScopeDAO
- assertNotNull(inst.getScopes());
- assertTrue(inst.getScopes().size() > 0);
- assertNotNull(inst.getScopes("Child1"));
- assertTrue(inst.getScopes("Child1").size() == 1);
- ScopeDAO childS = inst.getScopes("Child1").iterator().next();
- assertSame(childS,child1);
- assertSame(childS.getParentScope(),rs);
- assertNotNull(childS.getChildScopes());
- assertEquals(childS.getChildScopes().size(), 0);
- assertNotNull(childS.getVariables());
- assertTrue(childS.getVariables().size() > 0);
- assertNotNull(childS.getVariable("var1"));
- XmlDataDAO chsVar = childS.getVariable("var1");
- assertNotNull(childS.getPartnerLinks());
- assertTrue(childS.getPartnerLinks().size() > 0);
- PartnerLinkDAO spl = childS.getPartnerLinks().iterator().next();
- assertSame(spl,me.getPartnerLink());
- assertSame(spl,childS.getPartnerLink(spl.getPartnerLinkModelId()));
- assertNotNull(childS.getCorrelationSets());
- assertTrue(childS.getCorrelationSets().size() > 0);
- assertNotNull(childS.getCorrelationSet("TestCorrelationSet1"));
-
- // Assert CorrelationSetDAO
- CorrelationSetDAO cs = childS.getCorrelationSet("TestCorrelationSet1");
- assertEquals(cs.getName(),"TestCorrelationSet1");
- assertNotNull(cs.getProperties());
- assertTrue(cs.getProperties().size() > 0);
- assertSame(cs.getScope(),childS);
- assertNotNull(cs.getValue());
- assertEquals(cs.getProperties().get(new QName(TEST_NS,"name1")),"key1");
-
-
- // Assert PartnerLinkDAO
- assertNotNull(spl.getMyEPR());
- assertEquals(spl.getMyRoleName(),"MyRole1");
- assertEquals(spl.getMyRoleServiceName(),new QName(TEST_NS,"testRoleService"));
- assertEquals(spl.getMySessionId(),"TestMySessionID");
- assertNotNull(spl.getPartnerEPR());
- assertEquals(spl.getPartnerLinkModelId(),1);
- assertEquals(spl.getPartnerLinkName(),"Test PartnerLink1");
- assertEquals(spl.getPartnerRoleName(),"PartnerRole1");
- assertEquals(spl.getPartnerSessionId(),"TestPartnerSessionID");
-
- // Assert Variables
- assertNotNull(inst.getVariables("var1", 2));
- assertEquals(inst.getVariables("var1", 2).length,1);
- XmlDataDAO[] vars = inst.getVariables("var1", 2);
- assertSame(chsVar,vars[0]);
- assertNotNull(vars[0].get());
- assertEquals(vars[0].getName(),"var1");
- // assertEquals(vars[0].getProperty("key1"),"prop1");
- assertSame(vars[0].getScopeDAO(),childS);
-
- }
- }
-
- @Override
- protected void tearDown() throws Exception {
- _txm.commit();
- _txm = null;
- _ds = null;
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa.test;
+
+import junit.framework.TestCase;
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.bpel.common.CorrelationKeySet;
+import org.apache.ode.bpel.dao.ActivityRecoveryDAO;
+import org.apache.ode.bpel.dao.BpelDAOConnection;
+import org.apache.ode.bpel.dao.CorrelationSetDAO;
+import org.apache.ode.bpel.dao.CorrelatorDAO;
+import org.apache.ode.bpel.dao.FaultDAO;
+import org.apache.ode.bpel.dao.MessageDAO;
+import org.apache.ode.bpel.dao.MessageExchangeDAO;
+import org.apache.ode.bpel.dao.MessageRouteDAO;
+import org.apache.ode.bpel.dao.PartnerLinkDAO;
+import org.apache.ode.bpel.dao.ProcessDAO;
+import org.apache.ode.bpel.dao.ProcessInstanceDAO;
+import org.apache.ode.bpel.dao.ScopeDAO;
+import org.apache.ode.bpel.dao.ScopeStateEnum;
+import org.apache.ode.bpel.dao.XmlDataDAO;
+import org.apache.ode.dao.jpa.BPELDAOConnectionFactoryImpl;
+import org.apache.ode.il.EmbeddedGeronimoFactory;
+import org.apache.ode.utils.GUID;
+import org.hsqldb.jdbc.jdbcDataSource;
+
+import javax.persistence.EntityManager;
+import javax.sql.DataSource;
+import javax.transaction.TransactionManager;
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.Properties;
+import java.util.List;
+
+public class SelectObjectTest extends TestCase {
+
+ private EntityManager em;
+ private static final String TEST_NS = "http://org.apache.ode.jpa.test";
+ private String[] correlationKeys = { "key1", "key2" };
+ private String[] actions = { "action1","action2" };
+ private CorrelationKey key1 = new CorrelationKey("key1",correlationKeys);
+ private static final String CORRELATOR_ID1 = "testCorrelator1";
+ private static final String CORRELATOR_ID2 = "testCorrelator2";
+
+ TransactionManager _txm;
+ DataSource _ds;
+ BPELDAOConnectionFactoryImpl factory;
+
+ @Override
+ protected void setUp() throws Exception {
+ jdbcDataSource hsqlds = new jdbcDataSource();
+ hsqlds.setDatabase("jdbc:hsqldb:mem:" + new GUID().toString());
+ hsqlds.setUser("sa");
+ hsqlds.setPassword("");
+ _ds = hsqlds;
+
+ _txm = new EmbeddedGeronimoFactory().getTransactionManager();
+
+ factory = new BPELDAOConnectionFactoryImpl();
+ factory.setDataSource(_ds);
+ factory.setTransactionManager(_txm);
+ Properties props = new Properties();
+ props.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=false)");
+ factory.init(props);
+
+ _txm.begin();
+ }
+
+ public void testGetObject() throws Exception {
+ new InsertObjectTest().createStuff(factory);
+
+ _txm.commit();
+ _txm.begin();
+
+ BpelDAOConnection conn = factory.getConnection();
+
+ // Assert the ProcessDAO
+ ProcessDAO p = conn.getProcess(new QName(TEST_NS,"testPID1"));
+ assertNotNull( p );
+ Collection<ProcessInstanceDAO> insts = p.findInstance(key1);
+ assertNotNull( insts );
+ assertTrue( insts.size() > 0 );
+ assertNotNull(p.getType());
+ assertNotNull(p.getProcessId());
+ assertEquals( p.getVersion() , 1 );
+
+ // Assert the CorrelatorDAO
+ CorrelatorDAO corr = p.getCorrelator(CORRELATOR_ID1);
+ assertNotNull( corr );
+ assertEquals(corr.getCorrelatorId(),CORRELATOR_ID1);
+
+ // Assert the MessageRouteDAO
+ List<MessageRouteDAO> routes = corr.findRoute(new CorrelationKeySet().add(key1));
+ MessageRouteDAO route = null;
+ if (routes != null && routes.size() > 0) {
+ route = routes.get(0);
+ }
+ assertNotNull( route );
+ assertEquals(route.getGroupId(),"testRoute" );
+ assertEquals(route.getIndex() , 1 );
+ assertNotNull(route.getTargetInstance() );
+
+ // Assert the ProcessInstanceDAO
+ for ( ProcessInstanceDAO inst : insts ) {
+ Long id = inst.getInstanceId();
+ assertNotNull( id );
+
+ ProcessInstanceDAO inst2 = conn.getInstance(id);
+ assertSame(inst2,inst);
+
+ ProcessInstanceDAO inst3 = p.getInstance(id);
+ assertSame( inst3 , inst );
+
+ Long mon = inst.genMonotonic();
+ assertEquals(inst.getActivityFailureCount() , 2);
+ assertNotNull(inst.getActivityFailureDateTime() );
+ assertNotNull(inst.getCreateTime() );
+ assertTrue(inst.getExecutionState().length > 0 );
+ assertNotNull(inst.getLastActiveTime() );
+ assertSame(inst.getProcess() , p );
+ assertEquals(inst.getPreviousState() , 0);
+ assertEquals(inst.getState() , 1);
+
+ // Assert the Root ScopeDAO
+ ScopeDAO rs = inst.getRootScope();
+ assertNotNull( rs );
+ assertNotNull(rs.getChildScopes());
+ ScopeDAO child1 = null;
+ for ( ScopeDAO childItr : rs.getChildScopes()){
+ child1 = childItr;
+ break;
+ }
+ assertNotNull(child1);
+ assertNotNull(rs.getCorrelationSets());
+ assertEquals(rs.getCorrelationSets().size() , 0 );
+ assertEquals(rs.getModelId(),1);
+ assertEquals(rs.getName(),"Root");
+ assertTrue(rs.getParentScope() == null);
+ assertNotNull(rs.getPartnerLinks());
+ assertEquals(rs.getPartnerLinks().size() ,0);
+ assertSame(rs.getProcessInstance(),inst);
+ assertNotNull(rs.getScopeInstanceId());
+ assertEquals(rs.getState(),ScopeStateEnum.ACTIVE);
+ assertNotNull(rs.getVariables());
+ assertEquals(rs.getVariables().size(),0);
+
+
+ // Assert the ActivityRecoveryDAO
+ assertNotNull(inst.getActivityRecoveries());
+ ActivityRecoveryDAO rec1 = null;
+ for (ActivityRecoveryDAO recItr : inst.getActivityRecoveries()) {
+ if (recItr.getActivityId() == 3) {
+ rec1 = recItr;break;
+ }
+ }
+ assertNotNull(rec1);
+ String tmpAct = rec1.getActions();
+// assertEquals(rec1.getActionsList(),actions);
+ assertEquals(rec1.getActivityId(),3);
+ assertEquals(rec1.getChannel(),"testChannel1");
+ assertNotNull(rec1.getDateTime());
+// assertNotNull(rec1.getDetails());
+ assertEquals(rec1.getReason(),"testReason1");
+ assertEquals(rec1.getRetries(),2);
+
+ // Assert the CorrelationSetDAO
+ //assertNotNull(inst.getCorrelationSets());
+ //CorrelationSetDAO cs1 = null;
+ //for ( CorrelationSetDAO csItr : inst.getCorrelationSets() ) {
+ // cs1 = csItr;
+ // break;
+ //}
+ //assertNotNull(cs1);
+
+ // Assert the FaultDAO
+ FaultDAO fault = inst.getFault();
+ assertNotNull(fault);
+ assertEquals(fault.getActivityId(),1);
+ assertNotNull(fault.getData());
+ assertEquals(fault.getExplanation(),"testExplanation");
+ assertEquals(fault.getLineNo(),1);
+ assertEquals(fault.getName(),new QName(TEST_NS,"testFault"));
+
+ // Assert MessageExchangeDAO
+ CorrelatorDAO ic = inst.getInstantiatingCorrelator();
+ assertNotNull(ic);
+ assertEquals(ic.getCorrelatorId(),CORRELATOR_ID1);
+ // The message is dequeued but not persisted
+ MessageExchangeDAO me = ic.dequeueMessage(new CorrelationKeySet().add(key1));
+ assertNotNull(me);
+ assertEquals(me.getCallee(),new QName(TEST_NS,"testCallee"));
+ assertEquals(me.getPropagateTransactionFlag(),false);
+ assertEquals(me.getChannel(),"testChannel");
+ assertEquals(me.getCorrelationId(),"testCorrelationId");
+ //assertNotNull(me.getCreateTime());
+ assertEquals(me.getDirection(),'0');
+ assertNotNull(me.getEPR());
+ assertEquals(me.getFault().toString(),"testFault");
+ assertEquals(me.getFaultExplanation(),"testFaultExplanation");
+ assertSame(me.getInstance(),inst);
+ assertEquals(me.getOperation(),"testOperation");
+ assertNotNull(me.getPartnerLink());
+ assertEquals(me.getPartnerLinkModelId(),1);
+ assertEquals(me.getPattern(),"testPattern");
+ assertEquals(me.getPortType(),new QName(TEST_NS,"testPortType"));
+ assertSame(me.getProcess(),p);
+ assertEquals(me.getProperty("testProp1Key"),"testProp1");
+ assertNotNull(me.getRequest());
+ assertNotNull(me.getResponse());
+ assertEquals(me.getStatus(),"testStatus");
+
+ // Assert MessageDAO
+ MessageDAO m = me.getRequest();
+ assertNotNull(m.getData());
+ assertSame(m.getMessageExchange(),me);
+ assertEquals(m.getType(),new QName(TEST_NS,"testRequest"));
+
+
+ //Assert Child ScopeDAO
+ assertNotNull(inst.getScopes());
+ assertTrue(inst.getScopes().size() > 0);
+ assertNotNull(inst.getScopes("Child1"));
+ assertTrue(inst.getScopes("Child1").size() == 1);
+ ScopeDAO childS = inst.getScopes("Child1").iterator().next();
+ assertSame(childS,child1);
+ assertSame(childS.getParentScope(),rs);
+ assertNotNull(childS.getChildScopes());
+ assertEquals(childS.getChildScopes().size(), 0);
+ assertNotNull(childS.getVariables());
+ assertTrue(childS.getVariables().size() > 0);
+ assertNotNull(childS.getVariable("var1"));
+ XmlDataDAO chsVar = childS.getVariable("var1");
+ assertNotNull(childS.getPartnerLinks());
+ assertTrue(childS.getPartnerLinks().size() > 0);
+ PartnerLinkDAO spl = childS.getPartnerLinks().iterator().next();
+ assertSame(spl,me.getPartnerLink());
+ assertSame(spl,childS.getPartnerLink(spl.getPartnerLinkModelId()));
+ assertNotNull(childS.getCorrelationSets());
+ assertTrue(childS.getCorrelationSets().size() > 0);
+ assertNotNull(childS.getCorrelationSet("TestCorrelationSet1"));
+
+ // Assert CorrelationSetDAO
+ CorrelationSetDAO cs = childS.getCorrelationSet("TestCorrelationSet1");
+ assertEquals(cs.getName(),"TestCorrelationSet1");
+ assertNotNull(cs.getProperties());
+ assertTrue(cs.getProperties().size() > 0);
+ assertSame(cs.getScope(),childS);
+ assertNotNull(cs.getValue());
+ assertEquals(cs.getProperties().get(new QName(TEST_NS,"name1")),"key1");
+
+
+ // Assert PartnerLinkDAO
+ assertNotNull(spl.getMyEPR());
+ assertEquals(spl.getMyRoleName(),"MyRole1");
+ assertEquals(spl.getMyRoleServiceName(),new QName(TEST_NS,"testRoleService"));
+ assertEquals(spl.getMySessionId(),"TestMySessionID");
+ assertNotNull(spl.getPartnerEPR());
+ assertEquals(spl.getPartnerLinkModelId(),1);
+ assertEquals(spl.getPartnerLinkName(),"Test PartnerLink1");
+ assertEquals(spl.getPartnerRoleName(),"PartnerRole1");
+ assertEquals(spl.getPartnerSessionId(),"TestPartnerSessionID");
+
+ // Assert Variables
+ assertNotNull(inst.getVariables("var1", 2));
+ assertEquals(inst.getVariables("var1", 2).length,1);
+ XmlDataDAO[] vars = inst.getVariables("var1", 2);
+ assertSame(chsVar,vars[0]);
+ assertNotNull(vars[0].get());
+ assertEquals(vars[0].getName(),"var1");
+ // assertEquals(vars[0].getProperty("key1"),"prop1");
+ assertSame(vars[0].getScopeDAO(),childS);
+
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ _txm.commit();
+ _txm = null;
+ _ds = null;
+ }
+
+}
Modified: ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/resources/META-INF/persistence.xml
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/resources/META-INF/persistence.xml?rev=737256&r1=737255&r2=737256&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/resources/META-INF/persistence.xml (original)
+++ ode/branches/APACHE_ODE_1.X/dao-jpa-ojpa-derby/src/test/resources/META-INF/persistence.xml Fri Jan 23 23:53:17 2009
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
@@ -17,44 +17,44 @@
~ specific language governing permissions and limitations
~ under the License.
-->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
- <persistence-unit name="ode-unit-test-embedded">
- <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
- <class>org.apache.ode.dao.jpa.ActivityRecoveryDAOImpl</class>
- <class>org.apache.ode.dao.jpa.CorrelationSetDAOImpl</class>
- <class>org.apache.ode.dao.jpa.CorrelatorDAOImpl</class>
- <class>org.apache.ode.dao.jpa.EventDAOImpl</class>
- <class>org.apache.ode.dao.jpa.FaultDAOImpl</class>
- <class>org.apache.ode.dao.jpa.MessageDAOImpl</class>
- <class>org.apache.ode.dao.jpa.MessageExchangeDAOImpl</class>
- <class>org.apache.ode.dao.jpa.MessageRouteDAOImpl</class>
- <class>org.apache.ode.dao.jpa.PartnerLinkDAOImpl</class>
- <class>org.apache.ode.dao.jpa.ProcessDAOImpl</class>
- <class>org.apache.ode.dao.jpa.ProcessInstanceDAOImpl</class>
- <class>org.apache.ode.dao.jpa.ScopeDAOImpl</class>
- <class>org.apache.ode.dao.jpa.XmlDataDAOImpl</class>
-
- <properties>
- <!-- Properties for an embedded Derby connection
- <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
- <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.DerbyDictionary"/>
-
- <property name="openjpa.ConnectionProperties"
- value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/derby/ode-test-db;userid=sa;create=false,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
- -->
-
- <!-- Properties for an embedded Derby connection -->
- <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
- <property name="openjpa.ConnectionURL" value="jdbc:derby:target/database/derby/ode-test-db;create=false"/>
- <property name="openjpa.ConnectionUserName" value="SA"/>
- <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.DerbyDictionary"/>
-
- <!-- Use this property to generate DDL at runtime
- <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
- -->
-
-
- </properties>
- </persistence-unit>
-</persistence>
-
+<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0">
+ <persistence-unit name="ode-unit-test-embedded">
+ <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
+ <class>org.apache.ode.dao.jpa.ActivityRecoveryDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.CorrelationSetDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.CorrelatorDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.EventDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.FaultDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.MessageDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.MessageExchangeDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.MessageRouteDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.PartnerLinkDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.ProcessDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.ProcessInstanceDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.ScopeDAOImpl</class>
+ <class>org.apache.ode.dao.jpa.XmlDataDAOImpl</class>
+
+ <properties>
+ <!-- Properties for an embedded Derby connection
+ <property name="openjpa.ConnectionDriverName" value="org.apache.commons.dbcp.BasicDataSource"/>
+ <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.DerbyDictionary"/>
+
+ <property name="openjpa.ConnectionProperties"
+ value="DriverClassName=org.apache.derby.jdbc.EmbeddedDriver,Url=jdbc:derby:target/database/derby/ode-test-db;userid=sa;create=false,MaxActive=100,MaxWait=10000,TestOnBorrow=true"/>
+ -->
+
+ <!-- Properties for an embedded Derby connection -->
+ <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver"/>
+ <property name="openjpa.ConnectionURL" value="jdbc:derby:target/database/derby/ode-test-db;create=false"/>
+ <property name="openjpa.ConnectionUserName" value="SA"/>
+ <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.DerbyDictionary"/>
+
+ <!-- Use this property to generate DDL at runtime
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+ -->
+
+
+ </properties>
+ </persistence-unit>
+</persistence>
+
Modified: ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java?rev=737256&r1=737255&r2=737256&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/BPELDAOConnectionImpl.java Fri Jan 23 23:53:17 2009
@@ -1,356 +1,356 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ode.dao.jpa;
-
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import javax.persistence.EntityManager;
-import javax.persistence.Query;
-import javax.xml.namespace.QName;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.ode.bpel.common.BpelEventFilter;
-import org.apache.ode.bpel.common.Filter;
-import org.apache.ode.bpel.common.InstanceFilter;
-import org.apache.ode.bpel.common.ProcessState;
-import org.apache.ode.bpel.dao.BpelDAOConnection;
-import org.apache.ode.bpel.dao.CorrelationSetDAO;
-import org.apache.ode.bpel.dao.MessageExchangeDAO;
-import org.apache.ode.bpel.dao.ProcessDAO;
-import org.apache.ode.bpel.dao.ProcessInstanceDAO;
-import org.apache.ode.bpel.dao.ProcessManagementDAO;
-import org.apache.ode.bpel.dao.ScopeDAO;
-import org.apache.ode.bpel.evt.BpelEvent;
-import org.apache.ode.bpel.evt.ScopeEvent;
-import org.apache.ode.utils.ISO8601DateParser;
-import org.apache.openjpa.persistence.OpenJPAPersistence;
-import org.apache.openjpa.persistence.OpenJPAQuery;
-
-/**
- * @author Matthieu Riou <mriou at apache dot org>
- */
-public class BPELDAOConnectionImpl implements BpelDAOConnection {
-
- static final Log __log = LogFactory.getLog(BPELDAOConnectionImpl.class);
-
- protected EntityManager _em;
-
- public BPELDAOConnectionImpl(EntityManager em) {
- _em = em;
- }
-
- public List<BpelEvent> bpelEventQuery(InstanceFilter ifilter,
- BpelEventFilter efilter) {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public List<Date> bpelEventTimelineQuery(InstanceFilter ifilter,
- BpelEventFilter efilter) {
- // TODO
- throw new UnsupportedOperationException();
- }
-
- public ProcessInstanceDAO getInstance(Long iid) {
- ProcessInstanceDAOImpl instance = _em.find(ProcessInstanceDAOImpl.class, iid);
- return instance;
- }
-
- public void close() {
- _em = null;
- }
-
- public MessageExchangeDAO createMessageExchange(char dir) {
- MessageExchangeDAOImpl ret = new MessageExchangeDAOImpl(dir);
- _em.persist(ret);
- return ret;
- }
-
- public ProcessDAO createProcess(QName pid, QName type, String guid, long version) {
- ProcessDAOImpl ret = new ProcessDAOImpl(pid,type,guid,version);
- _em.persist(ret);
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- public ProcessDAO getProcess(QName processId) {
- List l = _em.createQuery("select x from ProcessDAOImpl x where x._processId = ?1")
- .setParameter(1, processId.toString()).getResultList();
- if (l.size() == 0) return null;
- ProcessDAOImpl p = (ProcessDAOImpl) l.get(0);
- return p;
- }
-
- public ScopeDAO getScope(Long siidl) {
- return _em.find(ScopeDAOImpl.class, siidl);
- }
-
- public void insertBpelEvent(BpelEvent event, ProcessDAO process, ProcessInstanceDAO instance) {
- EventDAOImpl eventDao = new EventDAOImpl();
- eventDao.setTstamp(new Timestamp(System.currentTimeMillis()));
- eventDao.setType(BpelEvent.eventName(event));
- String evtStr = event.toString();
- eventDao.setDetail(evtStr.substring(0, Math.min(254, evtStr.length())));
- if (process != null)
- eventDao.setProcess((ProcessDAOImpl) process);
- if (instance != null)
- eventDao.setInstance((ProcessInstanceDAOImpl) instance);
- if (event instanceof ScopeEvent)
- eventDao.setScopeId(((ScopeEvent) event).getScopeId());
- eventDao.setEvent(event);
- _em.persist(eventDao);
- }
-
- private static String dateFilter(String filter) {
- String date = Filter.getDateWithoutOp(filter);
- String op = filter.substring(0,filter.indexOf(date));
- Date dt = null;
- try {
- dt = ISO8601DateParser.parse(date);
- } catch (ParseException e) {
- e.printStackTrace();
- }
- Timestamp ts = new Timestamp(dt.getTime());
- return op + " '" + ts.toString() + "'";
- }
-
- @SuppressWarnings("unchecked")
- public Collection<ProcessInstanceDAO> instanceQuery(InstanceFilter criteria) {
- StringBuffer query = new StringBuffer();
- query.append("select pi from ProcessInstanceDAOImpl as pi left join fetch pi._fault ");
-
- if (criteria != null) {
- // Building each clause
- ArrayList<String> clauses = new ArrayList<String>();
-
- // iid filter
- if ( criteria.getIidFilter() != null ) {
- StringBuffer filters = new StringBuffer();
- List<String> iids = criteria.getIidFilter();
- for (int m = 0; m < iids.size(); m++) {
- filters.append(" pi._instanceId = '").append(iids.get(m)).append("'");
- if (m < iids.size() - 1) filters.append(" or");
- }
- clauses.add(" (" + filters + ")");
- }
-
- // pid filter
- if (criteria.getPidFilter() != null) {
- StringBuffer filters = new StringBuffer();
- List<String> pids = criteria.getPidFilter();
- for (int m = 0; m < pids.size(); m++) {
- filters.append(" pi._process._processId = '").append(pids.get(m)).append("'");
- if (m < pids.size() - 1) filters.append(" or");
- }
- clauses.add(" (" + filters + ")");
- }
-
- // name filter
- if (criteria.getNameFilter() != null) {
- String val = criteria.getNameFilter();
- if (val.endsWith("*")) {
- val = val.substring(0, val.length()-1) + "%";
- }
- //process type string begins with name space
- //this could possibly match more than you want
- //because the name space and name are stored together
- clauses.add(" pi._process._processType like '%" + val + "'");
- }
-
- // name space filter
- if (criteria.getNamespaceFilter() != null) {
- //process type string begins with name space
- //this could possibly match more than you want
- //because the name space and name are stored together
- clauses.add(" pi._process._processType like '{" +
- criteria.getNamespaceFilter() + "%'");
- }
-
- // started filter
- if (criteria.getStartedDateFilter() != null) {
- for ( String ds : criteria.getStartedDateFilter() ) {
- clauses.add(" pi._dateCreated " + dateFilter(ds));
- }
- }
-
- // last-active filter
- if (criteria.getLastActiveDateFilter() != null) {
- for ( String ds : criteria.getLastActiveDateFilter() ) {
- clauses.add(" pi._lastActive " + dateFilter(ds));
- }
- }
-
- // status filter
- if (criteria.getStatusFilter() != null) {
- StringBuffer filters = new StringBuffer();
- List<Short> states = criteria.convertFilterState();
- for (int m = 0; m < states.size(); m++) {
- filters.append(" pi._state = ").append(states.get(m));
- if (m < states.size() - 1) filters.append(" or");
- }
- clauses.add(" (" + filters.toString() + ")");
- }
-
- // $property filter
- if (criteria.getPropertyValuesFilter() != null) {
- Map<String,String> props = criteria.getPropertyValuesFilter();
- // join to correlation sets
- query.append(" inner join pi._rootScope._correlationSets as cs");
- int i = 0;
- for (String propKey : props.keySet()) {
- i++;
- // join to props for each prop
- query.append(" inner join cs._props as csp"+i);
- // add clause for prop key and value
- clauses.add(" csp"+i+".propertyKey = '"+propKey+
- "' and csp"+i+".propertyValue = '"+
- // spaces have to be escaped, might be better handled in InstanceFilter
- props.get(propKey).replaceAll(" ", " ")+"'");
- }
- }
-
- // order by
- StringBuffer orderby = new StringBuffer("");
- if (criteria.getOrders() != null) {
- orderby.append(" order by");
- List<String> orders = criteria.getOrders();
- for (int m = 0; m < orders.size(); m++) {
- String field = orders.get(m);
- String ord = " asc";
- if (field.startsWith("-")) {
- ord = " desc";
- }
- String fieldName = " pi._instanceId";
- if ( field.endsWith("name") || field.endsWith("namespace")) {
- fieldName = " pi._process._processType";
- }
- if ( field.endsWith("version")) {
- fieldName = " pi._process._version";
- }
- if ( field.endsWith("status")) {
- fieldName = " pi._state";
- }
- if ( field.endsWith("started")) {
- fieldName = " pi._dateCreated";
- }
- if ( field.endsWith("last-active")) {
- fieldName = " pi._lastActive";
- }
- orderby.append(fieldName + ord);
- if (m < orders.size() - 1) orderby.append(", ");
- }
-
- }
-
- // Preparing the statement
- if (clauses.size() > 0) {
- query.append(" where");
- for (int m = 0; m < clauses.size(); m++) {
- query.append(clauses.get(m));
- if (m < clauses.size() - 1) query.append(" and");
- }
- }
-
- query.append(orderby);
- }
-
- if (__log.isDebugEnabled()) {
- __log.debug(query.toString());
- }
-
- // criteria limit
- Query pq = _em.createQuery(query.toString());
- OpenJPAQuery kq = OpenJPAPersistence.cast(pq);
- kq.getFetchPlan().setFetchBatchSize(criteria.getLimit());
- List<ProcessInstanceDAO> ql = pq.getResultList();
-
- Collection<ProcessInstanceDAO> list = new ArrayList<ProcessInstanceDAO>();
- int num = 0;
- for (Iterator iterator = ql.iterator(); iterator.hasNext();) {
- if(num++ > criteria.getLimit()) break;
- ProcessInstanceDAO processInstanceDAO = (ProcessInstanceDAO) iterator.next();
- list.add(processInstanceDAO);
- }
-
- return list;
- }
-
-
- public Collection<ProcessInstanceDAO> instanceQuery(String expression) {
- return instanceQuery(new InstanceFilter(expression));
- }
-
- public void setEntityManger(EntityManager em) {
- _em = em;
- }
-
- public MessageExchangeDAO getMessageExchange(String mexid) {
- return _em.find(MessageExchangeDAOImpl.class, mexid);
- }
-
- public void deleteMessageExchange(MessageExchangeDAO mexDao) {
- _em.remove(mexDao);
- }
-
- public EntityManager getEntityManager() {
- return _em;
- }
-
- @SuppressWarnings("unchecked")
- public Map<Long, Collection<CorrelationSetDAO>> getCorrelationSets(Collection<ProcessInstanceDAO> instances) {
- if (instances.size() == 0) {
- return new HashMap<Long, Collection<CorrelationSetDAO>>();
- }
- ArrayList<Long> iids = new ArrayList<Long>(instances.size());
- for (ProcessInstanceDAO dao: instances) {
- iids.add(dao.getInstanceId());
- }
- Collection<CorrelationSetDAOImpl> csets = _em.createNamedQuery(CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES).setParameter("instances", iids).getResultList();
- Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>();
- for (CorrelationSetDAOImpl cset: csets) {
- Long id = cset.getScope().getProcessInstance().getInstanceId();
- Collection<CorrelationSetDAO> existing = map.get(id);
- if (existing == null) {
- existing = new ArrayList<CorrelationSetDAO>();
- map.put(id, existing);
- }
- existing.add(cset);
- }
- return map;
- }
-
- public Collection<CorrelationSetDAO> getActiveCorrelationSets() {
- return _em.createNamedQuery(CorrelationSetDAOImpl.SELECT_ACTIVE_SETS).setParameter("state", ProcessState.STATE_ACTIVE).getResultList();
- }
-
-
- public ProcessManagementDAO getProcessManagement() {
- return new ProcessManagementDAOImpl(_em);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa;
+
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+import javax.persistence.Query;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.ode.bpel.common.BpelEventFilter;
+import org.apache.ode.bpel.common.Filter;
+import org.apache.ode.bpel.common.InstanceFilter;
+import org.apache.ode.bpel.common.ProcessState;
+import org.apache.ode.bpel.dao.BpelDAOConnection;
+import org.apache.ode.bpel.dao.CorrelationSetDAO;
+import org.apache.ode.bpel.dao.MessageExchangeDAO;
+import org.apache.ode.bpel.dao.ProcessDAO;
+import org.apache.ode.bpel.dao.ProcessInstanceDAO;
+import org.apache.ode.bpel.dao.ProcessManagementDAO;
+import org.apache.ode.bpel.dao.ScopeDAO;
+import org.apache.ode.bpel.evt.BpelEvent;
+import org.apache.ode.bpel.evt.ScopeEvent;
+import org.apache.ode.utils.ISO8601DateParser;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+
+/**
+ * @author Matthieu Riou <mriou at apache dot org>
+ */
+public class BPELDAOConnectionImpl implements BpelDAOConnection {
+
+ static final Log __log = LogFactory.getLog(BPELDAOConnectionImpl.class);
+
+ protected EntityManager _em;
+
+ public BPELDAOConnectionImpl(EntityManager em) {
+ _em = em;
+ }
+
+ public List<BpelEvent> bpelEventQuery(InstanceFilter ifilter,
+ BpelEventFilter efilter) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public List<Date> bpelEventTimelineQuery(InstanceFilter ifilter,
+ BpelEventFilter efilter) {
+ // TODO
+ throw new UnsupportedOperationException();
+ }
+
+ public ProcessInstanceDAO getInstance(Long iid) {
+ ProcessInstanceDAOImpl instance = _em.find(ProcessInstanceDAOImpl.class, iid);
+ return instance;
+ }
+
+ public void close() {
+ _em = null;
+ }
+
+ public MessageExchangeDAO createMessageExchange(char dir) {
+ MessageExchangeDAOImpl ret = new MessageExchangeDAOImpl(dir);
+ _em.persist(ret);
+ return ret;
+ }
+
+ public ProcessDAO createProcess(QName pid, QName type, String guid, long version) {
+ ProcessDAOImpl ret = new ProcessDAOImpl(pid,type,guid,version);
+ _em.persist(ret);
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ProcessDAO getProcess(QName processId) {
+ List l = _em.createQuery("select x from ProcessDAOImpl x where x._processId = ?1")
+ .setParameter(1, processId.toString()).getResultList();
+ if (l.size() == 0) return null;
+ ProcessDAOImpl p = (ProcessDAOImpl) l.get(0);
+ return p;
+ }
+
+ public ScopeDAO getScope(Long siidl) {
+ return _em.find(ScopeDAOImpl.class, siidl);
+ }
+
+ public void insertBpelEvent(BpelEvent event, ProcessDAO process, ProcessInstanceDAO instance) {
+ EventDAOImpl eventDao = new EventDAOImpl();
+ eventDao.setTstamp(new Timestamp(System.currentTimeMillis()));
+ eventDao.setType(BpelEvent.eventName(event));
+ String evtStr = event.toString();
+ eventDao.setDetail(evtStr.substring(0, Math.min(254, evtStr.length())));
+ if (process != null)
+ eventDao.setProcess((ProcessDAOImpl) process);
+ if (instance != null)
+ eventDao.setInstance((ProcessInstanceDAOImpl) instance);
+ if (event instanceof ScopeEvent)
+ eventDao.setScopeId(((ScopeEvent) event).getScopeId());
+ eventDao.setEvent(event);
+ _em.persist(eventDao);
+ }
+
+ private static String dateFilter(String filter) {
+ String date = Filter.getDateWithoutOp(filter);
+ String op = filter.substring(0,filter.indexOf(date));
+ Date dt = null;
+ try {
+ dt = ISO8601DateParser.parse(date);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ Timestamp ts = new Timestamp(dt.getTime());
+ return op + " '" + ts.toString() + "'";
+ }
+
+ @SuppressWarnings("unchecked")
+ public Collection<ProcessInstanceDAO> instanceQuery(InstanceFilter criteria) {
+ StringBuffer query = new StringBuffer();
+ query.append("select pi from ProcessInstanceDAOImpl as pi left join fetch pi._fault ");
+
+ if (criteria != null) {
+ // Building each clause
+ ArrayList<String> clauses = new ArrayList<String>();
+
+ // iid filter
+ if ( criteria.getIidFilter() != null ) {
+ StringBuffer filters = new StringBuffer();
+ List<String> iids = criteria.getIidFilter();
+ for (int m = 0; m < iids.size(); m++) {
+ filters.append(" pi._instanceId = '").append(iids.get(m)).append("'");
+ if (m < iids.size() - 1) filters.append(" or");
+ }
+ clauses.add(" (" + filters + ")");
+ }
+
+ // pid filter
+ if (criteria.getPidFilter() != null) {
+ StringBuffer filters = new StringBuffer();
+ List<String> pids = criteria.getPidFilter();
+ for (int m = 0; m < pids.size(); m++) {
+ filters.append(" pi._process._processId = '").append(pids.get(m)).append("'");
+ if (m < pids.size() - 1) filters.append(" or");
+ }
+ clauses.add(" (" + filters + ")");
+ }
+
+ // name filter
+ if (criteria.getNameFilter() != null) {
+ String val = criteria.getNameFilter();
+ if (val.endsWith("*")) {
+ val = val.substring(0, val.length()-1) + "%";
+ }
+ //process type string begins with name space
+ //this could possibly match more than you want
+ //because the name space and name are stored together
+ clauses.add(" pi._process._processType like '%" + val + "'");
+ }
+
+ // name space filter
+ if (criteria.getNamespaceFilter() != null) {
+ //process type string begins with name space
+ //this could possibly match more than you want
+ //because the name space and name are stored together
+ clauses.add(" pi._process._processType like '{" +
+ criteria.getNamespaceFilter() + "%'");
+ }
+
+ // started filter
+ if (criteria.getStartedDateFilter() != null) {
+ for ( String ds : criteria.getStartedDateFilter() ) {
+ clauses.add(" pi._dateCreated " + dateFilter(ds));
+ }
+ }
+
+ // last-active filter
+ if (criteria.getLastActiveDateFilter() != null) {
+ for ( String ds : criteria.getLastActiveDateFilter() ) {
+ clauses.add(" pi._lastActive " + dateFilter(ds));
+ }
+ }
+
+ // status filter
+ if (criteria.getStatusFilter() != null) {
+ StringBuffer filters = new StringBuffer();
+ List<Short> states = criteria.convertFilterState();
+ for (int m = 0; m < states.size(); m++) {
+ filters.append(" pi._state = ").append(states.get(m));
+ if (m < states.size() - 1) filters.append(" or");
+ }
+ clauses.add(" (" + filters.toString() + ")");
+ }
+
+ // $property filter
+ if (criteria.getPropertyValuesFilter() != null) {
+ Map<String,String> props = criteria.getPropertyValuesFilter();
+ // join to correlation sets
+ query.append(" inner join pi._rootScope._correlationSets as cs");
+ int i = 0;
+ for (String propKey : props.keySet()) {
+ i++;
+ // join to props for each prop
+ query.append(" inner join cs._props as csp"+i);
+ // add clause for prop key and value
+ clauses.add(" csp"+i+".propertyKey = '"+propKey+
+ "' and csp"+i+".propertyValue = '"+
+ // spaces have to be escaped, might be better handled in InstanceFilter
+ props.get(propKey).replaceAll(" ", " ")+"'");
+ }
+ }
+
+ // order by
+ StringBuffer orderby = new StringBuffer("");
+ if (criteria.getOrders() != null) {
+ orderby.append(" order by");
+ List<String> orders = criteria.getOrders();
+ for (int m = 0; m < orders.size(); m++) {
+ String field = orders.get(m);
+ String ord = " asc";
+ if (field.startsWith("-")) {
+ ord = " desc";
+ }
+ String fieldName = " pi._instanceId";
+ if ( field.endsWith("name") || field.endsWith("namespace")) {
+ fieldName = " pi._process._processType";
+ }
+ if ( field.endsWith("version")) {
+ fieldName = " pi._process._version";
+ }
+ if ( field.endsWith("status")) {
+ fieldName = " pi._state";
+ }
+ if ( field.endsWith("started")) {
+ fieldName = " pi._dateCreated";
+ }
+ if ( field.endsWith("last-active")) {
+ fieldName = " pi._lastActive";
+ }
+ orderby.append(fieldName + ord);
+ if (m < orders.size() - 1) orderby.append(", ");
+ }
+
+ }
+
+ // Preparing the statement
+ if (clauses.size() > 0) {
+ query.append(" where");
+ for (int m = 0; m < clauses.size(); m++) {
+ query.append(clauses.get(m));
+ if (m < clauses.size() - 1) query.append(" and");
+ }
+ }
+
+ query.append(orderby);
+ }
+
+ if (__log.isDebugEnabled()) {
+ __log.debug(query.toString());
+ }
+
+ // criteria limit
+ Query pq = _em.createQuery(query.toString());
+ OpenJPAQuery kq = OpenJPAPersistence.cast(pq);
+ kq.getFetchPlan().setFetchBatchSize(criteria.getLimit());
+ List<ProcessInstanceDAO> ql = pq.getResultList();
+
+ Collection<ProcessInstanceDAO> list = new ArrayList<ProcessInstanceDAO>();
+ int num = 0;
+ for (Iterator iterator = ql.iterator(); iterator.hasNext();) {
+ if(num++ > criteria.getLimit()) break;
+ ProcessInstanceDAO processInstanceDAO = (ProcessInstanceDAO) iterator.next();
+ list.add(processInstanceDAO);
+ }
+
+ return list;
+ }
+
+
+ public Collection<ProcessInstanceDAO> instanceQuery(String expression) {
+ return instanceQuery(new InstanceFilter(expression));
+ }
+
+ public void setEntityManger(EntityManager em) {
+ _em = em;
+ }
+
+ public MessageExchangeDAO getMessageExchange(String mexid) {
+ return _em.find(MessageExchangeDAOImpl.class, mexid);
+ }
+
+ public void deleteMessageExchange(MessageExchangeDAO mexDao) {
+ _em.remove(mexDao);
+ }
+
+ public EntityManager getEntityManager() {
+ return _em;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<Long, Collection<CorrelationSetDAO>> getCorrelationSets(Collection<ProcessInstanceDAO> instances) {
+ if (instances.size() == 0) {
+ return new HashMap<Long, Collection<CorrelationSetDAO>>();
+ }
+ ArrayList<Long> iids = new ArrayList<Long>(instances.size());
+ for (ProcessInstanceDAO dao: instances) {
+ iids.add(dao.getInstanceId());
+ }
+ Collection<CorrelationSetDAOImpl> csets = _em.createNamedQuery(CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES).setParameter("instances", iids).getResultList();
+ Map<Long, Collection<CorrelationSetDAO>> map = new HashMap<Long, Collection<CorrelationSetDAO>>();
+ for (CorrelationSetDAOImpl cset: csets) {
+ Long id = cset.getScope().getProcessInstance().getInstanceId();
+ Collection<CorrelationSetDAO> existing = map.get(id);
+ if (existing == null) {
+ existing = new ArrayList<CorrelationSetDAO>();
+ map.put(id, existing);
+ }
+ existing.add(cset);
+ }
+ return map;
+ }
+
+ public Collection<CorrelationSetDAO> getActiveCorrelationSets() {
+ return _em.createNamedQuery(CorrelationSetDAOImpl.SELECT_ACTIVE_SETS).setParameter("state", ProcessState.STATE_ACTIVE).getResultList();
+ }
+
+
+ public ProcessManagementDAO getProcessManagement() {
+ return new ProcessManagementDAOImpl(_em);
+ }
+}
Modified: ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelationSetDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelationSetDAOImpl.java?rev=737256&r1=737255&r2=737256&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelationSetDAOImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelationSetDAOImpl.java Fri Jan 23 23:53:17 2009
@@ -1,123 +1,123 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ode.dao.jpa;
-
-import org.apache.ode.bpel.common.CorrelationKey;
-import org.apache.ode.bpel.dao.CorrelationSetDAO;
-import org.apache.ode.bpel.dao.ScopeDAO;
-import org.apache.ode.bpel.dao.ProcessDAO;
-import org.apache.ode.bpel.dao.ProcessInstanceDAO;
-
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.GenerationType;
-import javax.persistence.Id;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToMany;
-import javax.persistence.Table;
-import javax.xml.namespace.QName;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-@Entity
-@Table(name="ODE_CORRELATION_SET")
-@NamedQueries({
- @NamedQuery(name=CorrelationSetDAOImpl.DELETE_CORRELATION_SETS_BY_IDS, query="delete from CorrelationSetDAOImpl as c where c._correlationSetId in (:ids)"),
- @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope left join fetch c._props where c._scope._processInstance._instanceId in (:instances)"),
- @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_PROCESS, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance._process = :process"),
- @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_INSTANCE, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance = :instance"),
- @NamedQuery(name=CorrelationSetDAOImpl.SELECT_ACTIVE_SETS, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope where c._scope._processInstance._state = (:state)")
-})
-public class CorrelationSetDAOImpl implements CorrelationSetDAO {
- public final static String DELETE_CORRELATION_SETS_BY_IDS = "DELETE_CORRELATION_SETS_BY_IDS";
- public final static String SELECT_CORRELATION_SETS_BY_INSTANCES = "SELECT_CORRELATION_SETS_BY_INSTANCES";
- public final static String SELECT_CORRELATION_SET_IDS_BY_PROCESS = "SELECT_CORRELATION_SET_IDS_BY_PROCESS";
- public final static String SELECT_CORRELATION_SET_IDS_BY_INSTANCE = "SELECT_CORRELATION_SET_IDS_BY_INSTANCE";
- public final static String SELECT_ACTIVE_SETS = "SELECT_ACTIVE_SETS";
-
- @Id @Column(name="CORRELATION_SET_ID")
- @GeneratedValue(strategy=GenerationType.AUTO)
- private Long _correlationSetId;
- @Basic @Column(name="NAME")
- private String _name;
- @Basic @Column(name="CORRELATION_KEY")
- private String _correlationKey;
-
- @OneToMany(targetEntity=CorrSetProperty.class,mappedBy="_corrSet",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
- private Collection<CorrSetProperty> _props = new ArrayList<CorrSetProperty>();
- @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @Column(name="SCOPE_ID")
- private ScopeDAOImpl _scope;
-
- public CorrelationSetDAOImpl() {}
- public CorrelationSetDAOImpl(ScopeDAOImpl scope, String name) {
- _name = name;
- _scope = scope;
- }
-
- public Long getCorrelationSetId() {
- return _correlationSetId;
- }
-
- public String getName() {
- return _name;
- }
-
- public Map<QName, String> getProperties() {
- HashMap<QName, String> map = new HashMap<QName, String>();
- for (CorrSetProperty prop : _props) {
- map.put(QName.valueOf(prop.getPropertyKey()), prop.getPropertyValue());
- }
- return map;
- }
-
- public ScopeDAO getScope() {
- return _scope;
- }
-
- public CorrelationKey getValue() {
- if (_correlationKey == null) return null;
- return new CorrelationKey(_correlationKey);
- }
-
- public void setValue(QName[] names, CorrelationKey values) {
- _correlationKey = values.toCanonicalString();
- if (names != null)
- for (int m = 0; m < names.length; m++) {
- CorrSetProperty prop = new CorrSetProperty(names[m].toString(), values.getValues()[m]);
- _props.add(prop);
- prop.setCorrSet(this);
- }
- }
-
- public ProcessDAO getProcess() {
- return _scope.getProcessInstance().getProcess();
- }
- public ProcessInstanceDAO getInstance() {
- return _scope.getProcessInstance();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa;
+
+import org.apache.ode.bpel.common.CorrelationKey;
+import org.apache.ode.bpel.dao.CorrelationSetDAO;
+import org.apache.ode.bpel.dao.ScopeDAO;
+import org.apache.ode.bpel.dao.ProcessDAO;
+import org.apache.ode.bpel.dao.ProcessInstanceDAO;
+
+import javax.persistence.Basic;
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.ManyToOne;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+@Entity
+@Table(name="ODE_CORRELATION_SET")
+@NamedQueries({
+ @NamedQuery(name=CorrelationSetDAOImpl.DELETE_CORRELATION_SETS_BY_IDS, query="delete from CorrelationSetDAOImpl as c where c._correlationSetId in (:ids)"),
+ @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SETS_BY_INSTANCES, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope left join fetch c._props where c._scope._processInstance._instanceId in (:instances)"),
+ @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_PROCESS, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance._process = :process"),
+ @NamedQuery(name=CorrelationSetDAOImpl.SELECT_CORRELATION_SET_IDS_BY_INSTANCE, query="select c._correlationSetId from CorrelationSetDAOImpl as c where c._scope._processInstance = :instance"),
+ @NamedQuery(name=CorrelationSetDAOImpl.SELECT_ACTIVE_SETS, query="select c from CorrelationSetDAOImpl as c left join fetch c._scope where c._scope._processInstance._state = (:state)")
+})
+public class CorrelationSetDAOImpl implements CorrelationSetDAO {
+ public final static String DELETE_CORRELATION_SETS_BY_IDS = "DELETE_CORRELATION_SETS_BY_IDS";
+ public final static String SELECT_CORRELATION_SETS_BY_INSTANCES = "SELECT_CORRELATION_SETS_BY_INSTANCES";
+ public final static String SELECT_CORRELATION_SET_IDS_BY_PROCESS = "SELECT_CORRELATION_SET_IDS_BY_PROCESS";
+ public final static String SELECT_CORRELATION_SET_IDS_BY_INSTANCE = "SELECT_CORRELATION_SET_IDS_BY_INSTANCE";
+ public final static String SELECT_ACTIVE_SETS = "SELECT_ACTIVE_SETS";
+
+ @Id @Column(name="CORRELATION_SET_ID")
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ private Long _correlationSetId;
+ @Basic @Column(name="NAME")
+ private String _name;
+ @Basic @Column(name="CORRELATION_KEY")
+ private String _correlationKey;
+
+ @OneToMany(targetEntity=CorrSetProperty.class,mappedBy="_corrSet",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+ private Collection<CorrSetProperty> _props = new ArrayList<CorrSetProperty>();
+ @ManyToOne(fetch=FetchType.LAZY,cascade={CascadeType.PERSIST}) @Column(name="SCOPE_ID")
+ private ScopeDAOImpl _scope;
+
+ public CorrelationSetDAOImpl() {}
+ public CorrelationSetDAOImpl(ScopeDAOImpl scope, String name) {
+ _name = name;
+ _scope = scope;
+ }
+
+ public Long getCorrelationSetId() {
+ return _correlationSetId;
+ }
+
+ public String getName() {
+ return _name;
+ }
+
+ public Map<QName, String> getProperties() {
+ HashMap<QName, String> map = new HashMap<QName, String>();
+ for (CorrSetProperty prop : _props) {
+ map.put(QName.valueOf(prop.getPropertyKey()), prop.getPropertyValue());
+ }
+ return map;
+ }
+
+ public ScopeDAO getScope() {
+ return _scope;
+ }
+
+ public CorrelationKey getValue() {
+ if (_correlationKey == null) return null;
+ return new CorrelationKey(_correlationKey);
+ }
+
+ public void setValue(QName[] names, CorrelationKey values) {
+ _correlationKey = values.toCanonicalString();
+ if (names != null)
+ for (int m = 0; m < names.length; m++) {
+ CorrSetProperty prop = new CorrSetProperty(names[m].toString(), values.getValues()[m]);
+ _props.add(prop);
+ prop.setCorrSet(this);
+ }
+ }
+
+ public ProcessDAO getProcess() {
+ return _scope.getProcessInstance().getProcess();
+ }
+ public ProcessInstanceDAO getInstance() {
+ return _scope.getProcessInstance();
+ }
+}
Modified: ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelatorDAOImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelatorDAOImpl.java?rev=737256&r1=737255&r2=737256&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelatorDAOImpl.java (original)
+++ ode/branches/APACHE_ODE_1.X/dao-jpa/src/main/java/org/apache/ode/dao/jpa/CorrelatorDAOImpl.java Fri Jan 23 23:53:17 2009
@@ -1,162 +1,162 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.ode.dao.jpa;
-
-import org.apache.ode.bpel.common.CorrelationKeySet;
-import org.apache.ode.bpel.dao.*;
-
-import javax.persistence.*;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-@Entity
-@Table(name="ODE_CORRELATOR")
-@NamedQueries({
- @NamedQuery(name=CorrelatorDAOImpl.DELETE_CORRELATORS_BY_PROCESS, query="delete from CorrelatorDAOImpl as c where c._process = :process")
-})
-public class CorrelatorDAOImpl extends OpenJPADAO implements CorrelatorDAO {
- public final static String DELETE_CORRELATORS_BY_PROCESS = "DELETE_CORRELATORS_BY_PROCESS";
- private final static String ROUTE_BY_CKEY_HEADER = "select route from MessageRouteDAOImpl as route where route._correlator._process._processType = :ptype and route._correlator._correlatorKey = :corrkey";
-
- @Id @Column(name="CORRELATOR_ID")
- @GeneratedValue(strategy=GenerationType.AUTO)
- @SuppressWarnings("unused")
- private Long _correlatorId;
- @Basic @Column(name="CORRELATOR_KEY")
- private String _correlatorKey;
- @OneToMany(targetEntity=MessageRouteDAOImpl.class,mappedBy="_correlator",fetch=FetchType.EAGER,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
- private Collection<MessageRouteDAOImpl> _routes = new ArrayList<MessageRouteDAOImpl>();
- @OneToMany(targetEntity=MessageExchangeDAOImpl.class,mappedBy="_correlator",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
- private Collection<MessageExchangeDAOImpl> _exchanges = new ArrayList<MessageExchangeDAOImpl>();
- @ManyToOne(fetch= FetchType.LAZY,cascade={CascadeType.PERSIST}) @Column(name="PROC_ID")
- private ProcessDAOImpl _process;
-
- public CorrelatorDAOImpl(){}
- public CorrelatorDAOImpl(String correlatorKey, ProcessDAOImpl process) {
- _correlatorKey = correlatorKey;
- _process = process;
- }
-
- public void addRoute(String routeGroupId, ProcessInstanceDAO target, int index, CorrelationKeySet correlationKeySet, String routePolicy) {
- MessageRouteDAOImpl mr = new MessageRouteDAOImpl(correlationKeySet,
- routeGroupId, index, (ProcessInstanceDAOImpl) target, this, routePolicy);
- _routes.add(mr);
- }
-
- public MessageExchangeDAO dequeueMessage(CorrelationKeySet correlationKeySet) {
- // TODO: this thing does not seem to be scalable: loading up based on a correlator???
- for (Iterator<MessageExchangeDAOImpl> itr=_exchanges.iterator(); itr.hasNext();){
- MessageExchangeDAOImpl mex = itr.next();
- if (mex.getCorrelationKeySet().isRoutableTo(correlationKeySet, false)) {
- itr.remove();
- return mex;
- }
- }
- return null;
- }
-
- public void enqueueMessage(MessageExchangeDAO mex,
- CorrelationKeySet correlationKeySet) {
- MessageExchangeDAOImpl mexImpl = (MessageExchangeDAOImpl) mex;
- mexImpl.setCorrelationKeySet(correlationKeySet);
- _exchanges.add(mexImpl);
- mexImpl.setCorrelator(this);
- }
-
- public Collection<CorrelatorMessageDAO> getAllMessages() {
- return new ArrayList<CorrelatorMessageDAO>(_exchanges);
- }
-
- @SuppressWarnings("unchecked")
- public List<MessageRouteDAO> findRoute(CorrelationKeySet correlationKeySet) {
- List<CorrelationKeySet> subSets = correlationKeySet.findSubSets();
- Query qry = getEM().createQuery(generateSelectorQuery(ROUTE_BY_CKEY_HEADER, subSets));
- qry.setParameter("ptype", _process.getType().toString());
- qry.setParameter("corrkey", _correlatorKey);
- for( int i = 0; i < subSets.size(); i++ ) {
- qry.setParameter("s" + i, subSets.get(i).toCanonicalString());
- }
-
- List<MessageRouteDAO> routes = (List<MessageRouteDAO>) qry.getResultList();
- if (routes.size() > 0) {
- List<ProcessInstanceDAO> targets = new ArrayList<ProcessInstanceDAO>();
- for (int i = 0; i < routes.size(); i++) {
- MessageRouteDAO route = routes.get(i);
- if ("all".equals(route.getRoute()) ||
- ("one".equals(route.getRoute()) && !targets.contains(route.getTargetInstance()))) {
- targets.add(route.getTargetInstance());
- } else {
- routes.remove(i);
- }
- }
- return routes;
- } else {
- return null;
- }
- }
-
- private String generateSelectorQuery(String header, List<CorrelationKeySet> subSets) {
- StringBuffer filterQuery = new StringBuffer(header);
-
- if( subSets.size() == 1 ) {
- filterQuery.append(" and route._correlationKey = :s0");
- } else if( subSets.size() > 1 ) {
- filterQuery.append(" and route._correlationKey in(");
- for( int i = 0; i < subSets.size(); i++ ) {
- if( i > 0 ) {
- filterQuery.append(", ");
- }
- filterQuery.append(":s").append(i);
- }
- filterQuery.append(")");
- }
-
- return filterQuery.toString();
- }
-
- public String getCorrelatorId() {
- return _correlatorKey;
- }
-
- public void setCorrelatorId(String newId) {
- _correlatorKey = newId;
- }
-
- public void removeRoutes(String routeGroupId, ProcessInstanceDAO target) {
- // remove route across all correlators of the process
- ((ProcessInstanceDAOImpl)target).removeRoutes(routeGroupId);
- }
-
- void removeLocalRoutes(String routeGroupId, ProcessInstanceDAO target) {
- for (Iterator<MessageRouteDAOImpl> itr=_routes.iterator(); itr.hasNext(); ) {
- MessageRouteDAOImpl mr = itr.next();
- if ( mr.getGroupId().equals(routeGroupId) && mr.getTargetInstance().equals(target)) {
- itr.remove();
- getEM().remove(mr);
- }
- }
- }
-
- public Collection<MessageRouteDAO> getAllRoutes() {
- return new ArrayList<MessageRouteDAO>(_routes);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ode.dao.jpa;
+
+import org.apache.ode.bpel.common.CorrelationKeySet;
+import org.apache.ode.bpel.dao.*;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+@Entity
+@Table(name="ODE_CORRELATOR")
+@NamedQueries({
+ @NamedQuery(name=CorrelatorDAOImpl.DELETE_CORRELATORS_BY_PROCESS, query="delete from CorrelatorDAOImpl as c where c._process = :process")
+})
+public class CorrelatorDAOImpl extends OpenJPADAO implements CorrelatorDAO {
+ public final static String DELETE_CORRELATORS_BY_PROCESS = "DELETE_CORRELATORS_BY_PROCESS";
+ private final static String ROUTE_BY_CKEY_HEADER = "select route from MessageRouteDAOImpl as route where route._correlator._process._processType = :ptype and route._correlator._correlatorKey = :corrkey";
+
+ @Id @Column(name="CORRELATOR_ID")
+ @GeneratedValue(strategy=GenerationType.AUTO)
+ @SuppressWarnings("unused")
+ private Long _correlatorId;
+ @Basic @Column(name="CORRELATOR_KEY")
+ private String _correlatorKey;
+ @OneToMany(targetEntity=MessageRouteDAOImpl.class,mappedBy="_correlator",fetch=FetchType.EAGER,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+ private Collection<MessageRouteDAOImpl> _routes = new ArrayList<MessageRouteDAOImpl>();
+ @OneToMany(targetEntity=MessageExchangeDAOImpl.class,mappedBy="_correlator",fetch=FetchType.LAZY,cascade={CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH})
+ private Collection<MessageExchangeDAOImpl> _exchanges = new ArrayList<MessageExchangeDAOImpl>();
+ @ManyToOne(fetch= FetchType.LAZY,cascade={CascadeType.PERSIST}) @Column(name="PROC_ID")
+ private ProcessDAOImpl _process;
+
+ public CorrelatorDAOImpl(){}
+ public CorrelatorDAOImpl(String correlatorKey, ProcessDAOImpl process) {
+ _correlatorKey = correlatorKey;
+ _process = process;
+ }
+
+ public void addRoute(String routeGroupId, ProcessInstanceDAO target, int index, CorrelationKeySet correlationKeySet, String routePolicy) {
+ MessageRouteDAOImpl mr = new MessageRouteDAOImpl(correlationKeySet,
+ routeGroupId, index, (ProcessInstanceDAOImpl) target, this, routePolicy);
+ _routes.add(mr);
+ }
+
+ public MessageExchangeDAO dequeueMessage(CorrelationKeySet correlationKeySet) {
+ // TODO: this thing does not seem to be scalable: loading up based on a correlator???
+ for (Iterator<MessageExchangeDAOImpl> itr=_exchanges.iterator(); itr.hasNext();){
+ MessageExchangeDAOImpl mex = itr.next();
+ if (mex.getCorrelationKeySet().isRoutableTo(correlationKeySet, false)) {
+ itr.remove();
+ return mex;
+ }
+ }
+ return null;
+ }
+
+ public void enqueueMessage(MessageExchangeDAO mex,
+ CorrelationKeySet correlationKeySet) {
+ MessageExchangeDAOImpl mexImpl = (MessageExchangeDAOImpl) mex;
+ mexImpl.setCorrelationKeySet(correlationKeySet);
+ _exchanges.add(mexImpl);
+ mexImpl.setCorrelator(this);
+ }
+
+ public Collection<CorrelatorMessageDAO> getAllMessages() {
+ return new ArrayList<CorrelatorMessageDAO>(_exchanges);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<MessageRouteDAO> findRoute(CorrelationKeySet correlationKeySet) {
+ List<CorrelationKeySet> subSets = correlationKeySet.findSubSets();
+ Query qry = getEM().createQuery(generateSelectorQuery(ROUTE_BY_CKEY_HEADER, subSets));
+ qry.setParameter("ptype", _process.getType().toString());
+ qry.setParameter("corrkey", _correlatorKey);
+ for( int i = 0; i < subSets.size(); i++ ) {
+ qry.setParameter("s" + i, subSets.get(i).toCanonicalString());
+ }
+
+ List<MessageRouteDAO> routes = (List<MessageRouteDAO>) qry.getResultList();
+ if (routes.size() > 0) {
+ List<ProcessInstanceDAO> targets = new ArrayList<ProcessInstanceDAO>();
+ for (int i = 0; i < routes.size(); i++) {
+ MessageRouteDAO route = routes.get(i);
+ if ("all".equals(route.getRoute()) ||
+ ("one".equals(route.getRoute()) && !targets.contains(route.getTargetInstance()))) {
+ targets.add(route.getTargetInstance());
+ } else {
+ routes.remove(i);
+ }
+ }
+ return routes;
+ } else {
+ return null;
+ }
+ }
+
+ private String generateSelectorQuery(String header, List<CorrelationKeySet> subSets) {
+ StringBuffer filterQuery = new StringBuffer(header);
+
+ if( subSets.size() == 1 ) {
+ filterQuery.append(" and route._correlationKey = :s0");
+ } else if( subSets.size() > 1 ) {
+ filterQuery.append(" and route._correlationKey in(");
+ for( int i = 0; i < subSets.size(); i++ ) {
+ if( i > 0 ) {
+ filterQuery.append(", ");
+ }
+ filterQuery.append(":s").append(i);
+ }
+ filterQuery.append(")");
+ }
+
+ return filterQuery.toString();
+ }
+
+ public String getCorrelatorId() {
+ return _correlatorKey;
+ }
+
+ public void setCorrelatorId(String newId) {
+ _correlatorKey = newId;
+ }
+
+ public void removeRoutes(String routeGroupId, ProcessInstanceDAO target) {
+ // remove route across all correlators of the process
+ ((ProcessInstanceDAOImpl)target).removeRoutes(routeGroupId);
+ }
+
+ void removeLocalRoutes(String routeGroupId, ProcessInstanceDAO target) {
+ for (Iterator<MessageRouteDAOImpl> itr=_routes.iterator(); itr.hasNext(); ) {
+ MessageRouteDAOImpl mr = itr.next();
+ if ( mr.getGroupId().equals(routeGroupId) && mr.getTargetInstance().equals(target)) {
+ itr.remove();
+ getEM().remove(mr);
+ }
+ }
+ }
+
+ public Collection<MessageRouteDAO> getAllRoutes() {
+ return new ArrayList<MessageRouteDAO>(_routes);
+ }
+}