mirror of https://github.com/apache/openjpa.git
OPENJPA-1639 Create some simple openjpa-xmlstore tests
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@936851 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f35802f702
commit
fdb539d972
|
@ -69,7 +69,7 @@
|
|||
</executions>
|
||||
</plugin>
|
||||
|
||||
<!-- new way of using openjpa-maven-plugin to enhance classes
|
||||
<!-- new way of using openjpa-maven-plugin to enhance classes -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>openjpa-maven-plugin</artifactId>
|
||||
|
@ -92,7 +92,8 @@
|
|||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.openjpa</groupId>
|
||||
<artifactId>openjpa-all</artifactId>
|
||||
<!-- use o-p-j instead of openjpa to avoid cyclical dependency in maven graph -->
|
||||
<artifactId>openjpa-persistence-jdbc</artifactId>
|
||||
<version>${pom.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -119,7 +120,6 @@
|
|||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
-->
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
|
|
@ -0,0 +1,368 @@
|
|||
/*
|
||||
* 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.xmlstore.simple;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
import org.apache.openjpa.persistence.PersistentCollection;
|
||||
|
||||
@Entity
|
||||
public class AllFieldTypes implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static enum EnumType {Value1, Value2};
|
||||
|
||||
// @Basic types
|
||||
private short shortField;
|
||||
private int intField;
|
||||
private boolean booleanField;
|
||||
private long longField;
|
||||
private float floatField;
|
||||
private char charField;
|
||||
private double doubleField;
|
||||
private byte byteField;
|
||||
private Short wShortField;
|
||||
private Integer wIntegerField;
|
||||
private Boolean wBooleanField;
|
||||
private Long wLongField;
|
||||
private Float wFloatField;
|
||||
private Character wCharacterField;
|
||||
private Double wDoubleField;
|
||||
private Byte wByteField;
|
||||
private BigInteger bigIntegerField;
|
||||
private BigDecimal bigDecimalField;
|
||||
private String stringField;
|
||||
private Date dateField;
|
||||
private Calendar calendarField;
|
||||
private java.sql.Date sqlDateField;
|
||||
private java.sql.Time sqlTimeField;
|
||||
private java.sql.Timestamp sqlTimestampField;
|
||||
private byte[] byteLob;
|
||||
private Byte[] wByteLob;
|
||||
private char[] charLob;
|
||||
private Character[] wCharacterLob;
|
||||
private EnumType enumField;
|
||||
private Serializable serializableField;
|
||||
|
||||
// Additional types
|
||||
private Set<String> setOfStrings = new HashSet<String>();
|
||||
private String[] arrayOfStrings;
|
||||
|
||||
@PersistentCollection
|
||||
private int[] arrayOfInts;
|
||||
|
||||
// one-to-one and one-to-many relations to self
|
||||
@OneToOne
|
||||
private AllFieldTypes selfOneOne;
|
||||
@OneToMany
|
||||
private List<AllFieldTypes> selfOneMany = new ArrayList<AllFieldTypes>();
|
||||
|
||||
public void setShortField(short shortField) {
|
||||
this.shortField = shortField;
|
||||
}
|
||||
|
||||
public short getShortField() {
|
||||
return this.shortField;
|
||||
}
|
||||
|
||||
public void setIntField(int intField) {
|
||||
this.intField = intField;
|
||||
}
|
||||
|
||||
public int getIntField() {
|
||||
return this.intField;
|
||||
}
|
||||
|
||||
public void setBooleanField(boolean booleanField) {
|
||||
this.booleanField = booleanField;
|
||||
}
|
||||
|
||||
public boolean getBooleanField() {
|
||||
return this.booleanField;
|
||||
}
|
||||
|
||||
public void setLongField(long longField) {
|
||||
this.longField = longField;
|
||||
}
|
||||
|
||||
public long getLongField() {
|
||||
return this.longField;
|
||||
}
|
||||
|
||||
public void setFloatField(float floatField) {
|
||||
this.floatField = floatField;
|
||||
}
|
||||
|
||||
public float getFloatField() {
|
||||
return this.floatField;
|
||||
}
|
||||
|
||||
public void setCharField(char charField) {
|
||||
this.charField = charField;
|
||||
}
|
||||
|
||||
public char getCharField() {
|
||||
return this.charField;
|
||||
}
|
||||
|
||||
public void setDoubleField(double doubleField) {
|
||||
this.doubleField = doubleField;
|
||||
}
|
||||
|
||||
public double getDoubleField() {
|
||||
return this.doubleField;
|
||||
}
|
||||
|
||||
public void setByteField(byte byteField) {
|
||||
this.byteField = byteField;
|
||||
}
|
||||
|
||||
public byte getByteField() {
|
||||
return this.byteField;
|
||||
}
|
||||
|
||||
public void setStringField(String stringField) {
|
||||
this.stringField = stringField;
|
||||
}
|
||||
|
||||
public String getStringField() {
|
||||
return this.stringField;
|
||||
}
|
||||
|
||||
public void setDateField(Date dateField) {
|
||||
this.dateField = dateField;
|
||||
}
|
||||
|
||||
public Date getDateField() {
|
||||
return this.dateField;
|
||||
}
|
||||
|
||||
public void setSetOfStrings(Set<String> setOfStrings) {
|
||||
this.setOfStrings = setOfStrings;
|
||||
}
|
||||
|
||||
public Set<String> getSetOfStrings() {
|
||||
return this.setOfStrings;
|
||||
}
|
||||
|
||||
public void setArrayOfStrings(String[] arrayOfStrings) {
|
||||
this.arrayOfStrings = arrayOfStrings;
|
||||
}
|
||||
|
||||
public String[] getArrayOfStrings() {
|
||||
return this.arrayOfStrings;
|
||||
}
|
||||
|
||||
public void setArrayOfInts(int[] arrayOfInts) {
|
||||
this.arrayOfInts = arrayOfInts;
|
||||
}
|
||||
|
||||
public int[] getArrayOfInts() {
|
||||
return arrayOfInts;
|
||||
}
|
||||
|
||||
public BigDecimal getBigDecimalField() {
|
||||
return bigDecimalField;
|
||||
}
|
||||
|
||||
public void setBigDecimalField(BigDecimal bigDecimalField) {
|
||||
this.bigDecimalField = bigDecimalField;
|
||||
}
|
||||
|
||||
public BigInteger getBigIntegerField() {
|
||||
return bigIntegerField;
|
||||
}
|
||||
|
||||
public void setBigIntegerField(BigInteger bigIntegerField) {
|
||||
this.bigIntegerField = bigIntegerField;
|
||||
}
|
||||
|
||||
public byte[] getByteLob() {
|
||||
return byteLob;
|
||||
}
|
||||
|
||||
public void setByteLob(byte[] byteLob) {
|
||||
this.byteLob = byteLob;
|
||||
}
|
||||
|
||||
public Calendar getCalendarField() {
|
||||
return calendarField;
|
||||
}
|
||||
|
||||
public void setCalendarField(Calendar calendarField) {
|
||||
this.calendarField = calendarField;
|
||||
}
|
||||
|
||||
public char[] getCharLob() {
|
||||
return charLob;
|
||||
}
|
||||
|
||||
public void setCharLob(char[] charLob) {
|
||||
this.charLob = charLob;
|
||||
}
|
||||
|
||||
public EnumType getEnumField() {
|
||||
return enumField;
|
||||
}
|
||||
|
||||
public void setEnumField(EnumType enumField) {
|
||||
this.enumField = enumField;
|
||||
}
|
||||
|
||||
public Serializable getSerializableField() {
|
||||
return serializableField;
|
||||
}
|
||||
|
||||
public void setSerializableField(Serializable serializableField) {
|
||||
this.serializableField = serializableField;
|
||||
}
|
||||
|
||||
public java.sql.Date getSqlDateField() {
|
||||
return sqlDateField;
|
||||
}
|
||||
|
||||
public void setSqlDateField(java.sql.Date sqlDateField) {
|
||||
this.sqlDateField = sqlDateField;
|
||||
}
|
||||
|
||||
public java.sql.Time getSqlTimeField() {
|
||||
return sqlTimeField;
|
||||
}
|
||||
|
||||
public void setSqlTimeField(java.sql.Time sqlTimeField) {
|
||||
this.sqlTimeField = sqlTimeField;
|
||||
}
|
||||
|
||||
public java.sql.Timestamp getSqlTimestampField() {
|
||||
return sqlTimestampField;
|
||||
}
|
||||
|
||||
public void setSqlTimestampField(java.sql.Timestamp sqlTimestampField) {
|
||||
this.sqlTimestampField = sqlTimestampField;
|
||||
}
|
||||
|
||||
public Boolean getWBooleanField() {
|
||||
return wBooleanField;
|
||||
}
|
||||
|
||||
public void setWBooleanField(Boolean booleanField) {
|
||||
wBooleanField = booleanField;
|
||||
}
|
||||
|
||||
public Byte getWByteField() {
|
||||
return wByteField;
|
||||
}
|
||||
|
||||
public void setWByteField(Byte byteField) {
|
||||
wByteField = byteField;
|
||||
}
|
||||
|
||||
public Byte[] getWByteLob() {
|
||||
return wByteLob;
|
||||
}
|
||||
|
||||
public void setWByteLob(Byte[] byteLob) {
|
||||
wByteLob = byteLob;
|
||||
}
|
||||
|
||||
public Character getWCharacterField() {
|
||||
return wCharacterField;
|
||||
}
|
||||
|
||||
public void setWCharacterField(Character characterField) {
|
||||
wCharacterField = characterField;
|
||||
}
|
||||
|
||||
public Character[] getWCharacterLob() {
|
||||
return wCharacterLob;
|
||||
}
|
||||
|
||||
public void setWCharacterLob(Character[] characterLob) {
|
||||
wCharacterLob = characterLob;
|
||||
}
|
||||
|
||||
public Double getWDoubleField() {
|
||||
return wDoubleField;
|
||||
}
|
||||
|
||||
public void setWDoubleField(Double doubleField) {
|
||||
wDoubleField = doubleField;
|
||||
}
|
||||
|
||||
public Float getWFloatField() {
|
||||
return wFloatField;
|
||||
}
|
||||
|
||||
public void setWFloatField(Float floatField) {
|
||||
wFloatField = floatField;
|
||||
}
|
||||
|
||||
public Integer getWIntegerField() {
|
||||
return wIntegerField;
|
||||
}
|
||||
|
||||
public void setWIntegerField(Integer integerField) {
|
||||
wIntegerField = integerField;
|
||||
}
|
||||
|
||||
public Long getWLongField() {
|
||||
return wLongField;
|
||||
}
|
||||
|
||||
public void setWLongField(Long longField) {
|
||||
wLongField = longField;
|
||||
}
|
||||
|
||||
public Short getWShortField() {
|
||||
return wShortField;
|
||||
}
|
||||
|
||||
public void setWShortField(Short shortField) {
|
||||
wShortField = shortField;
|
||||
}
|
||||
|
||||
public AllFieldTypes getSelfOneOne() {
|
||||
return selfOneOne;
|
||||
}
|
||||
|
||||
public void setSelfOneOne(AllFieldTypes selfOneOne) {
|
||||
this.selfOneOne = selfOneOne;
|
||||
}
|
||||
|
||||
public List<AllFieldTypes> getSelfOneMany() {
|
||||
return selfOneMany;
|
||||
}
|
||||
|
||||
public void setSelfOneMany(List<AllFieldTypes> selfOneMany) {
|
||||
this.selfOneMany = selfOneMany;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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.xmlstore.simple;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Place implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String location;
|
||||
|
||||
@Id
|
||||
public String getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(String location) {
|
||||
this.location = location;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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.xmlstore.simple;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityTransaction;
|
||||
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManager;
|
||||
import org.apache.openjpa.persistence.OpenJPAEntityManagerFactorySPI;
|
||||
import org.apache.openjpa.persistence.test.AbstractPersistenceTestCase;
|
||||
|
||||
/**
|
||||
* Simple XMLStore test case to get an EntityManager and perform some basic operations.
|
||||
*/
|
||||
public class TestPersistence extends AbstractPersistenceTestCase {
|
||||
|
||||
public void testCreateEntityManager() {
|
||||
OpenJPAEntityManagerFactorySPI emf = createNamedEMF("xmlstore-simple");
|
||||
try {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
EntityTransaction t = em.getTransaction();
|
||||
assertNotNull(t);
|
||||
t.begin();
|
||||
t.setRollbackOnly();
|
||||
t.rollback();
|
||||
|
||||
// openjpa-facade test
|
||||
assertTrue(em instanceof OpenJPAEntityManager);
|
||||
OpenJPAEntityManager ojem = (OpenJPAEntityManager) em;
|
||||
ojem.getFetchPlan().setMaxFetchDepth(1);
|
||||
assertEquals(1, ojem.getFetchPlan().getMaxFetchDepth());
|
||||
em.close();
|
||||
} finally {
|
||||
closeEMF(emf);
|
||||
}
|
||||
}
|
||||
|
||||
public void testQuery() {
|
||||
OpenJPAEntityManagerFactorySPI emf = createNamedEMF("xmlstore-simple",
|
||||
CLEAR_TABLES, AllFieldTypes.class);
|
||||
try {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
AllFieldTypes aft = new AllFieldTypes();
|
||||
aft.setStringField("foo");
|
||||
aft.setIntField(10);
|
||||
em.persist(aft);
|
||||
em.getTransaction().commit();
|
||||
em.close();
|
||||
|
||||
em = emf.createEntityManager();
|
||||
em.getTransaction().begin();
|
||||
assertEquals(1, em.createQuery
|
||||
("select x from AllFieldTypes x where x.stringField = 'foo'").
|
||||
getResultList().size());
|
||||
assertEquals(0, em.createQuery
|
||||
("select x from AllFieldTypes x where x.stringField = 'bar'").
|
||||
getResultList().size());
|
||||
assertEquals(1, em.createQuery
|
||||
("select x from AllFieldTypes x where x.intField >= 10").
|
||||
getResultList().size());
|
||||
em.getTransaction().rollback();
|
||||
em.close();
|
||||
} finally {
|
||||
closeEMF(emf);
|
||||
}
|
||||
}
|
||||
|
||||
public void testNewDeleteNew() {
|
||||
OpenJPAEntityManagerFactorySPI emf = createNamedEMF("xmlstore-simple",
|
||||
CLEAR_TABLES, Place.class);
|
||||
try {
|
||||
EntityManager em = emf.createEntityManager();
|
||||
|
||||
// create new
|
||||
Place place = new Place();
|
||||
place.setLocation("Lexington");
|
||||
assertFalse(em.contains(place));
|
||||
em.getTransaction().begin();
|
||||
em.persist(place);
|
||||
em.getTransaction().commit();
|
||||
assertTrue(em.contains(place));
|
||||
|
||||
// find and verify
|
||||
place = em.find(Place.class, "Lexington");
|
||||
assertNotNull(place);
|
||||
assertEquals("Lexington", place.getLocation());
|
||||
|
||||
// delete
|
||||
em.getTransaction().begin();
|
||||
em.remove(place);
|
||||
em.getTransaction().commit();
|
||||
assertFalse(em.contains(place));
|
||||
|
||||
// recreate
|
||||
place = new Place();
|
||||
place.setLocation("Lexington");
|
||||
assertFalse(em.contains(place));
|
||||
em.getTransaction().begin();
|
||||
em.persist(place);
|
||||
em.getTransaction().commit();
|
||||
assertTrue(em.contains(place));
|
||||
|
||||
// find and verify
|
||||
place = em.find(Place.class, "Lexington");
|
||||
assertNotNull(place);
|
||||
assertEquals("Lexington", place.getLocation());
|
||||
em.close();
|
||||
} finally {
|
||||
closeEMF(emf);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
version="2.0">
|
||||
|
||||
<persistence-unit name="xmlstore-simple">
|
||||
<class>org.apache.openjpa.xmlstore.simple.AllFieldTypes</class>
|
||||
<class>org.apache.openjpa.xmlstore.simple.Place</class>
|
||||
<properties>
|
||||
<property name="openjpa.ConnectionURL"
|
||||
value="target/openjpa-xmlstore-db" />
|
||||
<property name="openjpa.BrokerFactory"
|
||||
value="org.apache.openjpa.abstractstore.AbstractStoreBrokerFactory" />
|
||||
<property name="openjpa.abstractstore.AbstractStoreManager"
|
||||
value="org.apache.openjpa.xmlstore.XMLStoreManager" />
|
||||
<property name="openjpa.LockManager"
|
||||
value="org.apache.openjpa.kernel.VersionLockManager" />
|
||||
<!--
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="buildSchema" />
|
||||
<property name="openjpa.jdbc.SynchronizeMappings"
|
||||
value="builma(ForeignKeys=true)"/>
|
||||
-->
|
||||
</properties>
|
||||
</persistence-unit>
|
||||
|
||||
</persistence>
|
||||
|
22
pom.xml
22
pom.xml
|
@ -728,7 +728,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-jpa_2.0_spec</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
|
@ -743,7 +743,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-validation_1.0_spec</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.derby</groupId>
|
||||
|
@ -1141,4 +1141,22 @@
|
|||
</plugins>
|
||||
</reporting>
|
||||
|
||||
<!-- added so the build can find stagged Geronimo Spec artifacts -->
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>apache.nexus.staging</id>
|
||||
<name>Apache Staging Repository</name>
|
||||
<layout>default</layout>
|
||||
<url>https://repository.apache.org/content/repositories/staging/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
<updatePolicy>always</updatePolicy>
|
||||
<checksumPolicy>warn</checksumPolicy>
|
||||
</releases>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
</project>
|
||||
|
|
Loading…
Reference in New Issue