This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch javax-index
in repository https://gitbox.apache.org/repos/asf/openjpa.git
The following commit(s) were added to refs/heads/javax-index by this push:
new a0eaa23 Tests are added
a0eaa23 is described below
commit a0eaa234eaf88f1068069fe9c5ff4ca8c1ad8010
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Sat Mar 2 16:55:21 2019 +0700
Tests are added
---
.../jdbc/AnnotationPersistenceMappingParser.java | 12 ----
.../openjpa/persistence/jdbc/MappingTag.java | 1 -
.../jdbc/annotations/EntityWithIndices.java | 76 ++++++++++++++++++++++
.../persistence/jdbc/annotations/TestIndices.java | 64 ++++++++++++++++++
4 files changed, 140 insertions(+), 13 deletions(-)
diff --git
a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
index 069de58..d22431b 100644
---
a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
+++
b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
@@ -49,7 +49,6 @@ import static
org.apache.openjpa.persistence.jdbc.MappingTag.ENUMERATED;
import static org.apache.openjpa.persistence.jdbc.MappingTag.FIELD_RESULT;
import static org.apache.openjpa.persistence.jdbc.MappingTag.FK;
import static org.apache.openjpa.persistence.jdbc.MappingTag.INDEX;
-import static org.apache.openjpa.persistence.jdbc.MappingTag.J_INDEX;
import static org.apache.openjpa.persistence.jdbc.MappingTag.INHERITANCE;
import static org.apache.openjpa.persistence.jdbc.MappingTag.JOIN_COL;
import static org.apache.openjpa.persistence.jdbc.MappingTag.JOIN_COLS;
@@ -263,7 +262,6 @@ public class AnnotationPersistenceMappingParser
_tags.put(EmbeddedMapping.class, EMBEDDED_MAPPING);
_tags.put(ForeignKey.class, FK);
_tags.put(Index.class, INDEX);
- _tags.put(javax.persistence.Index.class, J_INDEX);
_tags.put(MappingOverride.class, MAPPING_OVERRIDE);
_tags.put(MappingOverrides.class, MAPPING_OVERRIDES);
_tags.put(Nonpolymorphic.class, NONPOLY);
@@ -917,13 +915,6 @@ public class AnnotationPersistenceMappingParser
/**
* Parse the given index.
*/
- private void parseIndex(MappingInfo info, javax.persistence.Index idx) {
- parseIndex(info, idx.name(), true, idx.unique());
- }
-
- /**
- * Parse the given index.
- */
private void parseIndex(MappingInfo info, Index idx) {
parseIndex(info, idx.name(), idx.enabled(), idx.unique());
}
@@ -1350,9 +1341,6 @@ public class AnnotationPersistenceMappingParser
case INDEX:
parseIndex(fm.getValueInfo(), (Index) anno);
break;
- case J_INDEX:
- parseIndex(fm.getValueInfo(), (javax.persistence.Index)
anno);
- break;
case NONPOLY:
fm.setPolymorphic(toPolymorphicConstant
(((Nonpolymorphic) anno).value()));
diff --git
a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
index 9d6bf0b..07d1b7b 100644
---
a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
+++
b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
@@ -82,7 +82,6 @@ enum MappingTag {
FK_COL_NAMES,
FK_COL_NAME,
INDEX,
- J_INDEX,
KEY_COL,
KEY_COLS,
KEY_CLASS_CRIT,
diff --git
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EntityWithIndices.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EntityWithIndices.java
new file mode 100644
index 0000000..cc073d1
--- /dev/null
+++
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/EntityWithIndices.java
@@ -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.jdbc.annotations;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.Table;
+
+@Entity
+@Table(name = "INDICES1"
+ , indexes = {@Index(name = "idx_index1", columnList = "index1")
+ , @Index(name = "idx_long", columnList = "LONG_NAME", unique =
true)})
+public class EntityWithIndices {
+ @Id
+ @Column(name = "PK")
+ private Long pk;
+
+ @Column(name = "INDEX1")
+ private String index1;
+
+ @Column(name = "LONG_NAME")
+ private String longName;
+
+ @Column(name = "NAME")
+ private String name;
+
+ public Long getPk() {
+ return pk;
+ }
+
+ public void setPk(Long pk) {
+ this.pk = pk;
+ }
+
+ public String getIndex1() {
+ return index1;
+ }
+
+ public void setIndex1(String index1) {
+ this.index1 = index1;
+ }
+
+ public String getLongName() {
+ return longName;
+ }
+
+ public void setLongName(String longName) {
+ this.longName = longName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git
a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestIndices.java
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestIndices.java
new file mode 100644
index 0000000..f105d64
--- /dev/null
+++
b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/jdbc/annotations/TestIndices.java
@@ -0,0 +1,64 @@
+/*
+ * 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.jdbc.annotations;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.identifier.DBIdentifier;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Index;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+import org.junit.Test;
+
+public class TestIndices extends SingleEMFTestCase {
+ @Override
+ public void setUp() {
+ setUp(EntityWithIndices.class, CLEAR_TABLES
+// ,"openjpa.Log","SQL=trace"
+ );
+ }
+
+ @Test
+ public void testIndicesCreated() {
+ JDBCConfiguration conf = (JDBCConfiguration)
emf.getConfiguration();
+ ClassMapping cls =
conf.getMappingRepositoryInstance().getMapping(EntityWithIndices.class, null,
true);
+ Table table = cls.getTable();
+ Index idx1 =
table.getIndex(DBIdentifier.newIndex("idx_index1"));
+ assertNotNull("Defined index should exist", idx1);
+ assertFalse(idx1.isUnique());
+
+ Index idx2 = table.getIndex(DBIdentifier.newIndex("idx_long"));
+ assertNotNull("Defined index should exist", idx2);
+ assertTrue(idx2.isUnique());
+
+ Set<String> indexedCols = new HashSet<>();
+ for (Index idx : table.getIndexes()) {
+ for (Column col : idx.getColumns()) {
+ indexedCols.add(col.getIdentifier().getName());
+ }
+ }
+ assertTrue(indexedCols.contains("INDEX1"));
+ assertTrue(indexedCols.contains("LONG_NAME"));
+ assertFalse(indexedCols.contains("NAME"));
+ }
+}