Source Code Cross Referenced for ReferenceResolver.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » 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 » jaxor 3.5 » net.sourceforge.jaxor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jaxor;
002:
003:        import net.sourceforge.jaxor.api.FinderAdapter;
004:
005:        import java.io.Serializable;
006:        import java.util.ArrayList;
007:        import java.util.Iterator;
008:        import java.util.List;
009:
010:        /*
011:         * User: Mike
012:         * Date: Sep 2, 2003
013:         * Time: 9:12:55 PM
014:         */
015:
016:        public class ReferenceResolver implements  Serializable {
017:
018:            private final Class _finderClass;
019:            private final List _metaRowList = new ArrayList();
020:            private final boolean _unique;
021:            private final String _querySql;
022:            private final String _findSql;
023:            private final EntityRow _parent;
024:
025:            public ReferenceResolver(Class finderClass, EntityRow source,
026:                    boolean unique) {
027:                _finderClass = finderClass;
028:                _unique = unique;
029:                _parent = source;
030:                _querySql = null;
031:                _findSql = null;
032:            }
033:
034:            public ReferenceResolver(Class finderClass, EntityRow source,
035:                    boolean unique, String querySql, String findSql) {
036:                _finderClass = finderClass;
037:                _unique = unique;
038:                _parent = source;
039:                _querySql = querySql;
040:                _findSql = findSql;
041:            }
042:
043:            public void add(MetaField sourceMeta, MetaField targetMeta) {
044:                MetaPair pair = new MetaPair();
045:                pair.Source = sourceMeta;
046:                pair.Target = targetMeta;
047:                _metaRowList.add(pair);
048:            }
049:
050:            public List getKeys() {
051:                return _metaRowList;
052:            }
053:
054:            public static class MetaPair implements  Serializable {
055:                public MetaField Source;
056:                public MetaField Target;
057:            }
058:
059:            public Object getObject() {
060:                if (_parent == null || _parent.getJaxorContext() == null)
061:                    return null;
062:                FinderAdapter finder = createFinder();
063:                QueryParams params = new QueryParams();
064:
065:                for (Iterator iterator = _metaRowList.iterator(); iterator
066:                        .hasNext();) {
067:                    MetaPair pair = (MetaPair) iterator.next();
068:                    MetaField source = pair.Source;
069:                    Object value = getValue(source.getProperty());
070:                    params.add(source.getMapperInstance(), value);
071:                }
072:                if (_unique) {
073:                    try {
074:                        if (_querySql != null)
075:                            return finder.getFinder().query(_querySql, params)
076:                                    .entity();
077:                        else
078:                            return finder.getFinder().find(createFindSql(),
079:                                    params).entity();
080:                    } catch (EntityNotFoundException e) {
081:                        return null;
082:                    }
083:                } else {
084:                    List list = resolveList(finder, params);
085:                    return _parent.getJaxorContext().createListImpl(list,
086:                            finder.getFinder().getMetaRow().getListImplClass());
087:                }
088:            }
089:
090:            private List resolveList(FinderAdapter finder, QueryParams params) {
091:                if (_querySql != null)
092:                    return finder.getFinder().query(_querySql, params).list();
093:                else
094:                    return finder.getFinder().find(createFindSql(), params)
095:                            .list();
096:            }
097:
098:            public Object getValue(String propertyName) {
099:                return _parent.getPropertyValue(propertyName);
100:            }
101:
102:            private FinderAdapter createFinder() {
103:                return _parent.getJaxorContext().getFinder(_finderClass);
104:            }
105:
106:            public String createFindSql() {
107:                if (_findSql != null)
108:                    return _findSql;
109:                String sql = "where ";
110:                for (Iterator iterator = _metaRowList.iterator(); iterator
111:                        .hasNext();) {
112:                    MetaPair pair = (MetaPair) iterator.next();
113:                    sql += pair.Target.getColumn() + "=?";
114:                    if (iterator.hasNext())
115:                        sql += " AND ";
116:                }
117:                return sql;
118:            }
119:
120:            public EntityRow getSourceEntity() {
121:                return _parent;
122:            }
123:
124:            public boolean isUnique() {
125:                return _unique;
126:            }
127:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.