KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > patterns > listdata > persist > db > impl > ModifiableListDatabaseSchemaImpl


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ModifiableListDatabaseSchemaImpl.java,v 1.3 2007/02/01 07:24:13 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.patterns.listdata.persist.db.impl;
23
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.opensubsystems.core.error.OSSException;
28 import org.opensubsystems.core.persist.db.DatabaseSchema;
29 import org.opensubsystems.core.persist.db.ModifiableDatabaseSchemaImpl;
30 import org.opensubsystems.core.util.DatabaseUtils;
31 import org.opensubsystems.patterns.listdata.data.ListOptions;
32 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseSchema;
33 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseUtils;
34
35 /**
36  * Base class implementation for list database schemas that provide queries or
37  * operations that allow to modify data in tables managed by this schema as well
38  * as functionality needed to browse list of data objects.
39  *
40  * @version $Id: ModifiableListDatabaseSchemaImpl.java,v 1.3 2007/02/01 07:24:13 bastafidli Exp $
41  * @author Miro Halas
42  * @code.reviewer Miro Halas
43  * @code.reviewed Initial revision
44  */

45 public abstract class ModifiableListDatabaseSchemaImpl extends ModifiableDatabaseSchemaImpl
46                                                        implements ListDatabaseSchema
47 {
48    // Cached values ////////////////////////////////////////////////////////////
49

50    /**
51     * Map of all tables belonging to this schema that store data objects that
52     * can be accessed using the list data pattern. Key is the data type, value
53     * is the string with the table name.
54     */

55    protected Map JavaDoc m_mapListableTableNames;
56
57    /**
58     * Map of all columns belonging to this schema that have to be retrieved for
59     * a data object when a list of data objects is required. Key is the data
60     * type, value is the int array (int[]) of column codes, which has to be
61     * retrieved for a given data object.
62     */

63    protected Map JavaDoc m_mapMandatoryRetrieveColumns;
64
65    /**
66     * Map of all sortable columns belonging to this schema. Key is the data type,
67     * value is the int array (int[]) of column codes, which can be used for
68     * sorting the list of items.
69     */

70    protected Map JavaDoc m_mapSortableColumns;
71
72    /**
73     * Map of all filterable columns belonging to this schema. Key is the data
74     * type, value is the int array (int[]) of column codes, which can be used
75     * for filtering the list of items.
76     */

77    protected Map JavaDoc m_mapFilterableColumns;
78
79    // Constructors /////////////////////////////////////////////////////////////
80

81    /**
82     * Constructor allowing to specify attributes for database schema that
83     * support multiple data object types and therefore have multiple sets of
84     * table names and columns sets.
85     *
86     * @param arrDependentSchemas - array of dependent schemas
87     * @param strSchemaName - name of the schema
88     * @param iSchemaVersion - version of the schema
89     * @param bIsInDomain - flag signaling if object is in domain
90     * @param mapModifiableTableNames - map of all tables belonging to this schema
91     * that can be modified by the schema (e.g.
92     * schema allows insert, update or delete on
93     * this table)
94     * @param mapListableTableNames - map of all tables belonging to this schema
95     * that store data objects that can be accessed
96     * using the list data pattern. Key is the data
97     * type, value is the string with the table name.
98     * @param mapMandatoryRetrieveColumns - map of all columns belonging to this
99     * schema that have to be retrieved for
100     * a data object when a list of data
101     * objects is required. Key is the data
102     * type, value is the int array (int[])
103     * of column codes, which has to be
104     * retrieved for a given data object.
105     * @param mapSortableColumns - map of all sortable columns belonging to this
106     * schema. Key is the data type, value is the
107     * int array (int[]) of column codes, which can
108     * be used for sorting the list of items.
109     * @param mapFilterableColumns - map of all filterable columns belonging to
110     * this schema. Key is the data type, value is
111     * the int array (int[]) of column codes,
112     * which can be used for filtering the list of
113     * items.
114     * @throws OSSException - an error has occured
115     */

116    public ModifiableListDatabaseSchemaImpl(
117       DatabaseSchema[] arrDependentSchemas,
118       String JavaDoc strSchemaName,
119       int iSchemaVersion,
120       boolean bIsInDomain,
121       Map JavaDoc mapModifiableTableNames,
122       Map JavaDoc mapListableTableNames,
123       Map JavaDoc mapMandatoryRetrieveColumns,
124       Map JavaDoc mapSortableColumns,
125       Map JavaDoc mapFilterableColumns
126    ) throws OSSException
127    {
128       super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain,
129             mapModifiableTableNames);
130       
131       m_mapListableTableNames = mapListableTableNames;
132       m_mapMandatoryRetrieveColumns = mapMandatoryRetrieveColumns;
133       m_mapSortableColumns = mapSortableColumns;
134       m_mapFilterableColumns = mapFilterableColumns;
135    }
136
137    /**
138     * Constructor allowing to specify attributes for database schema that
139     * support only single data object type and therefore have most likely only
140     * one table name and single columns sets.
141     *
142     * @param iDataType - data type that can be modified and listed using
143     * operations in this schema
144     * @param arrDependentSchemas - array of dependent schemas
145     * @param strSchemaName - name of the schema
146     * @param iSchemaVersion - version of the schema
147     * @param strTableName - table belonging to this schema that can be modified
148     * by the schema (e.g. schema allows insert, update or
149     * delete on this table)
150     * @param bIsInDomain - flag signaling if object is in domain
151     * @param arrMandatoryRetrieveColumns - array of column codes of columns,
152     * which has to be retrieved for a
153     * given data object.
154     * @param arrSortableColumns - array of column codes of columns, which can
155     * be used for sorting the list of items.
156     * @param arrFilterableColumns - array of column codes of columns, which can
157     * be used for filtering the list of items.
158     * @throws OSSException - an error has occured
159     */

