KickJava   Java API By Example, From Geeks To Geeks.

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


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

32 class TestBindingTemplateTable
33 {
34   public static void main(String JavaDoc[] args)
35     throws Exception JavaDoc
36   {
37     // make sure we're using a DBCP DataSource and
38
// not trying to use JNDI to aquire one.
39
Config.setStringProperty("juddi.useConnectionPool","true");
40
41     Connection JavaDoc conn = null;
42     try {
43       conn = Database.aquireConnection();
44       test(conn);
45     }
46     finally {
47       if (conn != null)
48         conn.close();
49     }
50   }
51
52   public static void test(Connection JavaDoc connection)
53     throws Exception JavaDoc
54   {
55     Transaction txn = new Transaction();
56     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
57
58     if (connection != null)
59     {
60       try
61       {
62         String JavaDoc businessKey = uuidgen.uuidgen();
63         BusinessEntity business = new BusinessEntity();
64         business.setBusinessKey(businessKey);
65         business.setAuthorizedName("sviens");
66         business.setOperator("WebServiceRegistry.com");
67
68         String JavaDoc serviceKey = uuidgen.uuidgen();
69         BusinessService service = new BusinessService();
70         service.setBusinessKey(businessKey);
71         service.setServiceKey(serviceKey);
72
73         String JavaDoc bindingKey = uuidgen.uuidgen();
74         BindingTemplate binding = new BindingTemplate();
75         binding.setServiceKey(serviceKey);
76         binding.setBindingKey(bindingKey);
77         binding.setAccessPoint(new AccessPoint("http","http://juddi.org/bindingtemplate.html"));
78
79         String JavaDoc authorizedUserID = "sviens";
80
81         // begin a new transaction
82
txn.begin(connection);
83
84         // insert a new BusinessEntity
85
BusinessEntityTable.insert(business,authorizedUserID,connection);
86
87         // insert a new BusinessService
88
BusinessServiceTable.insert(service,connection);
89
90         // insert a new BindingTemplate
91
BindingTemplateTable.insert(binding,connection);
92
93         // insert another BindingTemplate
94
binding.setBindingKey(uuidgen.uuidgen());
95         BindingTemplateTable.insert(binding,connection);
96
97         // insert one more BindingTemplate
98
binding.setBindingKey(uuidgen.uuidgen());
99         BindingTemplateTable.insert(binding,connection);
100
101         // select a particular BindingTemplate
102
binding = BindingTemplateTable.select(bindingKey,connection);
103
104         // delete that BindingTemplate
105
BindingTemplateTable.delete(bindingKey,connection);
106
107         // re-select that BindingTemplate
108
binding = BindingTemplateTable.select(bindingKey,connection);
109
110         // select a Collection of BindingTemplate objects (by ServiceKey)
111
BindingTemplateTable.selectByServiceKey(serviceKey,connection);
112
113         // delete a Collection of BindingTemplate objects (by ServiceKey)
114
BindingTemplateTable.deleteByServiceKey(serviceKey,connection);
115
116         // re-select a Collection of BindingTemplate objects (by ServiceKey)
117
BindingTemplateTable.selectByServiceKey(serviceKey,connection);
118
119         // commit the transaction
120
txn.commit();
121       }
122       catch(Exception JavaDoc ex)
123       {
124         try { txn.rollback(); }
125         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
126         throw ex;
127       }
128     }
129   }
130 }
Popular Tags