View Javadoc

1   package org.apache.torque.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import java.util.Collection;
23  import java.util.HashMap;
24  import java.util.Map;
25  import java.util.Set;
26  
27  import org.apache.torque.Column;
28  import org.apache.torque.map.TableMap;
29  
30  /**
31   * A class containing values for database columns.
32   *
33   * @version $Id: ColumnValues.java 1374905 2012-08-20 03:24:18Z tfischer $
34   */
35  public class ColumnValues implements Map<Column, JdbcTypedValue>
36  {
37      /** The column values, keyed by the column names. */
38      private Map<Column, JdbcTypedValue> columnValues;
39  
40      /**
41       * The name of the database handle to use for connection opening if needed,
42       * or null to use the default database handle for the table.
43       */
44      private String dbName;
45  
46      /**
47       * Constructor with no contained column values.
48       *
49       * @throws NullPointerException if table is null.
50       */
51      public ColumnValues()
52      {
53          this.columnValues = new HashMap<Column, JdbcTypedValue>();
54      }
55  
56      /**
57       * Constructor with no contained column values.
58       *
59       * @param dbName the name of the database handle to use for connection
60       *        opening if needed, or null to use the default database handle
61       *        for the table.
62       *
63       * @throws NullPointerException if table is null.
64       */
65      public ColumnValues(TableMap table, String dbName)
66      {
67          this();
68          this.dbName = dbName;
69      }
70  
71      /**
72       * Constructor.
73       *
74       * @param columnValues the column values, or null.
75       *
76       * @throws NullPointerException if table is null.
77       */
78      public ColumnValues(
79              Map<Column, JdbcTypedValue> columnValues)
80      {
81          if (columnValues == null)
82          {
83              this.columnValues = new HashMap<Column, JdbcTypedValue>();
84          }
85          else
86          {
87              this.columnValues = columnValues;
88          }
89      }
90  
91      /**
92       * Constructor.
93       *
94       * @param columnValues the column values, or null.
95       * @param dbName the name of the database handle to use for connection
96       *        opening if needed, or null to use the default database handle
97       *        for the table.
98       *
99       * @throws NullPointerException if table is null.
100      */
101     public ColumnValues(
102             Map<Column, JdbcTypedValue> columnValues,
103             TableMap table,
104             String dbName)
105     {
106         this(columnValues);
107         this.dbName = dbName;
108     }
109 
110     /**
111      * Returns the name of the database handle to use for connection
112      * opening.
113      *
114      * @return the database name, or null to use the default database handle
115      *         for the table.
116      */
117     public String getDbName()
118     {
119         return dbName;
120     }
121 
122     public int size()
123     {
124         return columnValues.size();
125     }
126 
127     public boolean isEmpty()
128     {
129         return columnValues.isEmpty();
130     }
131 
132     public boolean containsKey(Object key)
133     {
134         return columnValues.containsKey(key);
135     }
136 
137     public boolean containsValue(Object value)
138     {
139         return columnValues.containsValue(value);
140     }
141 
142     public JdbcTypedValue get(Object key)
143     {
144         return columnValues.get(key);
145     }
146 
147     public JdbcTypedValue put(Column key, JdbcTypedValue value)
148     {
149         return columnValues.put(key, value);
150     }
151 
152     public JdbcTypedValue remove(Object key)
153     {
154         return columnValues.remove(key);
155     }
156 
157     public void putAll(Map<? extends Column, ? extends JdbcTypedValue> t)
158     {
159         columnValues.putAll(t);
160     }
161 
162     public void clear()
163     {
164         columnValues.clear();
165     }
166 
167     public Set<Column> keySet()
168     {
169         return columnValues.keySet();
170     }
171 
172     public Collection<JdbcTypedValue> values()
173     {
174         return columnValues.values();
175     }
176 
177     public Set<java.util.Map.Entry<Column, JdbcTypedValue>> entrySet()
178     {
179         return columnValues.entrySet();
180     }
181 
182     @Override
183     public String toString()
184     {
185         return "ColumnValues [dbName=" + dbName
186             + ", columnValues=" + columnValues + "]";
187     }
188 
189 }