001: /*
002: * TestStaticInnerClasses.java
003: *
004: * Created on October 13, 2006, 5:45 PM
005: *
006: * To change this template, choose Tools | Template Manager
007: * and open the template in the editor.
008: */
009:
010: /*
011: * Licensed to the Apache Software Foundation (ASF) under one
012: * or more contributor license agreements. See the NOTICE file
013: * distributed with this work for additional information
014: * regarding copyright ownership. The ASF licenses this file
015: * to you under the Apache License, Version 2.0 (the
016: * "License"); you may not use this file except in compliance
017: * with the License. You may obtain a copy of the License at
018: *
019: * http://www.apache.org/licenses/LICENSE-2.0
020: *
021: * Unless required by applicable law or agreed to in writing,
022: * software distributed under the License is distributed on an
023: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
024: * KIND, either express or implied. See the License for the
025: * specific language governing permissions and limitations
026: * under the License.
027: */
028: package org.apache.openjpa.persistence.kernel;
029:
030: import java.util.LinkedList;
031: import java.util.List;
032: import javax.persistence.Entity;
033: import javax.persistence.Table;
034:
035: import org.apache.openjpa.persistence.OpenJPAEntityManager;
036:
037: public class TestStaticInnerClasses extends BaseKernelTest {
038:
039: private Object _oid = null;
040:
041: /**
042: * Creates a new instance of TestStaticInnerClasses
043: */
044: public TestStaticInnerClasses() {
045: }
046:
047: public TestStaticInnerClasses(String name) {
048: super (name);
049: }
050:
051: public void setUp() throws Exception {
052: Inner inner = new Inner("foo");
053: inner.addTwin();
054: OpenJPAEntityManager pm = getPM();
055: startTx(pm);
056: pm.persist(inner);
057: _oid = pm.getObjectId(inner);
058: endTx(pm);
059: endEm(pm);
060: }
061:
062: public void testGetById() {
063: OpenJPAEntityManager pm = getPM();
064: Inner inner = (Inner) pm.find(Inner.class, _oid);
065: assertNotNull(inner);
066: assertEquals("foo", inner.getString());
067: endEm(pm);
068: }
069:
070: public void testGetByQuery() {
071: // OpenJPAEntityManager pm = getPM();
072: //
073: // OpenJPAQuery q = pm.createNativeQuery("",Inner.class);
074: // //FIXME jthomas
075: // /*
076: // q.ssetCandidates(pm.createExtent(Inner.class, false));
077: // q.declareVariables(Inner.class.getName() + " inner;");
078: // q.setFilter("twins.contains (inner) && inner.string == \"foo\"");
079: // q.setOrdering("string ascending, num descending");
080: // Iterator iter = null;
081: // try {
082: // iter = ((Collection) q.execute()).iterator();
083: // } catch (JDOException jdoe) {
084: // if (jdoe.getMessage().indexOf("is ambiguous") != -1)
085: // bug(AbstractTestCase.Platform.POSTGRESQL, 74, jdoe,
086: // "Sorts in PostgreSQL may result"
087: // + "in \"ORDER BY 'my_sort_key' is ambiguous\"");
088: // else
089: // throw jdoe;
090: // }
091: //
092: // assertNotNull(iter);
093: // assertTrue(iter.hasNext());
094: // assertEquals("foo", ((Inner) iter.next()).getString());
095: // */
096: // endEm(pm,());
097: /*OpenJPAEntityManager pm = getPM();
098: OpenJPAQuery q = pm.createQuery("SELECT c FROM TestStaticInnerClasses.Inner c WHERE c.string = 'foo' ORDER BY c.string ASC");
099: q.setCandidateCollection((Collection)pm.createExtent(TestStaticInnerClasses.Inner.class, false));
100:
101: try
102: {
103: Iterator iter = ((Collection) q.getResultList()).iterator();
104: }
105: catch (Exception jdoe)
106: {
107: if (jdoe.getMessage().indexOf("is ambiguous") != -1)
108: bug(AbstractTestCase.Platform.POSTGRESQL, 74, jdoe,
109: "Sorts in PostgreSQL may result"
110: + "in \"ORDER BY 'my_sort_key' is ambiguous\"");
111: else
112: throw jdoe;
113: }*/
114:
115: }
116:
117: @Entity
118: @Table(name="StaticInner")
119: public static class Inner {
120:
121: private int num = 0;
122: private String string = null;
123: private List twins = new LinkedList();
124:
125: protected Inner() {
126: }
127:
128: public Inner(String string) {
129: this .string = string;
130: }
131:
132: public void addTwin() {
133: twins.add(new Inner(string));
134: }
135:
136: public String getString() {
137: return string;
138: }
139: }
140: }
|