001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: Tosqltime.java 6739 2005-05-11 15:29:07Z ashah $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.jtests.tables;
027:
028: import java.rmi.RemoteException;
029: import java.sql.Connection;
030: import java.sql.PreparedStatement;
031: import java.sql.Statement;
032: import java.sql.Time;
033:
034: import javax.naming.NamingException;
035:
036: import org.objectweb.jonas.jtests.util.Env;
037: import org.objectweb.util.monolog.api.BasicLevel;
038:
039: /**
040: * Class to create tables for the 'osqltime' bean of 'etype'.
041: * @author Helene Joanin
042: */
043: public class Tosqltime extends Tmanager {
044:
045: /**
046: * Entry point
047: */
048: public static void init() throws NamingException, RemoteException {
049: mgrInit();
050: createTable("JT_EtypeOsqltimeEC");
051: }
052:
053: /**
054: * create a table for the osqltime bean of etype
055: */
056: private static void createTable(String name) throws RemoteException {
057:
058: // get connection
059: Connection conn = null;
060: try {
061: conn = dataSource.getConnection();
062: } catch (Exception e) {
063: throw new RemoteException("Cannot get Connection");
064: }
065:
066: Statement stmt;
067: PreparedStatement pStmt;
068: try {
069: stmt = conn.createStatement();
070: stmt.execute("DROP TABLE " + name);
071: stmt.close();
072: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
073: } catch (Exception e) {
074: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
075: + e);
076: }
077: try {
078: int dbType = Env.getDatabaseType(conn);
079: String cTypeName;
080: switch (dbType) {
081: case Env.DB_ORACLE:
082: cTypeName = "date";
083: break;
084: default:
085: cTypeName = "time"; // standard jdbc type name
086: }
087: stmt = conn.createStatement();
088: stmt.execute("create table " + name
089: + "( c_pk varchar(30) not null primary key, c_f1 "
090: + cTypeName + ")");
091: stmt.close();
092: pStmt = conn.prepareStatement("insert into " + name
093: + " values('pk1', ?)");
094: pStmt.setTime(1, Time.valueOf("01:00:00"));
095: pStmt.executeUpdate();
096: pStmt.close();
097: pStmt = conn.prepareStatement("insert into " + name
098: + " values('pk2', ?)");
099: pStmt.setTime(1, Time.valueOf("02:00:00"));
100: pStmt.executeUpdate();
101: pStmt.close();
102: pStmt = conn.prepareStatement("insert into " + name
103: + " values('pk3', ?)");
104: pStmt.setTime(1, Time.valueOf("03:00:00"));
105: pStmt.executeUpdate();
106: pStmt.close();
107: pStmt = conn.prepareStatement("insert into " + name
108: + " values('pk4', ?)");
109: pStmt.setTime(1, Time.valueOf("04:00:00"));
110: pStmt.executeUpdate();
111: pStmt.close();
112: pStmt = conn.prepareStatement("insert into " + name
113: + " values('pk5', ?)");
114: pStmt.setTime(1, Time.valueOf("05:00:00"));
115: pStmt.executeUpdate();
116: pStmt.close();
117: pStmt = conn.prepareStatement("insert into " + name
118: + " values('pk5bis', ?)");
119: pStmt.setTime(1, Time.valueOf("05:00:00"));
120: pStmt.executeUpdate();
121: pStmt.close();
122: pStmt = conn.prepareStatement("insert into " + name
123: + " values('pktoremove', ?)");
124: pStmt.setTime(1, Time.valueOf("12:00:00"));
125: pStmt.executeUpdate();
126: pStmt.close();
127: pStmt = conn.prepareStatement("insert into " + name
128: + " values('pknull', NULL)");
129: pStmt.executeUpdate();
130: pStmt.close();
131: pStmt = conn.prepareStatement("insert into " + name
132: + " values('pkchangenull', ?)");
133: pStmt.setTime(1, Time.valueOf("12:00:00"));
134: pStmt.executeUpdate();
135: pStmt.close();
136: conn.close(); // release connection
137: } catch (Exception e) {
138: logger.log(BasicLevel.ERROR, "Exception in createTable : "
139: + e);
140: throw new RemoteException("Exception in createTable : " + e);
141: }
142: logger.log(BasicLevel.INFO, "Table " + name + " created");
143: }
144:
145: }
|