KickJava   Java API By Example, From Geeks To Geeks.

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


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.publisher.Publisher;
21 import org.apache.juddi.util.Config;
22 import org.apache.juddi.util.jdbc.Transaction;
23 import org.apache.juddi.uuidgen.UUIDGen;
24 import org.apache.juddi.uuidgen.UUIDGenFactory;
25
26 /**
27  * @author Steve Viens (sviens@apache.org)
28  */

29 class TestAuthTokenTable
30 {
31   public static void main(String JavaDoc[] args)
32     throws Exception JavaDoc
33   {
34     // make sure we're using a DBCP DataSource and
35
// not trying to use JNDI to aquire one.
36
Config.setStringProperty("juddi.useConnectionPool","true");
37
38     Connection JavaDoc conn = null;
39     try {
40       conn = Database.aquireConnection();
41       test(conn);
42     }
43     finally {
44       if (conn != null)
45         conn.close();
46     }
47   }
48
49   public static void test(Connection JavaDoc connection)
50     throws Exception JavaDoc
51   {
52     Transaction txn = new Transaction();
53     UUIDGen uuidgen = UUIDGenFactory.getUUIDGen();
54
55     if (connection != null)
56     {
57       try
58       {
59         // begin a new transaction
60
txn.begin(connection);
61
62         String JavaDoc authToken1 = "juddi:"+uuidgen.uuidgen();
63         AuthTokenTable.insert(authToken1,new Publisher("sviens","Steve Viens"),connection);
64         AuthTokenTable.selectLastUsed(authToken1,connection);
65
66         String JavaDoc authToken2 = "juddi:"+uuidgen.uuidgen();
67         AuthTokenTable.insert(authToken2,new Publisher("sviens","Steve Viens"),connection);
68         AuthTokenTable.selectLastUsed(authToken2,connection);
69
70         System.out.println("PublisherID: "+AuthTokenTable.selectPublisher(authToken1,connection));
71
72         AuthTokenTable.delete(authToken1,connection);
73
74         Thread.sleep(3000);
75
76         AuthTokenTable.touch(authToken2,connection);
77         AuthTokenTable.touch(authToken2,connection);
78         AuthTokenTable.touch(authToken2,connection);
79         AuthTokenTable.selectLastUsed(authToken2,connection);
80         AuthTokenTable.touch(authToken2,connection);
81         AuthTokenTable.touch(authToken2,connection);
82         AuthTokenTable.touch(authToken2,connection);
83         AuthTokenTable.selectLastUsed(authToken2,connection);
84         AuthTokenTable.touch(authToken2,connection);
85         AuthTokenTable.touch(authToken2,connection);
86         AuthTokenTable.touch(authToken2,connection);
87         AuthTokenTable.selectLastUsed(authToken2,connection);
88         AuthTokenTable.touch(authToken2,connection);
89         AuthTokenTable.invalidate(authToken2,connection);
90         AuthTokenTable.selectLastUsed(authToken2,connection);
91
92         System.out.println("PublisherID: "+AuthTokenTable.selectPublisher(authToken1,connection));
93         System.out.println("PublisherID: "+AuthTokenTable.selectPublisher(authToken2,connection));
94
95         // commit the transaction
96
txn.commit();
97       }
98       catch(Exception JavaDoc ex)
99       {
100         try { txn.rollback(); }
101         catch(java.sql.SQLException JavaDoc sqlex) { sqlex.printStackTrace(); }
102         throw ex;
103       }
104     }
105   }
106 }
107
Popular Tags