KickJava   Java API By Example, From Geeks To Geeks.

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


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

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