You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by pc...@apache.org on 2006/07/19 23:35:07 UTC

svn commit: r423615 [43/44] - in /incubator/openjpa/trunk: ./ openjpa-jdbc-5/ openjpa-jdbc-5/src/ openjpa-jdbc-5/src/main/ openjpa-jdbc-5/src/main/java/ openjpa-jdbc-5/src/main/java/org/ openjpa-jdbc-5/src/main/java/org/apache/ openjpa-jdbc-5/src/main/...

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import org.apache.openjpa.jdbc.kernel.DelegatingJDBCFetchConfiguration;
+import org.apache.openjpa.jdbc.kernel.EagerFetchModes;
+import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
+import org.apache.openjpa.jdbc.kernel.LRSSizes;
+import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
+import org.apache.openjpa.kernel.DelegatingFetchConfiguration;
+import org.apache.openjpa.kernel.FetchConfiguration;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.PersistenceExceptions;
+
+/**
+ * JDBC extensions to the fetch plan.
+ *
+ * @since 4.0
+ * @author Abe White
+ * @published
+ */
+public class JDBCFetchPlan
+    extends FetchPlan
+    implements EagerFetchModes, LRSSizes, JoinSyntaxes {
+
+    private DelegatingJDBCFetchConfiguration _fetch;
+
+    /**
+     * Constructor; supply delegate.
+     */
+    public JDBCFetchPlan(FetchConfiguration fetch) {
+        super(fetch);
+    }
+
+    @Override
+    protected DelegatingFetchConfiguration newDelegatingFetchConfiguration
+        (FetchConfiguration fetch) {
+        _fetch = new DelegatingJDBCFetchConfiguration((JDBCFetchConfiguration)
+            fetch, PersistenceExceptions.TRANSLATOR);
+        return _fetch;
+    }
+
+    public int getEagerFetchMode() {
+        return _fetch.getEagerFetchMode();
+    }
+
+    public JDBCFetchPlan setEagerFetchMode(int mode) {
+        _fetch.setEagerFetchMode(mode);
+        return this;
+    }
+
+    public int getSubclassFetchMode() {
+        return _fetch.getSubclassFetchMode();
+    }
+
+    public JDBCFetchPlan setSubclassFetchMode(int mode) {
+        _fetch.setSubclassFetchMode(mode);
+        return this;
+    }
+
+    public int getResultSetType() {
+        return _fetch.getResultSetType();
+    }
+
+    public JDBCFetchPlan setResultSetType(int type) {
+        _fetch.setResultSetType(type);
+        return this;
+    }
+
+    public int getFetchDirection() {
+        return _fetch.getFetchDirection();
+    }
+
+    public JDBCFetchPlan setFetchDirection(int direction) {
+        _fetch.setFetchDirection(direction);
+        return this;
+    }
+
+    public int getLRSSize() {
+        return _fetch.getLRSSize();
+    }
+
+    public JDBCFetchPlan setLRSSize(int lrsSize) {
+        _fetch.setLRSSize(lrsSize);
+        return this;
+    }
+
+    public int getJoinSyntax() {
+        return _fetch.getJoinSyntax();
+    }
+
+    public JDBCFetchPlan setJoinSyntax(int syntax) {
+        _fetch.setJoinSyntax(syntax);
+        return this;
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCFetchPlan.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import org.apache.openjpa.conf.OpenJPAConfiguration;
+import org.apache.openjpa.conf.ProductDerivation;
+import org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl;
+import org.apache.openjpa.lib.conf.ConfigurationProvider;
+import org.apache.openjpa.persistence.FetchPlan;
+import org.apache.openjpa.persistence.PersistenceProductDerivation;
+
+/**
+ * Sets JDBC-specific JPA specification defaults.
+ *
+ * @author Abe White
+ * @nojavadoc
+ */
+public class JDBCPersistenceProductDerivation
+    implements ProductDerivation {
+
+    public int getType() {
+        return TYPE_SPEC_STORE;
+    }
+
+    public void beforeConfigurationConstruct(ConfigurationProvider cp) {
+    }
+
+    public void beforeConfigurationLoad(OpenJPAConfiguration c) {
+        if (!(c instanceof JDBCConfigurationImpl))
+            return;
+
+        c.getStoreFacadeTypeRegistry().registerImplementation(
+            FetchPlan.class, JDBCFetchPlan.class);
+
+        JDBCConfigurationImpl conf = (JDBCConfigurationImpl) c;
+        String jpa = PersistenceProductDerivation.SPEC_JPA;
+        String ejb = PersistenceProductDerivation.ALIAS_EJB;
+
+        conf.metaFactoryPlugin.setAlias(jpa,
+            PersistenceMappingFactory.class.getName());
+        conf.metaFactoryPlugin.setAlias(ejb,
+            PersistenceMappingFactory.class.getName());
+
+        conf.mappingFactoryPlugin.setAlias(jpa,
+            PersistenceMappingFactory.class.getName());
+        conf.mappingFactoryPlugin.setAlias(ejb,
+            PersistenceMappingFactory.class.getName());
+
+        conf.mappingDefaultsPlugin.setAlias(jpa,
+            PersistenceMappingDefaults.class.getName());
+        conf.mappingDefaultsPlugin.setAlias(ejb,
+            PersistenceMappingDefaults.class.getName());
+    }
+
+    public void afterSpecificationSet(OpenJPAConfiguration c) {
+        String jpa = PersistenceProductDerivation.SPEC_JPA;
+        if (!(c instanceof JDBCConfigurationImpl)
+            || !jpa.equals(c.getSpecification()))
+            return;
+
+        JDBCConfigurationImpl conf = (JDBCConfigurationImpl) c;
+        conf.mappingDefaultsPlugin.setDefault(jpa);
+        conf.mappingDefaultsPlugin.setString(jpa);
+    }
+
+    public void afterClose(OpenJPAConfiguration c) {
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/JDBCPersistenceProductDerivation.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverride.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverride.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverride.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverride.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+import javax.persistence.Column;
+
+/**
+ * Allows override of complex embedded or superclass mappings.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface MappingOverride {
+
+    String name() default "";
+
+    Column[] columns() default {};
+
+    XJoinColumn[] joinColumns() default {};
+
+    ElementJoinColumn[] elementJoinColumns() default {};
+
+    ContainerTable containerTable() default @ContainerTable(specified = false);
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverride.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverrides.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverrides.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverrides.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverrides.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Allows override of complex embedded or superclass mappings.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface MappingOverrides {
+
+    MappingOverride[] value() default {};
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingOverrides.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+/////////////////////////////////////////////////////////
+// NOTE: when adding a new type, make sure to update the
+// table in PersistenceMappingParser
+/////////////////////////////////////////////////////////
+
+/**
+ * Set of mapping tags used in JPA.
+ *
+ * @author Abe White
+ */
+enum MappingTag {
+
+    ASSOC_OVERRIDE,
+    ASSOC_OVERRIDES,
+    ATTR_OVERRIDE,
+    ATTR_OVERRIDES,
+    COL,
+    COLUMN_RESULT,
+    DISCRIM_COL,
+    DISCRIM_VAL,
+    ENTITY_RESULT,
+    ENUMERATED,
+    FIELD_RESULT,
+    GEN_ID_TABLE,
+    INHERITANCE,
+    JOIN_COL,
+    JOIN_COLS,
+    JOIN_TABLE,
+    PK_JOIN_COL,
+    PK_JOIN_COLS,
+    SECONDARY_TABLE,
+    SECONDARY_TABLES,
+    SQL_RESULT_SET_MAPPING,
+    SQL_RESULT_SET_MAPPINGS,
+    TABLE,
+    TABLE_GEN,
+    TEMPORAL,
+    // openjpa extensions
+    CLASS_CRIT,
+    COLS,
+    CONTAINER_TABLE,
+    DATASTORE_ID_COL,
+    DISCRIM_STRAT,
+    EAGER_FETCH_MODE,
+    ELEM_CLASS_CRIT,
+    ELEM_FK,
+    ELEM_INDEX,
+    ELEM_JOIN_COL,
+    ELEM_JOIN_COLS,
+    ELEM_NONPOLY,
+    EMBEDDED_MAPPING,
+    FK,
+    INDEX,
+    MAPPING_OVERRIDE,
+    MAPPING_OVERRIDES,
+    NONPOLY,
+    ORDER_COL,
+    STRAT,
+    SUBCLASS_FETCH_MODE,
+    UNIQUE,
+    VERSION_COL,
+    VERSION_COLS,
+    VERSION_STRAT,
+    X_JOIN_COL,
+    X_JOIN_COLS,
+    X_SECONDARY_TABLE,
+    X_SECONDARY_TABLES,
+    X_TABLE,
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/MappingTag.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Indicates that the annotated relation is not entirely polymorphic.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Nonpolymorphic {
+
+    NonpolymorphicType value() default NonpolymorphicType.EXACT;
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Nonpolymorphic.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+/**
+ * Nonpolymorphic settings.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+public enum NonpolymorphicType {
+
+    EXACT,
+    JOINABLE,
+    FALSE };

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/NonpolymorphicType.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/OrderColumn.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/OrderColumn.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/OrderColumn.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/OrderColumn.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Surrogate order column.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface OrderColumn {
+
+    String name() default "";
+
+    boolean enabled() default true;
+
+    boolean insertable() default true;
+
+    boolean updatable() default true;
+
+    String columnDefinition() default "";
+
+    int precision() default 0; // decimal precision
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/OrderColumn.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.Discriminator;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.MappingDefaultsImpl;
+import org.apache.openjpa.jdbc.meta.ValueMapping;
+import org.apache.openjpa.jdbc.meta.Version;
+import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.NoneDiscriminatorStrategy;
+import org.apache.openjpa.jdbc.meta.strats.NoneVersionStrategy;
+import org.apache.openjpa.jdbc.meta.strats.NumberVersionStrategy;
+import org.apache.openjpa.jdbc.meta.strats.SubclassJoinDiscriminatorStrategy;
+import org.apache.openjpa.jdbc.meta.strats.ValueMapDiscriminatorStrategy;
+import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Schema;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.jdbc.sql.JoinSyntaxes;
+import org.apache.openjpa.meta.JavaTypes;
+import serp.util.Strings;
+
+/**
+ * Supplies default mapping information in accordance with JPA spec.
+ *
+ * @author Steve Kim
+ * @author Abe White
+ */
+public class PersistenceMappingDefaults
+    extends MappingDefaultsImpl {
+
+    public PersistenceMappingDefaults() {
+        setDefaultMissingInfo(true);
+        setStoreEnumOrdinal(true);
+        setOrderLists(false);
+        setAddNullIndicator(false);
+        setDiscriminatorColumnName("DTYPE");
+    }
+
+    @Override
+    public Object getStrategy(Version vers, boolean adapt) {
+        Object strat = super.getStrategy(vers, adapt);
+        ClassMapping cls = vers.getClassMapping();
+        if (strat != null || cls.getJoinablePCSuperclassMapping() != null
+            || cls.getVersionField() != null)
+            return strat;
+
+        if (vers.getMappingInfo().getColumns().isEmpty())
+            return NoneVersionStrategy.getInstance();
+        return new NumberVersionStrategy();
+    }
+
+    @Override
+    public Object getStrategy(Discriminator disc, boolean adapt) {
+        Object strat = super.getStrategy(disc, adapt);
+        ClassMapping cls = disc.getClassMapping();
+        if (strat != null || cls.getJoinablePCSuperclassMapping() != null
+            || disc.getMappingInfo().getValue() != null)
+            return strat;
+
+        // don't use a column-based discriminator approach unless user has set
+        // a column explicitly or is using flat inheritance explicitly
+        if (!disc.getMappingInfo().getColumns().isEmpty())
+            return new ValueMapDiscriminatorStrategy();
+
+        ClassMapping base = cls;
+        while (base.getMappingInfo().getHierarchyStrategy() == null
+            && base.getPCSuperclassMapping() != null)
+            base = base.getPCSuperclassMapping();
+
+        strat = base.getMappingInfo().getHierarchyStrategy();
+        if (FlatClassStrategy.ALIAS.equals(strat))
+            return new ValueMapDiscriminatorStrategy();
+        if (VerticalClassStrategy.ALIAS.equals(strat)
+            && dict.joinSyntax != JoinSyntaxes.SYNTAX_TRADITIONAL)
+            return new SubclassJoinDiscriminatorStrategy();
+        return NoneDiscriminatorStrategy.getInstance();
+    }
+
+    @Override
+    public String getTableName(ClassMapping cls, Schema schema) {
+        return Strings.getClassName(cls.getDescribedType()).replace('$', '_');
+    }
+
+    @Override
+    public String getTableName(FieldMapping fm, Schema schema) {
+        // base name is table of defining type + '_'
+        String name = fm.getDefiningMapping().getTable().getName() + "_";
+
+        // 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
+        // suffix with the field name
+        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();
+        return name.replace('$', '_');
+    }
+
+    @Override
+    public void populateJoinColumn(FieldMapping fm, Table local, Table foreign,
+        Column col, Object target, int pos, int cols) {
+        // only use spec defaults with column targets
+        if (!(target instanceof Column))
+            return;
+
+        // if this is a bidi relation, prefix with inverse field name, else
+        // prefix with owning entity name
+        FieldMapping[] inverses = fm.getInverseMappings();
+        String name;
+        if (inverses.length > 0)
+            name = inverses[0].getName();
+        else
+            name = fm.getDefiningMapping().getTypeAlias();
+
+        // suffix with '_' + target column
+        name += "_" + ((Column) target).getName();
+        col.setName(name);
+    }
+
+    @Override
+    public void populateForeignKeyColumn(ValueMapping vm, String name,
+        Table local, Table foreign, Column col, Object target, boolean inverse,
+        int pos, int cols) {
+        // if this is a non-inverse collection element key, it must be in
+        // a join table; jpa says to use the target column name,
+        // which is the default
+        if (!inverse && vm == vm.getFieldMapping().getElement()
+            && vm.getFieldMapping().getTypeCode() != JavaTypes.MAP)
+            return;
+
+        // otherwise jpa always uses <field>_<pkcol> for column name, even
+        // when only one col
+        if (target instanceof Column)
+            col.setName(name + "_" + ((Column) target).getName());
+    }
+
+    @Override
+    public void populateColumns(Version vers, Table table, Column[] cols) {
+        // check for version field and use its name as column name
+        FieldMapping fm = vers.getClassMapping().getVersionFieldMapping();
+        if (fm != null && cols.length == 1)
+            cols[0].setName(fm.getName());
+        else
+            super.populateColumns(vers, table, cols);
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingDefaults.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingFactory.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingFactory.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingFactory.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingFactory.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.MappingRepository;
+import org.apache.openjpa.meta.MetaDataFactory;
+import org.apache.openjpa.persistence.AnnotationPersistenceMetaDataParser;
+import org.apache.openjpa.persistence.PersistenceMetaDataFactory;
+import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser;
+
+/**
+ * {@link MetaDataFactory} for JPA mapping information.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+public class PersistenceMappingFactory
+    extends PersistenceMetaDataFactory {
+
+    @Override
+    protected AnnotationPersistenceMetaDataParser newAnnotationParser() {
+        AnnotationPersistenceMappingParser parser =
+            new AnnotationPersistenceMappingParser((JDBCConfiguration)
+                repos.getConfiguration());
+        // strict mode means we're using a separate mapping parser, so if
+        // we're adapting parse metadata hints
+        if (strict)
+            parser.setMappingOverride(((MappingRepository) repos).
+                getStrategyInstaller().isAdapting());
+        return parser;
+    }
+
+    @Override
+    protected XMLPersistenceMetaDataParser newXMLParser(boolean loading) {
+        XMLPersistenceMappingParser parser = new XMLPersistenceMappingParser
+            ((JDBCConfiguration) repos.getConfiguration());
+        // strict mode means we're using a separate mapping parser, so if
+        // we're adapting parse metadata hints
+        if (strict && loading)
+            parser.setMappingOverride(((MappingRepository) repos).
+                getStrategyInstaller().isAdapting());
+        return parser;
+    }
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/PersistenceMappingFactory.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Strategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Strategy.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Strategy.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Strategy.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.*;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Mapping strategy.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE, METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Strategy {
+
+    String value() default "";
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Strategy.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Determines how to eager-fetch subclass data.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface SubclassFetchMode {
+
+    EagerFetchType value() default EagerFetchType.NONE;
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/SubclassFetchMode.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Unique.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Unique.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Unique.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Unique.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Unique constraint definition.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface Unique {
+
+    String name() default "";
+
+    boolean enabled() default true;
+
+    boolean deferred() default false;
+
+    String[] columnNames() default {};
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/Unique.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumn.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumn.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumn.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumn.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Surrogate version column.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface VersionColumn {
+
+    String name() default "";
+
+    boolean nullable() default true;
+
+    boolean insertable() default true;
+
+    boolean updatable() default true;
+
+    String columnDefinition() default "";
+
+    int length() default 255;
+
+    int precision() default 0; // decimal precision
+
+    int scale() default 0; // decimal scale
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumn.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumns.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumns.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumns.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumns.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Allows the specification of multiple version columns for complex versioning.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface VersionColumns {
+
+    VersionColumn[] value() default {};
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionColumns.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionStrategy.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionStrategy.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionStrategy.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionStrategy.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Version mapping strategy.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ TYPE })
+@Retention(RUNTIME)
+public @interface VersionStrategy {
+
+    String value() default "";
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/VersionStrategy.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumn.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumn.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumn.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumn.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Extended join column.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface XJoinColumn {
+
+    String name() default "";
+
+    String referencedColumnName() default "";
+
+    String referencedAttributeName() default "";
+
+    boolean unique() default false;
+
+    boolean nullable() default true;
+
+    boolean insertable() default true;
+
+    boolean updatable() default true;
+
+    String columnDefinition() default "";
+
+    String table() default "";
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumn.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumns.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumns.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumns.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumns.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import java.lang.annotation.Retention;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import java.lang.annotation.Target;
+
+/**
+ * Allows the specification of multiple columns for compound joins.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+@Target({ METHOD, FIELD })
+@Retention(RUNTIME)
+public @interface XJoinColumns {
+
+    XJoinColumn[] value() default {};
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XJoinColumns.java
------------------------------------------------------------------------------
    svn:executable = *

Added: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java (added)
+++ incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,867 @@
+/*
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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;
+
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.EnumType;
+import javax.persistence.InheritanceType;
+import javax.persistence.TemporalType;
+
+import org.apache.commons.lang.StringUtils;
+import org.xml.sax.Attributes;
+import org.xml.sax.SAXException;
+import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
+import org.apache.openjpa.jdbc.meta.ClassMapping;
+import org.apache.openjpa.jdbc.meta.ClassMappingInfo;
+import org.apache.openjpa.jdbc.meta.DiscriminatorMappingInfo;
+import org.apache.openjpa.jdbc.meta.FieldMapping;
+import org.apache.openjpa.jdbc.meta.MappingRepository;
+import org.apache.openjpa.jdbc.meta.QueryResultMapping;
+import org.apache.openjpa.jdbc.meta.SequenceMapping;
+import org.apache.openjpa.jdbc.meta.strats.EnumValueHandler;
+import org.apache.openjpa.jdbc.meta.strats.FlatClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.FullClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.NoneClassStrategy;
+import org.apache.openjpa.jdbc.meta.strats.VerticalClassStrategy;
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.Unique;
+import org.apache.openjpa.lib.log.Log;
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.meta.ClassMetaData;
+import org.apache.openjpa.meta.FieldMetaData;
+import org.apache.openjpa.meta.JavaTypes;
+import org.apache.openjpa.meta.MetaDataRepository;
+import org.apache.openjpa.persistence.XMLPersistenceMetaDataParser;
+import static org.apache.openjpa.persistence.jdbc.MappingTag.*;
+
+/**
+ * Custom SAX parser used by the system to parse persistence mapping files.
+ *
+ * @author Steve Kim
+ * @nojavadoc
+ */
+public class XMLPersistenceMappingParser
+    extends XMLPersistenceMetaDataParser {
+
+    private static final Map<String, MappingTag> _elems =
+        new HashMap<String, MappingTag>();
+
+    static {
+        _elems.put("association-override", ASSOC_OVERRIDE);
+        _elems.put("attribute-override", ATTR_OVERRIDE);
+        _elems.put("column", COL);
+        _elems.put("column-result", COLUMN_RESULT);
+        _elems.put("discriminator-column", DISCRIM_COL);
+        _elems.put("discriminator-value", DISCRIM_VAL);
+        _elems.put("entity-result", ENTITY_RESULT);
+        _elems.put("enumerated", ENUMERATED);
+        _elems.put("field-result", FIELD_RESULT);
+        _elems.put("inheritance", INHERITANCE);
+        _elems.put("join-column", JOIN_COL);
+        _elems.put("inverse-join-column", COL);
+        _elems.put("join-table", JOIN_TABLE);
+        _elems.put("primary-key-join-column", PK_JOIN_COL);
+        _elems.put("secondary-table", SECONDARY_TABLE);
+        _elems.put("sql-result-set-mapping", SQL_RESULT_SET_MAPPING);
+        _elems.put("table", TABLE);
+        _elems.put("table-generator", TABLE_GEN);
+        _elems.put("temporal", TEMPORAL);
+    }
+
+    private static final Localizer _loc = Localizer.forPackage
+        (XMLPersistenceMappingParser.class);
+
+    private String _override = null;
+    private String _schema = null;
+    private String _colTable = null;
+    private String _secondaryTable = null;
+    private List<Column> _cols = null;
+    private List<Column> _joinCols = null;
+    private List<Column> _supJoinCols = null;
+    private boolean _lob = false;
+    private TemporalType _temporal = null;
+    private EnumSet<UniqueFlag> _unique = EnumSet.noneOf(UniqueFlag.class);
+    private DiscriminatorType _discType;
+    private Column _discCol;
+    private int _resultIdx = 0;
+
+    /**
+     * Constructor; supply configuration.
+     */
+    public XMLPersistenceMappingParser(JDBCConfiguration conf) {
+        super(conf);
+    }
+
+    /**
+     * Create a new metadata repository.
+     */
+    @Override
+    protected MetaDataRepository newRepository() {
+        return ((JDBCConfiguration) getConfiguration()).
+            newMappingRepositoryInstance();
+    }
+
+    @Override
+    protected void reset() {
+        super.reset();
+        clearColumnInfo();
+        clearClassInfo();
+        clearSecondaryTableInfo();
+        _override = null;
+        _schema = null;
+        _resultIdx = 0;
+    }
+
+    @Override
+    protected Object startSystemMappingElement(String name, Attributes attrs)
+        throws SAXException {
+        MappingTag tag = _elems.get(name);
+        if (tag == null) {
+            if ("schema".equals(name))
+                return name;
+            return null;
+        }
+
+        boolean ret;
+        switch (tag) {
+            case TABLE_GEN:
+                ret = startTableGenerator(attrs);
+                break;
+            case SQL_RESULT_SET_MAPPING:
+                ret = startSQLResultSetMapping(attrs);
+                break;
+            case ENTITY_RESULT:
+                ret = startEntityResult(attrs);
+                break;
+            case FIELD_RESULT:
+                ret = startFieldResult(attrs);
+                break;
+            case COLUMN_RESULT:
+                ret = startColumnResult(attrs);
+                break;
+            default:
+                ret = false;
+        }
+        return (ret) ? tag : null;
+    }
+
+    @Override
+    protected void endSystemMappingElement(String name)
+        throws SAXException {
+        MappingTag tag = _elems.get(name);
+        if (tag == null) {
+            if ("schema".equals(name))
+                _schema = currentText();
+            return;
+        }
+
+        switch (tag) {
+            case SQL_RESULT_SET_MAPPING:
+                endSQLResultSetMapping();
+                break;
+            case ENTITY_RESULT:
+                endEntityResult();
+                break;
+        }
+    }
+
+    @Override
+    protected Object startClassMappingElement(String name, Attributes attrs)
+        throws SAXException {
+        MappingTag tag = _elems.get(name);
+        if (tag == null)
+            return null;
+
+        boolean ret;
+        switch (tag) {
+            case TABLE:
+                ret = startTable(attrs);
+                break;
+            case SECONDARY_TABLE:
+                ret = startSecondaryTable(attrs);
+                break;
+            case DISCRIM_COL:
+                _discCol = parseColumn(attrs);
+                ret = true;
+                break;
+            case DISCRIM_VAL:
+                ret = true;
+                break;
+            case INHERITANCE:
+                ret = startInheritance(attrs);
+                break;
+            case ASSOC_OVERRIDE:
+            case ATTR_OVERRIDE:
+                ret = startAttributeOverride(attrs);
+                break;
+            case PK_JOIN_COL:
+                ret = startPrimaryKeyJoinColumn(attrs);
+                break;
+            case COL:
+                ret = startColumn(attrs);
+                break;
+            case JOIN_COL:
+                ret = startJoinColumn(attrs);
+                break;
+            case JOIN_TABLE:
+                ret = startJoinTable(attrs);
+                break;
+            case TABLE_GEN:
+                ret = startTableGenerator(attrs);
+                break;
+            case UNIQUE:
+                getLog().warn(_loc.get("unique-constraints", currentElement()));
+                ret = false;
+                break;
+            case TEMPORAL:
+            case ENUMERATED:
+                ret = true;
+                break;
+            case SQL_RESULT_SET_MAPPING:
+                ret = startSQLResultSetMapping(attrs);
+                break;
+            case ENTITY_RESULT:
+                ret = startEntityResult(attrs);
+                break;
+            case FIELD_RESULT:
+                ret = startFieldResult(attrs);
+                break;
+            case COLUMN_RESULT:
+                ret = startColumnResult(attrs);
+                break;
+            default:
+                ret = false;
+        }
+        return (ret) ? tag : null;
+    }
+
+    @Override
+    protected void endClassMappingElement(String name)
+        throws SAXException {
+        MappingTag tag = _elems.get(name);
+        if (tag == null)
+            return;
+
+        switch (tag) {
+            case SECONDARY_TABLE:
+                endSecondaryTable();
+                break;
+            case DISCRIM_VAL:
+                endDiscriminatorValue();
+                break;
+            case ATTR_OVERRIDE:
+                endAttributeOverride();
+                break;
+            case JOIN_TABLE:
+                endJoinTable();
+                break;
+            case TEMPORAL:
+                endTemporal();
+                break;
+            case ENUMERATED:
+                endEnumerated();
+                break;
+            case SQL_RESULT_SET_MAPPING:
+                endSQLResultSetMapping();
+                break;
+            case ENTITY_RESULT:
+                endEntityResult();
+                break;
+        }
+    }
+
+    @Override
+    protected void startClassMapping(ClassMetaData meta, boolean mappedSuper,
+        Attributes attrs)
+        throws SAXException {
+        if (mappedSuper)
+            ((ClassMapping) meta).getMappingInfo().setStrategy
+                (NoneClassStrategy.ALIAS);
+    }
+
+    @Override
+    protected void endClassMapping(ClassMetaData meta)
+        throws SAXException {
+        ClassMapping cm = (ClassMapping) meta;
+        if (_supJoinCols != null)
+            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;
+                }
+            }
+            dinfo.setColumns(Arrays.asList(new Column[]{ _discCol }));
+        }
+        clearClassInfo();
+    }
+
+    /**
+     * Clear cached class mapping info.
+     */
+    private void clearClassInfo() {
+        _supJoinCols = null;
+        _discCol = null;
+        _discType = null;
+    }
+
+    /**
+     * Start tracking secondary table information and columns
+     */
+    private boolean startSecondaryTable(Attributes attrs)
+        throws SAXException {
+        _secondaryTable = toTableName(attrs.getValue("schema"),
+            attrs.getValue("name"));
+        return true;
+    }
+
+    /**
+     * Set the secondary table information back to the owning class mapping.
+     */
+    private void endSecondaryTable() {
+        ClassMapping cm = (ClassMapping) currentElement();
+        ClassMappingInfo info = cm.getMappingInfo();
+        info.setSecondaryTableJoinColumns(_secondaryTable, _joinCols);
+        clearSecondaryTableInfo();
+    }
+
+    /**
+     * Clear cached secondary table info.
+     */
+    private void clearSecondaryTableInfo() {
+        _joinCols = null;
+        _secondaryTable = null;
+    }
+
+    /**
+     * Parse table-generator.
+     */
+    private boolean startTableGenerator(Attributes attrs) {
+        String name = attrs.getValue("name");
+        Log log = getLog();
+        if (log.isInfoEnabled())
+            log.info(_loc.get("parse-gen", name));
+        if (getRepository().getCachedSequenceMetaData(name) != null
+            && log.isWarnEnabled())
+            log.warn(_loc.get("override-gen", name));
+
+        SequenceMapping seq = (SequenceMapping) getRepository().
+            addSequenceMetaData(name);
+        seq.setSequencePlugin(SequenceMapping.IMPL_VALUE_TABLE);
+        seq.setTable(toTableName(attrs.getValue("schema"),
+            attrs.getValue("table")));
+        seq.setPrimaryKeyColumn(attrs.getValue("pk-column-name"));
+        seq.setSequenceColumn(attrs.getValue("value-column-name"));
+        seq.setPrimaryKeyValue(attrs.getValue("pk-column-value"));
+        String val = attrs.getValue("initial-value");
+        if (val != null)
+            seq.setInitialValue(Integer.parseInt(val));
+        val = attrs.getValue("allocation-size");
+        if (val != null)
+            seq.setAllocate(Integer.parseInt(val));
+
+        Object cur = currentElement();
+        Object scope = (cur instanceof ClassMetaData)
+            ? ((ClassMetaData) cur).getDescribedType() : null;
+        seq.setSource(getSourceFile(), scope, seq.SRC_XML);
+        return true;
+    }
+
+    /**
+     * Parse inheritance.
+     */
+    private boolean startInheritance(Attributes attrs) {
+        String val = attrs.getValue("strategy");
+        if (val == null)
+            return true;
+
+        ClassMapping cm = (ClassMapping) currentElement();
+        ClassMappingInfo info = cm.getMappingInfo();
+        switch (Enum.valueOf(InheritanceType.class, val)) {
+            case SINGLE_TABLE:
+                info.setHierarchyStrategy(FlatClassStrategy.ALIAS);
+                break;
+            case JOINED:
+                info.setHierarchyStrategy(VerticalClassStrategy.ALIAS);
+                break;
+            case TABLE_PER_CLASS:
+                info.setHierarchyStrategy(FullClassStrategy.ALIAS);
+                break;
+        }
+        return true;
+    }
+
+    /**
+     * Parse discriminator-value.
+     */
+    private void endDiscriminatorValue() {
+        String val = currentText();
+        if (StringUtils.isEmpty(val))
+            return;
+
+        ClassMapping cm = (ClassMapping) currentElement();
+        cm.getDiscriminator().getMappingInfo().setValue(val);
+    }
+
+    /**
+     * Parse temporal.
+     */
+    private void endTemporal() {
+        String temp = currentText();
+        if (!StringUtils.isEmpty(temp))
+            _temporal = Enum.valueOf(TemporalType.class, temp);
+    }
+
+    /**
+     * Parse enumerated.
+     */
+    private void endEnumerated() {
+        String text = currentText();
+        if (StringUtils.isEmpty(text))
+            return;
+        EnumType type = Enum.valueOf(EnumType.class, text);
+
+        FieldMapping fm = (FieldMapping) currentElement();
+        String strat = EnumValueHandler.class.getName() + "(StoreOrdinal="
+            + String.valueOf(type == EnumType.ORDINAL) + ")";
+        fm.getValueInfo().setStrategy(strat);
+    }
+
+    @Override
+    protected boolean startLob(Attributes attrs)
+        throws SAXException {
+        if (super.startLob(attrs)) {
+            _lob = true;
+            return true;
+        }
+        return false;
+    }
+
+    /**
+     * Extend to clear annotation mapping info.
+     */
+    @Override
+    protected void startFieldMapping(FieldMetaData field, Attributes attrs)
+        throws SAXException {
+        super.startFieldMapping(field, attrs);
+        if (getAnnotationParser() != null) {
+            FieldMapping fm = (FieldMapping) field;
+            fm.getMappingInfo().clear();
+            fm.getValueInfo().clear();
+            fm.getElementMapping().getValueInfo().clear();
+            fm.getKeyMapping().getValueInfo().clear();
+        }
+    }
+
+    /**
+     * Extend to set the columns.
+     */
+    @Override
+    protected void endFieldMapping(FieldMetaData field)
+        throws SAXException {
+        // setup columns with cached lob and temporal info
+        FieldMapping fm = (FieldMapping) field;
+        if (_lob || _temporal != null) {
+            if (_cols == null) {
+                _cols = new ArrayList<Column>(1);
+                _cols.add(new Column());
+            }
+            for (Column col : _cols) {
+                if (_lob && (fm.getDeclaredTypeCode() == JavaTypes.STRING
+                    || fm.getDeclaredType() == char[].class
+                    || fm.getDeclaredType() == Character[].class)) {
+                    col.setSize(-1);
+                    col.setType(Types.CLOB);
+                } else if (_lob)
+                    col.setType(Types.BLOB);
+                else {
+                    switch (_temporal) {
+                        case DATE:
+                            col.setType(Types.DATE);
+                            break;
+                        case TIME:
+                            col.setType(Types.TIME);
+                            break;
+                        case TIMESTAMP:
+                            col.setType(Types.TIMESTAMP);
+                            break;
+                    }
+                }
+            }
+        }
+
+        if (_cols != null) {
+            switch (fm.getDeclaredTypeCode()) {
+                case JavaTypes.ARRAY:
+                    if (fm.getDeclaredType() == byte[].class
+                        || fm.getDeclaredType() == char[].class
+                        || fm.getDeclaredType() == Character[].class) {
+                        fm.getValueInfo().setColumns(_cols);
+                        break;
+                    }
+                    // else no break
+                case JavaTypes.COLLECTION:
+                case JavaTypes.MAP:
+                    fm.getElementMapping().getValueInfo().setColumns(_cols);
+                    break;
+                default:
+                    fm.getValueInfo().setColumns(_cols);
+            }
+            if (_colTable != null)
+                fm.getMappingInfo().setTableName(_colTable);
+            setUnique(fm);
+        }
+        clearColumnInfo();
+    }
+
+    /**
+     * Set unique for field.
+     */
+    private void setUnique(FieldMapping fm) {
+        if (_unique.size() == 2) // i.e. TRUE & FALSE
+            getLog().warn(_loc.get("inconsist-col-attrs", fm));
+        else if (_unique.contains(UniqueFlag.TRUE))
+            fm.getValueInfo().setUnique(new Unique());
+    }
+
+    /**
+     * Clear field level column information.
+     */
+    private void clearColumnInfo() {
+        _cols = null;
+        _joinCols = null;
+        _colTable = null;
+        _lob = false;
+        _temporal = null;
+        _unique.clear();
+    }
+
+    /**
+     * Parse attribute-override.
+     */
+    private boolean startAttributeOverride(Attributes attr) {
+        _override = attr.getValue("name");
+        return true;
+    }
+
+    /**
+     * Set attribute override into proper mapping.
+     */
+    private void endAttributeOverride()
+        throws SAXException {
+        Object elem = currentElement();
+        FieldMapping fm;
+        if (elem instanceof ClassMapping)
+            fm = getAttributeOverride((ClassMapping) elem);
+        else
+            fm = getAttributeOverride((FieldMapping) elem);
+        if (_cols != null) {
+            fm.getValueInfo().setColumns(_cols);
+            if (_colTable != null)
+                fm.getMappingInfo().setTableName(_colTable);
+            setUnique(fm);
+        }
+        clearColumnInfo();
+        _override = null;
+    }
+
+    /**
+     * Return the proper override.
+     */
+    private FieldMapping getAttributeOverride(ClassMapping cm) {
+        FieldMapping sup = (FieldMapping) cm.getDefinedSuperclassField
+            (_override);
+        if (sup == null)
+            sup = (FieldMapping) cm.addDefinedSuperclassField(_override,
+                Object.class, Object.class);
+        return sup;
+    }
+
+    /**
+     * Return the proper override.
+     */
+    private FieldMapping getAttributeOverride(FieldMapping fm)
+        throws SAXException {
+        ClassMapping embed = fm.getEmbeddedMapping();
+        if (embed == null)
+            throw getException(_loc.get("not-embedded", fm));
+
+        FieldMapping efm = embed.getFieldMapping(_override);
+        if (efm == null)
+            throw getException(_loc.get("embed-override-name",
+                fm, _override));
+        return efm;
+    }
+
+    /**
+     * Parse table.
+     */
+    private boolean startTable(Attributes attrs)
+        throws SAXException {
+        String table = toTableName(attrs.getValue("schema"),
+            attrs.getValue("name"));
+        if (table != null)
+            ((ClassMapping) currentElement()).getMappingInfo().setTableName
+                (table);
+        return true;
+    }
+
+    /**
+     * Parse join-table.
+     */
+    private boolean startJoinTable(Attributes attrs)
+        throws SAXException {
+        String table = toTableName(attrs.getValue("schema"),
+            attrs.getValue("name"));
+        if (table != null)
+            ((FieldMapping) currentElement()).getMappingInfo().setTableName
+                (table);
+        return true;
+    }
+
+    /**
+     * Set the join table information back.
+     */
+    private void endJoinTable() {
+        FieldMapping fm = (FieldMapping) currentElement();
+        if (_joinCols != null)
+            fm.getMappingInfo().setColumns(_joinCols);
+        if (_cols != null)
+            fm.getElementMapping().getValueInfo().setColumns(_cols);
+        clearColumnInfo();
+    }
+
+    /**
+     * Parse primary-key-join-column.
+     */
+    private boolean startPrimaryKeyJoinColumn(Attributes attrs)
+        throws SAXException {
+        Column col = parseColumn(attrs);
+        col.setFlag(Column.FLAG_PK_JOIN, true);
+        // pk join columns on fields act as field cols
+        if (currentElement() instanceof FieldMapping) {
+            if (_cols == null)
+                _cols = new ArrayList<Column>(3);
+            _cols.add(col);
+        } else if (currentParent() == SECONDARY_TABLE) {
+            // pk join columns in secondary table acts as join cols
+            if (_joinCols == null)
+                _joinCols = new ArrayList<Column>(3);
+            _joinCols.add(col);
+        } else {
+            // must be pk join cols from this class to superclass
+            if (_supJoinCols == null)
+                _supJoinCols = new ArrayList<Column>(3);
+            _supJoinCols.add(col);
+        }
+        return true;
+    }
+
+    /**
+     * Parse join-column.
+     */
+    private boolean startJoinColumn(Attributes attrs)
+        throws SAXException {
+        // only join cols in a join table join field table to class table;
+        // others act as data fk cols
+        if (currentParent() != JOIN_TABLE)
+            return startColumn(attrs);
+
+        if (_joinCols == null)
+            _joinCols = new ArrayList<Column>(3);
+        _joinCols.add(parseColumn(attrs));
+        return true;
+    }
+
+    /**
+     * Parse column.
+     */
+    private boolean startColumn(Attributes attrs)
+        throws SAXException {
+        if (_cols == null)
+            _cols = new ArrayList<Column>(3);
+        _cols.add(parseColumn(attrs));
+        return true;
+    }
+
+    /**
+     * Create a column with the given attributes.
+     */
+    private Column parseColumn(Attributes attrs)
+        throws SAXException {
+        Column col = new Column();
+        String val = attrs.getValue("name");
+        if (val != null)
+            col.setName(val);
+        val = attrs.getValue("referenced-column-name");
+        if (val != null)
+            col.setTarget(val);
+        val = attrs.getValue("column-definition");
+        if (val != null)
+            col.setTypeName(val);
+        val = attrs.getValue("precision");
+        if (val != null)
+            col.setSize(Integer.parseInt(val));
+        val = attrs.getValue("length");
+        if (val != null)
+            col.setSize(Integer.parseInt(val));
+        val = attrs.getValue("scale");
+        if (val != null)
+            col.setDecimalDigits(Integer.parseInt(val));
+        val = attrs.getValue("nullable");
+        if (val != null)
+            col.setNotNull("false".equals(val));
+        val = attrs.getValue("insertable");
+        if (val != null)
+            col.setFlag(Column.FLAG_UNINSERTABLE, "false".equals(val));
+        val = attrs.getValue("updatable");
+        if (val != null)
+            col.setFlag(Column.FLAG_UNUPDATABLE, "false".equals(val));
+
+        val = attrs.getValue("unique");
+        if (val != null)
+            _unique.add(Enum.valueOf(UniqueFlag.class, val.toUpperCase()));
+        val = attrs.getValue("table");
+        if (val != null) {
+            if (_colTable != null && !_colTable.equals(val))
+                throw getException(_loc.get("second-inconsist",
+                    currentElement()));
+            _colTable = val;
+        }
+        return col;
+    }
+
+    /**
+     * Return a table name for the given attributes.
+     */
+    private String toTableName(String schema, String table) {
+        if (StringUtils.isEmpty(table))
+            return null;
+        schema = StringUtils.isEmpty(schema) ? _schema : schema;
+        if (StringUtils.isEmpty(schema))
+            return table;
+        return schema + "." + table;
+    }
+
+    /**
+     * Start processing <code>sql-result-set-mapping</code> node.
+     * Pushes the {@link QueryResultMapping} onto the stack as current element.
+     */
+    private boolean startSQLResultSetMapping(Attributes attrs) {
+        String name = attrs.getValue("name");
+        Log log = getLog();
+        if (log.isInfoEnabled())
+            log.info(_loc.get("parse-sqlrsmapping", name));
+
+        MappingRepository repos = (MappingRepository) getRepository();
+        QueryResultMapping result = repos.getCachedQueryResultMapping
+            (null, name);
+        if (result != null && log.isWarnEnabled())
+            log.warn(_loc.get("override-sqlrsmapping", name,
+                currentLocation()));
+
+        result = repos.addQueryResultMapping(null, name);
+        result.setListingIndex(_resultIdx++);
+        addComments(result);
+
+        Object cur = currentElement();
+        Object scope = (cur instanceof ClassMetaData)
+            ? ((ClassMetaData) cur).getDescribedType() : null;
+        result.setSource(getSourceFile(), scope, result.SRC_XML);
+
+        pushElement(result);
+        return true;
+    }
+
+    private void endSQLResultSetMapping()
+        throws SAXException {
+        popElement();
+    }
+
+    /**
+     * Start processing <code>entity-result</code> node.
+     * Pushes the {@link QueryResultMapping.PCResult}
+     * onto the stack as current element.
+     */
+    private boolean startEntityResult(Attributes attrs)
+        throws SAXException {
+        Class entityClass = classForName(attrs.getValue("entity-class"));
+        String discriminator = attrs.getValue("discriminator-column");
+
+        QueryResultMapping parent = (QueryResultMapping) currentElement();
+        QueryResultMapping.PCResult result = parent.addPCResult(entityClass);
+        if (!StringUtils.isEmpty(discriminator))
+            result.addMapping(result.DISCRIMINATOR, discriminator);
+        pushElement(result);
+        return true;
+    }
+
+    private void endEntityResult()
+        throws SAXException {
+        popElement();
+    }
+
+    /**
+     * Process a <code>field-result</code> node.
+     */
+    private boolean startFieldResult(Attributes attrs)
+        throws SAXException {
+        String fieldName = attrs.getValue("name");
+        String columnName = attrs.getValue("column");
+
+        QueryResultMapping.PCResult parent = (QueryResultMapping.PCResult)
+            currentElement();
+        parent.addMapping(fieldName, columnName);
+        return true;
+    }
+
+    /**
+     * Process a <code>column-result</code> node.
+     */
+    private boolean startColumnResult(Attributes attrs)
+        throws SAXException {
+        QueryResultMapping parent = (QueryResultMapping) currentElement();
+        parent.addColumnResult(attrs.getValue("name"));
+        return true;
+    }
+
+    /**
+     * Track unique column settings.
+	 */
+	private static enum UniqueFlag
+	{
+		TRUE,
+		FALSE
+	}
+}

Propchange: incubator/openjpa/trunk/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/XMLPersistenceMappingParser.java
------------------------------------------------------------------------------
    svn:executable = *