From 4da7ad37907cbe2c68b86d3d6b33429c06f85fe8 Mon Sep 17 00:00:00 2001 From: Catalina Wei Date: Sun, 12 Apr 2009 03:19:46 +0000 Subject: [PATCH] OPENJPA-967 JPA2 Query support for embeddable MapKey improvement/rework git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@764279 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/exps/PCPath.java | 21 ++++--------------- .../meta/strats/EmbeddedClassStrategy.java | 6 +++++- .../RelationMapInverseKeyFieldStrategy.java | 14 +++++++++++-- .../strats/RelationMapTableFieldStrategy.java | 15 ++++++++++--- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java index b65c0a9d3..fcaf5d6cb 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/exps/PCPath.java @@ -809,31 +809,18 @@ public class PCPath LRSMapFieldStrategy strategy = (LRSMapFieldStrategy) pstate.field.getStrategy(); ClassMapping mapping = pstate.field.getKeyMapping().getTypeMapping(); - if (strategy instanceof HandlerRelationMapTableFieldStrategy) - strategy.selectKey(sel, mapping, null, ctx.store, ctx.fetch, - pstate.joins); - else { - sel.select(_class.getPrimaryKeyColumns(), pstate.joins); - FieldMapping[] fms = mapping.getDefinedFieldMappings(); - for (int i = 0; i < fms.length; i++) - sel.select(fms[i].getColumns(), pstate.joins); - } + strategy.selectKey(sel, mapping, null, ctx.store, ctx.fetch, + pstate.joins); } private Object loadEmbeddedMapKey(ExpContext ctx, ExpState state, Result res) throws SQLException { PathExpState pstate = (PathExpState) state; validateMapStrategy(pstate.field.getStrategy()); - FieldMapping fmd = (FieldMapping) pstate.field.getKey(). - getValueMappedByMetaData(); LRSMapFieldStrategy strategy = (LRSMapFieldStrategy) pstate.field.getStrategy(); - if (strategy instanceof HandlerRelationMapTableFieldStrategy) - return strategy.loadKey(null, ctx.store, ctx.fetch, res, - pstate.joins); - else - return fmd.getStrategy(). - loadProjection(ctx.store, ctx.fetch, res, pstate.joins); + return strategy.loadKey(null, ctx.store, ctx.fetch, res, + pstate.joins); } public void calculateValue(Select sel, ExpContext ctx, ExpState state, diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbeddedClassStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbeddedClassStrategy.java index f46c5454f..6b18ff85a 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbeddedClassStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/EmbeddedClassStrategy.java @@ -47,7 +47,11 @@ public class EmbeddedClassStrategy ClassMappingInfo info = cls.getMappingInfo(); info.assertNoSchemaComponents(cls, true); - ClassMapping owner = vm.getFieldMapping().getDefiningMapping(); + ClassMapping owner = null; + if (vm.getValueMappedByMapping() != null) + owner = vm.getValueMappedByMapping().getDefiningMapping(); + else + owner = vm.getFieldMapping().getDefiningMapping(); cls.setIdentityType(owner.getIdentityType()); cls.setObjectIdType(owner.getObjectIdType(), owner.isObjectIdTypeShared()); diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapInverseKeyFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapInverseKeyFieldStrategy.java index f3c151db9..b598acd1d 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapInverseKeyFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapInverseKeyFieldStrategy.java @@ -81,13 +81,23 @@ public class RelationMapInverseKeyFieldStrategy public void selectKey(Select sel, ClassMapping key, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Joins joins) { - throw new InternalException(); + ValueMapping vm = field.getKeyMapping(); + if (vm.isEmbedded()) + sel.select(key, field.getKeyMapping().getSelectSubclasses(), + store, fetch, JDBCFetchConfiguration.EAGER_NONE, joins); + else + throw new InternalException(); } public Object loadKey(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res, Joins joins) throws SQLException { - throw new InternalException(); + ValueMapping vm = field.getKeyMapping(); + if (vm.isEmbedded()) + return vm.getValueMappedByMapping(). + loadProjection(store, fetch, res, joins); + else + throw new InternalException(); } public Object deriveKey(JDBCStore store, Object value) { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapTableFieldStrategy.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapTableFieldStrategy.java index 57f44dbbe..b5374ef40 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapTableFieldStrategy.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/RelationMapTableFieldStrategy.java @@ -22,7 +22,6 @@ import java.sql.SQLException; import java.util.Collection; import java.util.Map; -import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration; import org.apache.openjpa.jdbc.kernel.JDBCStore; import org.apache.openjpa.jdbc.meta.ClassMapping; @@ -81,13 +80,23 @@ public class RelationMapTableFieldStrategy public void selectKey(Select sel, ClassMapping key, OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Joins joins) { - throw new InternalException(); + ValueMapping vm = field.getKeyMapping(); + if (vm.isEmbedded()) + sel.select(key, field.getKeyMapping().getSelectSubclasses(), + store, fetch, JDBCFetchConfiguration.EAGER_NONE, joins); + else + throw new InternalException(); } public Object loadKey(OpenJPAStateManager sm, JDBCStore store, JDBCFetchConfiguration fetch, Result res, Joins joins) throws SQLException { - throw new InternalException(); + ValueMapping vm = field.getKeyMapping(); + if (vm.isEmbedded()) + return vm.getValueMappedByMapping(). + loadProjection(store, fetch, res, joins); + else + throw new InternalException(); } public Object deriveKey(JDBCStore store, Object value) {