KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > functionTests > tests > jdbcapi > xaJNDI


1 /*
2
3    Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.xaJNDI
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
23
24 import org.apache.derby.jdbc.EmbeddedDataSource;
25 import org.apache.derby.jdbc.EmbeddedXADataSource;
26
27 import java.util.Hashtable JavaDoc;
28
29 import javax.naming.*;
30 import javax.naming.directory.*;
31
32 //The test compares the xa data source which is bound to jndi
33
//with the xa data source which is returned from the jndi lookup.
34
public class xaJNDI
35 {
36     public static void main(String JavaDoc[] args)
37     {
38         try
39         {
40             Hashtable JavaDoc env = new Hashtable JavaDoc();
41             env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
42             // using a fictional name - host and port & url will have to be
43
// modified to use a real ldap server machine & port & url
44
env.put(Context.PROVIDER_URL, "ldap://thehost.opensource.apache.com:389");
45             env.put(Context.SECURITY_AUTHENTICATION, "simple");
46             InitialDirContext ic = new InitialDirContext(env);
47
48             EmbeddedXADataSource rxads = new EmbeddedXADataSource();
49             rxads.setDatabaseName("rxads");
50             rxads.setCreateDatabase("create");
51             rxads.setDescription("XA DataSource");
52             ic.rebind("cn=compareDS, o=opensource.apache.com",rxads);
53       javax.sql.XADataSource JavaDoc ads =
54       (javax.sql.XADataSource JavaDoc)ic.lookup("cn=compareDS, o=opensource.apache.com");
55       if (rxads.equals(ads))
56         System.out.println("SUCCESS:The 2 data sources are same");
57       else
58           System.out.println("FAILURE:The 2 data sources should be same");
59
60         rxads.setCreateDatabase("");
61       if (rxads.equals(ads))
62         System.out.println("FAILURE:The 2 data sources should be different");
63       else
64           System.out.println("SUCCESS:The 2 data sources are different");
65
66         } catch (Exception JavaDoc e) {
67             e.printStackTrace();
68             System.out.println("caught " + e);
69         }
70     }
71
72 }
73
Popular Tags