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 [16/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-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RefreshStrategyInstaller.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RefreshStrategyInstaller.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RefreshStrategyInstaller.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RefreshStrategyInstaller.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,135 @@
+/*
+ * 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.jdbc.meta;
+
+import org.apache.openjpa.lib.util.Localizer;
+import org.apache.openjpa.util.MetaDataException;
+
+/**
+ * Attempts to install using the given mapping information. If that
+ * fails, clears the mapping information and constructs new mappings.
+ *
+ * @author Abe White
+ * @nojavadoc
+ * @since 4.0
+ */
+public class RefreshStrategyInstaller
+    extends StrategyInstaller {
+
+    private static final Localizer _loc = Localizer.forPackage
+        (RefreshStrategyInstaller.class);
+
+    /**
+     * Constructor; supply configuration.
+     */
+    public RefreshStrategyInstaller(MappingRepository repos) {
+        super(repos);
+    }
+
+    public boolean isAdapting() {
+        return true;
+    }
+
+    public void installStrategy(ClassMapping cls) {
+        ClassStrategy strat = repos.namedStrategy(cls);
+        if (strat == null)
+            strat = repos.defaultStrategy(cls, true);
+        try {
+            cls.setStrategy(strat, Boolean.TRUE);
+        } catch (MetaDataException mde) {
+            // if this is a custom strategy, don't attempt to override
+            if (isCustomStrategy(strat))
+                throw mde;
+
+            repos.getLog().warn(_loc.get("fatal-change", cls,
+                mde.getMessage()));
+            cls.clearMapping();
+            cls.setStrategy(repos.defaultStrategy(cls, true), Boolean.TRUE);
+        }
+        cls.setSourceMode(cls.MODE_MAPPING, true);
+    }
+
+    public void installStrategy(FieldMapping field) {
+        FieldStrategy strategy = repos.namedStrategy(field, true);
+        if (strategy == null)
+            strategy = repos.defaultStrategy(field, true, true);
+        try {
+            field.setStrategy(strategy, Boolean.TRUE);
+        } catch (MetaDataException mde) {
+            // if this is a custom strategy, don't override
+            if (isCustomStrategy(strategy))
+                throw mde;
+
+            repos.getLog().warn(_loc.get("fatal-change", field,
+                mde.getMessage()));
+            field.clearMapping();
+            field.setHandler(null);
+            field.getKeyMapping().setHandler(null);
+            field.getElementMapping().setHandler(null);
+            field.setStrategy(repos.defaultStrategy(field, true, true),
+                Boolean.TRUE);
+        }
+    }
+
+    public void installStrategy(Version version) {
+        VersionStrategy strat = repos.namedStrategy(version);
+        if (strat == null)
+            strat = repos.defaultStrategy(version, true);
+        try {
+            version.setStrategy(strat, Boolean.TRUE);
+        } catch (MetaDataException mde) {
+            // if this is a custom strategy, don't attempt to override
+            if (isCustomStrategy(strat))
+                throw mde;
+
+            repos.getLog().warn(_loc.get("fatal-change", version,
+                mde.getMessage()));
+            version.clearMapping();
+            version.setStrategy(repos.defaultStrategy(version, true),
+                Boolean.TRUE);
+        }
+    }
+
+    public void installStrategy(Discriminator discrim) {
+        DiscriminatorStrategy strat = repos.namedStrategy(discrim);
+        if (strat == null)
+            strat = repos.defaultStrategy(discrim, true);
+        try {
+            discrim.setStrategy(strat, Boolean.TRUE);
+        } catch (MetaDataException mde) {
+            // if this is a custom strategy, don't attempt to override
+            if (isCustomStrategy(strat))
+                throw mde;
+
+            repos.getLog().warn(_loc.get("fatal-change", discrim,
+                mde.getMessage()));
+
+            // retain old discriminator version, if any
+            String val = discrim.getMappingInfo().getValue();
+            discrim.clearMapping();
+            discrim.getMappingInfo().setValue(val);
+            discrim.setStrategy(repos.defaultStrategy(discrim, true),
+                Boolean.TRUE);
+        }
+    }
+
+    /**
+     * Return true if the given strategy is not a built-in type.
+     */
+    private static boolean isCustomStrategy(Strategy strat) {
+        return !strat.getClass().getName().startsWith("org.apache.openjpa.");
+    }
+}

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

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RelationId.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RelationId.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RelationId.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/RelationId.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.jdbc.meta;
+
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.kernel.OpenJPAStateManager;
+
+/**
+ * Callback to store a relation after the object id has been assigned.
+ *
+ * @author Abe White
+ * @since 4.0
+ */
+public interface RelationId {
+
+    /**
+     * Return the serialized value for the given related object, now that
+     * its id has been assigned.
+     */
+    public Object toRelationDataStoreValue(OpenJPAStateManager sm, Column col);
+}
+

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

Added: incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseCustomizer.java
URL: http://svn.apache.org/viewvc/incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseCustomizer.java?rev=423615&view=auto
==============================================================================
--- incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseCustomizer.java (added)
+++ incubator/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ReverseCustomizer.java Wed Jul 19 14:34:44 2006
@@ -0,0 +1,160 @@
+/*
+ * 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.jdbc.meta;
+
+import java.util.Properties;
+
+import org.apache.openjpa.jdbc.schema.Column;
+import org.apache.openjpa.jdbc.schema.ForeignKey;
+import org.apache.openjpa.jdbc.schema.Table;
+import org.apache.openjpa.lib.util.Closeable;
+
+/**
+ * Plugin in interface to customize the output of the
+ * {@link ReverseMappingTool}.
+ *
+ * @author Abe White
+ */
+public interface ReverseCustomizer
+    extends Closeable {
+
+    /**
+     * Set configuration properties given by the user.
+     */
+    public void setConfiguration(Properties props);
+
+    /**
+     * Set the reverse mapping tool using this customizer. You can use
+     * the tool to see how it is configured, or to use utility methods the
+     * tool provides.
+     */
+    public void setTool(ReverseMappingTool tool);
+
+    /**
+     * Return the type of the given table, or the given default type.
+     * See the TABLE_XXX constants in {@link ReverseMappingTool}.
+     */
+    public int getTableType(Table table, int defaultType);
+
+    /**
+     * Return the fully-qualified class name to generate for the given table.
+     * Return null to prevent the table from being mapped. Return the given
+     * default name if it is acceptable.
+     */
+    public String getClassName(Table table, String defaultName);
+
+    /**
+     * Customize the given class information produced by the reverse mapping
+     * tool. To change the application identity class, use
+     * {@link ReverseMappingTool#generateClass} to creat the new class object.
+     * The class will not have any fields at the time of this call.
+     */
+    public void customize(ClassMapping cls);
+
+    /**
+     * Return a code template for the given class, or null to use the standard
+     * system-generated Java code. To facilitate template reuse, the
+     * following parameters can appear in your template; the proper values
+     * will be subtituted by the system:
+     * <ul>
+     * <li>${packageDec}: The package declaration, in the form
+     * "package &lt;package name &gt;;", or empty string if no package.</li>
+     * <li>${imports}: Imports for the packages used by the declared
+     * field types.</li>
+     * <li>${className}: The name of the class, without package.</li>
+     * <li>${extendsDec}: Extends declaration, in the form
+     * "extends &lt;superclass&gt;", or empty string if no superclass.</li>
+     * <li>${constructor}: A constructor that takes in all primary key fields
+     * of the class, or empty string if the class uses datastore identity.</li>
+     * <li>${fieldDecs}: Declarations of all the generated fields.</li>
+     * <li>${fieldCode}: Get/set methods for all the generated fields.</li>
+     * </ul>
+     */
+    public String getClassCode(ClassMapping mapping);
+
+    /**
+     * Return the field name used to map the given columns, or null to prevent
+     * the columns from being mapped. Return the given default if it is
+     * acceptable.
+     *
+     * @param dec the class that will declare this field
+     * @param cols the column(s) this field will represent
+     * @param fk for relation fields, the foreign key to the related type
+     */
+    public String getFieldName(ClassMapping dec, Column[] cols, ForeignKey fk,
+        String defaultName);
+
+    /**
+     * Customize the given field information produced by the reverse mapping
+     * tool.
+     */
+    public void customize(FieldMapping field);
+
+    /**
+     * Return code for the initial value for the given field, or null to use
+     * the default generated by the system.
+     */
+    public String getInitialValue(FieldMapping field);
+
+    /**
+     * Return a code template for the declaration of the given field, or null
+     * to use the system-generated default Java code.
+     * To facilitate template reuse, the following parameters can appear in
+     * your template; the proper values will be subtituted by the system:
+     * <ul>
+     * <li>${fieldName}: The name of the field.</li>
+     * <li>${capFieldName}: The capitalized field name.</li>
+     * <li>${propertyName}: The field name without leading '_', if any.</li>
+     * <li>${fieldType}: The field's type name.</li>
+     * <li>${fieldValue}: The field's initial value, in the form
+     * " = &lt;value&gt;", or empty string if none.</li>
+     * </ul>
+     */
+    public String getDeclaration(FieldMapping field);
+
+    /**
+     * Return a code template for the get/set methods of the given field, or
+     * null to use the system-generated default Java code.
+     * To facilitate template reuse, the following parameters can appear in
+     * your template; the proper values will be subtituted by the system:
+     * <ul>
+     * <li>${fieldName}: The name of the field.</li>
+     * <li>${capFieldName}: The capitalized field name.</li>
+     * <li>${propertyName}: The field name without leading '_', if any.</li>
+     * <li>${fieldType}: The field's type name.</li>
+     * <li>${fieldValue}: The field's initial value, in the form
+     * "= &lt;value&gt;", or empty string if none.</li>
+     * </ul>
+     */
+    public String getFieldCode(FieldMapping field);
+
+    /**
+     * Notification that a table has gone unmapped. You can map the table
+     * yourself using this method. When mapping, use
+     * {@link ReverseMappingTool#generateClass} to create the class,
+     * {@link ReverseMappingTool#newClassMapping} to create the class metadata,
+     * and then {@link ClassMapping#addDeclaredFieldMapping} to add field
+     * metadata.
+     *
+     * @return true if you map the table, false otherwise
+     */
+    public boolean unmappedTable(Table table);
+
+    /**
+     * Invoked when the customizer is no longer needed.
+     */
+    public void close();
+}

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