KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright (c) 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: ListDatabaseFactoryImpl.java,v 1.4 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.List JavaDoc;
25
26 import org.opensubsystems.core.error.OSSException;
27 import org.opensubsystems.core.persist.db.DatabaseFactoryImpl;
28 import org.opensubsystems.patterns.listdata.data.ListDefinition;
29 import org.opensubsystems.patterns.listdata.data.ListOptions;
30 import org.opensubsystems.patterns.listdata.persist.ListFactory;
31 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseFactory;
32 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseSchema;
33 import org.opensubsystems.patterns.listdata.persist.db.ListDatabaseUtils;
34
35 /**
36  * Base class for all database factory mainly collecting reusable and useful code.
37  *
38  * @version $Id: ListDatabaseFactoryImpl.java,v 1.4 2007/02/01 07:24:13 bastafidli Exp $
39  * @author Miroslav Halas
40  * @code.reviewer Miroslav Halas
41  * @code.reviewed Initial revision
42  */

43 public abstract class ListDatabaseFactoryImpl extends DatabaseFactoryImpl
44                                               implements ListFactory,
45                                                          ListDatabaseFactory
46 {
47    // Cached values ////////////////////////////////////////////////////////////
48

49    /**
50     * Codes for columns to order the list of data object by, null if no sorting
51     * should be done.
52     */

53    protected int[] m_arrOrderColumnCodes;
54    
55    /**
56     * Directions how to order the list of data objects. See
57     * ListDefinition.ORDER_XXX constants.
58     */

59    protected String JavaDoc[] m_arrOrderDirections;
60    
61    /**
62     * Array of attributes to retrieve for each data object. Each attribute
63     * should have assigned unique code that can be used to identify that
64     * attribute and column where it is stored.
65     */

66    protected int[] m_arrShowColumnCodes;
67    
68    /**
69     * Schema that can be used to execute database dependent list operations.
70     */

71    protected ListDatabaseSchema m_listSchema;
72    
73    // Constructors /////////////////////////////////////////////////////////////
74

75    /**
76     * Constructor.
77     *
78     * @param iDataType - data type the factory will be used for
79     * @param arrOrderColumnCodes - codes for columns to order the list of data
80     * object by, null if no sorting should be done.
81     * @param arrOrderDirections - directions how to order the list of data
82     * objects. See ListDefinition.ORDER_XXX constants.
83     * @param arrShowColumnCodes - array of attributes to retrieve for each data
84     * object. Each attribute should have assigned
85     * unique code that can be used to identify that
86     * attribute and column where it is stored.
87     * @param listSchema - schema that can be used to execute database dependent
88     * list operations.
89     * @throws OSSException - an error has occured
90     */

91    public ListDatabaseFactoryImpl(
92       int iDataType,
93       int[] arrOrderColumnCodes,
94       String JavaDoc[] arrOrderDirections,
95       int[] arrShowColumnCodes,
96       ListDatabaseSchema listSchema
97    ) throws OSSException
98    {
99       super(iDataType);
100       
101       m_arrOrderColumnCodes = arrOrderColumnCodes;
102       m_arrOrderDirections = arrOrderDirections;
103       m_arrShowColumnCodes = arrShowColumnCodes;
104       m_listSchema = listSchema;
105    }
106    
107    // List operations //////////////////////////////////////////////////////////
108

109    /**
110     * {@inheritDoc}
111     */

112    public ListDefinition getDefaultListDefinition()
113    {
114       assert m_arrShowColumnCodes != null
115              : "No columns to retrieve were specified.";
116
117       return new ListDefinition(m_arrOrderColumnCodes,
118                                 m_arrOrderDirections,
119                                 m_arrShowColumnCodes);
120    }
121
122    /**
123     * {@inheritDoc}
124     */

125    public List JavaDoc get(
126       ListOptions options
127    ) throws OSSException
128    {
129       assert m_listSchema != null
130              : "No list database schema was specified.";
131
132       return ListDatabaseUtils.getInstance().getObjectList(
133                 options,
134                 m_listSchema.getSelectList(options, getDataType()),
135                 this, m_listSchema);
136    }
137    
138    /**
139     * Get the list database schema used by this factory.
140     *
141     * @return ListDatabaseSchema - list database schema used by this factory
142     */

143    public ListDatabaseSchema getListDatabaseSchema()
144    {
145       return m_listSchema;
146    }
147 }
148
Popular Tags