Source Code Cross Referenced for SpeedoQueryManager.java in  » Database-ORM » Speedo_1.4.5 » org » objectweb » speedo » query » lib » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Speedo_1.4.5 » org.objectweb.speedo.query.lib 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Speedo: an implementation of JDO compliant personality on top of JORM generic
003:         * I/O sub-system.
004:         * Copyright (C) 2001-2004 France Telecom R&D
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2 of the License, or (at your option) any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:         *
020:         *
021:         *
022:         * Contact: speedo@objectweb.org
023:         *
024:         * Authors: S. Chassande-Barrioz
025:         *
026:         */package org.objectweb.speedo.query.lib;
027:
028:        import org.objectweb.fractal.api.control.BindingController;
029:        import org.objectweb.jorm.api.PMapper;
030:        import org.objectweb.medor.eval.prefetch.api.PrefetchBufferFactory;
031:        import org.objectweb.medor.eval.prefetch.lib.PrefetchBufferFactoryImpl;
032:        import org.objectweb.medor.lib.Log;
033:        import org.objectweb.perseus.cache.api.CacheEntryFactory;
034:        import org.objectweb.perseus.cache.api.CacheEvent;
035:        import org.objectweb.perseus.cache.api.CacheEventListener;
036:        import org.objectweb.perseus.cache.api.CacheException;
037:        import org.objectweb.perseus.cache.api.CacheManager;
038:        import org.objectweb.perseus.cache.api.FixableCacheEntry;
039:        import org.objectweb.speedo.mapper.api.JormFactory;
040:        import org.objectweb.speedo.pm.api.POManagerFactoryItf;
041:        import org.objectweb.speedo.query.api.CompiledQuery;
042:        import org.objectweb.speedo.query.api.QueryDefinition;
043:        import org.objectweb.speedo.query.api.QueryManager;
044:        import org.objectweb.speedo.query.api.QueryManagerAttribute;
045:        import org.objectweb.util.monolog.api.BasicLevel;
046:        import org.objectweb.util.monolog.api.Logger;
047:        import org.objectweb.util.monolog.api.LoggerFactory;
048:
049:        /**
050:         * SpeedoQueryManager manages the association between SpeedoQuery and the
051:         * the compiled query: SpeedoCompiledQuery.
052:         *
053:         * @author S.Chassande-Barrioz
054:         */
055:        public abstract class SpeedoQueryManager implements  QueryManager,
056:                CacheEntryFactory, CacheEventListener, BindingController,
057:                QueryManagerAttribute {
058:
059:            public final static String MAPPER_BINDING = "mapper";
060:            public final static String JORM_FACTORY_BINDING = "jorm-factory";
061:            public final static String COMPILED_QUERY_CACHE_BINDING = "compiled-query-cache";
062:            public final static String PMF_BINDING = "po-manager-factory";
063:
064:            protected PMapper mapper = null;
065:
066:            protected JormFactory jormFactory = null;
067:
068:            private CacheManager compiledQueriesCache = null;
069:            protected PrefetchBufferFactory prefetchBufferFactory;
070:
071:            /**
072:             * The PMF
073:             */
074:            private POManagerFactoryItf pmf = null;
075:
076:            protected Logger logger = null;
077:            protected Logger cqlogger = null;
078:            protected Logger cqpvlogger = null;
079:            protected Logger cqpflogger = null;
080:            private boolean prefetchingOnQuery = true;
081:            private boolean prefetchingOnExtent = true;
082:
083:            /**
084:             * creates a new SpeedoQueryManager object.
085:             */
086:            public SpeedoQueryManager() {
087:                prefetchBufferFactory = new PrefetchBufferFactoryImpl();
088:            }
089:
090:            public FixableCacheEntry create(Object id, Object obj) {
091:                return (CompiledQuery) obj;
092:            }
093:
094:            public boolean getPrefetchActivatedOnQuery() {
095:                return prefetchingOnQuery;
096:            }
097:
098:            public void setPrefetchActivatedOnQuery(boolean prefetch) {
099:                prefetchingOnQuery = prefetch;
100:            }
101:
102:            public boolean getPrefetchActivatedOnExtent() {
103:                return prefetchingOnExtent;
104:            }
105:
106:            public void setPrefetchActivatedOnExtent(boolean prefetch) {
107:                prefetchingOnExtent = prefetch;
108:            }
109:
110:            // IMPLEMENTATION OF UserBindingController INTERFACE //
111:            //---------------------------------------------------//
112:
113:            public String[] listFc() {
114:                return new String[] { MAPPER_BINDING, JORM_FACTORY_BINDING,
115:                        COMPILED_QUERY_CACHE_BINDING, PMF_BINDING };
116:            }
117:
118:            public Object lookupFc(String s) {
119:                if (MAPPER_BINDING.equals(s))
120:                    return mapper;
121:                else if (JORM_FACTORY_BINDING.equals(s))
122:                    return jormFactory;
123:                else if (COMPILED_QUERY_CACHE_BINDING.equals(s))
124:                    return compiledQueriesCache;
125:                else if (PMF_BINDING.equals(s))
126:                    return pmf;
127:                else
128:                    return null;
129:            }
130:
131:            public void bindFc(String s, Object o) {
132:                if ("monolog-factory".equals(s)) {
133:                    Log.loggerFactory = (LoggerFactory) o;
134:                    String bn = logger.getName();
135:                    cqlogger = Log.loggerFactory.getLogger(bn
136:                            + ".compiled-query");
137:                    cqpvlogger = Log.loggerFactory.getLogger(cqlogger.getName()
138:                            + ".parser.variable");
139:                    cqpflogger = Log.loggerFactory.getLogger(cqlogger.getName()
140:                            + ".parser.filter");
141:                    logger = Log.loggerFactory.getLogger(cqlogger.getName()
142:                            + ".allocator");
143:                } else if ("logger".equals(s)) {
144:                    logger = (Logger) o;
145:                } else if (PMF_BINDING.equals(s)) {
146:                    pmf = (POManagerFactoryItf) o;
147:                } else if (MAPPER_BINDING.equals(s))
148:                    mapper = (PMapper) o;
149:                else if (COMPILED_QUERY_CACHE_BINDING.equals(s))
150:                    compiledQueriesCache = (CacheManager) o;
151:                else if (JORM_FACTORY_BINDING.equals(s))
152:                    jormFactory = (JormFactory) o;
153:            }
154:
155:            public void unbindFc(String s) {
156:                if (MAPPER_BINDING.equals(s))
157:                    mapper = null;
158:                else if (JORM_FACTORY_BINDING.equals(s))
159:                    jormFactory = null;
160:                else if (COMPILED_QUERY_CACHE_BINDING.equals(s))
161:                    compiledQueriesCache = null;
162:            }
163:
164:            // IMPLEMENTATION OF CacheEventListener INTERFACE //
165:            //------------------------------------------------//
166:
167:            /**
168:             * An entry has been added in the cache.
169:             * @param event describes the added entry
170:             */
171:            public void entryBound(CacheEvent event) {
172:            }
173:
174:            /**
175:             * An entry has been evicted from the cache.
176:             * @param event describes the evicted entry
177:             */
178:            public void entryUnbound(CacheEvent event) {
179:            }
180:
181:            // IMPLEMENTATION OF QueryManager INTERFACE //
182:            //------------------------------------------//
183:
184:            /**
185:             * returns a CompiledQuery implementation, creates it if it does not exists,
186:             * or just returns an existing one.
187:             * @param qd	a QueryDefinition
188:             * @return	a (new/existing) CompiledQuery instance.
189:             */
190:            public synchronized CompiledQuery getQueryCompiler(
191:                    QueryDefinition qd) {
192:                CompiledQuery cq = (CompiledQuery) compiledQueriesCache
193:                        .lookup(qd);
194:                if (cq == null) {
195:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
196:                        logger.log(BasicLevel.DEBUG,
197:                                "Allocation of a new compiled query: "
198:                                        + qd.qdToString(false));
199:                    }
200:                    cq = createCompileQuery(qd);
201:                    qd.withPrefetch(prefetchingOnExtent && qd.withPrefetch());
202:                    try {
203:                        compiledQueriesCache.bind(cq.getCeIdentifier(), cq);
204:                    } catch (CacheException e) {
205:                        logger
206:                                .log(
207:                                        BasicLevel.WARN,
208:                                        "Impossible to bind a new compiled query from the cache: ",
209:                                        e);
210:                        //nothing to do, the compiled query is not cached
211:                    }
212:                } else {
213:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
214:                        logger.log(BasicLevel.DEBUG, "Reuse a compiled query: "
215:                                + qd.qdToString(false));
216:                    }
217:                }
218:                return cq;
219:            }
220:
221:            public POManagerFactoryItf getPMF() {
222:                return pmf;
223:            }
224:
225:            public void setPMF(POManagerFactoryItf pmf) {
226:                this .pmf = pmf;
227:            }
228:
229:            public void clean() {
230:                try {
231:                    //clean the compiled query cache
232:                    compiledQueriesCache.unbindAll();
233:                } catch (CacheException e) {
234:                    logger
235:                            .log(
236:                                    BasicLevel.WARN,
237:                                    "Impossible to clean the compiled query cache: ",
238:                                    e);
239:                }
240:            }
241:
242:            protected abstract CompiledQuery createCompileQuery(
243:                    QueryDefinition qd);
244:
245:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.