160    public ModifiableListDatabaseSchemaImpl(
161       DatabaseSchema[] arrDependentSchemas,
162       String JavaDoc strSchemaName,
163       int iSchemaVersion,
164       boolean bIsInDomain,
165       Integer JavaDoc iDataType,
166       String JavaDoc strTableName,
167       int[] arrMandatoryRetrieveColumns,
168       int[] arrSortableColumns,
169       int[] arrFilterableColumns
170    ) throws OSSException
171    {
172       super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain,
173             iDataType, strTableName);
174
175       m_mapListableTableNames = new HashMap JavaDoc(1);
176       m_mapListableTableNames.put(iDataType, strTableName);
177       m_mapMandatoryRetrieveColumns = new HashMap JavaDoc();
178       m_mapMandatoryRetrieveColumns.put(iDataType, arrMandatoryRetrieveColumns);
179       m_mapSortableColumns = new HashMap JavaDoc();
180       m_mapSortableColumns.put(iDataType, arrSortableColumns);
181       m_mapFilterableColumns = new HashMap JavaDoc(1);
182       m_mapFilterableColumns.put(iDataType, arrFilterableColumns);
183    }
184    
185    /**
186     * Constructor allowing to specify attributes for database schema that
187     * support only single listable data object type and therefore have most
188     * likely only one single columns sets but may consist of multiple tables
189     * storing the data for a given data object that can be modified.
190     *
191     * @param arrDependentSchemas - array of dependent schemas
192     * @param strSchemaName - name of the schema
193     * @param iSchemaVersion - version of the schema
194     * @param bIsInDomain - flag signaling if object is in domain
195     * @param mapModifiableTableNames - map of all tables belonging to this schema
196     * that can be modified by the schema (e.g.
197     * schema allows insert, update or delete on
198     * this table)
199     * @param iListableDataType - data type that can be listed using the list
200     * data pattern
201     * in this schema
202     * @param strListableTableName - table belonging to this schema that stores
203     * data objects that can be accessed using the
204     * list data pattern
205     * @param arrMandatoryRetrieveColumns - array of column codes of columns,
206     * which has to be retrieved for a
207     * given data object.
208     * @param arrSortableColumns - array of column codes of columns, which can
209     * be used for sorting the list of items.
210     * @param arrFilterableColumns - array of column codes of columns, which can
211     * be used for filtering the list of items.
212     * @throws OSSException - an error has occured
213     */

