01: /*
02:
03: Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.xaJNDI
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to You under the Apache License, Version 2.0
09: (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;
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: public static void main(String[] args) {
36: try {
37: Hashtable env = new Hashtable();
38: env.put(Context.INITIAL_CONTEXT_FACTORY,
39: "com.sun.jndi.ldap.LdapCtxFactory");
40: // using a fictional name - host and port & url will have to be
41: // modified to use a real ldap server machine & port & url
42: env.put(Context.PROVIDER_URL,
43: "ldap://thehost.opensource.apache.com:389");
44: env.put(Context.SECURITY_AUTHENTICATION, "simple");
45: InitialDirContext ic = new InitialDirContext(env);
46:
47: EmbeddedXADataSource rxads = new EmbeddedXADataSource();
48: rxads.setDatabaseName("rxads");
49: rxads.setCreateDatabase("create");
50: rxads.setDescription("XA DataSource");
51: ic.rebind("cn=compareDS, o=opensource.apache.com", rxads);
52: javax.sql.XADataSource ads = (javax.sql.XADataSource) ic
53: .lookup("cn=compareDS, o=opensource.apache.com");
54: if (rxads.equals(ads))
55: System.out
56: .println("SUCCESS:The 2 data sources are same");
57: else
58: System.out
59: .println("FAILURE:The 2 data sources should be same");
60:
61: rxads.setCreateDatabase("");
62: if (rxads.equals(ads))
63: System.out
64: .println("FAILURE:The 2 data sources should be different");
65: else
66: System.out
67: .println("SUCCESS:The 2 data sources are different");
68:
69: } catch (Exception e) {
70: e.printStackTrace();
71: System.out.println("caught " + e);
72: }
73: }
74:
75: }
|