PageRenderTime 64ms CodeModel.GetById 28ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/com/google/appengine/datanucleus/jdo/JDOOneToManyPolymorphicSetTest.java

http://datanucleus-appengine.googlecode.com/
Java | 493 lines | 434 code | 39 blank | 20 comment | 0 complexity | f90db9f472178bc0c25a9eedddb8a90b MD5 | raw file
  1/**********************************************************************
  2Copyright (c) 2011 Google Inc.
  3
  4Licensed under the Apache License, Version 2.0 (the "License");
  5you may not use this file except in compliance with the License.
  6You may obtain a copy of the License at
  7
  8http://www.apache.org/licenses/LICENSE-2.0
  9
 10Unless required by applicable law or agreed to in writing, software
 11distributed under the License is distributed on an "AS IS" BASIS,
 12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13See the License for the specific language governing permissions and
 14limitations under the License.
 15**********************************************************************/
 16package com.google.appengine.datanucleus.jdo;
 17
 18import com.google.appengine.api.datastore.EntityNotFoundException;
 19import com.google.appengine.datanucleus.Utils;
 20import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirBottom;
 21import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirBottomLongPk;
 22import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirBottomUnencodedStringPk;
 23import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirMiddle;
 24import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirMiddleLongPk;
 25import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirMiddleUnencodedStringPk;
 26import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirTop;
 27import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirTopLongPk;
 28import com.google.appengine.datanucleus.test.jdo.BidirectionalSuperclassTableChildSetJDO.BidirTopUnencodedStringPkJDO;
 29import com.google.appengine.datanucleus.test.jdo.HasPolymorphicRelationsSetJDO.HasOneToManyKeyPkSet;
 30import com.google.appengine.datanucleus.test.jdo.HasPolymorphicRelationsSetJDO.HasOneToManyLongPkSet;
 31import com.google.appengine.datanucleus.test.jdo.HasPolymorphicRelationsSetJDO.HasOneToManySet;
 32import com.google.appengine.datanucleus.test.jdo.HasPolymorphicRelationsSetJDO.HasOneToManyUnencodedStringPkSet;
 33import com.google.appengine.datanucleus.test.jdo.UnidirectionalSuperclassTableChildJDO.UnidirBottom;
 34import com.google.appengine.datanucleus.test.jdo.UnidirectionalSuperclassTableChildJDO.UnidirMiddle;
 35import com.google.appengine.datanucleus.test.jdo.UnidirectionalSuperclassTableChildJDO.UnidirTop;
 36
 37import java.util.Collection;
 38
 39import static com.google.appengine.datanucleus.PolymorphicTestUtils.getEntityKind;
 40
 41public class JDOOneToManyPolymorphicSetTest extends JDOOneToManyPolymorphicTestCase {
 42
 43  public void testInsertNewParentAndChild() throws EntityNotFoundException {
 44    testInsertNewParentAndChild(TXN_START_END);
 45  }
 46  public void testInsertNewParentAndChild_NoTxn() throws EntityNotFoundException {
 47    switchDatasource(PersistenceManagerFactoryName.nontransactional);
 48    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
 49    testInsertNewParentAndChild(NEW_PM_START_END);
 50  }
 51  private void testInsertNewParentAndChild(StartEnd startEnd) throws EntityNotFoundException {
 52    String expectedBidirKind = getEntityKind(BidirTop.class);
 53    String expectedUnidirKind  = getEntityKind(UnidirTop.class);
 54    
 55    testInsert_NewParentAndChild(new HasOneToManySet(), new BidirTop(), startEnd, UnidirLevel.Bottom,
 56	expectedBidirKind, expectedUnidirKind, 1, 1);
 57    testInsert_NewParentAndChild(new HasOneToManySet(), new BidirMiddle(), startEnd, UnidirLevel.Top,
 58	expectedBidirKind, expectedUnidirKind, 2, 2);
 59    testInsert_NewParentAndChild(new HasOneToManySet(), new BidirBottom(), startEnd, UnidirLevel.Middle,
 60	expectedBidirKind, expectedUnidirKind, 3, 3);
 61  }
 62
 63  public void testInsertExistingParentNewChild() throws EntityNotFoundException {
 64    testInsertExistingParentNewChild(TXN_START_END);
 65  }
 66  public void testInsertExistingParentNewChild_NoTxn() throws EntityNotFoundException {
 67    switchDatasource(PersistenceManagerFactoryName.nontransactional);
 68    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
 69    testInsertExistingParentNewChild(NEW_PM_START_END);
 70  }
 71  private void testInsertExistingParentNewChild(StartEnd startEnd) throws EntityNotFoundException {
 72    String expectedBidirKind = getEntityKind(BidirTop.class);
 73    String expectedUnidirKind  = getEntityKind(UnidirTop.class);
 74
 75    testInsert_ExistingParentNewChild(new HasOneToManySet(), new BidirBottom(), startEnd, UnidirLevel.Middle,
 76	expectedBidirKind, expectedUnidirKind, 1, 1);
 77    testInsert_ExistingParentNewChild(new HasOneToManySet(), new BidirTop(), startEnd, UnidirLevel.Bottom,
 78	expectedBidirKind, expectedUnidirKind, 2, 2);
 79    testInsert_ExistingParentNewChild(new HasOneToManySet(), new BidirMiddle(), startEnd, UnidirLevel.Top,
 80	expectedBidirKind, expectedUnidirKind, 3, 3);
 81  }
 82
 83  public void testUpdateUpdateChildWithMerge() throws EntityNotFoundException {
 84    testUpdateUpdateChildWithMerge(TXN_START_END);
 85  }
 86  public void testUpdateUpdateChildWithMerge_NoTxn() throws EntityNotFoundException {
 87    switchDatasource(PersistenceManagerFactoryName.nontransactional);
 88    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
 89    testUpdateUpdateChildWithMerge(NEW_PM_START_END);
 90  }
 91  private void testUpdateUpdateChildWithMerge(StartEnd startEnd) throws EntityNotFoundException {
 92    String expectedBidirKind = getEntityKind(BidirTop.class);
 93    String expectedUnidirKind  = getEntityKind(UnidirTop.class);
 94
 95    testUpdate_UpdateChildWithMerge(new HasOneToManySet(), new BidirTop(), startEnd,
 96	expectedBidirKind, expectedUnidirKind, UnidirLevel.Bottom, 1);
 97    testUpdate_UpdateChildWithMerge(new HasOneToManySet(), new BidirMiddle(), startEnd,
 98	expectedBidirKind, expectedUnidirKind, UnidirLevel.Top, 2);
 99    testUpdate_UpdateChildWithMerge(new HasOneToManySet(), new BidirBottom(), startEnd,
100	expectedBidirKind, expectedUnidirKind, UnidirLevel.Middle, 3);
101  }
102
103  public void testUpdateUpdateChild() throws EntityNotFoundException {
104    testUpdateUpdateChild(TXN_START_END);
105  }
106  public void testUpdateUpdateChild_NoTxn() throws EntityNotFoundException {
107    switchDatasource(PersistenceManagerFactoryName.nontransactional);
108    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
109    testUpdateUpdateChild(NEW_PM_START_END);
110  }
111  private void testUpdateUpdateChild(StartEnd startEnd) throws EntityNotFoundException {
112    String expectedBidirKind = getEntityKind(BidirTop.class);
113    String expectedUnidirKind  = getEntityKind(UnidirTop.class);
114    testUpdate_UpdateChild(new HasOneToManySet(), new BidirTop(), startEnd,
115	expectedBidirKind, expectedUnidirKind, UnidirLevel.Middle, 1);
116    testUpdate_UpdateChild(new HasOneToManySet(), new BidirMiddle(), startEnd,
117	expectedBidirKind, expectedUnidirKind, UnidirLevel.Top, 2);
118    testUpdate_UpdateChild(new HasOneToManySet(), new BidirBottom(), startEnd,
119	expectedBidirKind, expectedUnidirKind, UnidirLevel.Bottom, 3);
120  }
121
122
123  public void testUpdateNullOutChildren() throws EntityNotFoundException {
124    testUpdateNullOutChildren(TXN_START_END);
125  }
126  public void testUpdateNullOutChildren_NoTxn() throws EntityNotFoundException {
127    switchDatasource(PersistenceManagerFactoryName.nontransactional);
128    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
129    testUpdateNullOutChildren(NEW_PM_DETACH_ON_CLOSE_START_END);
130  }
131  private void testUpdateNullOutChildren(StartEnd startEnd) throws EntityNotFoundException {
132    testUpdate_NullOutChildren(new HasOneToManySet(), new BidirBottom(), startEnd,
133	UnidirLevel.Bottom, 1);
134    testUpdate_NullOutChildren(new HasOneToManySet(), new BidirMiddle(), startEnd,
135	UnidirLevel.Middle, 2);
136    testUpdate_NullOutChildren(new HasOneToManySet(), new BidirTop(), startEnd,
137	UnidirLevel.Top, 3);
138  }
139
140  public void testUpdateClearOutChildren() throws EntityNotFoundException {
141    testUpdateClearOutChildren(TXN_START_END);
142  }
143  public void testUpdateClearOutChildren_NoTxn() throws EntityNotFoundException {
144    switchDatasource(PersistenceManagerFactoryName.nontransactional);
145    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
146    testUpdateClearOutChildren(NEW_PM_DETACH_ON_CLOSE_START_END);
147  }
148  private void testUpdateClearOutChildren(StartEnd startEnd) throws EntityNotFoundException {
149    testUpdate_ClearOutChildren(new HasOneToManySet(), new BidirTop(), startEnd,
150	UnidirLevel.Bottom, 1);
151    testUpdate_ClearOutChildren(new HasOneToManySet(), new BidirBottom(), startEnd,
152	UnidirLevel.Middle, 2);
153    testUpdate_ClearOutChildren(new HasOneToManySet(), new BidirMiddle(), startEnd,
154	UnidirLevel.Top, 3);
155  }
156
157  public void testFind() throws EntityNotFoundException {
158    testFind(TXN_START_END);
159  }
160  public void testFind_NoTxn() throws EntityNotFoundException {
161    switchDatasource(PersistenceManagerFactoryName.nontransactional);
162    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
163    testFind(NEW_PM_START_END);
164  }
165  private void testFind(StartEnd startEnd) throws EntityNotFoundException {
166    testFind(HasOneToManySet.class, BidirMiddle.class, startEnd,
167	getEntityKind(BidirTop.class), UnidirLevel.Top);
168    testFind(HasOneToManySet.class, BidirBottom.class, startEnd,
169	getEntityKind(BidirTop.class), UnidirLevel.Middle);
170    testFind(HasOneToManySet.class, BidirTop.class, startEnd,
171	getEntityKind(BidirTop.class), UnidirLevel.Bottom);
172  }
173
174  public void testQuery() throws EntityNotFoundException {
175    testQuery(TXN_START_END);
176  }
177  public void testQuery_NoTxn() throws EntityNotFoundException {
178    switchDatasource(PersistenceManagerFactoryName.nontransactional);
179    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
180    testQuery(NEW_PM_START_END);
181  }
182  private void testQuery(StartEnd startEnd) throws EntityNotFoundException {
183    testQuery(HasOneToManySet.class, BidirTop.class, startEnd, 
184	getEntityKind(BidirTop.class), UnidirLevel.Middle);
185    testQuery(HasOneToManySet.class, BidirBottom.class, startEnd, 
186	getEntityKind(BidirTop.class), UnidirLevel.Top);
187    testQuery(HasOneToManySet.class, BidirMiddle.class, startEnd, 
188	getEntityKind(BidirTop.class), UnidirLevel.Bottom);
189  }
190
191  public void testChildFetchedLazily() throws Exception {
192    testChildFetchedLazily(HasOneToManySet.class, BidirTop.class);
193    testChildFetchedLazily(HasOneToManySet.class, BidirMiddle.class);
194    testChildFetchedLazily(HasOneToManySet.class, BidirBottom.class);
195  }
196
197  public void testDeleteParentDeletesChild() throws Exception {
198    testDeleteParentDeletesChild(TXN_START_END);
199  }
200  public void testDeleteParentDeletesChild_NoTxn() throws Exception {
201    switchDatasource(PersistenceManagerFactoryName.nontransactional);
202    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
203    testDeleteParentDeletesChild(NEW_PM_START_END);
204  }
205  private void testDeleteParentDeletesChild(StartEnd startEnd) throws Exception {
206    testDeleteParentDeletesChild(HasOneToManySet.class, BidirTop.class, startEnd,
207	getEntityKind(BidirTop.class), UnidirLevel.Top);
208    testDeleteParentDeletesChild(HasOneToManySet.class, BidirMiddle.class, startEnd,
209	getEntityKind(BidirTop.class), UnidirLevel.Middle);
210    testDeleteParentDeletesChild(HasOneToManySet.class, BidirBottom.class, startEnd,
211	getEntityKind(BidirTop.class), UnidirLevel.Bottom);
212  }
213
214  public void testRemoveAll() throws EntityNotFoundException {
215    testRemoveAll(TXN_START_END);
216  }
217  public void testRemoveAll_NoTxn() throws EntityNotFoundException {
218    switchDatasource(PersistenceManagerFactoryName.nontransactional);
219    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
220    testRemoveAll(NEW_PM_START_END);
221  }
222  private void testRemoveAll(StartEnd startEnd) throws EntityNotFoundException {
223    testRemoveAll(new HasOneToManySet(), new BidirTop(),
224                  new BidirMiddle(), new BidirBottom(), startEnd);
225  }
226
227  public void testRemoveAll_LongPkOnParent() throws EntityNotFoundException {
228    testRemoveAll_LongPkOnParent(TXN_START_END);
229  }
230  public void testRemoveAll_LongPkOnParent_NoTxn() throws EntityNotFoundException {
231    switchDatasource(PersistenceManagerFactoryName.nontransactional);
232    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
233    testRemoveAll_LongPkOnParent(NEW_PM_DETACH_ON_CLOSE_START_END);
234  }
235  private void testRemoveAll_LongPkOnParent(StartEnd startEnd) throws EntityNotFoundException {
236    testRemoveAll_LongPkOnParent(new HasOneToManyLongPkSet(), new BidirTopLongPk(),
237                  new BidirMiddleLongPk(), new BidirBottomLongPk(), startEnd);
238  }
239
240  public void testRemoveAll_UnencodedStringPkOnParent() throws EntityNotFoundException {
241    testRemoveAll_UnencodedStringPkOnParent(TXN_START_END);
242  }
243  public void testRemoveAll_UnencodedStringPkOnParent_NoTxn() throws EntityNotFoundException {
244    switchDatasource(PersistenceManagerFactoryName.nontransactional);
245    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
246    testRemoveAll_UnencodedStringPkOnParent(NEW_PM_START_END);
247  }
248  private void testRemoveAll_UnencodedStringPkOnParent(StartEnd startEnd) throws EntityNotFoundException {
249    HasOneToManyUnencodedStringPkSet parent = new HasOneToManyUnencodedStringPkSet();
250    parent.setId("parent id");
251    testRemoveAll_UnencodedStringPkOnParent(parent, new BidirTopUnencodedStringPkJDO(),
252                  new BidirBottomUnencodedStringPk(),
253                  new BidirMiddleUnencodedStringPk(), startEnd);
254  }
255
256  public void testChangeParent() {
257    testChangeParent(TXN_START_END);
258  }
259  public void testChangeParent_NoTxn() {
260    switchDatasource(PersistenceManagerFactoryName.nontransactional);
261    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
262    testChangeParent(NEW_PM_START_END);
263  }
264  private void testChangeParent(StartEnd startEnd) {
265    testChangeParent(new HasOneToManySet(), new HasOneToManySet(), startEnd,
266	UnidirLevel.Top);
267    testChangeParent(new HasOneToManySet(), new HasOneToManySet(), startEnd,
268	UnidirLevel.Middle);
269    testChangeParent(new HasOneToManySet(), new HasOneToManySet(), startEnd,
270	UnidirLevel.Bottom);
271  }
272
273  public void testNewParentNewChild_NamedKeyOnChild() throws EntityNotFoundException {
274    testNewParentNewChild_NamedKeyOnChild(TXN_START_END);
275  }
276  public void testNewParentNewChild_NamedKeyOnChild_NoTxn() throws EntityNotFoundException {
277    switchDatasource(PersistenceManagerFactoryName.nontransactional);
278    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
279    testNewParentNewChild_NamedKeyOnChild(NEW_PM_START_END);
280  }
281  private void testNewParentNewChild_NamedKeyOnChild(StartEnd startEnd) throws EntityNotFoundException {
282    testNewParentNewChild_NamedKeyOnChild(new HasOneToManySet(), startEnd, UnidirLevel.Middle);
283    testNewParentNewChild_NamedKeyOnChild(new HasOneToManySet(), startEnd, UnidirLevel.Top);
284    testNewParentNewChild_NamedKeyOnChild(new HasOneToManySet(), startEnd, UnidirLevel.Bottom);
285  }
286
287  public void testAddAlreadyPersistedChildToParent_NoTxnSamePm() {
288    switchDatasource(PersistenceManagerFactoryName.nontransactional);
289    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
290    testAddAlreadyPersistedChildToParent_NoTxnSamePm(new HasOneToManySet(), UnidirLevel.Middle, 1);
291    testAddAlreadyPersistedChildToParent_NoTxnSamePm(new HasOneToManySet(), UnidirLevel.Top, 2);
292    testAddAlreadyPersistedChildToParent_NoTxnSamePm(new HasOneToManySet(), UnidirLevel.Bottom, 3);
293
294  }
295
296  public void testAddAlreadyPersistedChildToParent_NoTxnDifferentPm() {
297    testAddAlreadyPersistedChildToParent_NoTxnDifferentPm(new HasOneToManySet(), UnidirLevel.Middle, 1);
298    testAddAlreadyPersistedChildToParent_NoTxnDifferentPm(new HasOneToManySet(), UnidirLevel.Bottom, 2);
299    testAddAlreadyPersistedChildToParent_NoTxnDifferentPm(new HasOneToManySet(), UnidirLevel.Top, 3);
300  }
301
302  public void testFetchOfOneToManyParentWithKeyPk() {
303    testFetchOfOneToManyParentWithKeyPk(TXN_START_END);
304  }
305  public void testFetchOfOneToManyParentWithKeyPk_NoTxn() {
306    switchDatasource(PersistenceManagerFactoryName.nontransactional);
307    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
308    testFetchOfOneToManyParentWithKeyPk(NEW_PM_START_END);
309  }
310  private void testFetchOfOneToManyParentWithKeyPk(StartEnd startEnd) {
311    testFetchOfOneToManyParentWithKeyPk(new HasOneToManyKeyPkSet(), startEnd);
312  }
313
314  public void testFetchOfOneToManyParentWithLongPk() {
315    testFetchOfOneToManyParentWithLongPk(TXN_START_END);
316  }
317  public void testFetchOfOneToManyParentWithLongPk_NoTxn() {
318    switchDatasource(PersistenceManagerFactoryName.nontransactional);
319    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
320    testFetchOfOneToManyParentWithLongPk(NEW_PM_START_END);
321  }
322  private void testFetchOfOneToManyParentWithLongPk(StartEnd startEnd) {
323    testFetchOfOneToManyParentWithLongPk(new HasOneToManyLongPkSet(), startEnd);
324  }
325
326  public void testFetchOfOneToManyParentWithUnencodedStringPk() {
327    testFetchOfOneToManyParentWithUnencodedStringPk(TXN_START_END);
328  }
329  public void testFetchOfOneToManyParentWithUnencodedStringPk_NoTxn() {
330    switchDatasource(PersistenceManagerFactoryName.nontransactional);
331    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
332    testFetchOfOneToManyParentWithUnencodedStringPk(NEW_PM_START_END);
333  }
334  private void testFetchOfOneToManyParentWithUnencodedStringPk(StartEnd startEnd) {
335    testFetchOfOneToManyParentWithUnencodedStringPk(new HasOneToManyUnencodedStringPkSet(), startEnd);
336  }
337
338  public void testAddChildToOneToManyParentWithLongPk() throws EntityNotFoundException {
339    testAddChildToOneToManyParentWithLongPk(TXN_START_END);
340  }
341  public void testAddChildToOneToManyParentWithLongPk_NoTxn() throws EntityNotFoundException {
342    switchDatasource(PersistenceManagerFactoryName.nontransactional);
343    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
344    testAddChildToOneToManyParentWithLongPk(NEW_PM_START_END);
345  }
346  private void testAddChildToOneToManyParentWithLongPk(StartEnd startEnd) throws EntityNotFoundException {
347    testAddChildToOneToManyParentWithLongPk(
348        new HasOneToManyLongPkSet(), new BidirTopLongPk(), startEnd, UnidirLevel.Top);
349    testAddChildToOneToManyParentWithLongPk(
350        new HasOneToManyLongPkSet(), new BidirMiddleLongPk(), startEnd, UnidirLevel.Middle);
351    testAddChildToOneToManyParentWithLongPk(
352        new HasOneToManyLongPkSet(), new BidirBottomLongPk(), startEnd, UnidirLevel.Bottom);
353  }
354
355  public void testAddChildToOneToManyParentWithUnencodedStringPk() throws EntityNotFoundException {
356    testAddChildToOneToManyParentWithUnencodedStringPk(TXN_START_END);
357  }
358  public void testAddChildToOneToManyParentWithUnencodedStringPk_NoTxn() throws EntityNotFoundException {
359    switchDatasource(PersistenceManagerFactoryName.nontransactional);
360    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
361    testAddChildToOneToManyParentWithUnencodedStringPk(NEW_PM_START_END);
362  }
363  private void testAddChildToOneToManyParentWithUnencodedStringPk(StartEnd startEnd) throws EntityNotFoundException {
364    testAddChildToOneToManyParentWithUnencodedStringPk(
365        new HasOneToManyUnencodedStringPkSet(), new BidirMiddleUnencodedStringPk(),
366        startEnd, UnidirLevel.Middle, "yar");
367    testAddChildToOneToManyParentWithUnencodedStringPk(
368        new HasOneToManyUnencodedStringPkSet(), new BidirTopUnencodedStringPkJDO(),
369        startEnd, UnidirLevel.Bottom, "yas");
370    testAddChildToOneToManyParentWithUnencodedStringPk(
371        new HasOneToManyUnencodedStringPkSet(), new BidirBottomUnencodedStringPk(),
372        startEnd, UnidirLevel.Top, "yat");
373  }
374
375  public void testAddQueriedParentToBidirChild() throws EntityNotFoundException {
376    testAddQueriedParentToBidirChild(TXN_START_END);
377  }
378  public void testAddQueriedParentToBidirChild_NoTxn() throws EntityNotFoundException {
379    switchDatasource(PersistenceManagerFactoryName.nontransactional);
380    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
381    testAddQueriedParentToBidirChild(NEW_PM_START_END);
382  }
383  private void testAddQueriedParentToBidirChild(StartEnd startEnd) throws EntityNotFoundException {
384    testAddQueriedParentToBidirChild(new HasOneToManySet(), new BidirMiddle(), startEnd, 
385	  getEntityKind(BidirTop.class));
386    testAddQueriedParentToBidirChild(new HasOneToManySet(), new BidirTop(), startEnd, 
387	  getEntityKind(BidirTop.class));
388    testAddQueriedParentToBidirChild(new HasOneToManySet(), new BidirBottom(), startEnd, 
389	  getEntityKind(BidirTop.class));
390  }
391
392  public void testAddFetchedParentToBidirChild() throws EntityNotFoundException {
393    testAddFetchedParentToBidirChild(TXN_START_END);
394  }
395  public void testAddFetchedParentToBidirChild_NoTxn() throws EntityNotFoundException {
396    switchDatasource(PersistenceManagerFactoryName.nontransactional);
397    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
398    testAddFetchedParentToBidirChild(NEW_PM_START_END);
399  }
400  private void testAddFetchedParentToBidirChild(StartEnd startEnd) throws EntityNotFoundException {
401    testAddFetchedParentToBidirChild(new HasOneToManySet(), new BidirTop(), startEnd, 
402	getEntityKind(BidirTop.class));
403    testAddFetchedParentToBidirChild(new HasOneToManySet(), new BidirMiddle(), startEnd, 
404	getEntityKind(BidirTop.class));
405    testAddFetchedParentToBidirChild(new HasOneToManySet(), new BidirBottom(), startEnd, 
406	getEntityKind(BidirTop.class));
407  }
408
409  public void testReplaceBidirColl() {
410    testReplaceBidirColl(TXN_START_END);
411  }
412  public void testReplaceBidirColl_NoTxn() {
413    switchDatasource(PersistenceManagerFactoryName.nontransactional);
414    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
415    testReplaceBidirColl(NEW_PM_START_END);
416  }
417  private void testReplaceBidirColl(StartEnd startEnd) {
418    Collection<BidirTop> childList = Utils.<BidirTop>newHashSet(
419        new BidirMiddle(), new BidirBottom());
420    testReplaceBidirColl(new HasOneToManySet(), new BidirTop(), 
421	childList, startEnd);
422  }
423
424  public void testOnlyOneParentPutOnParentAndChildUpdate() throws Throwable {
425    testOnlyOneParentPutOnParentAndChildUpdate(TXN_START_END);
426  }
427  public void testOnlyOneParentPutOnParentAndChildUpdate_NoTxn() throws Throwable {
428    switchDatasource(PersistenceManagerFactoryName.nontransactional);
429    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
430    testOnlyOneParentPutOnParentAndChildUpdate(NEW_PM_START_END);
431  }
432  private void testOnlyOneParentPutOnParentAndChildUpdate(StartEnd startEnd) throws Throwable {
433    testOnlyOneParentPutOnParentAndChildUpdate(
434        new HasOneToManySet(), new BidirMiddle(), startEnd);
435    testOnlyOneParentPutOnParentAndChildUpdate(
436        new HasOneToManySet(), new BidirTop(), startEnd);
437    testOnlyOneParentPutOnParentAndChildUpdate(
438        new HasOneToManySet(), new BidirBottom(), startEnd);
439  }
440
441  public void testOnlyOnePutOnChildUpdate() throws Throwable {
442    testOnlyOnePutOnChildUpdate(TXN_START_END);
443  }
444  public void testOnlyOnePutOnChildUpdate_NoTxn() throws Throwable {
445    switchDatasource(PersistenceManagerFactoryName.nontransactional);
446    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
447    testOnlyOnePutOnChildUpdate(NEW_PM_START_END);
448  }
449  private void testOnlyOnePutOnChildUpdate(StartEnd startEnd) throws Throwable {
450    testOnlyOnePutOnChildUpdate(new HasOneToManySet(), new BidirBottom(), startEnd);
451    testOnlyOnePutOnChildUpdate(new HasOneToManySet(), new BidirMiddle(), startEnd);
452    testOnlyOnePutOnChildUpdate(new HasOneToManySet(), new BidirTop(), startEnd);
453  }
454
455  public void testOnlyOneParentPutOnChildDelete() throws Throwable {
456    testOnlyOneParentPutOnChildDelete(TXN_START_END);
457  }
458  public void testOnlyOneParentPutOnChildDelete_NoTxn() throws Throwable {
459    switchDatasource(PersistenceManagerFactoryName.nontransactional);
460    getExecutionContext().setProperty(PROP_DETACH_ON_CLOSE, true);
461    testOnlyOneParentPutOnChildDelete(NEW_PM_START_END);
462  }
463  private void testOnlyOneParentPutOnChildDelete(StartEnd startEnd) throws Throwable {
464    testOnlyOneParentPutOnChildDelete(new HasOneToManySet(), new BidirTop(), startEnd);
465    testOnlyOneParentPutOnChildDelete(new HasOneToManySet(), new BidirBottom(), startEnd);
466    testOnlyOneParentPutOnChildDelete(new HasOneToManySet(), new BidirMiddle(), startEnd);
467  }
468
469  public void testNonTxnAddOfChildToParentFailsPartwayThrough() throws Throwable {
470    testNonTxnAddOfChildToParentFailsPartwayThrough(new HasOneToManySet());
471  }
472  
473  @Override
474  boolean isIndexed() {
475    return false;
476  }
477  @Override
478  protected void registerSubclasses() {
479    // Make sure all subclasses of UnidirTop, ... are known. Only the meta data
480    // of the top class in the inheritance tree (element type of the collections)
481    // is known otherwise when getting the pojo. This would work if UnidirTop and
482    // BidirTopLongPk would use the inheritance mapping strategy CLASS_NAME, 
483    // but it uses VALUE_MAP. This problem exists with RDBMS datanucleus plugin as well.
484    getExecutionContext().getStoreManager().addClass(UnidirMiddle.class.getName(),
485	getExecutionContext().getClassLoaderResolver());
486    getExecutionContext().getStoreManager().addClass(UnidirBottom.class.getName(),
487	getExecutionContext().getClassLoaderResolver());
488    getExecutionContext().getStoreManager().addClass(BidirMiddleLongPk.class.getName(),
489	getExecutionContext().getClassLoaderResolver());
490    getExecutionContext().getStoreManager().addClass(BidirBottomLongPk.class.getName(),
491	getExecutionContext().getClassLoaderResolver());
492  }
493}