214    public ModifiableListDatabaseSchemaImpl(
215       DatabaseSchema[] arrDependentSchemas,
216       String JavaDoc strSchemaName,
217       int iSchemaVersion,
218       boolean bIsInDomain,
219       Map JavaDoc mapModifiableTableNames,
220       Integer JavaDoc iListableDataType,
221       String JavaDoc strListableTableName,
222       int[] arrMandatoryRetrieveColumns,
223       int[] arrSortableColumns,
224       int[] arrFilterableColumns
225    ) throws OSSException
226    {
227       super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain,
228             mapModifiableTableNames);
229
230       m_mapListableTableNames = new HashMap JavaDoc(1);
231       m_mapListableTableNames.put(iListableDataType, strListableTableName);
232       m_mapMandatoryRetrieveColumns = new HashMap JavaDoc();
233       m_mapMandatoryRetrieveColumns.put(iListableDataType, arrMandatoryRetrieveColumns);
234       m_mapSortableColumns = new HashMap JavaDoc();
235       m_mapSortableColumns.put(iListableDataType, arrSortableColumns);
236       m_mapFilterableColumns = new HashMap JavaDoc(1);
237       m_mapFilterableColumns.put(iListableDataType, arrFilterableColumns);
238    }
239    
240    // List data pattern specific logic /////////////////////////////////////////
241
// These operations has to be exact copy of those implemented in
242
// ListDatabaseSchemaImpl
243

244    /**
245     * Get collection of all columns that has to be retrieved for each data object
246     * supported by this schema.
247     *
248     * @return Map - key is the data type, value is the int array (int[]) of
249     * column codes which has to be retrieved for a given data object.
250     */

251    public Map JavaDoc getMandatoryRetrieveColumns()
252    {
253       return m_mapMandatoryRetrieveColumns;
254    }
255
256    /**
257     * Get collection of all columns that can be used to sort data objects
258     * supported by this schema.
259     *
260     * @return Map - Key is the data type, value is the array of column codes
261     * (int[])which can be used for sorting.
262     */

263    public Map JavaDoc getSortableColumns()
264    {
265       return m_mapSortableColumns;
266    }
267
268    /**
269     * Get collection of all columns that can be used to sort data objects
270     * supported by this schema.
271     *
272     * @return Map - Key is the data type, value is the array of column codes
273     * (int[])which can be used for sorting.
274     */

275    public Map JavaDoc getFilterbleColumns()
276    {
277       return m_mapFilterableColumns;
278    }
279
280    /**
281     * {@inheritDoc}
282     */

283    public String JavaDoc getSelectList(
284       ListOptions options,
285       // TODO: Improve: The data type should be part of the list options rather
286
// than specifying it explicitely like this
287
int iDataType
288    ) throws OSSException
289    {
290       int[] arrMandatoryRetrieveColumns;
291       int[] arrSortableColumns;
292       int[] arrFilterableColumns;
293       String JavaDoc strTableName;
294       Integer JavaDoc intDataType = new Integer JavaDoc(iDataType);
295       
296       arrMandatoryRetrieveColumns = (int[])m_mapMandatoryRetrieveColumns.get(intDataType);
297       arrSortableColumns = (int[])m_mapSortableColumns.get(intDataType);
298       arrFilterableColumns = (int[])m_mapFilterableColumns.get(intDataType);
299       strTableName = (String JavaDoc)m_mapListableTableNames.get(intDataType);
300       
301       options.setRetrieveColumnCodes(DatabaseUtils.mergeColumnsSafely(
302                                      options.getShowColumnCodes(),
303                                      arrMandatoryRetrieveColumns));
304       options.setSortableColumnCodes(arrSortableColumns);
305       options.setFilterableColumnCodes(arrFilterableColumns);
306
307       return ListDatabaseUtils.getInstance().getSelectList(strTableName,
308                                                            options, this);
309    }
310 }
311
Popular Tags