KickJava   Java API By Example, From Geeks To Geeks.

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


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.Description;
22 import org.apache.juddi.datatype.OverviewDoc;
23 import org.apache.juddi.datatype.binding.AccessPoint;
24 import org.apache.juddi.datatype.binding.BindingTemplate;
25 import org.apache.juddi.datatype.binding.TModelInstanceInfo;
26 import org.apache.juddi.datatype.business.BusinessEntity;
27 import org.apache.juddi.datatype.service.BusinessService;
28 import org.apache.juddi.util.Config;
29 import org.apache.juddi.util.jdbc.Transaction;
30 import org.apache.juddi.uuidgen.UUIDGen;
31 import org.apache.juddi.uuidgen.UUIDGenFactory;
32
33 /**
34  * @author Steve Viens (sviens@apache.org)
35  */

36 class TestInstanceDetailsDocDescTable
37 {
38   public static void main(String JavaDoc[] args)
39     throws Exception JavaDoc
40   {
41     // make sure we're using a DBCP DataSource and
42
// not trying to use JNDI to aquire one.
43
Config.setStringProperty("juddi.useConnectionPool","true");
44
45     Connection JavaDoc conn = null;
46     try {
47       conn = Database.aquireConnection();
48       test(conn);
49     }
50     finally {
51       if (conn != null)
52         conn.close();
53     }
54   }
55
56   public static void test(Connection JavaDoc connection) throws Exception JavaDoc
57   {
58     Transaction txn = new Transaction();
59     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
60
61     if (connection != null)
62     {
63       try
64       {
65         String JavaDoc businessKey = uuidgen.uuidgen();
66         BusinessEntity business = new BusinessEntity();
67         business.setBusinessKey(businessKey);
68         business.setAuthorizedName("sviens");
69         business.setOperator("WebServiceRegistry.com");
70
71         String JavaDoc serviceKey = uuidgen.uuidgen();
72         BusinessService service = new BusinessService();
73         service.setBusinessKey(businessKey);
74         service.setServiceKey(serviceKey);
75
76         String JavaDoc bindingKey = uuidgen.uuidgen();
77         BindingTemplate binding = new BindingTemplate();
78         binding.setServiceKey(serviceKey);
79         binding.setBindingKey(bindingKey);
80         binding.setAccessPoint(
81           new AccessPoint("http://www.juddi.org/bindingtemplate.html", "http"));
82
83         Vector JavaDoc infoList = new Vector JavaDoc();
84         infoList.add(new TModelInstanceInfo(uuidgen.uuidgen()));
85         int infoID = 0;
86
87         OverviewDoc overviewDoc = new OverviewDoc();
88         overviewDoc.setOverviewURL("http://www.juddi.org/overviewdoc.html");
89
90         Vector JavaDoc descList = new Vector JavaDoc();
91         descList.add(new Description("blah, blah, blah", "en"));
92         descList.add(new Description("Yadda, Yadda, Yadda", "it"));
93         descList.add(new Description("WhoobWhoobWhoobWhoob", "cy"));
94         descList.add(new Description("Haachachachacha", "km"));
95
96         String JavaDoc authorizedUserID = "sviens";
97
98         // begin a new transaction
99
txn.begin(connection);
100
101         // insert a new BusinessEntity
102
BusinessEntityTable.insert(business, authorizedUserID, connection);
103
104         // insert a new BusinessService
105
BusinessServiceTable.insert(service, connection);
106
107         // insert a new BindingTemplate
108
BindingTemplateTable.insert(binding, connection);
109
110         // insert a Collection of TModelInstanceInfo objects
111
TModelInstanceInfoTable.insert(bindingKey, infoList, connection);
112
113         // insert a Collection of Description objects
114
InstanceDetailsDocDescTable.insert(
115           bindingKey,
116           infoID,
117           descList,
118           connection);
119
120         // select the Collection of Description objects
121
descList =
122           InstanceDetailsDocDescTable.select(bindingKey, infoID, connection);
123
124         // delete the Collection of Description objects
125
InstanceDetailsDocDescTable.delete(bindingKey, connection);
126
127         // re-select the Collection of Description objects
128
descList =
129           InstanceDetailsDocDescTable.select(bindingKey, infoID, 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