Source Code Cross Referenced for IBatisSimpleTestApp.java in  » Net » Terracotta » com » tctest » 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 » Net » Terracotta » com.tctest 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.tctest;
002:
003:        import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
004:
005:        import com.ibatis.common.resources.Resources;
006:        import com.ibatis.sqlmap.client.SqlMapClient;
007:        import com.ibatis.sqlmap.client.SqlMapClientBuilder;
008:        import com.tc.object.config.ConfigVisitor;
009:        import com.tc.object.config.DSOClientConfigHelper;
010:        import com.tc.object.config.spec.CyclicBarrierSpec;
011:        import com.tc.simulator.app.ApplicationConfig;
012:        import com.tc.simulator.listener.ListenerProvider;
013:        import com.tc.test.HSqlDBServer;
014:        import com.tc.util.Assert;
015:        import com.tc.util.TIMUtil;
016:        import com.tctest.domain.Account;
017:        import com.tctest.domain.Customer;
018:        import com.tctest.runner.AbstractTransparentApp;
019:
020:        import java.io.Reader;
021:        import java.sql.Connection;
022:        import java.sql.PreparedStatement;
023:        import java.sql.SQLException;
024:
025:        public class IBatisSimpleTestApp extends AbstractTransparentApp {
026:            private CyclicBarrier barrier;
027:
028:            private SqlMapClient sqlMapper;
029:
030:            private Customer cus;
031:            private HSqlDBServer dbServer = null;
032:
033:            public IBatisSimpleTestApp(String appId, ApplicationConfig cfg,
034:                    ListenerProvider listenerProvider) {
035:                super (appId, cfg, listenerProvider);
036:                barrier = new CyclicBarrier(getParticipantCount());
037:            }
038:
039:            public void run() {
040:                try {
041:                    int id = barrier.barrier();
042:
043:                    try {
044:
045:                        if (id == 0) {
046:
047:                            setupDatabaseResource();
048:
049:                            Account acc = new Account();
050:                            acc.setNumber("ASI-001");
051:                            insertAccount(acc);
052:                            Customer cus = new Customer();
053:                            cus.setEmailAddress("asi@yahoo.com");
054:                            cus.setFirstName("Antonio");
055:                            cus.setLastName("Si");
056:                            cus.setAccount(acc);
057:                            insertCustomer(cus);
058:
059:                        }
060:
061:                        barrier.barrier();
062:
063:                        if (id == 0) {
064:                            Customer cus1 = selectCustomerById(0);
065:                            cus = cus1;
066:                        }
067:                        barrier.barrier();
068:
069:                        if (id == 1) {
070:                            Account acc = cus.getAccount();
071:                            Assert.assertEquals("ASI-001", acc.getNumber());
072:                        }
073:
074:                        barrier.barrier();
075:
076:                    } finally {
077:                        if (id == 0) {
078:                            shutdownDatabase();
079:                        }
080:                    }
081:
082:                } catch (Throwable e) {
083:                    notifyError(e);
084:                }
085:
086:            }
087:
088:            private void setupDatabaseResource() throws Exception {
089:                sqlMapper = connectDatabase();
090:
091:                Connection conn = sqlMapper.getDataSource().getConnection();
092:                PreparedStatement stmt = conn
093:                        .prepareStatement("create table ACCOUNT (acc_id int not null, acc_number varchar(80) null, constraint pk_acc_id primary key (acc_id))");
094:                stmt.execute();
095:
096:                stmt = conn
097:                        .prepareStatement("create table CUSTOMER (cus_id int not null, cus_first_name varchar(80) null, cus_last_name varchar(80) null, cus_email varchar(80) null, cus_account_id varchar(80) null, constraint pk_cus_id primary key (cus_id))");
098:                stmt.execute();
099:            }
100:
101:            private SqlMapClient connectDatabase() throws Exception {
102:                dbServer = new HSqlDBServer();
103:                dbServer.start();
104:
105:                Reader reader = Resources
106:                        .getResourceAsReader("com/tctest/SqlMapConfig.xml");
107:                SqlMapClient sqlMapper = SqlMapClientBuilder
108:                        .buildSqlMapClient(reader);
109:                reader.close();
110:
111:                return sqlMapper;
112:            }
113:
114:            private void shutdownDatabase() throws Exception {
115:                dbServer.stop();
116:            }
117:
118:            public Customer selectCustomerById(int id) throws SQLException {
119:                return (Customer) sqlMapper.queryForObject(
120:                        "selectCustomerById", new Integer(id));
121:            }
122:
123:            public void insertAccount(Account acc) throws SQLException {
124:                sqlMapper.insert("insertAccount", acc);
125:            }
126:
127:            public void insertCustomer(Customer customer) throws SQLException {
128:                sqlMapper.insert("insertCustomer", customer);
129:            }
130:
131:            public static void visitL1DSOConfig(ConfigVisitor visitor,
132:                    DSOClientConfigHelper config) {
133:                String testClass = IBatisSimpleTestApp.class.getName();
134:
135:                config.getOrCreateSpec(testClass).addRoot("barrier", "barrier")
136:                        .addRoot("cus", "cus");
137:
138:                config.addWriteAutolock("* " + testClass + "*.*(..)");
139:                config.addIncludePattern("com.tctest.domain.Account");
140:                config.addIncludePattern("com.tctest.domain.Customer");
141:                new CyclicBarrierSpec().visit(visitor, config);
142:
143:                config.addModule(TIMUtil.IBATIS_2_2_0, TIMUtil
144:                        .getVersion(TIMUtil.IBATIS_2_2_0));
145:
146:                // transient stuff
147:                config.addModule(TIMUtil.CGLIB_2_1_3, TIMUtil
148:                        .getVersion(TIMUtil.CGLIB_2_1_3));
149:            }
150:
151:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.