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


001:        package org.hibernate.id.insert;
002:
003:        import org.hibernate.exception.JDBCExceptionHelper;
004:        import org.hibernate.pretty.MessageHelper;
005:        import org.hibernate.engine.SessionImplementor;
006:        import org.hibernate.id.PostInsertIdentityPersister;
007:
008:        import java.sql.PreparedStatement;
009:        import java.sql.SQLException;
010:        import java.sql.ResultSet;
011:        import java.io.Serializable;
012:
013:        /**
014:         * Abstract InsertGeneratedIdentifierDelegate implementation where the
015:         * underlying strategy requires an subsequent select after the insert
016:         * to determine the generated identifier.
017:         *
018:         * @author Steve Ebersole
019:         */
020:        public abstract class AbstractSelectingDelegate implements 
021:                InsertGeneratedIdentifierDelegate {
022:            private final PostInsertIdentityPersister persister;
023:
024:            protected AbstractSelectingDelegate(
025:                    PostInsertIdentityPersister persister) {
026:                this .persister = persister;
027:            }
028:
029:            public final Serializable performInsert(String insertSQL,
030:                    SessionImplementor session, Binder binder) {
031:                try {
032:                    // prepare and execute the insert
033:                    PreparedStatement insert = session.getBatcher()
034:                            .prepareStatement(insertSQL, false);
035:                    try {
036:                        binder.bindValues(insert);
037:                        insert.executeUpdate();
038:                    } finally {
039:                        session.getBatcher().closeStatement(insert);
040:                    }
041:                } catch (SQLException sqle) {
042:                    throw JDBCExceptionHelper.convert(session.getFactory()
043:                            .getSQLExceptionConverter(), sqle,
044:                            "could not insert: "
045:                                    + MessageHelper.infoString(persister),
046:                            insertSQL);
047:                }
048:
049:                final String selectSQL = getSelectSQL();
050:
051:                try {
052:                    //fetch the generated id in a separate query
053:                    PreparedStatement idSelect = session.getBatcher()
054:                            .prepareStatement(selectSQL);
055:                    try {
056:                        bindParameters(session, idSelect, binder.getEntity());
057:                        ResultSet rs = idSelect.executeQuery();
058:                        try {
059:                            return getResult(session, rs, binder.getEntity());
060:                        } finally {
061:                            rs.close();
062:                        }
063:                    } finally {
064:                        session.getBatcher().closeStatement(idSelect);
065:                    }
066:
067:                } catch (SQLException sqle) {
068:                    throw JDBCExceptionHelper.convert(session.getFactory()
069:                            .getSQLExceptionConverter(), sqle,
070:                            "could not retrieve generated id after insert: "
071:                                    + MessageHelper.infoString(persister),
072:                            insertSQL);
073:                }
074:            }
075:
076:            /**
077:             * Get the SQL statement to be used to retrieve generated key values.
078:             *
079:             * @return The SQL command string
080:             */
081:            protected abstract String getSelectSQL();
082:
083:            /**
084:             * Bind any required parameter values into the SQL command {@link #getSelectSQL}.
085:             *
086:             * @param session The session
087:             * @param ps The prepared {@link #getSelectSQL SQL} command
088:             * @param entity The entity being saved.
089:             * @throws SQLException
090:             */
091:            protected void bindParameters(SessionImplementor session,
092:                    PreparedStatement ps, Object entity) throws SQLException {
093:            }
094:
095:            /**
096:             * Extract the generated key value from the given result set.
097:             *
098:             * @param session The session
099:             * @param rs The result set containing the generated primay key values.
100:             * @param entity The entity being saved.
101:             * @return The generated identifier
102:             * @throws SQLException
103:             */
104:            protected abstract Serializable getResult(
105:                    SessionImplementor session, ResultSet rs, Object entity)
106:                    throws SQLException;
107:
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.