Author: tv
Date: Fri Aug  5 16:20:31 2016
New Revision: 1755362

URL: http://svn.apache.org/viewvc?rev=1755362&view=rev
Log:
TORQUE-347: Don't repeat yourself

Added:
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java
   (with props)
Modified:
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
    
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java?rev=1755362&r1=1755361&r2=1755362&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/ColumnMap.java
 Fri Aug  5 16:20:31 2016
@@ -38,7 +38,7 @@ import org.apache.torque.Column;
  * @author <a href="mailto:greg.mon...@dukece.com";>Greg Monroe</a>
  * @version $Id$
  */
-public class ColumnMap implements Column, Serializable
+public class ColumnMap extends OptionSupport implements Column, Serializable
 {
     /**
      * Serial version.
@@ -117,10 +117,6 @@ public class ColumnMap implements Column
     /** Column position in the table (one based). */
     private int position = -1;
 
-    /** Associated of inheritance maps. */
-    private final Map<String, String> optionsMap = Collections
-            .synchronizedMap(new LinkedHashMap<String, String>());
-
     /**
      * Constructor.
      *
@@ -154,6 +150,7 @@ public class ColumnMap implements Column
      *
      * @return A String with the column name.
      */
+    @Override
     public String getColumnName()
     {
         return columnName;
@@ -164,6 +161,7 @@ public class ColumnMap implements Column
      *
      * @return A String with the table name.
      */
+    @Override
     public String getTableName()
     {
         return table.getName();
@@ -174,6 +172,7 @@ public class ColumnMap implements Column
      *
      * @return A String with the table name.
      */
+    @Override
     public String getFullTableName()
     {
         String schema = table.getSchemaName();
@@ -189,6 +188,7 @@ public class ColumnMap implements Column
      *
      * @return A String with the schema name, or null if no schema is given.
      */
+    @Override
     public String getSchemaName()
     {
         return table.getSchemaName();
@@ -627,39 +627,6 @@ public class ColumnMap implements Column
     }
 
     /**
-     * Returns an unmodifiable map of all options.
-     *
-     * @return A map containing all options, not null.
-     */
-    public Map<String, String> getOptions()
-    {
-        return Collections.unmodifiableMap(optionsMap);
-    }
-
-    /**
-     * Sets an option.
-     *
-     * @param key the key of the option
-     * @param value the value of the option.
-     */
-    public void setOption(final String key, final String value)
-    {
-        optionsMap.put(key, value);
-    }
-
-    /**
-     * Returns the value of an option.
-     *
-     * @param key the key of the option.
-     *
-     * @return the value of the option, or null if not set.
-     */
-    public String getOption(final String key)
-    {
-        return optionsMap.get(key);
-    }
-
-    /**
      * Returns the SQL expression for the fully qualified column name.
      * This is tableName.columnName if the database for this column has no
      * schema and defaultSchema is null,
@@ -668,6 +635,7 @@ public class ColumnMap implements Column
      *
      * @return the SQL expression for the column, not null.
      */
+    @Override
     public String getSqlExpression()
     {
         return table.getFullyQualifiedTableName() + '.' + columnName;

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java?rev=1755362&r1=1755361&r2=1755362&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/DatabaseMap.java
 Fri Aug  5 16:20:31 2016
@@ -40,7 +40,7 @@ import org.apache.torque.TorqueException
  * @author <a href="mailto:greg.mon...@dukece.com";>Greg Monroe</a>
  * @version $Id$
  */
-public class DatabaseMap implements Serializable
+public class DatabaseMap extends OptionSupport implements Serializable
 {
     /**
      * Serial version.
@@ -104,10 +104,6 @@ public class DatabaseMap implements Seri
     /** Flag indicating that all tables have been loaded via initialize() */
     private boolean isInitialized = false;
 
-    /** Associated options. */
-    private final Map<String, String> optionsMap
-            = Collections.synchronizedMap(new LinkedHashMap<String, String>());
-
     /**
      * Constructs a new DatabaseMap.
      */
@@ -246,39 +242,6 @@ public class DatabaseMap implements Seri
     }
 
     /**
-     * Returns an unmodifiable map of all options.
-     *
-     * @return A map containing all options, not null.
-     */
-    public Map<String, String> getOptions()
-    {
-        return Collections.unmodifiableMap(optionsMap);
-    }
-
-    /**
-     * Sets an option.
-     *
-     * @param key the key of the option
-     * @param value the value of the option.
-     */
-    public void setOption(final String key, final String value)
-    {
-        optionsMap.put(key, value);
-    }
-
-    /**
-     * Returns the value of an option.
-     *
-     * @param key the key of the option.
-     *
-     * @return the value of the option, or null if not set.
-     */
-    public String getOption(final String key)
-    {
-        return optionsMap.get(key);
-    }
-
-    /**
      * Fully populate this DatabaseMap with all the TablesMaps.  This
      * is only needed if the application needs to use the complete OM
      * mapping information.  Otherwise, the OM Mapping information
@@ -420,8 +383,11 @@ public class DatabaseMap implements Seri
     public void copyFrom(final DatabaseMap databaseMap)
     {
         this.isInitialized = databaseMap.isInitialized;
-        this.optionsMap.clear();
-        this.optionsMap.putAll(databaseMap.optionsMap);
+        this.clearOptions();
+        for (Map.Entry<String, String> option : 
databaseMap.getOptions().entrySet())
+        {
+            this.setOption(option.getKey(), option.getValue());
+        }
         this.tables.clear();
         this.tables.putAll(databaseMap.tables);
     }

Added: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java?rev=1755362&view=auto
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java
 (added)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java
 Fri Aug  5 16:20:31 2016
@@ -0,0 +1,84 @@
+package org.apache.torque.map;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * OptionSupport provides the basic methods for the management of options
+ * within the database schema model.
+ *
+ * @author <a href="mailto:t...@apache.org";>Thomas Vandahl</a>
+ * @version $Id: ColumnMap.java 1484252 2013-05-19 09:58:00Z tfischer $
+ */
+public abstract class OptionSupport implements Serializable
+{
+    /**
+     * Serial version.
+     */
+    private static final long serialVersionUID = 1L;
+
+    /** Associated options. */
+    private final Map<String, String> optionsMap = new 
ConcurrentHashMap<String, String>();
+
+    /**
+     * Returns an unmodifiable map of all options.
+     *
+     * @return A map containing all options, not null.
+     */
+    public Map<String, String> getOptions()
+    {
+        return Collections.unmodifiableMap(optionsMap);
+    }
+
+    /**
+     * Sets an option.
+     *
+     * @param key the key of the option
+     * @param value the value of the option.
+     */
+    public void setOption(final String key, final String value)
+    {
+        optionsMap.put(key, value);
+    }
+
+    /**
+     * Returns the value of an option.
+     *
+     * @param key the key of the option.
+     *
+     * @return the value of the option, or null if not set.
+     */
+    public String getOption(final String key)
+    {
+        return optionsMap.get(key);
+    }
+
+    /**
+     * Clears all options.
+     */
+    public void clearOptions()
+    {
+        optionsMap.clear();
+    }
+}

Propchange: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/OptionSupport.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
URL: 
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java?rev=1755362&r1=1755361&r2=1755362&view=diff
==============================================================================
--- 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
 (original)
+++ 
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/map/TableMap.java
 Fri Aug  5 16:20:31 2016
@@ -45,7 +45,7 @@ import org.apache.torque.adapter.IDMetho
  * @author <a href="mailto:greg.mon...@dukece.com";>Greg Monroe</a>
  * @version $Id$
  */
-public class TableMap implements Serializable
+public class TableMap extends OptionSupport implements Serializable
 {
     /**
      * Serial version.
@@ -113,10 +113,6 @@ public class TableMap implements Seriali
     private final Map<IDMethod, Object> pkInfoMap
             = new HashMap<IDMethod, Object>();
 
-    /** Associated options. */
-    private final Map<String, String> optionsMap
-            = Collections.synchronizedMap(new LinkedHashMap<String, String>());
-
     /**
      * Constructor.
      *
@@ -636,39 +632,6 @@ public class TableMap implements Seriali
     }
 
     /**
-     * Returns an unmodifiable map of all options.
-     *
-     * @return A map containing all options, not null.
-     */
-    public Map<String, String> getOptions()
-    {
-        return Collections.unmodifiableMap(optionsMap);
-    }
-
-    /**
-     * Sets an option.
-     *
-     * @param key the key of the option
-     * @param value the value of the option.
-     */
-    public void setOption(String key, String value)
-    {
-        optionsMap.put(key, value);
-    }
-
-    /**
-     * Returns the value of an option.
-     *
-     * @param key the key of the option.
-     *
-     * @return the value of the option, or null if not set.
-     */
-    public String getOption(String key)
-    {
-        return optionsMap.get(key);
-    }
-
-    /**
      * Returns the single primary key of this table, if it exists
      *
      * @return the single primary key column.



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscr...@db.apache.org
For additional commands, e-mail: torque-dev-h...@db.apache.org

Reply via email to