KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > datastore > jdbc > TestBindingCategoryTable


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.datastore.jdbc;
17
18 import java.sql.Connection JavaDoc;
19 import java.util.Vector JavaDoc;
20
21 import org.apache.juddi.datatype.KeyedReference;
22 import org.apache.juddi.datatype.binding.AccessPoint;
23 import org.apache.juddi.datatype.binding.BindingTemplate;
24 import org.apache.juddi.datatype.business.BusinessEntity;
25 import org.apache.juddi.datatype.service.BusinessService;
26 import org.apache.juddi.util.Config;
27 import org.apache.juddi.util.jdbc.Transaction;
28 import org.apache.juddi.uuidgen.UUIDGen;
29 import org.apache.juddi.uuidgen.UUIDGenFactory;
30
31 /**
32  * @author Steve Viens (sviens@apache.org)
33  */

34 class TestBindingCategoryTable
35 {
36   public static void main(String JavaDoc[] args)
37     throws Exception JavaDoc
38   {
39     // make sure we're using a DBCP DataSource and
40
// not trying to use JNDI to aquire one.
41
Config.setStringProperty("juddi.useConnectionPool","true");
42
43     Connection JavaDoc conn = null;
44     try {
45       conn = Database.aquireConnection();
46       test(conn);
47     }
48     finally {
49       if (conn != null)
50         conn.close();
51     }
52   }
53
54   public static void test(Connection JavaDoc connection) throws Exception JavaDoc
55   {
56     Transaction txn = new Transaction();
57     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
58
59     if (connection != null)
60     {
61       try
62       {
63         //BusinessKey businessKey = BusinessKey.createKey();
64
String JavaDoc businessKey = uuidgen.uuidgen();
65         BusinessEntity business = new BusinessEntity();
66         business.setBusinessKey(businessKey);
67         business.setAuthorizedName("sviens");
68         business.setOperator("WebServiceRegistry.com");
69
70         //ServiceKey serviceKey = ServiceKey.createKey();
71
String JavaDoc serviceKey = uuidgen.uuidgen();
72         BusinessService service = new BusinessService();
73         service.setServiceKey(serviceKey);
74         service.setBusinessKey(businessKey);
75
76         //BindingKey bindingKey = BindingKey.createKey();
77
String JavaDoc bindingKey = uuidgen.uuidgen();
78         BindingTemplate binding = new BindingTemplate();
79         binding.setAccessPoint(
80           new AccessPoint("http://www.juddi.org/binding.html", "http"));
81         binding.setHostingRedirector(null);
82         binding.setBindingKey(bindingKey);
83         binding.setServiceKey(serviceKey);
84
85         // Keyed References for the Binding Template CategoryBag.
86
Vector JavaDoc keyRefs = new Vector JavaDoc();
87         keyRefs.add(
88           new KeyedReference(
89             "uuid:" + uuidgen.uuidgen(),
90             "alpha",
91             "abcdefghi"));
92         keyRefs.add(
93           new KeyedReference("uuid:" + uuidgen.uuidgen(), "beta", "jklmnopqr"));
94         keyRefs.add(
95           new KeyedReference("uuid:" + uuidgen.uuidgen(), "omega", "stuvwxyz"));
96
97         String JavaDoc authorizedUserID = "sviens";
98
99         // begin a new transaction
100
txn.begin(connection);
101
102         // insert a new BusinessEntity
103
BusinessEntityTable.insert(business, authorizedUserID, connection);
104
105         // insert a new BusinessService
106
BusinessServiceTable.insert(service, connection);
107
108         // insert a new BindingTemplate
109
BindingTemplateTable.insert(binding, connection);
110
111         // insert a Collection of new Category KeyedReference objects
112
BindingCategoryTable.insert(bindingKey, keyRefs, connection);
113
114         // select the Collection of KeyedReference objects
115
keyRefs = BindingCategoryTable.select(bindingKey, connection);
116
117         for (int i = 0; i < keyRefs.size(); i++)
118         {
119           KeyedReference keyRef = (KeyedReference) keyRefs.elementAt(i);
120           System.out.println(" Key Name: " + keyRef.getKeyName());
121           System.out.println("Key Value: " + keyRef.getKeyValue());
122           System.out.println("TModelKey: " + keyRef.getTModelKey());
123         }
124
125         // delete the Collection of KeyedReference objects
126
BindingCategoryTable.delete(bindingKey, connection);
127
128         // select the Collection of KeyedReference objects
129
keyRefs = BindingCategoryTable.select(bindingKey, connection);
130
131         // commit the transaction
132
txn.commit();
133       }
134       catch (Exception JavaDoc ex)
135       {
136         try
137         {
138           txn.rollback();
139         }
140         catch (java.sql.SQLException JavaDoc sqlex)
141         {
142           sqlex.printStackTrace();
143         }
144         throw ex;
145       }
146     }
147   }
148 }
149
Popular Tags