Enable some of the new tests.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@628375 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Patrick Linskey 2008-02-16 19:30:20 +00:00
parent 7d44e7a355
commit de8a4760c8
22 changed files with 126 additions and 974 deletions

View File

@ -226,7 +226,7 @@ public class ClassMappingInfo
* Return the table for the given class.
*/
public Table getTable(final ClassMapping cls, boolean adapt) {
return createTable(cls, new TableDefaults() {
Table t = createTable(cls, new TableDefaults() {
public String get(Schema schema) {
// delay this so that we don't do schema reflection for unique
// table name unless necessary
@ -234,6 +234,10 @@ public class ClassMappingInfo
getTableName(cls, schema);
}
}, _schemaName, _tableName, adapt);
t.setComment(cls.getTypeAlias() == null
? cls.getDescribedType().getName()
: cls.getTypeAlias());
return t;
}
/**

View File

@ -699,6 +699,9 @@ public abstract class MappingInfo
if (decimals != 0)
col.setDecimalDigits(decimals);
}
if (tmplate.hasComment())
col.setComment(tmplate.getComment());
return col;
}

View File

@ -76,6 +76,7 @@ public class FullClassStrategy
Column id = new Column();
id.setName("id");
id.setJavaType(JavaTypes.LONG);
id.setComment("datastore id");
if (cls.getIdentityStrategy() == ValueStrategies.AUTOASSIGN)
id.setAutoAssigned(true);
id.setNotNull(true);

View File

@ -72,7 +72,8 @@ public class Column
private int _index = 0;
private boolean _pk = false;
private VersionStrategy _versionStrategy = null;
private String _comment = null;
/**
* Default constructor.
*/
@ -733,4 +734,16 @@ public class Column
public void setVersionStrategy(VersionStrategy strategy) {
this._versionStrategy = strategy;
}
public boolean hasComment() {
return _comment != null && !_comment.equalsIgnoreCase(_name);
}
public String getComment() {
return _comment;
}
public void setComment(String comment) {
_comment = comment;
}
}

View File

@ -60,6 +60,7 @@ public class Table
private ForeignKey[] _fks = null;
private Index[] _idxs = null;
private Unique[] _unqs = null;
private String _comment = null;
/**
* Default constructor.
@ -689,4 +690,16 @@ public class Table
public String toString() {
return getFullName();
}
public boolean hasComment() {
return _comment != null && !_comment.equalsIgnoreCase(_name);
}
public String getComment() {
return _comment;
}
public void setComment(String comment) {
_comment = comment;
}
}

View File

@ -193,6 +193,7 @@ public class DBDictionary
public boolean supportsDefaultUpdateAction = true;
public boolean supportsAlterTableWithAddColumn = true;
public boolean supportsAlterTableWithDropColumn = true;
public boolean supportsComments = false;
public String reservedWords = null;
public String systemSchemas = null;
public String systemTables = null;
@ -2972,36 +2973,57 @@ public class DBDictionary
*/
public String[] getCreateTableSQL(Table table) {
StringBuffer buf = new StringBuffer();
buf.append("CREATE TABLE ").append(getFullName(table, false)).
append(" (");
Column[] cols = table.getColumns();
for (int i = 0; i < cols.length; i++) {
if (i > 0)
buf.append(", ");
buf.append(getDeclareColumnSQL(cols[i], false));
buf.append("CREATE TABLE ").append(getFullName(table, false));
if (supportsComments && table.hasComment()) {
buf.append(" ");
comment(buf, table.getComment());
buf.append("\n (");
} else {
buf.append(" (");
}
// do this before getting the columns so we know how to handle
// the last comma
StringBuffer endBuf = new StringBuffer();
PrimaryKey pk = table.getPrimaryKey();
String pkStr;
if (pk != null) {
pkStr = getPrimaryKeyConstraintSQL(pk);
if (pkStr != null)
buf.append(", ").append(pkStr);
endBuf.append(pkStr);
}
Unique[] unqs = table.getUniques();
String unqStr;
for (int i = 0; i < unqs.length; i++) {
unqStr = getUniqueConstraintSQL(unqs[i]);
if (unqStr != null)
buf.append(", ").append(unqStr);
if (unqStr != null) {
if (endBuf.length() > 0)
endBuf.append(", ");
endBuf.append(unqStr);
}
}
Column[] cols = table.getColumns();
for (int i = 0; i < cols.length; i++) {
buf.append(getDeclareColumnSQL(cols[i], false));
if (i < cols.length - 1 || endBuf.length() > 0)
buf.append(", ");
if (supportsComments && cols[i].hasComment()) {
comment(buf, cols[i].getComment());
buf.append("\n ");
}
}
buf.append(endBuf.toString());
buf.append(")");
return new String[]{ buf.toString() };
}
protected StringBuffer comment(StringBuffer buf, String comment) {
return buf.append("-- ").append(comment);
}
/**
* Return a series of SQL statements to drop the given table. Indexes
* will be dropped separately. Returns

View File

@ -61,6 +61,8 @@ public class DerbyDictionary
requiresCastForMathFunctions = true;
requiresCastForComparisons = true;
supportsComments = true;
fixedSizeTypeNameSet.addAll(Arrays.asList(new String[]{
"BIGINT", "INTEGER",
}));

View File

@ -4339,9 +4339,12 @@ public class BrokerImpl
if (_closedException == null) // TRACE not enabled
throw new InvalidStateException(_loc.get("closed-notrace"))
.setFatal(true);
else
throw new InvalidStateException(_loc.get("closed"),
_closedException).setFatal(true);
else {
OpenJPAException e = new InvalidStateException(
_loc.get("closed"), _closedException).setFatal(true);
e.setCause(_closedException);
throw e;
}
}
}

View File

@ -327,6 +327,10 @@
<!-- exclude new tests that aren't passing yet -->
<exclude>org/apache/openjpa/persistence/jpql/clauses/TestEJBQueryInterface.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java</exclude>
<exclude>org/apache/openjpa/persistence/query/TestQuotedNumbersInFilters2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBEmbedded.java</exclude>
<exclude>org/apache/openjpa/persistence/annotations/TestAdvAnnot.java</exclude>
<exclude>org/apache/openjpa/persistence/annotations/TestDDCallbackMethods.java</exclude>
@ -436,72 +440,35 @@
<exclude>org/apache/openjpa/persistence/kernel/TestArrayValues2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestBigDecimals.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestBrokerFactoryPooling.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestCalendarFields.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestCheckConsistency.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestClassStringConstructor.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestConnectionRetainMode.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestDateQueries.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestDependentFields2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestDetachedStateManager.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBEntityManager.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBGetObjectByIdValue.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBIncrementalFlushes.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBLobs.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBLocales.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBManagedInverses.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBNoPersistentFields.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBNullValues.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBObjectCollections.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBRetainValues.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBState.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBTransactionalClass.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestEJBTransactions.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestExtents.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestExtents2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFetchGroups.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFetchGroupsExtent.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFetchGroupsQuery.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFetchPlan.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFieldRange.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFieldRange2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestFieldState.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestGetObjectsById.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestIncrementalFlushes.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestIncrementalFlushesDeletes.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestInheritance.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestInitialValueFetching.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestInstanceCallbacks.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestManagedInterfaces.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestManagedInterfacesAppId.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestMultiThreaded.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestNTW.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestOpenResultsCommit.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestOptimisticLockGroups.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPCClass.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPersistenceManager.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPersistenceManagerFactoryImpl.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPersistentMaps.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPessimisticLocking.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPMMemory.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestPojoWithoutAnnotationsCannotBePersisted.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestProxies2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestQueries.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestRestoreValues.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestRetainValuesInOptimistic.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSavepointEmbedded.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSavepointEmbeddedPreFlush.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSavepointOrdering.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSavepoints.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSecondClassValues.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSecurityContext.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSequence.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSerialize.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSimple.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSpecialNumbers.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestSpecialNumbers2.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestStateManagerImplData.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestStaticInnerClasses.java</exclude>
<exclude>org/apache/openjpa/persistence/kernel/TestStoreBlob.java</exclude>
<exclude>org/apache/openjpa/persistence/meta/TestClassMetaData.java</exclude>
<exclude>org/apache/openjpa/persistence/meta/TestExternalValues.java</exclude>
<exclude>org/apache/openjpa/persistence/meta/TestFieldDeclarationOrder.java</exclude>

View File

@ -203,7 +203,8 @@ public abstract class AbstractTestCase extends PersistenceTestCase {
protected void addProperties(Map map) {
if (!map.containsKey("openjpa.jdbc.SynchronizeMappings"))
map.put("openjpa.jdbc.SynchronizeMappings",
"buildSchema(ForeignKeys=true)");
"buildSchema(ForeignKeys=true," +
"SchemaAction='add,deleteTableContents')");
}
protected OpenJPAEntityManagerFactory getEmf() {

View File

@ -81,10 +81,6 @@ public abstract class BaseKernelTest extends org.apache.openjpa.persistence.comm
return em;
}
protected OpenJPAStateManager getStateManager(Object obj,EntityManager pm) {
return getStateManager(obj,pm);
}
protected Object persist(Object ob) {
//FIXME - this is just a workaround
// Broker broker = .getBrokerFactory().newBroker();

View File

@ -480,11 +480,11 @@ public class TestDependentFields2 extends BaseKernelTest {
action = COMMIT;
} else {
try {
endTx(pm);
pm.getTransaction().commit();
fail("Committed with ref to deleted dependent object");
} catch (Exception je) {
} finally {
rollbackTx(pm);
} finally {
}
break;
}

View File

@ -159,6 +159,7 @@ public class TestEJBLobs extends AbstractTestCase {
@SuppressWarnings("serial")
@Entity
@Table(name="Inner2")
public static class Inner2 implements Serializable {
@Id

View File

@ -1,490 +0,0 @@
/*
* 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.kernel;
import java.util.List;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterface;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceEmbed;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceOwner;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceSup;
import org.apache.openjpa.persistence.kernel.common.apps.MixedInterface;
import org.apache.openjpa.persistence.kernel.common.apps.MixedInterfaceImpl;
import org.apache.openjpa.persistence.kernel.common.apps.NonMappedInterfaceImpl;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.OpenJPAQuery;
public class TestManagedInterfaces extends BaseKernelTest {
public void setUp() {
deleteAll(ManagedInterfaceSup.class);
deleteAll(ManagedInterfaceOwner.class);
deleteAll(MixedInterface.class);
deleteAll(MixedInterfaceImpl.class);
deleteAll(NonMappedInterfaceImpl.class);
deleteAll(RuntimeTest1.class);
}
public void testManagedInterface() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterface pc =
(ManagedInterface) pm.createInstance(ManagedInterface.class);
pc.setIntFieldSup(3);
pc.setIntField(4);
pc.setEmbed((ManagedInterfaceEmbed) pm
.createInstance(ManagedInterfaceEmbed.class));
pc.getEmbed().setIntField(5);
assertEquals(5, pc.getEmbed().getIntField());
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = pm.find(ManagedInterface.class, oid);
assertEquals(3, pc.getIntFieldSup());
assertEquals(4, pc.getIntField());
assertEquals(5, pc.getEmbed().getIntField());
startTx(pm);
pc.setIntField(14);
endTx(pm);
endEm(pm);
pm = getPM();
startTx(pm);
// Query query = pm.newQuery(ManagedInterface.class, "intField==14");
// Collection c = (Collection) query.execute();
OpenJPAQuery query = pm.createQuery(
"SELECT o FROM ManagedInterface o WHERE o.intField = 14");
List l = query.getResultList();
assertEquals(1, l.size());
pc = (ManagedInterface) l.iterator().next();
assertEquals(14, pc.getIntField());
pm.remove(pc);
endTx(pm);
endEm(pm);
pm = getPM();
try {
pm.find(ManagedInterface.class, oid);
fail();
} catch (Exception onfe) {
}
endEm(pm);
}
// public void testInterfaceOwner() {
// OpenJPAEntityManager pm = getPM();
// ManagedInterfaceOwner pc = new ManagedInterfaceOwner();
// pc.setIFace((ManagedInterfaceSup) pm.createInstance
// (ManagedInterfaceSup.class));
// pc.setEmbed((ManagedInterfaceEmbed) pm.createInstance
// (ManagedInterfaceEmbed.class));
// pc.getIFace().setIntFieldSup(3);
// pc.getEmbed().setIntField(5);
//
// startTx(pm);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// endTx(pm);
// pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
// assertEquals(3, pc.getIFace().getIntFieldSup());
// assertEquals(5, pc.getEmbed().getIntField());
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
// assertEquals(3, pc.getIFace().getIntFieldSup());
// assertEquals(5, pc.getEmbed().getIntField());
// endEm(pm);
//
// pm = getPM();
// startTx(pm);
// Query q = pm.newQuery(ManagedInterfaceOwner.class,
// "iface.intFieldSup==3 && embed.intField==5");
// Collection c = (Collection) q.execute();
// pc = (ManagedInterfaceOwner) c.iterator().next();
// assertEquals(3, pc.getIFace().getIntFieldSup());
// assertEquals(5, pc.getEmbed().getIntField());
//
// pc.getIFace().setIntFieldSup(13);
// pc.getEmbed().setIntField(15);
// assertEquals(13, pc.getIFace().getIntFieldSup());
// assertEquals(15, pc.getEmbed().getIntField());
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterfaceOwner) pm.getObjectById(oid, true);
// assertEquals(13, pc.getIFace().getIntFieldSup());
// assertEquals(15, pc.getEmbed().getIntField());
// endEm(pm);
// }
//
// public void testCollection() {
// OpenJPAEntityManager pm = getPM();
// startTx(pm);
// ManagedInterface pc = (ManagedInterface) pm.createInstance
// (ManagedInterface.class);
// Set set = new HashSet();
// set.add(new Integer(3));
// set.add(new Integer(4));
// set.add(new Integer(5));
// pc.setSetInteger(set);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetInteger();
// assertEquals(3, set.size());
// assertTrue(set.contains(new Integer(3)));
// assertTrue(set.contains(new Integer(4)));
// assertTrue(set.contains(new Integer(5)));
// startTx(pm);
// set.remove(new Integer(4));
// set.add(new Integer(14));
// set.add(new Integer(15));
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetInteger();
// assertEquals(4, set.size());
// assertTrue(set.contains(new Integer(3)));
// assertTrue(set.contains(new Integer(5)));
// assertTrue(set.contains(new Integer(14)));
// assertTrue(set.contains(new Integer(15)));
// startTx(pm);
// pc.setSetInteger(null);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetInteger();
// assertTrue (set == null || set.size() == 0);
// endEm(pm);
// }
//
// public void testCollectionPC() {
// OpenJPAEntityManager pm = getPM();
// startTx(pm);
// ManagedInterface pc = (ManagedInterface) pm.createInstance
// (ManagedInterface.class);
// Set set = new HashSet();
// set.add(new RuntimeTest1("a", 3));
// set.add(new RuntimeTest1("b", 4));
// set.add(new RuntimeTest1("c", 5));
// pc.setSetPC(set);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetPC();
// assertEquals(3, set.size());
// Collection seen = new ArrayList();
// RuntimeTest1 rel;
// RuntimeTest1 toRem = null;
// for (Iterator it = set.iterator(); it.hasNext();) {
// rel = (RuntimeTest1) it.next();
// seen.add(rel.getStringField());
// if (rel.getIntField() == 4)
// toRem = rel;
// }
// assertEquals(3, seen.size());
// assertTrue(seen.contains("a"));
// assertTrue(seen.contains("b"));
// assertTrue(seen.contains("c"));
// startTx(pm);
// assertNotNull(toRem);
// set.remove(toRem);
// set.add(new RuntimeTest1("x", 14));
// set.add(new RuntimeTest1("y", 15));
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetPC();
// assertEquals(4, set.size());
// seen.clear();
// for (Iterator it = set.iterator(); it.hasNext();) {
// rel = (RuntimeTest1) it.next();
// seen.add(rel.getStringField());
// }
// assertEquals(4, seen.size());
// assertTrue(seen.contains("a"));
// assertTrue(seen.contains("c"));
// assertTrue(seen.contains("x"));
// assertTrue(seen.contains("y"));
// startTx(pm);
// pc.setSetPC(null);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetPC();
// assertTrue (set == null || set.size() == 0);
// endEm(pm);
// }
//
// public void testCollectionInterfaces() {
// OpenJPAEntityManager pm = getPM();
// startTx(pm);
// ManagedInterface pc = (ManagedInterface) pm.createInstance
// (ManagedInterface.class);
// Set set = new HashSet();
// set.add(createInstance(pm, 3));
// set.add(createInstance(pm, 4));
// set.add(createInstance(pm, 5));
// pc.setSetI(set);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetI();
// assertEquals(3, set.size());
// Collection seen = new ArrayList();
// ManagedInterface rel = null;
// ManagedInterface toRem = null;
// for (Iterator it = set.iterator(); it.hasNext();) {
// rel = (ManagedInterface) it.next();
// seen.add(new Integer(rel.getIntField()));
// if (rel.getIntField() == 4)
// toRem = rel;
// }
// assertEquals(3, seen.size());
// assertTrue(seen.contains(new Integer(3)));
// assertTrue(seen.contains(new Integer(4)));
// assertTrue(seen.contains(new Integer(5)));
// startTx(pm);
// assertNotNull(toRem);
// set.remove(toRem);
// set.add(createInstance(pm, 14));
// set.add(createInstance(pm, 15));
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetI();
// assertEquals(4, set.size());
// seen.clear();
// for (Iterator it = set.iterator(); it.hasNext();) {
// rel = (ManagedInterface) it.next();
// seen.add(new Integer(rel.getIntField()));
// }
// assertEquals(4, seen.size());
// assertTrue(seen.contains(new Integer(3)));
// assertTrue(seen.contains(new Integer(5)));
// assertTrue(seen.contains(new Integer(14)));
// assertTrue(seen.contains(new Integer(15)));
// startTx(pm);
// pc.setSetPC(null);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// set = pc.getSetPC();
// assertTrue (set == null || set.size() == 0);
// endEm(pm);
// }
//
// public void testMixedQuery() {
// createMixed();
//
// OpenJPAEntityManager pm = getPM();
// Query q = pm.newQuery(MixedInterface.class, "intField==4");
// Collection c = (Collection) q.execute();
// Set seen = new HashSet();
// assertEquals(2, c.size());
// MixedInterface pc;
// for (Iterator it = c.iterator(); it.hasNext();) {
// pc = (MixedInterface) it.next();
// assertEquals(4, pc.getIntField());
// seen.add(pc.getClass());
// }
// assertEquals(2, seen.size());
// endEm(pm);
// }
//
// public void testMixedExtent() {
// createMixed();
//
// OpenJPAEntityManager pm = getPM();
// Extent e = pm.getExtent(MixedInterface.class, true);
// Set seen = new HashSet();
// int size = 0;
// for (Iterator it = e.iterator(); it.hasNext();) {
// seen.add(it.next().getClass());
// size++;
// }
// assertEquals(3, size);
// assertEquals(2, seen.size());
//
// e = pm.getExtent(MixedInterface.class, false);
// seen = new HashSet();
// size = 0;
// for (Iterator it = e.iterator(); it.hasNext();) {
// seen.add(it.next().getClass());
// size++;
// }
// assertEquals(1, size);
// assertNotEquals(MixedInterfaceImpl.class, seen.iterator().next());
// endEm(pm);
// }
//
// private void createMixed() {
// OpenJPAEntityManager pm = getPM();
// startTx(pm);
// MixedInterface pc = (MixedInterface) pm.createInstance
// (MixedInterface.class);
// pc.setIntField(4);
// pm.persist(pc);
// pc = new MixedInterfaceImpl();
// pc.setIntField(4);
// pm.persist(pc);
// pc = new MixedInterfaceImpl();
// pc.setIntField(8);
// pm.persist(pc);
// endTx(pm);
// endEm(pm);
// }
//
// public void testUnimplementedThrowsException() {
// OpenJPAEntityManager pm = getPM();
// ManagedInterface pc = createInstance(pm, 1);
// try {
// pc.unimplemented();
// fail("Exception expected.");
// } catch (JDOUserException jdoe) {} // good
// endEm(pm);
// }
//
// public void testNonMappedcreateInstanceException() {
// OpenJPAEntityManager pm = getPM();
// try {
// pm.createInstance(NonMappedInterface.class);
// fail("Exception expected");
// } catch (JDOUserException jdoe) {} // good
// endEm(pm);
// }
//
// public void testNonMappedPropertyAlias()
// throws Exception {
// Object oid = createNonMappedImpl();
// OpenJPAEntityManager pm = getPM();
// Query q = pm.newQuery(NonMappedInterface.class, "intField==4");
// Collection c = (Collection) q.execute();
// assertEquals(1, c.size());
// assertEquals(oid, pm.getObjectId(c.iterator().next()));
// endEm(pm);
// }
//
// public void testNonMappedPropertyAliasInMemory()
// throws Exception {
// Object oid = createNonMappedImpl();
// OpenJPAEntityManager pm = getPM();
// Query q = pm.newQuery(NonMappedInterface.class, "intField==4");
// q.setCandidates((Collection) pm.newQuery(NonMappedInterfaceImpl.class).
// execute());
// Collection c = (Collection) q.execute();
// assertEquals(1, c.size());
// assertEquals(oid, pm.getObjectId(c.iterator().next()));
// endEm(pm);
// }
//
// private Object createNonMappedImpl()
// throws Exception {
// // load non-mapped-impl
// Class.forName(NonMappedInterfaceImpl.class.getNametrue,
// NonMappedInterfaceImpl.class.getClassLoader());
//
//
// OpenJPAEntityManager pm = getPM();
// startTx(pm);
// NonMappedInterface pc = new NonMappedInterfaceImpl();
// pc.setIntField(4);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// pc = new NonMappedInterfaceImpl();
// pc.setIntField(8);
// pm.persist(pc);
// endTx(pm);
// endEm(pm);
// return oid;
// }
//
// public void testDetach() {
// KodoOpenJPAEntityManager pm = getPM();
// startTx(pm);
// ManagedInterface pc = createInstance(pm, 4);
// pm.persist(pc);
// Object oid = pm.getObjectId(pc);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// ManagedInterface pcx = (ManagedInterface) pm.getObjectById(oid, true);
// pc = (ManagedInterface) pm.detachCopy(pcx);
// endEm(pm);
//
// assertTrue(pm.isDetached(pc));
// pc.setIntField(7);
//
// pm = getPM();
// startTx(pm);
// pm.persist(pc);
// endTx(pm);
// endEm(pm);
//
// pm = getPM();
// pc = (ManagedInterface) pm.getObjectById(oid, true);
// assertEquals(7, pc.getIntField());
// endEm(pm);
//
// }
private ManagedInterface createInstance(OpenJPAEntityManager pm, int i) {
ManagedInterface pc = (ManagedInterface) pm.createInstance
(ManagedInterface.class);
pc.setIntField(i);
return pc;
}
}

View File

@ -1,399 +0,0 @@
/*
* TestManagedInterfacesAppId.java
*
* Created on October 16, 2006, 4:49 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/*
* 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.kernel;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceAppId;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceEmbed;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceOwnerAppId;
import org.apache.openjpa.persistence.kernel.common.apps.ManagedInterfaceSupAppId;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
import org.apache.openjpa.persistence.OpenJPAQuery;
public class TestManagedInterfacesAppId extends BaseKernelTest {
/**
* Creates a new instance of TestManagedInterfacesAppId
*/
public TestManagedInterfacesAppId(String name) {
super(name);
}
public void setUp() {
deleteAll(ManagedInterfaceSupAppId.class);
deleteAll(ManagedInterfaceOwnerAppId.class);
deleteAll(RuntimeTest1.class);
}
public void testManagedInterface() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance(
(ManagedInterfaceAppId.class));
pc.setId1(9);
pc.setId2(19);
pc.setIntFieldSup(3);
pc.setIntField(4);
pc.setEmbed((ManagedInterfaceEmbed) pm.createInstance
(ManagedInterfaceEmbed.class));
pc.getEmbed().setIntField(5);
assertEquals(5, pc.getEmbed().getIntField());
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
assertEquals(9, pc.getId1());
assertEquals(19, pc.getId2());
assertEquals(3, pc.getIntFieldSup());
assertEquals(4, pc.getIntField());
assertEquals(5, pc.getEmbed().getIntField());
startTx(pm);
pc.setIntField(14);
endTx(pm);
endEm(pm);
pm = getPM();
Object newId = new ManagedInterfaceSupAppId.Id("9,19");
pc =
(ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, newId);
assertEquals(9, pc.getId1());
assertEquals(19, pc.getId2());
assertEquals(3, pc.getIntFieldSup());
assertEquals(14, pc.getIntField());
assertEquals(5, pc.getEmbed().getIntField());
endEm(pm);
pm = getPM();
startTx(pm);
OpenJPAQuery query =
pm.createNativeQuery("intField==14", ManagedInterfaceAppId.class);
Collection c = (Collection) query.getResultList();
assertEquals(1, c.size());
pc = (ManagedInterfaceAppId) c.iterator().next();
assertEquals(14, pc.getIntField());
pm.remove(pc);
endTx(pm);
endEm(pm);
pm = getPM();
try {
pm.find(ManagedInterfaceAppId.class, oid);
fail();
} catch (Exception onfe) {
}
endEm(pm);
}
public void testInterfaceOwner() {
OpenJPAEntityManager pm = getPM();
ManagedInterfaceOwnerAppId pc = new ManagedInterfaceOwnerAppId();
pc.setIFace((ManagedInterfaceSupAppId) pm.createInstance
(ManagedInterfaceSupAppId.class));
pc.getIFace().setIntFieldSup(3);
startTx(pm);
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
pc = (ManagedInterfaceOwnerAppId) pm
.find(ManagedInterfaceOwnerAppId.class, oid);
assertEquals(3, pc.getIFace().getIntFieldSup());
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceOwnerAppId) pm
.find(ManagedInterfaceOwnerAppId.class, oid);
assertEquals(3, pc.getIFace().getIntFieldSup());
endEm(pm);
pm = getPM();
startTx(pm);
OpenJPAQuery q = pm.createNativeQuery("iface.intFieldSup==3",
ManagedInterfaceOwnerAppId.class);
Collection c = (Collection) q.getResultList();
pc = (ManagedInterfaceOwnerAppId) c.iterator().next();
assertEquals(3, pc.getIFace().getIntFieldSup());
pc.getIFace().setIntFieldSup(13);
assertEquals(13, pc.getIFace().getIntFieldSup());
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceOwnerAppId) pm
.find(ManagedInterfaceOwnerAppId.class, oid);
assertEquals(13, pc.getIFace().getIntFieldSup());
endEm(pm);
}
public void testCollection() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
(ManagedInterfaceAppId.class);
Set set = new HashSet();
set.add(new Integer(3));
set.add(new Integer(4));
set.add(new Integer(5));
pc.setSetInteger(set);
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetInteger();
assertEquals(3, set.size());
assertTrue(set.contains(new Integer(3)));
assertTrue(set.contains(new Integer(4)));
assertTrue(set.contains(new Integer(5)));
startTx(pm);
set.remove(new Integer(4));
set.add(new Integer(14));
set.add(new Integer(15));
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetInteger();
assertEquals(4, set.size());
assertTrue(set.contains(new Integer(3)));
assertTrue(set.contains(new Integer(5)));
assertTrue(set.contains(new Integer(14)));
assertTrue(set.contains(new Integer(15)));
startTx(pm);
pc.setSetInteger(null);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetInteger();
assertTrue(set == null || set.size() == 0);
endEm(pm);
}
public void testCollectionPC() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
(ManagedInterfaceAppId.class);
Set set = new HashSet();
set.add(new RuntimeTest1("a", 3));
set.add(new RuntimeTest1("b", 4));
set.add(new RuntimeTest1("c", 5));
pc.setSetPC(set);
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetPC();
assertEquals(3, set.size());
Collection seen = new ArrayList();
RuntimeTest1 rel;
RuntimeTest1 toRem = null;
for (Iterator it = set.iterator(); it.hasNext();) {
rel = (RuntimeTest1) it.next();
seen.add(rel.getStringField());
if (rel.getIntField() == 4)
toRem = rel;
}
assertEquals(3, seen.size());
assertTrue(seen.contains("a"));
assertTrue(seen.contains("b"));
assertTrue(seen.contains("c"));
startTx(pm);
assertNotNull(toRem);
set.remove(toRem);
set.add(new RuntimeTest1("x", 14));
set.add(new RuntimeTest1("y", 15));
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetPC();
assertEquals(4, set.size());
seen.clear();
for (Iterator it = set.iterator(); it.hasNext();) {
rel = (RuntimeTest1) it.next();
seen.add(rel.getStringField());
}
assertEquals(4, seen.size());
assertTrue(seen.contains("a"));
assertTrue(seen.contains("c"));
assertTrue(seen.contains("x"));
assertTrue(seen.contains("y"));
startTx(pm);
pc.setSetPC(null);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetPC();
assertTrue(set == null || set.size() == 0);
endEm(pm);
}
public void testCollectionInterfaces() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm.createInstance
(ManagedInterfaceAppId.class);
Set set = new HashSet();
set.add(createInstance(pm, 3));
set.add(createInstance(pm, 4));
set.add(createInstance(pm, 5));
pc.setSetI(set);
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetI();
assertEquals(3, set.size());
Collection seen = new ArrayList();
ManagedInterfaceAppId rel = null;
ManagedInterfaceAppId toRem = null;
for (Iterator it = set.iterator(); it.hasNext();) {
rel = (ManagedInterfaceAppId) it.next();
seen.add(new Integer(rel.getIntField()));
if (rel.getIntField() == 4)
toRem = rel;
}
assertEquals(3, seen.size());
assertTrue(seen.contains(new Integer(3)));
assertTrue(seen.contains(new Integer(4)));
assertTrue(seen.contains(new Integer(5)));
startTx(pm);
assertNotNull(toRem);
set.remove(toRem);
set.add(createInstance(pm, 14));
set.add(createInstance(pm, 15));
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetI();
assertEquals(4, set.size());
seen.clear();
for (Iterator it = set.iterator(); it.hasNext();) {
rel = (ManagedInterfaceAppId) it.next();
seen.add(new Integer(rel.getIntField()));
}
assertEquals(4, seen.size());
assertTrue(seen.contains(new Integer(3)));
assertTrue(seen.contains(new Integer(5)));
assertTrue(seen.contains(new Integer(14)));
assertTrue(seen.contains(new Integer(15)));
startTx(pm);
pc.setSetPC(null);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
set = pc.getSetPC();
assertTrue(set == null || set.size() == 0);
endEm(pm);
}
public void testUnimplementedThrowsException() {
OpenJPAEntityManager pm = getPM();
ManagedInterfaceAppId pc = createInstance(pm, 1);
try {
pc.unimplemented();
fail("Exception expected.");
} catch (Exception jdoe) {
} // good
endEm(pm);
}
public void testDetach() {
OpenJPAEntityManager pm = getPM();
startTx(pm);
ManagedInterfaceAppId pc = createInstance(pm, 4);
pm.persist(pc);
Object oid = pm.getObjectId(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
pc = (ManagedInterfaceAppId) pm.detach(pc);
endEm(pm);
assertTrue(pm.isDetached(pc));
pc.setIntField(7);
pm = getPM();
startTx(pm);
pm.persist(pc);
endTx(pm);
endEm(pm);
pm = getPM();
pc = (ManagedInterfaceAppId) pm.find(ManagedInterfaceAppId.class, oid);
assertEquals(7, pc.getIntField());
endEm(pm);
}
private ManagedInterfaceAppId createInstance(OpenJPAEntityManager pm,
int i) {
ManagedInterfaceAppId pc = (ManagedInterfaceAppId) pm
.createInstance(ManagedInterfaceAppId.class);
pc.setId1(i * 10);
pc.setId2(i * -10);
pc.setIntField(i);
return pc;
}
}

