Source Code Cross Referenced for Aggregate.java in  » Database-ORM » openjpa » org » apache » openjpa » jdbc » kernel » exps » 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 » openjpa » org.apache.openjpa.jdbc.kernel.exps 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements.  See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership.  The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License.  You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied.  See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.    
018:         */
019:        package org.apache.openjpa.jdbc.kernel.exps;
020:
021:        import java.sql.SQLException;
022:
023:        import org.apache.openjpa.jdbc.meta.ClassMapping;
024:        import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
025:        import org.apache.openjpa.jdbc.sql.Result;
026:        import org.apache.openjpa.jdbc.sql.SQLBuffer;
027:        import org.apache.openjpa.jdbc.sql.Select;
028:        import org.apache.openjpa.kernel.Filters;
029:        import org.apache.openjpa.kernel.exps.ExpressionVisitor;
030:        import org.apache.openjpa.meta.ClassMetaData;
031:
032:        /**
033:         * Aggregate listener that evaluates to a value.
034:         *
035:         * @author Abe White
036:         */
037:        class Aggregate extends AbstractVal {
038:
039:            private final JDBCAggregateListener _listener;
040:            private final Val _arg;
041:            private final ClassMapping _candidate;
042:            private ClassMetaData _meta = null;
043:            private Class _cast = null;
044:
045:            /**
046:             * Constructor.
047:             */
048:            public Aggregate(JDBCAggregateListener listener, Val arg,
049:                    ClassMapping candidate) {
050:                _listener = listener;
051:                _arg = arg;
052:                _candidate = candidate;
053:            }
054:
055:            public ClassMetaData getMetaData() {
056:                return _meta;
057:            }
058:
059:            public void setMetaData(ClassMetaData meta) {
060:                _meta = meta;
061:            }
062:
063:            public boolean isAggregate() {
064:                return true;
065:            }
066:
067:            public Class getType() {
068:                if (_cast != null)
069:                    return _cast;
070:                return _listener.getType(getArgTypes());
071:            }
072:
073:            private Class[] getArgTypes() {
074:                if (_arg == null)
075:                    return null;
076:                if (_arg instanceof  Args)
077:                    return ((Args) _arg).getTypes();
078:                return new Class[] { _arg.getType() };
079:            }
080:
081:            public void setImplicitType(Class type) {
082:                _cast = type;
083:            }
084:
085:            public ExpState initialize(Select sel, ExpContext ctx, int flags) {
086:                if (_arg == null)
087:                    return ExpState.NULL;
088:
089:                // note that we tell targets and args to extensions that are sql
090:                // paths to go ahead and join to their related object (if any),
091:                // because we assume that, unlike most operations, if a relation
092:                // field like a 1-1 is given as the target of an extension, then
093:                // the extension probably acts on some field or column in the
094:                // related object, not the 1-1 field itself
095:                return _arg.initialize(sel, ctx, JOIN_REL);
096:            }
097:
098:            public void select(Select sel, ExpContext ctx, ExpState state,
099:                    boolean pks) {
100:                sel.select(newSQLBuffer(sel, ctx, state), this );
101:                sel.setAggregate(true);
102:            }
103:
104:            public void selectColumns(Select sel, ExpContext ctx,
105:                    ExpState state, boolean pks) {
106:                if (_arg != null)
107:                    _arg.selectColumns(sel, ctx, state, true);
108:            }
109:
110:            public void groupBy(Select sel, ExpContext ctx, ExpState state) {
111:                sel.groupBy(newSQLBuffer(sel, ctx, state));
112:            }
113:
114:            public void orderBy(Select sel, ExpContext ctx, ExpState state,
115:                    boolean asc) {
116:                sel.orderBy(newSQLBuffer(sel, ctx, state), asc, false);
117:            }
118:
119:            private SQLBuffer newSQLBuffer(Select sel, ExpContext ctx,
120:                    ExpState state) {
121:                calculateValue(sel, ctx, state, null, null);
122:                SQLBuffer buf = new SQLBuffer(ctx.store.getDBDictionary());
123:                appendTo(sel, ctx, state, buf, 0);
124:                return buf;
125:            }
126:
127:            public Object load(ExpContext ctx, ExpState state, Result res)
128:                    throws SQLException {
129:                return Filters.convert(res.getObject(this ,
130:                        JavaSQLTypes.JDBC_DEFAULT, null), getType());
131:            }
132:
133:            public void calculateValue(Select sel, ExpContext ctx,
134:                    ExpState state, Val other, ExpState otherState) {
135:                if (_arg != null)
136:                    _arg.calculateValue(sel, ctx, state, null, null);
137:            }
138:
139:            public int length(Select sel, ExpContext ctx, ExpState state) {
140:                return 1;
141:            }
142:
143:            public void appendTo(Select sel, ExpContext ctx, ExpState state,
144:                    SQLBuffer sql, int index) {
145:                _listener.appendTo(sql, getArgs(sel, ctx, state), _candidate,
146:                        ctx.store);
147:                sel.append(sql, state.joins);
148:            }
149:
150:            private FilterValue[] getArgs(Select sel, ExpContext ctx,
151:                    ExpState state) {
152:                if (_arg == null)
153:                    return null;
154:                if (_arg instanceof  Args)
155:                    return ((Args) _arg).newFilterValues(sel, ctx, state);
156:                return new FilterValue[] { new FilterValueImpl(sel, ctx, state,
157:                        _arg) };
158:            }
159:
160:            public void acceptVisit(ExpressionVisitor visitor) {
161:                visitor.enter(this);
162:                if (_arg != null)
163:                    _arg.acceptVisit(visitor);
164:                visitor.exit(this);
165:            }
166:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.