Line 0
Link Here
|
|
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 1998, 2011 Oracle. All rights reserved. |
3 |
* This program and the accompanying materials are made available under the |
4 |
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 |
5 |
* which accompanies this distribution. |
6 |
* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html |
7 |
* and the Eclipse Distribution License is available at |
8 |
* http://www.eclipse.org/org/documents/edl-v10.php. |
9 |
* |
10 |
* Contributors: |
11 |
* dminsky - initial API and implementation |
12 |
******************************************************************************/ |
13 |
package org.eclipse.persistence.testing.tests.queries; |
14 |
|
15 |
import java.util.List; |
16 |
import java.util.Vector; |
17 |
|
18 |
import org.eclipse.persistence.queries.ReadAllQuery; |
19 |
import org.eclipse.persistence.queries.ScrollableCursor; |
20 |
|
21 |
import org.eclipse.persistence.testing.framework.TestCase; |
22 |
import org.eclipse.persistence.testing.models.employee.domain.Employee; |
23 |
|
24 |
/** |
25 |
* Test using a ScrollableCursor with a simple joined attribute. |
26 |
* Bug 351509 - Null Pointer Exception when using ScrollableCursor on a OneToMany Mapping |
27 |
*/ |
28 |
public class ScrollableCursorJoinedAttributeTest extends TestCase { |
29 |
|
30 |
protected List cursoredResults; |
31 |
protected Exception caughtException; |
32 |
|
33 |
public ScrollableCursorJoinedAttributeTest() { |
34 |
super(); |
35 |
setDescription("Scrollable Cursor Test incorporating a joined attribute"); |
36 |
} |
37 |
|
38 |
public void test() { |
39 |
getSession().getIdentityMapAccessor().initializeAllIdentityMaps(); |
40 |
|
41 |
cursoredResults = new Vector(); |
42 |
ReadAllQuery cursoredQuery = new ReadAllQuery(Employee.class); |
43 |
cursoredQuery.useScrollableCursor(); |
44 |
cursoredQuery.addJoinedAttribute(cursoredQuery.getExpressionBuilder().anyOfAllowingNone("phoneNumbers")); |
45 |
cursoredQuery.addOrdering(cursoredQuery.getExpressionBuilder().get("id")); |
46 |
|
47 |
try { |
48 |
ScrollableCursor cursor = (ScrollableCursor)getSession().executeQuery(cursoredQuery); |
49 |
while (cursor.hasNext()) { |
50 |
Object result = cursor.next(); |
51 |
cursoredResults.add(result); |
52 |
} |
53 |
cursor.close(); |
54 |
} catch (Exception e) { |
55 |
caughtException = e; |
56 |
} |
57 |
} |
58 |
|
59 |
public void verify() { |
60 |
if (caughtException != null) { |
61 |
throwError("Cursored query should not result in an exception", caughtException); |
62 |
} |
63 |
assertNotSame("Test data for cursored results should be nonzero", 0, cursoredResults.size()); |
64 |
} |
65 |
|
66 |
public void reset() { |
67 |
this.cursoredResults = null; |
68 |
} |
69 |
|
70 |
} |