KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListDatabaseSchemaImpl.java,v 1.6 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.DatabaseSchemaImpl;
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
37  * functionality needed to browse list of data objects.
38  *
39  * @version $Id: ListDatabaseSchemaImpl.java,v 1.6 2007/02/01 07:24:13 bastafidli Exp $
40  * @author Miro Halas
41  * @code.reviewer Miro Halas
42  * @code.reviewed Initial revision
43  */

44 public abstract class ListDatabaseSchemaImpl extends DatabaseSchemaImpl
45                                              implements ListDatabaseSchema
46 {
47    // Attributes ////////////////////////////////////////////////////////////
48

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

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

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

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

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

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

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

154    public ListDatabaseSchemaImpl(
155       DatabaseSchema[] arrDependentSchemas,
156       String JavaDoc strSchemaName,
157       int iSchemaVersion,
158       boolean bIsInDomain,
159       Integer JavaDoc iListableDataType,
160       String JavaDoc strListableTableName,
161       int[] arrMandatoryRetrieveColumns,
162       int[] arrSortableColumns,
163       int[] arrFilterableColumns
164    ) throws OSSException
165    {
166       super(arrDependentSchemas, strSchemaName, iSchemaVersion, bIsInDomain);
167
168       m_mapListableTableNames = new HashMap JavaDoc(1);
169       m_mapListableTableNames.put(iListableDataType, strListableTableName);
170       m_mapMandatoryRetrieveColumns = new HashMap JavaDoc(1);
171       m_mapMandatoryRetrieveColumns.put(iListableDataType, arrMandatoryRetrieveColumns);
172       m_mapSortableColumns = new HashMap JavaDoc(1);
173       m_mapSortableColumns.put(iListableDataType, arrSortableColumns);
174       m_mapFilterableColumns = new HashMap JavaDoc(1);
175       m_mapFilterableColumns.put(iListableDataType, arrFilterableColumns);
176    }
177    
178    // Accessors ////////////////////////////////////////////////////////////////
179

180    // These operations has to be exact copy of those implemented in
181
// ModifiableListDatabaseSchemaImpl
182

183    /**
184     * Get collection of all columns that has to be retrieved for each data object
185     * supported by this schema.
186     *
187     * @return Map - key is the data type, value is the int array (int[]) of
188     * column codes which has to be retrieved for a given data object.
189     */

190    public Map JavaDoc getMandatoryRetrieveColumns()
191    {
192       return m_mapMandatoryRetrieveColumns;
193    }
194
195    /**
196     * Get collection of all columns that can be used to sort data objects
197     * supported by this schema.
198     *
199     * @return Map - Key is the data type, value is the array of column codes
200     * (int[])which can be used for sorting.
201     */

202    public Map JavaDoc getSortableColumns()
203    {
204       return m_mapSortableColumns;
205    }
206
207    /**
208     * Get collection of all columns that can be used to sort data objects
209     * supported by this schema.
210     *
211     * @return Map - Key is the data type, value is the array of column codes
212     * (int[])which can be used for sorting.
213     */

214    public Map JavaDoc getFilterbleColumns()
215    {
216       return m_mapFilterableColumns;
217    }
218
219    /**
220     * {@inheritDoc}
221     */

222    public String JavaDoc getSelectList(
223       ListOptions options,
224       // TODO: Improve: The data type should be part of the list options rather
225
// than specifying it explicitely like this
226
int iDataType
227    ) throws OSSException
228    {
229       int[] arrMandatoryRetrieveColumns;
230       int[] arrSortableColumns;
231       int[] arrFilterableColumns;
232       String JavaDoc strTableName;
233       Integer JavaDoc intDataType = new Integer JavaDoc(iDataType);
234       
235       arrMandatoryRetrieveColumns = (int[])m_mapMandatoryRetrieveColumns.get(intDataType);
236       arrSortableColumns = (int[])m_mapSortableColumns.get(intDataType);
237       arrFilterableColumns = (int[])m_mapFilterableColumns.get(intDataType);
238       strTableName = (String JavaDoc)m_mapListableTableNames.get(intDataType);
239       
240       options.setRetrieveColumnCodes(DatabaseUtils.mergeColumnsSafely(
241                                      options.getShowColumnCodes(),
242                                      arrMandatoryRetrieveColumns));
243       options.setSortableColumnCodes(arrSortableColumns);
244       options.setFilterableColumnCodes(arrFilterableColumns);
245
246       return ListDatabaseUtils.getInstance().getSelectList(strTableName,
247                                                            options, this);
248    }
249 }
250
Popular Tags