1 /*
2 QueryJ
3
4 Copyright (C) 2002 Jose San Leandro Armend?riz
5 jsanleandro@yahoo.es
6 chousz@yahoo.com
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 Thanks to ACM S.L. for distributing this library under the GPL license.
23 Contact info: jsanleandro@yahoo.es
24 Postal Address: c/Playa de Lagoa, 1
25 Urb. Valdecaba?as
26 Boadilla del monte
27 28660 Madrid
28 Spain
29
30 ******************************************************************************
31 *
32 * Filename: $RCSfile: QueryFactory.java,v $
33 *
34 * Author: Jose San Leandro Armend?riz
35 *
36 * Description: Has the responsiblity of knowing how to create queries.
37 *
38 * Last modified by: $Author: chous $ at $Date: 2003/08/29 08:14:59 $
39 *
40 * File version: $Revision: 1.1 $
41 *
42 * Project version: $Name: $
43 *
44 * $Id: QueryFactory.java,v 1.1 2003/08/29 08:14:59 chous Exp $
45 *
46 */
47 package org.acmsl.queryj;
48
49 /*
50 * Importing ACM-SL classes.
51 */
52 import org.acmsl.queryj.Query;
53 import org.acmsl.queryj.SelectQuery;
54
55 /*
56 * Importing some JDK classes.
57 */
58 import java.lang.ref.WeakReference;
59
60 /***
61 * Has the responsiblity of knowing how to create queries.
62 * @author <a href="mailto:jsanleandro@yahoo.es">Jose San Leandro</a>
63 * @version $Revision: 1.1 $
64 */
65 public abstract class QueryFactory
66 {
67 /***
68 * Singleton implemented as a weak reference.
69 */
70 private static WeakReference singleton;
71
72 /***
73 * Protected constructor to avoid accidental instantiation.
74 */
75 protected QueryFactory() {};
76
77 /***
78 * Specifies a new weak reference.
79 * @param factory the factory instance to use.
80 */
81 protected static void setReference(QueryFactory factory)
82 {
83 singleton = new WeakReference(factory);
84 }
85
86 /***
87 * Retrieves the weak reference.
88 * @return such reference.
89 */
90 protected static WeakReference getReference()
91 {
92 return singleton;
93 }
94
95 /***
96 * Retrieves a QueryFactory instance.
97 * @return such instance.
98 */
99 public static QueryFactory getInstance()
100 {
101 QueryFactory result = null;
102
103 WeakReference reference = getReference();
104
105 if (reference != null)
106 {
107 result = (QueryFactory) reference.get();
108 }
109
110 if (result == null)
111 {
112 result = new QueryFactory() {};
113
114 setReference(result);
115 }
116
117 return result;
118 }
119
120 /***
121 * Creates a select query.
122 * @return such query.
123 */
124 public SelectQuery createSelectQuery()
125 {
126 return new SelectQuery() {};
127 }
128 }
This page was automatically generated by Maven