Now using connections managed by JPA instead of using JNDI mocking.
[utils] / test / toplink-essentials / src / main / java / org / wamblee / support / persistence / toplink / JndiSessionCustomizer.java
index 11bcd071c2e3e450e071357ae612e148272aa65b..71d95d6f13c66e428e2e4e76e49036c4ea76f71d 100644 (file)
@@ -1,6 +1,17 @@
 /*
- * SCJD assignment, URLyBird, Erik Brakkee.
- * Candidate ID: sr1399267.
+ * Copyright 2005-2010 the original author or authors.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 package org.wamblee.support.persistence.toplink;
 
@@ -34,40 +45,36 @@ public class JndiSessionCustomizer implements SessionCustomizer {
      * 
      * 
      */
-    public void customize(Session session) throws Exception {
+    public void customize(Session aSession) throws Exception {
         JNDIConnector connector = null;
         Context context = null;
 
         try {
             context = new InitialContext();
 
-            if (null != context) {
-                connector = (JNDIConnector) session.getLogin().getConnector(); // possible
-                                                                               // CCE
-                // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
-                // Note: if both jta and non-jta elements exist this will only
-                // change the first one - and may still result in
-                // the COMPOSITE_NAME_LOOKUP being set
-                // Make sure only jta-data-source is in persistence.xml with no
-                // non-jta-data-source property set
+            connector = (JNDIConnector) aSession.getLogin().getConnector(); // possible
+            // CCE
+            // Change from COMPOSITE_NAME_LOOKUP to STRING_LOOKUP
+            // Note: if both jta and non-jta elements exist this will only
+            // change the first one - and may still result in
+            // the COMPOSITE_NAME_LOOKUP being set
+            // Make sure only jta-data-source is in persistence.xml with no
+            // non-jta-data-source property set
 
-                connector.setLookupType(JNDIConnector.STRING_LOOKUP);
+            connector.setLookupType(JNDIConnector.STRING_LOOKUP);
 
-                // Or, if you are specifying both JTA and non-JTA in your
-                // persistence.xml then set both connectors to be safe
-                JNDIConnector writeConnector = (JNDIConnector) session
-                    .getLogin().getConnector();
-                writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+            // Or, if you are specifying both JTA and non-JTA in your
+            // persistence.xml then set both connectors to be safe
+            JNDIConnector writeConnector = (JNDIConnector) aSession.getLogin()
+                .getConnector();
+            writeConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
 
-                JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) session)
-                    .getReadConnectionPool().getLogin()).getConnector();
-                readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
+            JNDIConnector readConnector = (JNDIConnector) ((DatabaseLogin) ((ServerSession) aSession)
+                .getReadConnectionPool().getLogin()).getConnector();
+            readConnector.setLookupType(JNDIConnector.STRING_LOOKUP);
 
-                System.out.println("JndiSessionCustomizer: configured " +
-                    connector.getName());
-            } else {
-                throw new Exception("JndiSessionCustomizer: Context is null");
-            }
+            System.out.println("JndiSessionCustomizer: configured " +
+                connector.getName());
         } catch (Exception e) {
             e.printStackTrace();
         }