View File

@ -192,7 +192,7 @@ public class TestPersistenceManagerFactoryImpl extends BaseKernelTest {
protected OpenJPAEntityManagerFactory getEmf(Map props) {
props.put("openjpa.BrokerFactory", BrokerFactoryTest.class.getName());
return (OpenJPAEntityManagerFactory) getEmf(props);
return (OpenJPAEntityManagerFactory) super.getEmf(props);
}
public static class BrokerFactoryTest extends AbstractBrokerFactory {

View File

@ -67,6 +67,12 @@ public class TestRetainValuesInOptimistic extends BaseKernelTest {
endEm(pm);
}
@Override
protected void addProperties(Map map) {
super.addProperties(map);
map.put("openjpa.Log", "SQL=TRACE, Runtime=TRACE");
}
public void testRetain() {
clearTest(true);
optLockTest(true);

View File

@ -62,14 +62,14 @@ public class TestSpecialNumbers extends BaseKernelTest {
public void testShortMax() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestshort(Short.MAX_VALUE);
saveAndQuery(aftt, "testshort == param", new Short(Short.MAX_VALUE));
saveAndQuery(aftt, "testshort = :param", new Short(Short.MAX_VALUE));
}
public void testShortMin() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestshort(Short.MIN_VALUE);
try {
saveAndQuery(aftt, "testshort == param",
saveAndQuery(aftt, "testshort = :param",
new Short(Short.MIN_VALUE));
} catch (Throwable t) {
bug(AbstractTestCase.Platform.EMPRESS, 889, t,
@ -80,14 +80,14 @@ public class TestSpecialNumbers extends BaseKernelTest {
public void testLongMax() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestlong(Long.MAX_VALUE);
saveAndQuery(aftt, "testlong == param", new Long(Long.MAX_VALUE));
saveAndQuery(aftt, "testlong = :param", new Long(Long.MAX_VALUE));
}
public void testLongMin() {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestlong(Long.MIN_VALUE);
saveAndQuery(aftt, "testlong == param", new Long(Long.MIN_VALUE));
saveAndQuery(aftt, "testlong = :param", new Long(Long.MIN_VALUE));
} catch (Throwable t) {
bug(AbstractTestCase.Platform.HYPERSONIC, 474, t,
"Some databases cannot store Long.MIN_VALUE");
@ -97,7 +97,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
public void testIntegerMax() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestint(Integer.MAX_VALUE);
saveAndQuery(aftt, "testint == param",
saveAndQuery(aftt, "testint = :param",
new Integer(Integer.MAX_VALUE));
}
@ -105,7 +105,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestint(Integer.MIN_VALUE);
try {
saveAndQuery(aftt, "testint == param",
saveAndQuery(aftt, "testint = :param",
new Integer(Integer.MIN_VALUE));
} catch (Throwable t) {
bug(AbstractTestCase.Platform.EMPRESS, 889, t,
@ -117,7 +117,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestfloat(Float.MAX_VALUE);
saveAndQuery(aftt, "testfloat == param",
saveAndQuery(aftt, "testfloat = :param",
new Float(Float.MAX_VALUE));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
@ -132,7 +132,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestfloat(Float.MIN_VALUE);
saveAndQuery(aftt, "testfloat == param",
saveAndQuery(aftt, "testfloat = :param",
new Float(Float.MIN_VALUE));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
@ -152,7 +152,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestfloat(Float.NaN);
saveAndQuery(aftt, "testfloat == param", new Float(Float.NaN));
saveAndQuery(aftt, "testfloat = :param", new Float(Float.NaN));
} catch (Throwable t) {
bug(461, t, "NaN problems");
}
@ -162,7 +162,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestfloat(Float.NEGATIVE_INFINITY);
saveAndQuery(aftt, "testfloat == param",
saveAndQuery(aftt, "testfloat = :param",
new Float(Float.NEGATIVE_INFINITY));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
@ -181,7 +181,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestfloat(Float.POSITIVE_INFINITY);
saveAndQuery(aftt, "testfloat == param",
saveAndQuery(aftt, "testfloat = :param",
new Float(Float.POSITIVE_INFINITY));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
@ -200,7 +200,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestdouble(Double.MAX_VALUE);
saveAndQuery(aftt, "testdouble == param",
saveAndQuery(aftt, "testdouble = :param",
new Double(Double.MAX_VALUE));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POINTBASE,
@ -219,7 +219,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestdouble(Double.MIN_VALUE);
saveAndQuery(aftt, "testdouble == param",
saveAndQuery(aftt, "testdouble = :param",
new Double(Double.MIN_VALUE));
} catch (Exception e) {
bug(EnumSet.of(AbstractTestCase.Platform.POSTGRESQL,
@ -240,7 +240,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestdouble(Double.NaN);
saveAndQuery(aftt, "testdouble == param", new Double(Double.NaN));
saveAndQuery(aftt, "testdouble = :param", new Double(Double.NaN));
} catch (Throwable t) {
bug(461, t, "NaN problems");
}
@ -250,7 +250,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestdouble(Double.NEGATIVE_INFINITY);
saveAndQuery(aftt, "testdouble == param",
saveAndQuery(aftt, "testdouble = :param",
new Double(Double.NEGATIVE_INFINITY));
} catch (Throwable t) {
bug(461, t, "infinity problems");
@ -261,7 +261,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
try {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestdouble(Double.POSITIVE_INFINITY);
saveAndQuery(aftt, "testdouble == param",
saveAndQuery(aftt, "testdouble = :param",
new Double(Double.POSITIVE_INFINITY));
} catch (Throwable t) {
bug(461, t, "infinity problems");
@ -272,7 +272,7 @@ public class TestSpecialNumbers extends BaseKernelTest {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestbyte(Byte.MIN_VALUE);
try {
saveAndQuery(aftt, "testbyte == param", new Byte(Byte.MIN_VALUE));
saveAndQuery(aftt, "testbyte = :param", new Byte(Byte.MIN_VALUE));
} catch (Throwable t) {
bug(AbstractTestCase.Platform.EMPRESS, 889, t,
"Empress cannot store min values");
@ -282,19 +282,19 @@ public class TestSpecialNumbers extends BaseKernelTest {
public void testByteMax() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestbyte(Byte.MAX_VALUE);
saveAndQuery(aftt, "testbyte == param", new Byte(Byte.MAX_VALUE));
saveAndQuery(aftt, "testbyte = :param", new Byte(Byte.MAX_VALUE));
}
public void testZeroBigInteger() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestBigInteger(BigInteger.ZERO);
saveAndQuery(aftt, "testBigInteger == param", BigInteger.ZERO);
saveAndQuery(aftt, "testBigInteger = :param", BigInteger.ZERO);
}
public void testOneBigInteger() {
AllFieldTypesTest aftt = new AllFieldTypesTest();
aftt.setTestBigInteger(BigInteger.ONE);
saveAndQuery(aftt, "testBigInteger == param", BigInteger.ONE);
saveAndQuery(aftt, "testBigInteger = :param", BigInteger.ONE);
}
private void saveAndQuery(Object obj, String query, Object param) {
@ -305,9 +305,9 @@ public class TestSpecialNumbers extends BaseKernelTest {
endEm(pm);
pm = getPM();
OpenJPAQuery q = pm.createNativeQuery(query, obj.getClass());
//FIXME jthomas
//q.declareParameters("Object param");
OpenJPAQuery q = pm.createQuery("select o from "
+ obj.getClass().getName() + " o where " + query);
q.setParameter("param", param);
Collection c = (Collection) q.getResultList();
assertSize(1, c);
endEm(pm);

View File

@ -30,7 +30,7 @@ package org.apache.openjpa.persistence.kernel;
import java.util.LinkedList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Table;
import org.apache.openjpa.persistence.OpenJPAEntityManager;
@ -116,6 +116,7 @@ public class TestStaticInnerClasses extends BaseKernelTest {
}
@Entity
@Table(name="StaticInner")
public static class Inner {
private int num = 0;

View File

@ -24,6 +24,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Column;
@Entity
@Table(name = "nullvalue")
@ -31,8 +32,11 @@ public class Inner {
@Basic
private Integer none = null;
@Basic(optional = false)
@Column(name="exception_col")
private Integer exception = null;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int Id;

View File

@ -29,6 +29,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Column;
import org.apache.openjpa.persistence.FetchAttribute;
import org.apache.openjpa.persistence.FetchGroup;
@ -63,6 +64,7 @@ public class PCDirectory {
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
@Column(name="name_col")
private String _name;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)

View File

@ -26,10 +26,12 @@ import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Column;
@Entity
public class PCFile {
@Column(name="name_col")
private String _name;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)