001: /*
002: * TestOpenResultsCommit.java
003: *
004: * Created on October 12, 2006, 2:43 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009: /*
010: * Licensed to the Apache Software Foundation (ASF) under one
011: * or more contributor license agreements. See the NOTICE file
012: * distributed with this work for additional information
013: * regarding copyright ownership. The ASF licenses this file
014: * to you under the Apache License, Version 2.0 (the
015: * "License"); you may not use this file except in compliance
016: * with the License. You may obtain a copy of the License at
017: *
018: * http://www.apache.org/licenses/LICENSE-2.0
019: *
020: * Unless required by applicable law or agreed to in writing,
021: * software distributed under the License is distributed on an
022: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
023: * KIND, either express or implied. See the License for the
024: * specific language governing permissions and limitations
025: * under the License.
026: */
027: package org.apache.openjpa.persistence.kernel;
028:
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.Map;
032: import java.util.EnumSet;
033:
034: import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
035: import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
036:
037: import org.apache.openjpa.persistence.OpenJPAEntityManager;
038: import org.apache.openjpa.persistence.OpenJPAEntityManagerFactory;
039:
040: public class TestOpenResultsCommit extends BaseKernelTest {
041:
042: /**
043: * Creates a new instance of TestOpenResultsCommit
044: */
045: public TestOpenResultsCommit() {
046: }
047:
048: public TestOpenResultsCommit(String testName) {
049: super (testName);
050: }
051:
052: public void setUp() throws Exception {
053: super .setUp();
054:
055: deleteAll(RuntimeTest1.class);
056:
057: OpenJPAEntityManager pm = getPM();
058: startTx(pm);
059: for (int i = 0; i < 50; i++)
060: pm.persist(new RuntimeTest1("open results #" + i, i));
061: endTx(pm);
062: endEm(pm);
063: }
064:
065: public void testCommitWithModeTransaction() {
066: try {
067: testCommitWithOpenResults("transaction");
068: } catch (Exception e) {
069: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
070: AbstractTestCase.Platform.INFORMIX,
071: AbstractTestCase.Platform.EMPRESS), 718, e,
072: "Cannot keep results open across commit");
073: }
074: }
075:
076: public void testCommitWithModeOpenJPAEntityManager() {
077: try {
078: testCommitWithOpenResults("persistence-manager");
079: } catch (Exception e) {
080: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
081: AbstractTestCase.Platform.INFORMIX,
082: AbstractTestCase.Platform.EMPRESS), 718, e,
083: "Cannot keep results open across commit");
084: }
085: }
086:
087: public void testCommitWithModeOnDemand() {
088: try {
089: testCommitWithOpenResults("on-demand");
090: } catch (Exception e) {
091: bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
092: AbstractTestCase.Platform.INFORMIX,
093: AbstractTestCase.Platform.EMPRESS), 718, e,
094: "Cannot keep results open across commit");
095: }
096: }
097:
098: private void testCommitWithOpenResults(String crm) {
099: Map props = new HashMap();
100: props.put("openjpa.DefaultFetchThreshold", 1 + "");
101: props.put("openjpa.ConnectionRetainMode", crm);
102:
103: OpenJPAEntityManagerFactory pmf = (OpenJPAEntityManagerFactory) getEmf(props);
104: OpenJPAEntityManager pm = pmf.createEntityManager();
105:
106: startTx(pm);
107: Iterator results = pm.createExtent(RuntimeTest1.class, false)
108: .iterator();
109: results.next();
110: ((RuntimeTest1) results.next()).setStringField("changed name");
111: endTx(pm);
112: while (results.hasNext())
113: results.next();
114: endEm(pm);
115: }
116: }
|