You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by jr...@apache.org on 2009/05/29 20:54:09 UTC
svn commit: r780068 - in /openjpa/trunk:
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/
openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/
openjpa-persistence-jdbc/src/main/java/...
Author: jrbauer
Date: Fri May 29 18:54:08 2009
New Revision: 780068
URL: http://svn.apache.org/viewvc?rev=780068&view=rev
Log:
OPENJPA-962 Committing code and tests contributed by Dianne Richards
Added:
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java (with props)
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java (with props)
Modified:
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/SequenceMapping.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java
openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityF.java
openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimId.java
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/SequenceMapping.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/SequenceMapping.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/SequenceMapping.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/SequenceMapping.java Fri May 29 18:54:08 2009
@@ -158,6 +158,7 @@
return new JDBCSeqValue(property);
}
+ @Override
protected void addStandardProperties(StringBuffer props) {
super.addStandardProperties(props);
// Quotes are conditionally added to the following because the props
@@ -166,31 +167,11 @@
// properties are intentionally delimited with quotes. So, an extra
// set preserves the intended ones. While this is an ugly solution,
// it's less ugly than other ones.
- String table = _table;
- if (table != null && table.startsWith("\"")
- && table.endsWith("\"")) {
- table = "\"" + table + "\"";
- }
- String sequenceColumn = _sequenceColumn;
- if (sequenceColumn != null && sequenceColumn.startsWith("\"")
- && sequenceColumn.endsWith("\"")) {
- sequenceColumn = "\"" + sequenceColumn + "\"";
- }
- String primaryKeyColumn = _primaryKeyColumn;
- if (primaryKeyColumn !=null && primaryKeyColumn.startsWith("\"")
- && primaryKeyColumn.endsWith("\"")) {
- primaryKeyColumn = "\"" + primaryKeyColumn + "\"";
- }
- String primaryKeyValue = _primaryKeyValue;
- if (primaryKeyValue != null && primaryKeyValue.startsWith("\"")
- && primaryKeyValue.endsWith("\"")) {
- primaryKeyValue = "\"" + primaryKeyValue + "\"";
- }
- appendProperty(props, PROP_TABLE, table);
- appendProperty(props, PROP_SEQUENCE_COL, sequenceColumn);
- appendProperty(props, PROP_PK_COL, primaryKeyColumn);
- appendProperty(props, PROP_PK_VALUE, primaryKeyValue);
+ appendProperty(props, PROP_TABLE, addQuotes(_table));
+ appendProperty(props, PROP_SEQUENCE_COL, addQuotes(_sequenceColumn));
+ appendProperty(props, PROP_PK_COL, addQuotes(_primaryKeyColumn));
+ appendProperty(props, PROP_PK_VALUE, addQuotes(_primaryKeyValue));
// Array of unique column names are passed to configuration
// as a single string "x|y|z". The configurable (TableJDBCSeq) must
// parse it back.
@@ -198,4 +179,11 @@
appendProperty(props, PROP_UNIQUE,
StringUtils.join(_uniqueColumns,'|'));
}
+
+ private String addQuotes(String name) {
+ if (name != null && name.startsWith("\"") && name.endsWith("\"")) {
+ return "\"" + name + "\"";
+ }
+ return name;
+ }
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/schema/SchemaGenerator.java Fri May 29 18:54:08 2009
@@ -488,7 +488,6 @@
Table table;
String tableSchema;
for (int i = 0; cols != null && i < cols.length; i++) {
- // TODO: Is this where we should handle this?
if (tableName == null || tableName.equals("%")) {
tableName = cols[i].getTableName();
}
@@ -528,8 +527,14 @@
if (_log.isTraceEnabled())
_log.trace(_loc.get("gen-column", cols[i].getName(), table));
- if (table.getColumn(cols[i].getName()) == null)
- table.importColumn(cols[i]);
+ if (table.getColumn(cols[i].getName()) == null) {
+ // It's possible that the original column name was delimited,
+ // so delimit it and try again
+ String delimCol = _dict.addDelimiters(cols[i].getName());
+ if (table.getColumn(delimCol) == null) {
+ table.importColumn(cols[i]);
+ }
+ }
}
}
Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java (original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java Fri May 29 18:54:08 2009
@@ -3024,16 +3024,7 @@
String tableName = table.getName();
int len = Math.min(tableName.length(), 7);
String shortTableName = shorten(tableName, len);
- String delim = getDelimiter();
- if (shortTableName.startsWith(delim)
- && shortTableName.endsWith(delim)) {
- name = delim + "I_"
- + shortTableName.substring(1, shortTableName.length() - 1)
- + "_" + name + delim;
- }
- else {
- name = "I_" + shortTableName + "_" + name;
- }
+ name = combineNames("I", shortTableName, name);
return makeNameValid(name, table.getSchema().getSchemaGroup(),
maxIndexNameLength, NAME_ANY);
@@ -3048,10 +3039,29 @@
name = name.substring(1);
String tableName = table.getName();
int len = Math.min(tableName.length(), 7);
- name = "U_" + shorten(tableName, len) + "_" + name;
+ name = combineNames("U", shorten(tableName, len), name);
return makeNameValid(name, table.getSchema().getSchemaGroup(),
maxConstraintNameLength, NAME_ANY);
}
+
+ public boolean isDelimited(String name) {
+ return (name.startsWith(getDelimiter())
+ && name.endsWith(getDelimiter()));
+ }
+
+ public String stripDelimiters(String name) {
+ String delimiter = getDelimiter();
+ int delimLen = delimiter.length();
+ if (isDelimited(name)) {
+ return name.substring(delimLen, name.length() - delimLen);
+ }
+ return name;
+ }
+
+ public String addDelimiters(String name) {
+ String delimiter = getDelimiter();
+ return delimiter + name + delimiter;
+ }
/**
* Shorten the specified name to the specified target name. This will
@@ -4122,9 +4132,7 @@
return null;
// Handle delimited string differently. Return unquoted name.
- if (delimitIds ||
- objectName.startsWith(getDelimiter()) &&
- objectName.endsWith(getDelimiter())) {
+ if (delimitIds || isDelimited(objectName)) {
String delimCase = getDelimitedCase();
if (SCHEMA_CASE_UPPER.equals(delimCase)) {
objectName.toUpperCase();
@@ -4133,11 +4141,7 @@
objectName.toLowerCase();
}
- // TODO: maybe have a different method to remove quotes and
- // call it from the calling methods
- int delimLen = getDelimiter().length();
- return objectName.substring(delimLen,
- objectName.length() - delimLen);
+ return stripDelimiters(objectName);
}
String scase = getSchemaCase();
@@ -4972,4 +4976,29 @@
public void setDelimitIds(boolean delimitIds) {
this.delimitIds = delimitIds;
}
+
+ // TODO: Should we pass in combining char, or just assume '_'?
+ public String combineNames(String... names) {
+ boolean delimited = false;
+ String combined = null;
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (isDelimited(name)) {
+ delimited = true;
+ name = stripDelimiters(name);
+ }
+ if (i == 0) {
+ combined = name;
+ }
+ else {
+ combined = combined + "_" + name;
+ }
+ }
+
+ if (delimited) {
+ combined = addDelimiters(combined);
+ }
+
+ return combined;
+ }
}
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java Fri May 29 18:54:08 2009
@@ -136,16 +136,6 @@
Table table = getTable(clm);
String name = table.getName();
- String delim = dict.getDelimiter();
- boolean isDelimited = false;
- if (name.startsWith(delim) && name.endsWith(delim)) {
- isDelimited = true;
- name = name.substring(0,name.length()-1) + "_";
- }
- else {
- name = name + "_";
- }
-
// if this is an assocation table, spec says to suffix with table of
// the related type. spec doesn't cover other cases; we're going to
@@ -153,15 +143,16 @@
ClassMapping rel = fm.getElementMapping().getTypeMapping();
boolean assoc = rel != null && rel.getTable() != null
&& fm.getTypeCode() != JavaTypes.MAP;
- if (assoc)
- name += rel.getTable().getName();
- else
- name += fm.getName();
-
- if (isDelimited) {
- name += "\"";
+ String name2 = null;
+ if (assoc) {
+ name2 = rel.getTable().getName();
+ }
+ else {
+ name2 = fm.getName();
}
+ name = dict.combineNames(name, name2);
+
return name.replace('$', '_');
}
@@ -202,7 +193,7 @@
// suffix with '_' + target column
if (tempName == null)
tempName = name;
- name = tempName + "_" + targetName;
+ name = dict.combineNames(tempName, targetName);
name = dict.getValidColumnName(name, foreign);
col.setName(name);
}
@@ -228,8 +219,9 @@
if (isRemoveHungarianNotation())
name = removeHungarianNotation(name);
-
- name = name + "_" + ((Column) target).getName();
+
+ name = dict.combineNames(name, ((Column)target).getName());
+
// No need to check for uniqueness.
name = dict.getValidColumnName(name, local, false);
col.setName(name);
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java Fri May 29 18:54:08 2009
@@ -0,0 +1,90 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.Table;
+
+@Entity
+@Inheritance
+// Note: delimited columnDefinition is not supported on DB2 or Derby
+// TODO: Find out what DB supports this and write a specific test case for it
+@DiscriminatorColumn(name="\"discr col\"", columnDefinition="VARCHAR(10)")
+@Table(name="\"Animal\"")
+public class Animal {
+ @Id
+ private int id;
+
+ @Column(name="\"animal type\"")
+ protected String type;
+ @Column(name="\"animal name\"")
+ protected String name;
+
+ public Animal() {}
+
+ public Animal(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @param type the type to set
+ */
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Animal.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java Fri May 29 18:54:08 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("Cat")
+public class Cat extends Animal {
+ public Cat() {}
+
+ public Cat(int id) {
+ super(id);
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Cat.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java Fri May 29 18:54:08 2009
@@ -0,0 +1,32 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Entity;
+
+@Entity
+@DiscriminatorValue("Dog")
+public class Dog extends Animal {
+ public Dog() {}
+
+ public Dog(int id) {
+ super(id);
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/Dog.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java Fri May 29 18:54:08 2009
@@ -0,0 +1,181 @@
+/*
+ * 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.delimited.identifiers;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.JoinTable;
+import javax.persistence.ManyToMany;
+import javax.persistence.MapKeyJoinColumn;
+import javax.persistence.OneToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity c\"", schema="\"delim id\"")
+@SecondaryTable(name="\"sec join table\"", schema="\"delim id\"",
+ pkJoinColumns=@PrimaryKeyJoinColumn(name="\"entity c\"",
+ referencedColumnName="\"c id\""))
+public class EntityC {
+ @Id
+ @Column(name="\"c id\"")
+ private int id;
+ private String name;
+
+ @Column(table="\"sec join table\"")
+ private String secName;
+
+ @ManyToMany
+ @JoinTable(name="\"c d\"", schema="\"delim id\"")
+ private Collection<EntityD> entityDs = new HashSet<EntityD>();
+
+ @OneToOne
+ @JoinColumn(name="\"entd2 id\"", referencedColumnName="\"entityD2 id\"")
+ private EntityD2 entityD2;
+
+ @ManyToMany
+ @JoinTable(name="\"map join table\"", schema="\"delim id\"")
+ @MapKeyJoinColumn(name="map_ed3", referencedColumnName="\"entityD3 id\"")
+ Map<EntityD3,EntityD4> map = new HashMap<EntityD3,EntityD4>();
+
+ @ManyToMany
+ @JoinTable(name="\"map2 join table\"", schema="\"delim id\"")
+ @MapKeyJoinColumn(name="\"map ed4\"",
+ referencedColumnName="\"entityD4 id\"")
+ Map<EntityD4,EntityD3> map2 = new HashMap<EntityD4,EntityD3>();
+
+ public EntityC() {}
+
+ public EntityC(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ /**
+ * @return the entityDs
+ */
+ public Collection<EntityD> getEntityDs() {
+ return entityDs;
+ }
+ /**
+ * @param entityDs the entityDs to set
+ */
+ public void setEntityDs(Collection<EntityD> entityDs) {
+ this.entityDs = entityDs;
+ }
+
+ public void addEntityD(EntityD entityD) {
+ entityDs.add(entityD);
+ }
+
+ /**
+ * @return the entityD2
+ */
+ public EntityD2 getEntityD2() {
+ return entityD2;
+ }
+
+ /**
+ * @param entityD2 the entityD2 to set
+ */
+ public void setEntityD2(EntityD2 entityD2) {
+ this.entityD2 = entityD2;
+ }
+
+ /**
+ * @return the map
+ */
+ public Map<EntityD3, EntityD4> getMap() {
+ return map;
+ }
+
+ /**
+ * @param map the map to set
+ */
+ public void setMap(Map<EntityD3, EntityD4> map) {
+ this.map = map;
+ }
+
+ public void addMapValues(EntityD3 key, EntityD4 value) {
+ map.put(key, value);
+ }
+
+ /**
+ * @return the map2
+ */
+ public Map<EntityD4, EntityD3> getMap2() {
+ return map2;
+ }
+
+ /**
+ * @param map2 the map2 to set
+ */
+ public void setMap2(Map<EntityD4, EntityD3> map2) {
+ this.map2 = map2;
+ }
+
+ public void addMap2Values(EntityD4 key, EntityD3 value) {
+ map2.put(key, value);
+ }
+
+ /**
+ * @return the secName
+ */
+ public String getSecName() {
+ return secName;
+ }
+
+ /**
+ * @param secName the secName to set
+ */
+ public void setSecName(String secName) {
+ this.secName = secName;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityC.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java Fri May 29 18:54:08 2009
@@ -0,0 +1,89 @@
+/*
+ * 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.delimited.identifiers;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity d\"", schema="\"delim id\"")
+public class EntityD {
+ @Id
+ private int id;
+ private String name;
+ @ManyToMany(mappedBy="entityDs")
+ private Collection<EntityC> entityCs = new HashSet<EntityC>();
+
+ public EntityD() {}
+
+ public EntityD(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the entityCs
+ */
+ public Collection<EntityC> getEntityCs() {
+ return entityCs;
+ }
+
+ /**
+ * @param entityCs the entityCs to set
+ */
+ public void setEntityCs(Collection<EntityC> entityCs) {
+ this.entityCs = entityCs;
+ }
+
+ public void addEntityC(EntityC entityC) {
+ entityCs.add(entityC);
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java Fri May 29 18:54:08 2009
@@ -0,0 +1,87 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity d2\"", schema="\"delim id\"")
+public class EntityD2 {
+ @Id
+ @Column(name="\"entityD2 id\"")
+ private int id;
+ private String name;
+
+ @OneToOne
+ @PrimaryKeyJoinColumn
+ private EntityD3 entityD3;
+
+ public EntityD2() {}
+
+ public EntityD2(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the entityD3
+ */
+ public EntityD3 getEntityD3() {
+ return entityD3;
+ }
+
+ /**
+ * @param entityD3 the entityD3 to set
+ */
+ public void setEntityD3(EntityD3 entityD3) {
+ this.entityD3 = entityD3;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD2.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java Fri May 29 18:54:08 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity d3\"", schema="\"delim id\"")
+public class EntityD3 {
+ @Id
+ @Column(name="\"entityD3 id\"")
+ int id;
+ String name;
+
+ public EntityD3() {}
+
+ public EntityD3(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD3.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java Fri May 29 18:54:08 2009
@@ -0,0 +1,65 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity d4\"", schema="\"delim id\"")
+public class EntityD4 {
+ @Id
+ @Column(name="\"entityD4 id\"")
+ int id;
+ String name;
+
+ public EntityD4() {}
+
+ public EntityD4(int id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityD4.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java Fri May 29 18:54:08 2009
@@ -0,0 +1,76 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+import javax.persistence.SequenceGenerator;
+import javax.persistence.Table;
+
+@Entity
+//@Table(name="primary_entityE", schema="delim_id")
+@Table(name="\"primary entityE\"", schema="\"delim id\"")
+public class EntityE {
+ @Id
+ @SequenceGenerator(name="entityE_seq_gen_name",
+ sequenceName="\"entityE_seq_gen\"", schema="\"delim_id\"")
+ @GeneratedValue(strategy=GenerationType.SEQUENCE,
+ generator="entityE_seq_gen_name")
+ private int id;
+ @Column(name="e_name")
+ private String name;
+
+ public EntityE(String name) {
+ this.name = name;
+// id = 1;
+ }
+
+// public EntityE(int id, String name) {
+// this.id = id;
+// this.name = name;
+// }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityE.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityF.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityF.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityF.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityF.java Fri May 29 18:54:08 2009
@@ -27,19 +27,33 @@
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MapKeyColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;
+import javax.persistence.TableGenerator;
+import javax.persistence.UniqueConstraint;
@Entity
-@Table(name="\"primary entityF\"", schema="\"delim id\"")
-@SecondaryTable(name="\"secondary entityF\"", schema="\"delim id\"")
-//@Table(name="primary_entityF", schema="delim_id")
+@Table(name="\"primary entityF\"", schema="\"delim id\"",
+ uniqueConstraints=
+ @UniqueConstraint(columnNames={"\"f name\"", "f_nonDelimName"}))
+@SecondaryTable(name="\"secondary entityF\"", schema="\"delim id\"",
+ uniqueConstraints=
+ @UniqueConstraint(name="\"sec_unq\"",
+ columnNames={"\"secondary name\""}))
public class EntityF {
+ @TableGenerator(name = "f_id_gen", table = "\"f_id_gen\"",
+ schema = "\"delim id\"",
+ pkColumnName = "\"gen_pk\"", valueColumnName = "\"gen_value\"")
+ @GeneratedValue(strategy = GenerationType.TABLE, generator = "f_id_gen")
@Id
private int id;
- @Column(name="\"f name\"")
+ // Note: Delimited columnDefinition is not supported on some DBs
+ // TODO: copy into a separate entity and conditionally run a different test
+ @Column(name="\"f name\"", columnDefinition="char(15)")
private String name;
@Column(name="f_nonDelimName")
private String nonDelimName;
@@ -56,20 +70,19 @@
private Set<String> collectionDelimSet = new HashSet<String>();
@ElementCollection
+ // MapKeyColumn with default name generation
@MapKeyColumn
private Map<String, String> collectionMap = new HashMap<String, String>();
@ElementCollection
- @MapKeyColumn(name = "\"mapKey\"")
- private Map<String, String> delimCollectionMap =
+ // Note: Delimited column definition is not supported on some DBs, so
+ // it is not delimited here
+ // TODO: create a separate entity and conditionally run the test
+ @MapKeyColumn(name="\"mapKey\"", columnDefinition="varchar(20)")
+ private Map<String, String> delimCollectionMap =
new HashMap<String, String>();
-
- public EntityF(String name) {
- this.name = name;
- }
- public EntityF(int id, String name) {
- this.id = id;
+ public EntityF(String name) {
this.name = name;
}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java Fri May 29 18:54:08 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.delimited.identifiers;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+@Entity
+@Table(name="\"entity d4\"", schema="\"delim id\"")
+//@Table(name="xxx")
+public class EntityG {
+ @Id
+// @Column(name="\"entityD4 id\"")
+ int id;
+ String name;
+
+ public EntityG() {}
+
+ public EntityG(int id) {
+ this.id = id;
+ }
+
+ public EntityG(int id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ /**
+ * @return the id
+ */
+ public int getId() {
+ return id;
+ }
+ /**
+ * @param id the id to set
+ */
+ public void setId(int id) {
+ this.id = id;
+ }
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/EntityG.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimId.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimId.java?rev=780068&r1=780067&r2=780068&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimId.java (original)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimId.java Fri May 29 18:54:08 2009
@@ -3,6 +3,10 @@
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.Query;
import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
import org.apache.openjpa.jdbc.schema.Column;
@@ -17,12 +21,11 @@
JDBCConfiguration conf;
DBDictionary dict;
+ @Override
public void setUp() throws Exception {
- // TODO: retest with DROP to figure out problem
-// super.setUp(EntityF2.class,DROP_TABLES);
super.setUp(
- org.apache.openjpa.persistence.delimited.identifiers.
- EntityF.class);
+ org.apache.openjpa.persistence.delimited.identifiers.EntityF.class,
+ DROP_TABLES);
assertNotNull(emf);
em = emf.createEntityManager();
@@ -32,8 +35,10 @@
dict = conf.getDBDictionaryInstance();
}
+ // TODO: remove parameter
public void createEntityF(int id) {
- entityF = new EntityF(id, "fName");
+// entityF = new EntityF(id, "fName");
+ entityF = new EntityF("fName");
entityF.setNonDelimName("fNonDelimName");
entityF.setSecName("sec name");
entityF.addCollectionSet("xxx");
@@ -46,7 +51,36 @@
entityF.addDelimCollectionMap("yyy", "zzz");
}
-
+// TODO: temp - test on multiple DBs
+// public void testDBCapability() {
+// Connection conn = (Connection)em.getConnection();
+// try {
+// DatabaseMetaData meta = conn.getMetaData();
+// System.out.println("LC - " +
+// meta.storesLowerCaseIdentifiers());
+// System.out.println("LCQ - " +
+// meta.storesLowerCaseQuotedIdentifiers());
+// System.out.println("MC - " +
+// meta.storesMixedCaseIdentifiers());
+// System.out.println("MCQ - " +
+// meta.storesMixedCaseQuotedIdentifiers());
+// System.out.println("UC - " +
+// meta.storesUpperCaseIdentifiers());
+// System.out.println("UCQ - " +
+// meta.storesUpperCaseQuotedIdentifiers());
+// System.out.println("");
+// System.out.println("db product name - " +
+// meta.getDatabaseProductName());
+// System.out.println("db product version - " +
+// meta.getDatabaseProductVersion());
+// System.out.println("driver name - " +
+// meta.getDriverName());
+// System.out.println("driver version - " +
+// meta.getDriverVersion());
+// } catch (SQLException e) {
+// e.printStackTrace();
+// }
+// }
public void testCreateF() {
id++;
@@ -56,9 +90,46 @@
em.persist(entityF);
em.getTransaction().commit();
- System.out.println(super.toString(sql));
+ runQueries();
}
- // TODO: change to boolean return and remove assert
+
+ private void runQueries() {
+ em.clear();
+ queryOnEntityOnly();
+ em.clear();
+ queryOnColumnValue();
+ em.clear();
+ queryCollection();
+ }
+
+ private void queryOnEntityOnly() {
+ String query =
+ "SELECT DISTINCT f " +
+ "FROM EntityF f";
+ Query q = em.createQuery(query);
+ List<EntityF> results = (List<EntityF>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ private void queryOnColumnValue() {
+ String query =
+ "SELECT DISTINCT f " +
+ "FROM EntityF f " +
+ "WHERE f.name = 'fName'";
+ Query q = em.createQuery(query);
+ List<EntityF> results = (List<EntityF>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ private void queryCollection() {
+ String query =
+ "SELECT DISTINCT f " +
+ "FROM EntityF f, IN(f.collectionDelimSet) s " +
+ "WHERE s = 'aaa'";
+ Query q = em.createQuery(query);
+ List<EntityF> results = (List<EntityF>)q.getResultList();
+ assertEquals(1,results.size());
+ }
}
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java Fri May 29 18:54:08 2009
@@ -0,0 +1,106 @@
+/*
+ * 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.delimited.identifiers;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestManualDelimIdSeqGen extends SQLListenerTestCase {
+ OpenJPAEntityManager em;
+ JDBCConfiguration conf;
+ DBDictionary dict;
+ boolean supportsNativeSequence = false;
+
+ EntityE entityE;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp(EntityE.class,DROP_TABLES);
+ assertNotNull(emf);
+
+ conf = (JDBCConfiguration) emf.getConfiguration();
+ dict = conf.getDBDictionaryInstance();
+ supportsNativeSequence = dict.nextSequenceQuery != null;
+
+ if (supportsNativeSequence) {
+ em = emf.createEntityManager();
+ assertNotNull(em);
+ }
+ }
+
+ public void createEntityE() {
+ entityE = new EntityE("e name");
+ }
+
+ // TODO: temp
+// public void testDBCapability() {
+// Connection conn = (Connection)em.getConnection();
+// try {
+// DatabaseMetaData meta = conn.getMetaData();
+// System.out.println("LC - " +
+// meta.storesLowerCaseIdentifiers());
+// System.out.println("LCQ - " +
+// meta.storesLowerCaseQuotedIdentifiers());
+// System.out.println("MC - " +
+// meta.storesMixedCaseIdentifiers());
+// System.out.println("MCQ - " +
+// meta.storesMixedCaseQuotedIdentifiers());
+// System.out.println("UC - " +
+// meta.storesUpperCaseIdentifiers());
+// System.out.println("UCQ - " +
+// meta.storesUpperCaseQuotedIdentifiers());
+//
+// System.out.println("db product name - " +
+// meta.getDatabaseProductName());
+// System.out.println("db product version - " +
+// meta.getDatabaseProductVersion());
+// System.out.println("driver name - " +
+// meta.getDriverName());
+// System.out.println("driver version - " +
+// meta.getDriverVersion());
+// } catch (SQLException e) {
+// e.printStackTrace();
+// }
+// }
+
+ public void testSeqGen() {
+ if (!supportsNativeSequence) {
+ return;
+ }
+ createEntityE();
+
+ em.getTransaction().begin();
+ em.persist(entityE);
+ em.getTransaction().commit();
+
+ System.out.println(super.toString(sql));
+
+ int genId = entityE.getId();
+ System.out.println("generated id - " + genId);
+ em.clear();
+ em.getTransaction().begin();
+ EntityE eA = em.find(EntityE.class, genId);
+ assertEquals("e name", eA.getName());
+
+ em.getTransaction().commit();
+ em.close();
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimIdSeqGen.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java Fri May 29 18:54:08 2009
@@ -0,0 +1,106 @@
+package org.apache.openjpa.persistence.delimited.identifiers;
+
+import java.util.List;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+/*
+ * 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.
+ */
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestManualDelimInheritance extends SQLListenerTestCase {
+ OpenJPAEntityManager em;
+ int id = 0;
+ Dog dog;
+ Cat cat;
+ JDBCConfiguration conf;
+ DBDictionary dict;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp(
+ org.apache.openjpa.persistence.delimited.identifiers.Animal.class,
+ org.apache.openjpa.persistence.delimited.identifiers.Dog.class,
+ org.apache.openjpa.persistence.delimited.identifiers.Cat.class);
+ assertNotNull(emf);
+
+ em = emf.createEntityManager();
+ assertNotNull(em);
+
+ conf = (JDBCConfiguration) emf.getConfiguration();
+ dict = conf.getDBDictionaryInstance();
+ }
+
+ private void createDog(int id) {
+ dog = new Dog(id);
+ dog.setName("Spot");
+ dog.setType("dog");
+ }
+
+ private void createCat(int id) {
+ cat = new Cat(id);
+ cat.setName("Puff");
+ cat.setType("cat");
+ }
+
+ public void testCreate() {
+ id++;
+ createDog(id);
+ id++;
+ createCat(id);
+
+ em.getTransaction().begin();
+ em.persist(dog);
+ em.persist(cat);
+ em.getTransaction().commit();
+
+ runQueries();
+ }
+
+ private void runQueries() {
+ em.clear();
+ queryCat();
+ em.clear();
+ queryDog();
+ }
+
+ private void queryCat() {
+ String query =
+ "SELECT DISTINCT a " +
+ "FROM Animal a " +
+ "WHERE a.type = 'cat'";
+ Query q = em.createQuery(query);
+ List<Animal> results = (List<Animal>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ // Use native query
+ private void queryDog() {
+ String query =
+ "SELECT * " +
+ "FROM \"Animal\" a " +
+ "WHERE a.\"discr col\" = 'Dog'";
+ Query q = em.createNativeQuery(query);
+ List<Animal> results = (List<Animal>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimInheritance.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java?rev=780068&view=auto
==============================================================================
--- openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java (added)
+++ openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java Fri May 29 18:54:08 2009
@@ -0,0 +1,155 @@
+/*
+ * 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.delimited.identifiers;
+
+import java.util.List;
+
+import javax.persistence.Query;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.sql.DBDictionary;
+import org.apache.openjpa.persistence.OpenJPAEntityManager;
+import org.apache.openjpa.persistence.test.SQLListenerTestCase;
+
+public class TestManualDelimitedJoinAnnotations extends SQLListenerTestCase {
+ OpenJPAEntityManager em;
+ int id = 0;
+ EntityC entityC;
+ EntityD entityD;
+ EntityD2 entityD2;
+ EntityD3 entityD3;
+ EntityD4 entityD4;
+ JDBCConfiguration conf;
+ DBDictionary dict;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp(
+ org.apache.openjpa.persistence.delimited.identifiers.EntityC.class,
+ org.apache.openjpa.persistence.delimited.identifiers.EntityD.class,
+ org.apache.openjpa.persistence.delimited.identifiers.EntityD2.class,
+ org.apache.openjpa.persistence.delimited.identifiers.EntityD3.class,
+ org.apache.openjpa.persistence.delimited.identifiers.EntityD4.class,
+ DROP_TABLES);
+ assertNotNull(emf);
+
+ em = emf.createEntityManager();
+ assertNotNull(em);
+
+ conf = (JDBCConfiguration) emf.getConfiguration();
+ dict = conf.getDBDictionaryInstance();
+ }
+
+ private void createCandD(int id) {
+ entityC = new EntityC(id);
+ entityC.setName("ec");
+ entityC.setSecName("secName1");
+
+ entityD = new EntityD(id);
+ entityD.setName("ed");
+
+ entityD2 = new EntityD2(id);
+ entityD2.setName("ed2");
+
+ entityD3 = new EntityD3(id);
+ entityD3.setName("ed3");
+
+ entityD4 = new EntityD4(id);
+ entityD4.setName("ed4");
+
+ entityC.addEntityD(entityD);
+ entityD.addEntityC(entityC);
+
+ entityC.setEntityD2(entityD2);
+
+ entityC.addMapValues(entityD3, entityD4);
+ entityC.addMap2Values(entityD4, entityD3);
+
+ entityD2.setEntityD3(entityD3);
+ }
+
+ public void testCreate() {
+ id++;
+ createCandD(id);
+ // TODO: Maybe create another one.
+
+ em.getTransaction().begin();
+ em.persist(entityC);
+ em.persist(entityD);
+ em.persist(entityD2);
+ em.persist(entityD3);
+ em.persist(entityD4);
+ em.getTransaction().commit();
+
+ runQueries();
+ }
+
+ private void runQueries() {
+ em.clear();
+ queryJoinTable();
+ em.clear();
+ queryJoinColumn();
+ em.clear();
+ querySecondaryTableValue();
+ em.clear();
+ queryMapValue();
+ }
+
+ private void queryJoinTable() {
+ String query =
+ "SELECT c " +
+ "FROM EntityC c JOIN c.entityDs d " +
+ "WHERE d.name = 'ed'";
+ Query q = em.createQuery(query);
+ List<EntityC> results = (List<EntityC>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ private void queryJoinColumn() {
+ String query =
+ "SELECT c " +
+ "FROM EntityC c JOIN c.entityD2 d2 " +
+ "WHERE d2.name = 'ed2'";
+ Query q = em.createQuery(query);
+ List<EntityC> results = (List<EntityC>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ private void querySecondaryTableValue() {
+ String query =
+ "SELECT c " +
+ "FROM EntityC c " +
+ "WHERE c.secName = 'secName1'";
+ Query q = em.createQuery(query);
+ List<EntityC> results = (List<EntityC>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+ private void queryMapValue() {
+ String query =
+ "SELECT c " +
+ "FROM EntityC c, IN(c.map2) m " +
+ "WHERE m.name = 'ed3'";
+ Query q = em.createQuery(query);
+ List<EntityC> results = (List<EntityC>)q.getResultList();
+ assertEquals(1,results.size());
+ }
+
+
+}
Propchange: openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/delimited/identifiers/TestManualDelimitedJoinAnnotations.java
------------------------------------------------------------------------------
svn:eol-style = native