Source Code Cross Referenced for PicoTest.java in  » Database-ORM » jaxor-3.5 » net » sourceforge » jaxor » example » pico » 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 » jaxor 3.5 » net.sourceforge.jaxor.example.pico 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.jaxor.example.pico;
002:
003:        import net.sourceforge.jaxor.JaxorContextImpl;
004:        import net.sourceforge.jaxor.MetaRow;
005:        import net.sourceforge.jaxor.impl.MapperRegistryImpl;
006:        import net.sourceforge.jaxor.api.*;
007:        import net.sourceforge.jaxor.db.SingleConnectionTransaction;
008:        import net.sourceforge.jaxor.example.domain.AddressEntity;
009:        import net.sourceforge.jaxor.example.domain.AddressFinderBase;
010:        import net.sourceforge.jaxor.example.domain.AddressMetaRow;
011:        import net.sourceforge.jaxor.example.domain.Logger;
012:        import net.sourceforge.jaxor.example.tests.TableTestCase;
013:        import net.sourceforge.jaxor.impl.InstanceCacheImpl;
014:        import net.sourceforge.jaxor.impl.UnitOfWorkImpl;
015:        import net.sourceforge.jaxor.util.MethodCache;
016:        import org.picocontainer.MutablePicoContainer;
017:        import org.picocontainer.PicoContainer;
018:        import org.picocontainer.defaults.DefaultPicoContainer;
019:
020:        import java.sql.Connection;
021:
022:        /**
023:         * Created By:   Mike
024:         * Date:         Jan 15, 2004
025:         * Time:         7:19:49 PM
026:         *
027:         * Last Checkin: $Author: mrettig $
028:         * Date:         $Date: 2004/02/03 01:50:15 $
029:         * Revision:     $Revision: 1.12 $
030:         */
031:        public class PicoTest extends TableTestCase {
032:
033:            protected MetaRow getRow() {
034:                return new AddressMetaRow();
035:            }
036:
037:            public void testConfiguration() {
038:                MutablePicoContainer container = configureContainer();
039:                PicoContainer pico = container;
040:
041:                PicoInstanceFactory fact = (PicoInstanceFactory) pico
042:                        .getComponentInstance(PicoInstanceFactory.class);
043:                assertTrue(fact.getContainer() == pico);
044:                JaxorContext jaxorContext = (JaxorContext) pico
045:                        .getComponentInstance(JaxorContext.class);
046:
047:                AddressFinderBase finder = (AddressFinderBase) jaxorContext
048:                        .getFinder(AddressFinderBase.class);
049:                assertTrue(finder == (AddressFinderBase) jaxorContext
050:                        .getFinder(AddressFinderBase.class));
051:                AddressEntity address = finder.newInstance(new Long(123));
052:                assertNotNull(
053:                        "Logger should be passed to the entity through the instance factory",
054:                        address.getLog());
055:                assertTrue(pico.getComponentInstance(Logger.class) == address
056:                        .getLog());
057:                address.setCity("Chicago");
058:                address.setStreet("899 Madison");
059:                address.setZipCode("60661");
060:                address.setState("IL");
061:
062:                //this will stop the container, committing the object to the db and closes the connection.
063:                container.stop();
064:
065:                //We'll simulate another session by creating a new container.
066:                MutablePicoContainer otherContainer2 = configureContainer();
067:                PicoContainer picoContainer2 = otherContainer2;
068:                JaxorContext jaxorContext2 = (JaxorContext) picoContainer2
069:                        .getComponentInstance(JaxorContext.class);
070:                AddressFinderBase finder2 = (AddressFinderBase) jaxorContext2
071:                        .getFinder(AddressFinderBase.class);
072:                AddressEntity addressEntity = finder2
073:                        .selectByAddressId(new Long(123));
074:                assertEquals(new Long(123), addressEntity.getAddressId());
075:                assertEquals("mrettig", address.getInsertUser());
076:
077:                otherContainer2.stop();
078:            }
079:
080:            private MutablePicoContainer configureContainer() {
081:                MutablePicoContainer pico = new DefaultPicoContainer();
082:
083:                pico.registerComponentImplementation(JaxorContainer.class);
084:                pico.registerComponentImplementation(JaxorContext.class,
085:                        JaxorContextImpl.class);
086:                pico.registerComponentImplementation(UnitOfWork.class,
087:                        UnitOfWorkImpl.class);
088:                pico.registerComponentImplementation(InstanceCache.class,
089:                        InstanceCacheImpl.class);
090:                pico.registerComponentImplementation(QueryCache.class,
091:                        MethodCache.class);
092:                pico.registerComponentImplementation(JaxorTransaction.class,
093:                        SingleConnectionTransaction.class);
094:                pico.registerComponentImplementation(MapperRegistry.class,
095:                        MapperRegistryImpl.class);
096:
097:                //the instance factory uses pico to configure and create new entities and finders.
098:                pico.registerComponentImplementation(PicoInstanceFactory.class);
099:
100:                pico.registerComponentImplementation(Logger.class);
101:
102:                //The testcase sets up the connection, so we'll reuse it here.
103:                //The prep for the testcase creates the table using this connection.
104:                Connection conn = getConnection();
105:                pico.registerComponentInstance(conn);
106:                //pico.registerComponentInstance(pico);
107:                JaxorContext context = (JaxorContext) pico
108:                        .getComponentInstance(JaxorContext.class);
109:                //this is the context user. We use this for setting the auditing fields (insert/update user) in the db.
110:                //pico has support for setting bean properties, but we'll just set the property here for simplicity.
111:                context.setUser("mrettig");
112:                pico.start();
113:                return pico;
114:            }
115:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.