Source Code Cross Referenced for IndexNode.java in  » Database-ORM » hibernate » org » hibernate » hql » ast » tree » 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 » hibernate » org.hibernate.hql.ast.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: IndexNode.java 7460 2005-07-12 20:27:29Z steveebersole $
002:        package org.hibernate.hql.ast.tree;
003:
004:        import org.hibernate.QueryException;
005:        import org.hibernate.engine.JoinSequence;
006:        import org.hibernate.hql.ast.SqlGenerator;
007:        import org.hibernate.hql.ast.util.SessionFactoryHelper;
008:        import org.hibernate.persister.collection.QueryableCollection;
009:        import org.hibernate.type.CollectionType;
010:        import org.hibernate.type.Type;
011:
012:        import antlr.RecognitionException;
013:        import antlr.SemanticException;
014:        import antlr.collections.AST;
015:
016:        import org.apache.commons.logging.Log;
017:        import org.apache.commons.logging.LogFactory;
018:
019:        /**
020:         * Represents the [] operator and provides it's semantics.
021:         *
022:         * @author josh Aug 14, 2004 7:07:10 AM
023:         */
024:        public class IndexNode extends FromReferenceNode {
025:
026:            private static final Log log = LogFactory.getLog(IndexNode.class);
027:
028:            public void setScalarColumnText(int i) throws SemanticException {
029:                throw new UnsupportedOperationException(
030:                        "An IndexNode cannot generate column text!");
031:            }
032:
033:            public void prepareForDot(String propertyName)
034:                    throws SemanticException {
035:                FromElement fromElement = getFromElement();
036:                if (fromElement == null) {
037:                    throw new IllegalStateException(
038:                            "No FROM element for index operator!");
039:                }
040:                QueryableCollection queryableCollection = fromElement
041:                        .getQueryableCollection();
042:                if (queryableCollection != null
043:                        && !queryableCollection.isOneToMany()) {
044:
045:                    FromReferenceNode collectionNode = (FromReferenceNode) getFirstChild();
046:                    String path = collectionNode.getPath() + "[]."
047:                            + propertyName;
048:                    if (log.isDebugEnabled()) {
049:                        log
050:                                .debug("Creating join for many-to-many elements for "
051:                                        + path);
052:                    }
053:                    FromElementFactory factory = new FromElementFactory(
054:                            fromElement.getFromClause(), fromElement, path);
055:                    // This will add the new from element to the origin.
056:                    FromElement elementJoin = factory
057:                            .createElementJoin(queryableCollection);
058:                    setFromElement(elementJoin);
059:                }
060:            }
061:
062:            public void resolveIndex(AST parent) throws SemanticException {
063:                throw new UnsupportedOperationException();
064:            }
065:
066:            public void resolve(boolean generateJoin, boolean implicitJoin,
067:                    String classAlias, AST parent) throws SemanticException {
068:                if (isResolved()) {
069:                    return;
070:                }
071:                FromReferenceNode collectionNode = (FromReferenceNode) getFirstChild();
072:                SessionFactoryHelper sessionFactoryHelper = getSessionFactoryHelper();
073:                collectionNode.resolveIndex(this ); // Fully resolve the map reference, create implicit joins.
074:
075:                Type type = collectionNode.getDataType();
076:                if (!type.isCollectionType()) {
077:                    throw new SemanticException(
078:                            "The [] operator cannot be applied to type "
079:                                    + type.toString());
080:                }
081:                String collectionRole = ((CollectionType) type).getRole();
082:                QueryableCollection queryableCollection = sessionFactoryHelper
083:                        .requireQueryableCollection(collectionRole);
084:                if (!queryableCollection.hasIndex()) {
085:                    throw new QueryException(
086:                            "unindexed fromElement before []: "
087:                                    + collectionNode.getPath());
088:                }
089:
090:                // Generate the inner join -- The elements need to be joined to the collection they are in.
091:                FromElement fromElement = collectionNode.getFromElement();
092:                String elementTable = fromElement.getTableAlias();
093:                FromClause fromClause = fromElement.getFromClause();
094:                String path = collectionNode.getPath();
095:
096:                FromElement elem = fromClause.findCollectionJoin(path);
097:                if (elem == null) {
098:                    FromElementFactory factory = new FromElementFactory(
099:                            fromClause, fromElement, path);
100:                    elem = factory.createCollectionElementsJoin(
101:                            queryableCollection, elementTable);
102:                    if (log.isDebugEnabled()) {
103:                        log
104:                                .debug("No FROM element found for the elements of collection join path "
105:                                        + path + ", created " + elem);
106:                    }
107:                } else {
108:                    if (log.isDebugEnabled()) {
109:                        log
110:                                .debug("FROM element found for collection join path "
111:                                        + path);
112:                    }
113:                }
114:
115:                // Add the condition to the join sequence that qualifies the indexed element.
116:                AST index = collectionNode.getNextSibling(); // The index should be a constant, which will have been processed already.
117:                if (index == null) {
118:                    throw new QueryException("No index value!");
119:                }
120:
121:                setFromElement(fromElement); // The 'from element' that represents the elements of the collection.
122:
123:                // Sometimes use the element table alias, sometimes use the... umm... collection table alias (many to many)
124:                String collectionTableAlias = elementTable;
125:                if (elem.getCollectionTableAlias() != null) {
126:                    collectionTableAlias = elem.getCollectionTableAlias();
127:                }
128:
129:                // TODO: get SQL rendering out of here, create an AST for the join expressions.
130:                // Use the SQL generator grammar to generate the SQL text for the index expression.
131:                JoinSequence joinSequence = fromElement.getJoinSequence();
132:                String[] indexCols = queryableCollection.getIndexColumnNames();
133:                if (indexCols.length != 1) {
134:                    throw new QueryException("composite-index appears in []: "
135:                            + collectionNode.getPath());
136:                }
137:                SqlGenerator gen = new SqlGenerator(getSessionFactoryHelper()
138:                        .getFactory());
139:                try {
140:                    gen.simpleExpr(index); //TODO: used to be exprNoParens! was this needed?
141:                } catch (RecognitionException e) {
142:                    throw new QueryException(e.getMessage(), e);
143:                }
144:                String expression = gen.getSQL();
145:                joinSequence.addCondition(collectionTableAlias + '.'
146:                        + indexCols[0] + " = " + expression);
147:
148:                // Now, set the text for this node.  It should be the element columns.
149:                String[] elementColumns = queryableCollection
150:                        .getElementColumnNames(elementTable);
151:                setText(elementColumns[0]);
152:                setResolved();
153:            }
154:
155:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.