Author: mikedd
Date: Thu Aug 16 10:59:57 2007
New Revision: 566788
URL: http://svn.apache.org/viewvc?view=rev&rev=566788
Log:
OPENJPA-143
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java
(with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java
(with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/Discriminator.java
Thu Aug 16 10:59:57 2007
@@ -33,6 +33,7 @@
import org.apache.openjpa.kernel.OpenJPAStateManager;
import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.meta.MetaDataContext;
import org.apache.openjpa.meta.MetaDataModes;
import org.apache.openjpa.meta.MetaDataRepository;
@@ -64,6 +65,8 @@
private Index _idx = null;
private boolean _subsLoaded = false;
private Object _value = null;
+
+ private int _javaType = -1;
/**
* Constructor. Supply owning mapping.
@@ -412,5 +415,22 @@
public String toString() {
return _mapping + "<discriminator>";
+ }
+
+ public void setJavaType(int javaType) {
+ _javaType = javaType;
+ }
+
+ public int getJavaType() {
+ if (_javaType == -1) {
+ ClassMapping superMapping = _mapping.getPCSuperclassMapping();
+
+ if (superMapping != null &&
+ superMapping.getDiscriminator() != null) {
+ _javaType = superMapping.getDiscriminator().getJavaType();
+ }
+ }
+
+ return _javaType;
}
}
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/DiscriminatorMappingInfo.java
Thu Aug 16 10:59:57 2007
@@ -20,6 +20,7 @@
import java.lang.reflect.Modifier;
+import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.jdbc.meta.strats.NoneDiscriminatorStrategy;
import org.apache.openjpa.jdbc.meta.strats.SuperclassDiscriminatorStrategy;
import org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy;
@@ -28,6 +29,7 @@
import org.apache.openjpa.jdbc.schema.SchemaGroup;
import org.apache.openjpa.jdbc.schema.Table;
import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.JavaTypes;
import org.apache.openjpa.util.MetaDataException;
/**
@@ -45,7 +47,7 @@
(DiscriminatorMappingInfo.class);
private String _value = null;
-
+
/**
* Raw discriminator value string.
*/
@@ -66,28 +68,20 @@
public Object getValue(Discriminator discrim, boolean adapt) {
if (discrim.getValue() != null)
return discrim.getValue();
- if (_value == null)
+ if (StringUtils.isEmpty(_value)) {
return discrim.getMappingRepository().getMappingDefaults().
getDiscriminatorValue(discrim, adapt);
-
- if (_value.length() > 0 && (_value.charAt(0) == '-'
- || Character.isDigit(_value.charAt(0)))) {
- try {
- if (_value.indexOf('.') == -1)
- return new Integer(_value);
- return new Double(_value);
- } catch (RuntimeException re) {
- throw new MetaDataException(_loc.get("bad-discrim-value",
- discrim.getClassMapping(), _value));
- }
}
- if ("null".equalsIgnoreCase(_value))
- return Discriminator.NULL;
-
- // strip quotes
- if (_value.length() > 0 && _value.charAt(0) == '\'')
- return _value.substring(1, _value.length() - 1);
- return _value;
+
+ switch(discrim.getJavaType()) {
+ case JavaTypes.INT:
+ return Integer.valueOf(_value);
+ case JavaTypes.CHAR:
+ return Character.valueOf(_value.charAt(_value.indexOf('\'')+1));
+ case JavaTypes.STRING:
+ default:
+ return _value;
+ }
}
/**
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
(original)
+++
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/MappingDefaultsImpl.java
Thu Aug 16 10:59:57 2007
@@ -455,14 +455,47 @@
return null;
}
+ /**
+ * Provides a default value for the given Discriminator.
+ *
+ * <P>
+ * The type of the object returned relies on the javaType field being set
on
+ * the Discriminator which is provided.
+ * <TABLE border="2">
+ * <TH>JavaType
+ * <TH>Default value
+ * <TBODY>
+ * <TR><TD>[EMAIL PROTECTED] JavaTypes.INT}<TD> The hashcode of the entity
name</TR>
+ * <TR><TD>[EMAIL PROTECTED] JavaTypes.CHAR}<TD>The first character of the
entity name
+ * </TR>
+ * <TR><TD>[EMAIL PROTECTED] JavaTypes.STRING}<TD>The entity name</TR>
+ * </TBODY>
+ * </TABLE>
+ *
+ * @param disc The discriminator that needs a default value
+ * @param adapt
+ *
+ * @return A new object containing the generated Discriminator value.
+ */
public Object getDiscriminatorValue(Discriminator disc, boolean adapt) {
if (!adapt && !defaultMissingInfo())
return null;
// WARNING: CHANGING THIS WILL INVALIDATE EXISTING DATA IF DEFAULTING
// MISSING MAPPING INFO
- return Strings.getClassName(disc.getClassMapping().
- getDescribedType());
+
+ String alias = Strings.getClassName(disc.getClassMapping()
+ .getTypeAlias());
+
+ switch (disc.getJavaType()) {
+ case JavaTypes.INT:
+ return new Integer(alias.hashCode());
+ case JavaTypes.CHAR:
+ return new Character(alias.charAt(0));
+ case JavaTypes.STRING:
+ default:
+ return alias;
+ }
}
public String getTableName(ClassMapping cls, Schema schema) {
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
Thu Aug 16 10:59:57 2007
@@ -20,6 +20,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Modifier;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
@@ -57,6 +58,7 @@
import org.apache.openjpa.jdbc.kernel.EagerFetchModes;
import org.apache.openjpa.jdbc.meta.ClassMapping;
import org.apache.openjpa.jdbc.meta.ClassMappingInfo;
+import org.apache.openjpa.jdbc.meta.Discriminator;
import org.apache.openjpa.jdbc.meta.FieldMapping;
import org.apache.openjpa.jdbc.meta.MappingInfo;
import org.apache.openjpa.jdbc.meta.MappingRepository;
@@ -262,6 +264,12 @@
case DISCRIM_VAL:
cm.getDiscriminator().getMappingInfo().setValue
(((DiscriminatorValue) anno).value());
+ if (Modifier.isAbstract(cm.getDescribedType().
+ getModifiers()) && getLog().isInfoEnabled()) {
+ getLog().info(
+ _loc.get("discriminator-on-abstract-class", cm
+ .getDescribedType().getName()));
+ }
break;
case INHERITANCE:
parseInheritance(cm, (Inheritance) anno);
@@ -525,18 +533,22 @@
col.setName(dcol.name());
if (!StringUtils.isEmpty(dcol.columnDefinition()))
col.setTypeName(dcol.columnDefinition());
+ Discriminator discrim = cm.getDiscriminator();
switch (dcol.discriminatorType()) {
case CHAR:
col.setJavaType(JavaTypes.CHAR);
+ discrim.setJavaType(JavaTypes.CHAR);
break;
case INTEGER:
col.setJavaType(JavaTypes.INT);
if (dcol.length() != 31)
col.setSize(dcol.length());
+ discrim.setJavaType(JavaTypes.INT);
break;
default:
col.setJavaType(JavaTypes.STRING);
col.setSize(dcol.length());
+ discrim.setJavaType(JavaTypes.STRING);
}
cm.getDiscriminator().getMappingInfo().setColumns
(Arrays.asList(new Column[]{ col }));
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
Thu Aug 16 10:59:57 2007
@@ -18,6 +18,7 @@
*/
package org.apache.openjpa.persistence.jdbc;
+import java.lang.reflect.Modifier;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
@@ -197,6 +198,7 @@
ret = startSecondaryTable(attrs);
break;
case DISCRIM_COL:
+ parseDiscriminatorColumn(attrs);
_discCol = parseColumn(attrs);
ret = true;
break;
@@ -314,20 +316,21 @@
cm.getMappingInfo().setColumns(_supJoinCols);
if (_discCol != null) {
- DiscriminatorMappingInfo dinfo = cm.getDiscriminator().
- getMappingInfo();
- if (_discType != null) {
- switch (_discType) {
- case CHAR:
- _discCol.setJavaType(JavaTypes.CHAR);
- break;
- case INTEGER:
- _discCol.setJavaType(JavaTypes.INT);
- break;
- default:
- _discCol.setJavaType(JavaTypes.STRING);
- break;
- }
+ DiscriminatorMappingInfo dinfo = cm.getDiscriminator()
+ .getMappingInfo();
+ switch (_discType) {
+ case CHAR:
+ _discCol.setJavaType(JavaTypes.CHAR);
+ cm.getDiscriminator().setJavaType(JavaTypes.CHAR);
+ break;
+ case INTEGER:
+ _discCol.setJavaType(JavaTypes.INT);
+ cm.getDiscriminator().setJavaType(JavaTypes.INT);
+ break;
+ default:
+ _discCol.setJavaType(JavaTypes.STRING);
+ cm.getDiscriminator().setJavaType(JavaTypes.STRING);
+ break;
}
dinfo.setColumns(Arrays.asList(new Column[]{ _discCol }));
}
@@ -439,6 +442,13 @@
ClassMapping cm = (ClassMapping) currentElement();
cm.getDiscriminator().getMappingInfo().setValue(val);
+
+ if (Modifier.isAbstract(cm.getDescribedType().getModifiers())
+ && getLog().isInfoEnabled()) {
+ getLog().info(
+ _loc.get("discriminator-on-abstract-class", cm
+ .getDescribedType().getName()));
+ }
}
/**
@@ -915,5 +925,13 @@
{
TRUE,
FALSE
+ }
+
+ private void parseDiscriminatorColumn(Attributes attrs) {
+ String val = attrs.getValue("discriminator-type");
+ if (val != null) {
+ _discType = Enum.valueOf(DiscriminatorType.class, val);
+ }
+
}
}
Modified:
openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties?view=diff&rev=566788&r1=566787&r2=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
(original)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/main/resources/org/apache/openjpa/persistence/jdbc/localizer.properties
Thu Aug 16 10:59:57 2007
@@ -48,3 +48,7 @@
no-gen-table: No generated table found at "{0}".
empty-unique-column: A unique constraint "{0}" specified in mapping of class \
"{1}" includes an empty column.
+discriminator-on-abstract-class: A discriminator value has been specified for \
+ the abstract class "{0}". The discriminator will never be used and may
be \
+ safely removed.
+
\ No newline at end of file
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,53 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED](strategy=InheritanceType.SINGLE_TABLE)
[EMAIL PROTECTED](name="DISC_COL", discriminatorType=DiscriminatorType.CHAR)
+public abstract class CharAbstractEntity {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @Column(length=16)
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharAbstractEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Entity;
+
[EMAIL PROTECTED](name="chrLeaf")
+public class CharLeafEntity
+ extends CharRootEntity {
+
+ private int subInt;
+
+ public int getSubInt() {
+ return subInt;
+ }
+
+ public void setSubInt(int subInt) {
+ this.subInt = subInt;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharLeafEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,27 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]("R")
+public class CharRootEntity extends CharAbstractEntity {
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/CharRootEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED](strategy = InheritanceType.SINGLE_TABLE)
[EMAIL PROTECTED](name = "DISC_COL",
+ discriminatorType = DiscriminatorType.INTEGER)
+public abstract class IntegerAbstractEntity {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @Column(length=16)
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerAbstractEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Entity;
+
[EMAIL PROTECTED](name="intLeaf")
+public class IntegerLeafEntity
+ extends IntegerRootEntity {
+
+ private int subInt;
+
+ public int getSubInt() {
+ return subInt;
+ }
+
+ public void setSubInt(int subInt) {
+ this.subInt = subInt;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerLeafEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,28 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]("10101")
+public class IntegerRootEntity extends IntegerAbstractEntity {
+
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/IntegerRootEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,54 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED](strategy = InheritanceType.SINGLE_TABLE)
[EMAIL PROTECTED](name = "DISC_COL",
+ discriminatorType = DiscriminatorType.STRING)
+public abstract class StringAbstractEntity {
+
+ @Id
+ @GeneratedValue
+ private long id;
+
+ @Column(length = 16)
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringAbstractEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,36 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.Entity;
+
[EMAIL PROTECTED](name="strLeaf")
+public class StringLeafEntity
+ extends StringRootEntity {
+
+ private int subInt;
+
+ public int getSubInt() {
+ return subInt;
+ }
+
+ public void setSubInt(int subInt) {
+ this.subInt = subInt;
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringLeafEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,27 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
[EMAIL PROTECTED]
[EMAIL PROTECTED]("StringRoot")
+public class StringRootEntity extends StringAbstractEntity {
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/StringRootEntity.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java
URL:
http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java?view=auto&rev=566788
==============================================================================
---
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java
(added)
+++
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java
Thu Aug 16 10:59:57 2007
@@ -0,0 +1,100 @@
+/*
+ * 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.discriminator;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.Discriminator;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+public class TestDiscriminatorTypes extends SingleEMFTestCase {
+
+ protected void setUp() {
+ super.setUp(CharAbstractEntity.class, CharLeafEntity.class,
+ CharRootEntity.class, IntegerAbstractEntity.class,
+ IntegerLeafEntity.class, IntegerRootEntity.class,
+ StringAbstractEntity.class, StringLeafEntity.class,
+ StringRootEntity.class);
+ }
+
+ public void testCharDiscriminators() {
+ EntityManager em = emf.createEntityManager(); // load types
+
+ Discriminator discrim = getMapping("CharAbstractEntity")
+ .getDiscriminator();
+ assertEquals(new Character('C'), discrim.getValue()); // Generated
+ assertEquals(JavaTypes.CHAR, discrim.getJavaType());
+
+ discrim = getMapping("chrLeaf").getDiscriminator();
+ assertEquals(new Character('c'), discrim.getValue());
+ assertEquals(JavaTypes.CHAR, discrim.getJavaType());
+
+ discrim = getMapping("CharRootEntity").getDiscriminator();
+ assertEquals(new Character('R'), discrim.getValue());
+ assertEquals(JavaTypes.CHAR, discrim.getJavaType());
+
+ em.close();
+ }
+
+ public void testIntDiscriminators() {
+ EntityManager em = emf.createEntityManager(); // load the types
+
+ Discriminator discrim = getMapping("IntegerAbstractEntity")
+ .getDiscriminator();
+ assertEquals(new Integer("IntegerAbstractEntity".hashCode()), discrim
+ .getValue()); // Generated value
+ assertEquals(JavaTypes.INT, discrim.getJavaType());
+
+ discrim = getMapping("intLeaf").getDiscriminator();
+ assertEquals(new Integer("intLeaf".hashCode()), discrim.getValue());
+ assertEquals(JavaTypes.INT, discrim.getJavaType());
+
+ discrim = getMapping("IntegerRootEntity").getDiscriminator();
+ assertEquals(new Integer(10101), discrim.getValue());
+ assertEquals(JavaTypes.INT, discrim.getJavaType());
+
+ em.close();
+ }
+
+ public void testStringDiscriminators() {
+ EntityManager em = emf.createEntityManager(); // load the types
+ Discriminator discrim = getMapping("StringAbstractEntity")
+ .getDiscriminator();
+ assertEquals("StringAbstractEntity", discrim.getValue()); // Generated
+ assertEquals(JavaTypes.STRING, discrim.getJavaType());
+
+ discrim = getMapping("strLeaf").getDiscriminator();
+ assertEquals("strLeaf", discrim.getValue());
+ assertEquals(JavaTypes.STRING, discrim.getJavaType());
+
+ discrim = getMapping("StringRootEntity").getDiscriminator();
+ assertEquals("StringRoot", discrim.getValue());
+ assertEquals(JavaTypes.STRING, discrim.getJavaType());
+ em.close();
+ }
+
+ private ClassMapping getMapping(String name) {
+ return (ClassMapping) OpenJPAPersistence.cast(emf).getConfiguration()
+ .getMetaDataRepositoryInstance().getMetaData(name,
+ getClass().getClassLoader(), true);
+ }
+}
Propchange:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/discriminator/TestDiscriminatorTypes.java
------------------------------------------------------------------------------
svn:eol-style = native