Source Code Cross Referenced for DbPersistenceServiceFactory.java in  » Workflow-Engines » jbpm-jpdl-3.2.2 » org » jbpm » persistence » db » 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 » Workflow Engines » jbpm jpdl 3.2.2 » org.jbpm.persistence.db 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source
003:         * Copyright 2005, JBoss Inc., and individual contributors as indicated
004:         * by the @authors tag. See the copyright.txt in the distribution for a
005:         * full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jbpm.persistence.db;
023:
024:        import javax.sql.DataSource;
025:
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.hibernate.SessionFactory;
029:        import org.hibernate.cfg.Configuration;
030:        import org.hibernate.tool.hbm2ddl.SchemaExport;
031:        import org.jbpm.JbpmConfiguration;
032:        import org.jbpm.db.hibernate.HibernateHelper;
033:        import org.jbpm.svc.Service;
034:        import org.jbpm.svc.ServiceFactory;
035:        import org.jbpm.util.JndiUtil;
036:
037:        public class DbPersistenceServiceFactory implements  ServiceFactory {
038:
039:            private static final long serialVersionUID = 1L;
040:
041:            Configuration configuration = null;
042:
043:            String sessionFactoryJndiName = null;
044:            SessionFactory sessionFactory = null;
045:
046:            String dataSourceJndiName = null;
047:            DataSource dataSource = null;
048:
049:            boolean isTransactionEnabled = true;
050:            boolean isCurrentSessionEnabled = false;
051:
052:            SchemaExport schemaExport = null;
053:
054:            public Service openService() {
055:                log.debug("creating persistence service");
056:                return new DbPersistenceService(this );
057:            }
058:
059:            public synchronized Configuration getConfiguration() {
060:                if (configuration == null) {
061:                    String hibernateCfgXmlResource = null;
062:                    if (JbpmConfiguration.Configs
063:                            .hasObject("resource.hibernate.cfg.xml")) {
064:                        hibernateCfgXmlResource = JbpmConfiguration.Configs
065:                                .getString("resource.hibernate.cfg.xml");
066:                    }
067:                    String hibernatePropertiesResource = null;
068:                    if (JbpmConfiguration.Configs
069:                            .hasObject("resource.hibernate.properties")) {
070:                        hibernatePropertiesResource = JbpmConfiguration.Configs
071:                                .getString("resource.hibernate.properties");
072:                    }
073:                    configuration = HibernateHelper.createConfiguration(
074:                            hibernateCfgXmlResource,
075:                            hibernatePropertiesResource);
076:                }
077:                return configuration;
078:            }
079:
080:            public synchronized SchemaExport getSchemaExport() {
081:                if (schemaExport == null) {
082:                    log.debug("creating schema export");
083:                    schemaExport = new SchemaExport(getConfiguration());
084:                }
085:                return schemaExport;
086:            }
087:
088:            public synchronized SessionFactory getSessionFactory() {
089:                if (sessionFactory == null) {
090:
091:                    if (sessionFactoryJndiName != null) {
092:                        log
093:                                .debug("looking up hibernate session factory in jndi '"
094:                                        + sessionFactoryJndiName + "'");
095:                        sessionFactory = (SessionFactory) JndiUtil.lookup(
096:                                sessionFactoryJndiName, SessionFactory.class);
097:
098:                    } else {
099:                        log.debug("building hibernate session factory");
100:                        sessionFactory = getConfiguration()
101:                                .buildSessionFactory();
102:                    }
103:                }
104:                return sessionFactory;
105:            }
106:
107:            public DataSource getDataSource() {
108:                if ((dataSource == null) && (dataSourceJndiName != null)) {
109:                    log.debug("looking up datasource from jndi location '"
110:                            + dataSourceJndiName + "'");
111:                    dataSource = (DataSource) JndiUtil.lookup(
112:                            dataSourceJndiName, DataSource.class);
113:                }
114:                return dataSource;
115:            }
116:
117:            public void createSchema() {
118:                getSchemaExport().create(getScript(), true);
119:                HibernateHelper.clearHibernateCache(getSessionFactory());
120:            }
121:
122:            public void dropSchema() {
123:                HibernateHelper.clearHibernateCache(getSessionFactory());
124:                getSchemaExport().drop(getScript(), true);
125:            }
126:
127:            boolean getScript() {
128:                boolean script = false;
129:                String showSql = getConfiguration().getProperty(
130:                        "hibernate.show_sql");
131:                if ("true".equalsIgnoreCase(showSql)) {
132:                    script = true;
133:                }
134:                return script;
135:            }
136:
137:            public void close() {
138:                if (sessionFactory != null) {
139:                    log.debug("closing hibernate session factory");
140:                    sessionFactory.close();
141:                }
142:            }
143:
144:            public String getDataSourceJndiName() {
145:                return dataSourceJndiName;
146:            }
147:
148:            public void setDataSourceJndiName(String dataSourceJndiName) {
149:                this .dataSourceJndiName = dataSourceJndiName;
150:            }
151:
152:            public String getSessionFactoryJndiName() {
153:                return sessionFactoryJndiName;
154:            }
155:
156:            public void setSessionFactoryJndiName(String sessionFactoryJndiName) {
157:                this .sessionFactoryJndiName = sessionFactoryJndiName;
158:            }
159:
160:            public void setConfiguration(Configuration configuration) {
161:                this .configuration = configuration;
162:            }
163:
164:            public void setDataSource(DataSource dataSource) {
165:                this .dataSource = dataSource;
166:            }
167:
168:            public void setSchemaExport(SchemaExport schemaExport) {
169:                this .schemaExport = schemaExport;
170:            }
171:
172:            public void setSessionFactory(SessionFactory sessionFactory) {
173:                this .sessionFactory = sessionFactory;
174:            }
175:
176:            public boolean isTransactionEnabled() {
177:                return isTransactionEnabled;
178:            }
179:
180:            public void setTransactionEnabled(boolean isTransactionEnabled) {
181:                this .isTransactionEnabled = isTransactionEnabled;
182:            }
183:
184:            public boolean isCurrentSessionEnabled() {
185:                return isCurrentSessionEnabled;
186:            }
187:
188:            public void setCurrentSessionEnabled(boolean isCurrentSessionEnabled) {
189:                this .isCurrentSessionEnabled = isCurrentSessionEnabled;
190:            }
191:
192:            private static Log log = LogFactory
193:                    .getLog(DbPersistenceServiceFactory.class);
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.