Java Doc for SqlMapClient.java in  » Database-ORM » iBATIS » com » ibatis » sqlmap » client » 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 » iBATIS » com.ibatis.sqlmap.client 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


com.ibatis.sqlmap.client.SqlMapClient

SqlMapClient
public interface SqlMapClient extends SqlMapExecutor,SqlMapTransactionManager(Code)
A thread safe client for working with your SQL Maps (Start Here). This interface inherits transaction control and execution methods from the SqlMapTransactionManager and SqlMapExecutor interfaces.

The SqlMapClient is the central class for working with SQL Maps. This class will allow you to run mapped statements (select, insert, update, delete etc.), and also demarcate transactions and work with batches. Once you have an SqlMapClient instance, everything you need to work with SQL Maps is easily available.

The SqlMapClient can either be worked with directly as a multi-threaded client (internal session management), or you can get a single threaded session and work with that. There may be a slight performance increase if you explicitly get a session (using the openSession() method), as it saves the SqlMapClient from having to manage threads contexts. But for most cases it won't make much of a difference, so choose whichever paradigm suits your needs or preferences.

An SqlMapClient instance can be safely made static or applied as a Singleton. Generally it's a good idea to make a simple configuration class that will configure the instance (using SqlMapClientBuilder) and provide access to it.

The following example will demonstrate the use of SqlMapClient.

 
 //
 // autocommit simple query --these are just examples...not patterns
 //
 
 Employee emp = (Employee) sqlMap.queryForObject("getEmployee", new Integer(1));
 
 //
 // transaction --these are just examples...not patterns
 //
 
 try {
 sqlMap.startTransaction()
 Employee emp2 = new Employee();
 // ...set emp2 data
 Integer generatedKey = (Integer) sqlMap.insert ("insertEmployee", emp2);
 emp2.setFavouriteColour ("green");
 sqlMap.update("updateEmployee", emp2);
 sqlMap.commitTransaction();
 } finally {
 sqlMap.endTransaction();
 }
 
 //
 // session --these are just examples...not patterns
 //
 
 try {
 SqlMapSession session = sqlMap.openSession()
 session.startTransaction()
 Employee emp2 = new Employee();
 // ...set emp2 data
 Integer generatedKey = (Integer) session.insert ("insertEmployee", emp2);
 emp2.setFavouriteColour ("green");
 session.update("updateEmployee", emp2);
 session.commitTransaction();
 } finally {
 try {
 session.endTransaction();
 } finally {
 session.close();
 }
 // Generally your session scope would be in a wider context and therefore the
 // ugly nested finally block above would not be there.  Realize that sessions
 // MUST be closed if explicitly opened (via openSession()).
 }
 
 //
 // batch --these are just examples...not patterns
 //
 
 try {
 sqlMap.startTransaction()
 List list = (Employee) sqlMap.queryForList("getFiredEmployees", null);
 sqlMap.startBatch ();
 for (int i=0, n=list.size(); i < n; i++) {
 sqlMap.delete ("deleteEmployee", list.get(i));
 }
 sqlMap.executeBatch();
 sqlMap.commitTransaction();
 } finally {
 sqlMap.endTransaction();
 }
 

See Also:   SqlMapClientBuilder
See Also:   SqlMapSession
See Also:   SqlMapExecutor




Method Summary
public  voidflushDataCache()
     Flushes all data caches.
public  voidflushDataCache(String cacheId)
     Flushes the data cache that matches the cache model ID provided.
public  SqlMapSessiongetSession()
     TODO : Deprecated and will be removed.
public  SqlMapSessionopenSession()
     Returns a single threaded SqlMapSession implementation for use by one user.
public  SqlMapSessionopenSession(Connection conn)
     Returns a single threaded SqlMapSession implementation for use by one user.



Method Detail
flushDataCache
public void flushDataCache()(Code)
Flushes all data caches.



flushDataCache
public void flushDataCache(String cacheId)(Code)
Flushes the data cache that matches the cache model ID provided. cacheId should include the namespace, even when useStatementNamespaces="false".
Parameters:
  cacheId - The cache model to flush



getSession
public SqlMapSession getSession()(Code)
TODO : Deprecated and will be removed. A session (DEPRECATED)



openSession
public SqlMapSession openSession()(Code)
Returns a single threaded SqlMapSession implementation for use by one user. Remember though, that SqlMapClient itself is a thread safe SqlMapSession implementation, so you can also just work directly with it. If you do get a session explicitly using this method be sure to close it! You can close a session using the sqlMapSession.close() method.

An SqlMapSession instance.




openSession
public SqlMapSession openSession(Connection conn)(Code)
Returns a single threaded SqlMapSession implementation for use by one user. Remember though, that SqlMapClient itself is a thread safe SqlMapSession implementation, so you can also just work directly with it. If you do get a session explicitly using this method be sure to close it! You can close a session using the SqlMapSession.close() method.

This particular implementation takes a user provided connection as a parameter. This connection will be used for executing statements, and therefore overrides any configured datasources. Using this approach allows the developer to easily use an externally supplied connection for executing statements.

Important: Using a user supplied connection basically sidesteps the datasource so you are responsible for appropriately handling your connection lifecycle (i.e. closing). Here's a (very) simple example (throws SQLException):

 try {
 Connection connection = dataSource.getConnection();
 SqlMapSession session = sqlMap.openSession(connection);
 // do work
 connection.commit();
 } catch (SQLException e) {
 try {
 if (connection != null) commit.rollback();
 } catch (SQLException ignored) {
 // generally ignored
 }
 throw e;  // rethrow the exception
 } finally {
 try {
 if (connection != null) connection.close();
 } catch (SQLException ignored) {
 // generally ignored
 }
 }
 

Parameters:
  conn - - the connection to use for the session An SqlMapSession instance.



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.