Author: hthomann
Date: Fri Jun 1 16:02:31 2012
New Revision: 1345263
URL: http://svn.apache.org/viewvc?rev=1345263&view=rev
Log:
OPENJPA-2095: Applied Helen Xu's patch to trunk with Albert's test case changes.
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java
(with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java?rev=1345263&r1=1345262&r2=1345263&view=diff
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/AbstractUpdateManager.java
Fri Jun 1 16:02:31 2012
@@ -34,6 +34,8 @@ import org.apache.openjpa.jdbc.meta.Fiel
import org.apache.openjpa.jdbc.meta.Strategy;
import org.apache.openjpa.jdbc.meta.Version;
import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.jdbc.sql.Row;
+import org.apache.openjpa.jdbc.sql.RowImpl;
import org.apache.openjpa.jdbc.sql.RowManager;
import org.apache.openjpa.jdbc.sql.SQLExceptions;
import org.apache.openjpa.kernel.OpenJPAStateManager;
@@ -156,14 +158,17 @@ public abstract class AbstractUpdateMana
protected Collection populateRowManager(OpenJPAStateManager sm,
RowManager rowMgr, JDBCStore store, Collection exceps,
Collection customs) {
+ int action = Row.ACTION_UPDATE;
try {
BitSet dirty;
if (sm.getPCState() == PCState.PNEW && !sm.isFlushed()) {
- insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
+ action = Row.ACTION_INSERT;
+ insert(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
customs);
} else if (sm.getPCState() == PCState.PNEWFLUSHEDDELETED
|| sm.getPCState() == PCState.PDELETED) {
- delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
+ action = Row.ACTION_DELETE;
+ delete(sm, (ClassMapping) sm.getMetaData(), rowMgr, store,
customs);
} else if ((dirty = ImplHelper.getUpdateFields(sm)) != null) {
update(sm, dirty, (ClassMapping) sm.getMetaData(), rowMgr,
@@ -180,6 +185,10 @@ public abstract class AbstractUpdateMana
} catch (SQLException se) {
exceps = addException(exceps, SQLExceptions.getStore(se, dict));
} catch (OpenJPAException ke) {
+ RowImpl row = (RowImpl) rowMgr.getRow(((ClassMapping)
sm.getMetaData()).getTable(), action, sm, false);
+ if (row != null) {
+ row.setFlushed(true);
+ }
exceps = addException(exceps, ke);
}
return exceps;
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java?rev=1345263&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java
Fri Jun 1 16:02:31 2012
@@ -0,0 +1,119 @@
+/*
+ * 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.openjpa.persistence.jdbc.common.apps;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.PersistenceException;
+
+@Entity
+public class EntityWithFailedExternalizer implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ @Id
+ private int iref;
+
+ private String name;
+
+ private String data;
+
+ @org.apache.openjpa.persistence.Persistent
+ @org.apache.openjpa.persistence.Externalizer("check")
+ private TestExternal ext;
+
+ public static class TestExternal
+ {
+ private static final long serialVersionUID = 1L;
+ public boolean throwEx=false;
+
+ private String value = "test - TE";
+
+ public TestExternal() {
+ super();
+ }
+
+ public TestExternal(String s) {
+ value = s;
+ }
+
+ public String check() throws Exception {
+ if (throwEx){
+ throw new PersistenceException("test exception externalizer");
+ }
+ return value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void getValue(String s) {
+ value = s;
+ }
+ }
+
+ public EntityWithFailedExternalizer() {
+ super();
+ }
+
+ public EntityWithFailedExternalizer(int iref, String name, String data) {
+ super();
+ this.iref = iref;
+ this.name = name;
+ this.data = data;
+ this.ext = new TestExternal();
+ }
+
+ public int getIref() {
+ return this.iref;
+ }
+
+ public void setIref(int iref) {
+ this.iref = iref;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getData() {
+ return this.data;
+ }
+
+ public void setData(String data) {
+ this.data = data;
+ }
+
+ public void setExt(TestExternal te){
+ this.ext = te;
+ return;
+ }
+
+ public TestExternal getExt(){
+ return this.ext;
+ }
+}
+
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/common/apps/EntityWithFailedExternalizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java?rev=1345263&view=auto
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java
Fri Jun 1 16:02:31 2012
@@ -0,0 +1,71 @@
+/*
+ * 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.openjpa.persistence.jdbc.kernel;
+
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityTransaction;
+
+import org.apache.openjpa.persistence.PersistenceException;
+import org.apache.openjpa.persistence.RollbackException;
+import
org.apache.openjpa.persistence.jdbc.common.apps.EntityWithFailedExternalizer;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+/*
+ * when there is a metadata exception during the flushing for a batch job, the
AbstractUpdateManager
+ * should capture the exception and skip the flushing of the failed object.
+ */
+public class TestBatchFlushWithMetadataException extends SQLListenerTestCase {
+
+ @Override
+ public void setUp() throws Exception {
+ setUp(DROP_TABLES, EntityWithFailedExternalizer.class);
+ }
+
+ public void testCreate(){
+ EntityManager em = emf.createEntityManager();
+ EntityTransaction tx = em.getTransaction();
+
+ tx.begin();
+ EntityWithFailedExternalizer item1 = new
EntityWithFailedExternalizer(1001, "MyName1", "description1");
+ EntityWithFailedExternalizer item2 = new
EntityWithFailedExternalizer(1002, "MyName2", "description2");
+ item1.getExt().throwEx=true;
+ EntityWithFailedExternalizer item3 = new
EntityWithFailedExternalizer(1003, "MyName3", "description3");
+
+ em.persist(item1);
+ em.persist(item2);
+ em.persist(item3);
+ commitAndValidate(tx);
+ em.close();
+ }
+
+ private void commitAndValidate(EntityTransaction tx){
+ try {
+ resetSQL();
+ tx.commit();
+ fail("RollbackException should have been thrown from the
externalizer");
+ }catch (RollbackException rollBackException) {
+ Throwable[] throwables = rollBackException.getNestedThrowables();
+ assertTrue(throwables[0] instanceof PersistenceException);
+ PersistenceException persistentException = (PersistenceException)
throwables[0];
+ assertNotNull(persistentException);
+ assertEquals(1, persistentException.getNestedThrowables().length);
+ }
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/kernel/TestBatchFlushWithMetadataException.java
------------------------------------------------------------------------------
svn:eol-style = native