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


001:        //$Id: JTATransactionFactory.java 10339 2006-08-24 15:07:03Z steve.ebersole@jboss.com $
002:        package org.hibernate.transaction;
003:
004:        import java.util.Properties;
005:
006:        import javax.naming.InitialContext;
007:        import javax.naming.NamingException;
008:        import javax.transaction.SystemException;
009:        import javax.transaction.UserTransaction;
010:
011:        import org.apache.commons.logging.Log;
012:        import org.apache.commons.logging.LogFactory;
013:        import org.hibernate.ConnectionReleaseMode;
014:        import org.hibernate.HibernateException;
015:        import org.hibernate.Transaction;
016:        import org.hibernate.TransactionException;
017:        import org.hibernate.jdbc.JDBCContext;
018:        import org.hibernate.cfg.Environment;
019:        import org.hibernate.util.NamingHelper;
020:        import org.hibernate.util.JTAHelper;
021:
022:        /**
023:         * Factory for <tt>JTATransaction</tt>.
024:         *
025:         * @see JTATransaction
026:         * @author Gavin King
027:         */
028:        public class JTATransactionFactory implements  TransactionFactory {
029:
030:            private static final Log log = LogFactory
031:                    .getLog(JTATransactionFactory.class);
032:            private static final String DEFAULT_USER_TRANSACTION_NAME = "java:comp/UserTransaction";
033:
034:            protected InitialContext context;
035:            protected String utName;
036:
037:            public void configure(Properties props) throws HibernateException {
038:                try {
039:                    context = NamingHelper.getInitialContext(props);
040:                } catch (NamingException ne) {
041:                    log.error("Could not obtain initial context", ne);
042:                    throw new HibernateException(
043:                            "Could not obtain initial context", ne);
044:                }
045:
046:                utName = props.getProperty(Environment.USER_TRANSACTION);
047:
048:                if (utName == null) {
049:                    TransactionManagerLookup lookup = TransactionManagerLookupFactory
050:                            .getTransactionManagerLookup(props);
051:                    if (lookup != null)
052:                        utName = lookup.getUserTransactionName();
053:                }
054:
055:                if (utName == null)
056:                    utName = DEFAULT_USER_TRANSACTION_NAME;
057:            }
058:
059:            public Transaction createTransaction(JDBCContext jdbcContext,
060:                    Context transactionContext) throws HibernateException {
061:                return new JTATransaction(context, utName, jdbcContext,
062:                        transactionContext);
063:            }
064:
065:            public ConnectionReleaseMode getDefaultReleaseMode() {
066:                return ConnectionReleaseMode.AFTER_STATEMENT;
067:            }
068:
069:            public boolean isTransactionManagerRequired() {
070:                return false;
071:            }
072:
073:            public boolean areCallbacksLocalToHibernateTransactions() {
074:                return false;
075:            }
076:
077:            public boolean isTransactionInProgress(JDBCContext jdbcContext,
078:                    Context transactionContext, Transaction transaction) {
079:                try {
080:                    // Essentially:
081:                    // 1) If we have a local (Hibernate) transaction in progress
082:                    //      and it already has the UserTransaction cached, use that
083:                    //      UserTransaction to determine the status.
084:                    // 2) If a transaction manager has been located, use
085:                    //      that transaction manager to determine the status.
086:                    // 3) Finally, as the last resort, try to lookup the
087:                    //      UserTransaction via JNDI and use that to determine the
088:                    //      status.
089:                    if (transaction != null) {
090:                        UserTransaction ut = ((JTATransaction) transaction)
091:                                .getUserTransaction();
092:                        if (ut != null) {
093:                            return JTAHelper.isInProgress(ut.getStatus());
094:                        }
095:                    }
096:
097:                    if (jdbcContext.getFactory().getTransactionManager() != null) {
098:                        return JTAHelper.isInProgress(jdbcContext.getFactory()
099:                                .getTransactionManager().getStatus());
100:                    } else {
101:                        try {
102:                            UserTransaction ut = (UserTransaction) context
103:                                    .lookup(utName);
104:                            return ut != null
105:                                    && JTAHelper.isInProgress(ut.getStatus());
106:                        } catch (NamingException ne) {
107:                            throw new TransactionException(
108:                                    "Unable to locate UserTransaction to check status",
109:                                    ne);
110:                        }
111:                    }
112:                } catch (SystemException se) {
113:                    throw new TransactionException(
114:                            "Unable to check transaction status", se);
115:                }
116:            }
117:
118:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.