Source Code Cross Referenced for JaxorContextImpl.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.*;
004:        import net.sourceforge.jaxor.db.SingleConnectionTransaction;
005:        import net.sourceforge.jaxor.impl.InstanceCacheImpl;
006:        import net.sourceforge.jaxor.impl.InstanceFactoryImpl;
007:        import net.sourceforge.jaxor.impl.QueryResultImpl;
008:        import net.sourceforge.jaxor.impl.UnitOfWorkImpl;
009:        import net.sourceforge.jaxor.impl.MapperRegistryImpl;
010:        import net.sourceforge.jaxor.util.MethodCache;
011:        import net.sourceforge.jaxor.util.SystemException;
012:
013:        import java.sql.Connection;
014:        import java.sql.ResultSet;
015:        import java.sql.SQLException;
016:        import java.util.List;
017:
018:        public class JaxorContextImpl implements  JaxorContext {
019:
020:            private UnitOfWork _uow;
021:            private QueryCache _queryCache;
022:            private InstanceCache _cache;
023:            private JaxorTransaction _transaction = null;
024:            private final InstanceFactory _instanceFactory;
025:            private MapperRegistry _mapperRegistry;
026:            private String _user;
027:
028:            public JaxorContextImpl(Connection conn) {
029:                this (new SingleConnectionTransaction(conn));
030:            }
031:
032:            public JaxorContextImpl(ConnectionFactory fact) {
033:                this (new SingleConnectionTransaction(fact));
034:            }
035:
036:            public JaxorContextImpl(JaxorTransaction trans) {
037:                this (trans, new InstanceCacheImpl(), new MethodCache(),
038:                        new UnitOfWorkImpl());
039:            }
040:
041:            public JaxorContextImpl(JaxorTransaction conn, InstanceCache cache,
042:                    QueryCache queryCache, UnitOfWork uow) {
043:                this (conn, cache, queryCache, uow, new InstanceFactoryImpl(),
044:                        new MapperRegistryImpl());
045:            }
046:
047:            public JaxorContextImpl(JaxorTransaction conn, InstanceCache cache,
048:                    QueryCache queryCache, UnitOfWork uow,
049:                    InstanceFactory factory, MapperRegistry reg) {
050:                _transaction = conn;
051:                _cache = cache;
052:                _queryCache = queryCache;
053:                _uow = uow;
054:                _instanceFactory = factory;
055:                _mapperRegistry = reg;
056:            }
057:
058:            public String getUser() {
059:                return _user;
060:            }
061:
062:            public void setUser(String user) {
063:                _user = user;
064:            }
065:
066:            public InstanceFactory getInstanceFactory() {
067:                return _instanceFactory;
068:            }
069:
070:            public EntityInterface load(ResultSet rs, MetaRow clzz) {
071:                EntityInterface result = createEntity(clzz);
072:                try {
073:                    result.getFields().load(rs);
074:                } catch (SQLException e) {
075:                    throw new SystemException(e);
076:                }
077:                EntityInterface cache = cache(result);
078:                if (cache == result || cache == null) {// need to do a null check in case we are using a null proxy
079:                    result.setJaxorContext(this );
080:                    if (result instanceof  LifeCycleListener)
081:                        ((LifeCycleListener) result).afterLoad();
082:                    result.registerLoad();
083:                }
084:                return cache;
085:            }
086:
087:            public EntityInterface createEntity(MetaRow clzz) {
088:                EntityInterface entity = _instanceFactory.createEntity(clzz
089:                        .getImplClass());
090:                entity.setMetaRow(clzz);
091:                return entity;
092:            }
093:
094:            private EntityInterface cache(EntityInterface result) {
095:                return _cache.updateCache(result);
096:            }
097:
098:            public QueryResult query(String sql, MetaRow implClass) {
099:                return query(sql, new QueryParams(), implClass);
100:            }
101:
102:            public QueryResult query(final String sql, final QueryParams args,
103:                    final MetaRow _meta) {
104:                return new QueryResultImpl(_meta, sql, args, this );
105:            }
106:
107:            public void flush() {
108:                _queryCache.clear();
109:                if (_uow.size() > 0) {
110:                    Connection connection = this .getConnection();
111:                    try {
112:                        _uow.flush(connection);
113:                    } finally {
114:                        try {
115:                            connection.close();
116:                        } catch (SQLException e) {
117:                            e.printStackTrace();
118:                        }
119:                    }
120:                }
121:            }
122:
123:            public void commit() {
124:                flush();
125:                _transaction.commit();
126:            }
127:
128:            public void end() {
129:                if (_transaction != null)
130:                    _transaction.end();
131:            }
132:
133:            public Connection getConnection() {
134:                Connection conn = _transaction.getConnection();
135:                if (conn == null)
136:                    throw new NullPointerException(
137:                            "JaxorTransaction returned a null connection");
138:                return conn;
139:            }
140:
141:            public InstanceCache getCache() {
142:                return _cache;
143:            }
144:
145:            public QueryCache getQueryCache() {
146:                return _queryCache;
147:            }
148:
149:            public UnitOfWork getUnitOfWork() {
150:                return _uow;
151:            }
152:
153:            public void setCache(InstanceCache cache) {
154:                _cache = cache;
155:            }
156:
157:            public void setQueryCache(QueryCache cache) {
158:                _queryCache = cache;
159:            }
160:
161:            public void setUnitOfWork(UnitOfWork work) {
162:                _uow = work;
163:            }
164:
165:            public void setTransaction(JaxorTransaction fact) {
166:                _transaction = fact;
167:            }
168:
169:            public JaxorTransaction getTransaction() {
170:                return _transaction;
171:            }
172:
173:            public MapperRegistry getMapperRegistry() {
174:                return _mapperRegistry;
175:            }
176:
177:            public void registerNew(EntityInterface entity) {
178:                if (entity instanceof  LifeCycleListener)
179:                    ((LifeCycleListener) entity).beforeCreate();
180:                entity.setJaxorContext(this );
181:                _uow.registerNew(entity);
182:                if (entity instanceof  LifeCycleListener)
183:                    ((LifeCycleListener) entity).afterCreate();
184:                cache(entity);
185:            }
186:
187:            public FinderAdapter getFinder(Class finderClass) {
188:                return getInstanceFactory().createFinder(finderClass, this );
189:            }
190:
191:            public Object createListImpl(List list, Class listImplClass) {
192:                return getInstanceFactory().createListImpl(list, listImplClass);
193:            }
194:
195:            public void registerUpdate(EntityInterface entity) {
196:                _uow.registerUpdate(entity);
197:            }
198:
199:            public void registerDelete(EntityInterface entity) {
200:                _uow.registerDelete(entity);
201:            }
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.