diff --git a/openjpa-xmlstore/pom.xml b/openjpa-xmlstore/pom.xml index fb346a060..3d47911d8 100644 --- a/openjpa-xmlstore/pom.xml +++ b/openjpa-xmlstore/pom.xml @@ -69,7 +69,7 @@ - org.codehaus.mojo openjpa-maven-plugin @@ -92,7 +92,8 @@ org.apache.openjpa - openjpa-all + + openjpa-persistence-jdbc ${pom.version} @@ -119,7 +120,6 @@ - --> diff --git a/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/AllFieldTypes.java b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/AllFieldTypes.java new file mode 100644 index 000000000..080755fbd --- /dev/null +++ b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/AllFieldTypes.java @@ -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 setOfStrings = new HashSet(); + private String[] arrayOfStrings; + + @PersistentCollection + private int[] arrayOfInts; + + // one-to-one and one-to-many relations to self + @OneToOne + private AllFieldTypes selfOneOne; + @OneToMany + private List selfOneMany = new ArrayList(); + + 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 setOfStrings) { + this.setOfStrings = setOfStrings; + } + + public Set 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 getSelfOneMany() { + return selfOneMany; + } + + public void setSelfOneMany(List selfOneMany) { + this.selfOneMany = selfOneMany; + } +} + diff --git a/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/Place.java b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/Place.java new file mode 100644 index 000000000..7d835198c --- /dev/null +++ b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/Place.java @@ -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; + } +} + diff --git a/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/TestPersistence.java b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/TestPersistence.java new file mode 100644 index 000000000..5a6d6b9f3 --- /dev/null +++ b/openjpa-xmlstore/src/test/java/org/apache/openjpa/xmlstore/simple/TestPersistence.java @@ -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); + } + } + +} + diff --git a/openjpa-xmlstore/src/test/resources/META-INF/persistence.xml b/openjpa-xmlstore/src/test/resources/META-INF/persistence.xml new file mode 100644 index 000000000..6dda6cbfa --- /dev/null +++ b/openjpa-xmlstore/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,46 @@ + + + + + + org.apache.openjpa.xmlstore.simple.AllFieldTypes + org.apache.openjpa.xmlstore.simple.Place + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index a1ac49398..ed1dd796c 100644 --- a/pom.xml +++ b/pom.xml @@ -728,7 +728,7 @@ org.apache.geronimo.specs geronimo-jpa_2.0_spec - 1.0 + 1.2 org.apache.geronimo.specs @@ -743,7 +743,7 @@ org.apache.geronimo.specs geronimo-validation_1.0_spec - 1.0 + 1.1 org.apache.derby @@ -1141,4 +1141,22 @@ + + + + apache.nexus.staging + Apache Staging Repository + default + https://repository.apache.org/content/repositories/staging/ + + false + + + true + always + warn + + + +