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: Tosqldate.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.Date;
031: import java.sql.PreparedStatement;
032: import java.sql.Statement;
033:
034: import javax.naming.NamingException;
035:
036: import org.objectweb.util.monolog.api.BasicLevel;
037:
038: /**
039: * Class to create tables for the 'osqldate' bean of 'etype'.
040: * @author Helene Joanin
041: */
042: public class Tosqldate extends Tmanager {
043:
044: /**
045: * Entry point
046: */
047: public static void init() throws NamingException, RemoteException {
048: mgrInit();
049: createTable("JT_EtypeOsqldateEC");
050: }
051:
052: /**
053: * create a table for the osqldate bean of etype
054: */
055: private static void createTable(String name) throws RemoteException {
056:
057: // get connection
058: Connection conn = null;
059: try {
060: conn = dataSource.getConnection();
061: } catch (Exception e) {
062: throw new RemoteException("Cannot get Connection");
063: }
064:
065: Statement stmt;
066: PreparedStatement pStmt;
067: try {
068: stmt = conn.createStatement();
069: stmt.execute("DROP TABLE " + name);
070: stmt.close();
071: logger.log(BasicLevel.INFO, "Table " + name + " dropped");
072: } catch (Exception e) {
073: logger.log(BasicLevel.DEBUG, "Exception in dropTable : \n"
074: + e);
075: }
076: try {
077: String cTypeName = "date"; // standard jdbc type name
078: stmt = conn.createStatement();
079: stmt.execute("create table " + name
080: + "( c_pk varchar(30) not null primary key, c_f1 "
081: + cTypeName + ")");
082: stmt.close();
083: pStmt = conn.prepareStatement("insert into " + name
084: + " values('pk1', ?)");
085: pStmt.setDate(1, Date.valueOf("1970-01-01"));
086: pStmt.executeUpdate();
087: pStmt.close();
088: pStmt = conn.prepareStatement("insert into " + name
089: + " values('pk2', ?)");
090: pStmt.setDate(1, Date.valueOf("1970-01-02"));
091: pStmt.executeUpdate();
092: pStmt.close();
093: pStmt = conn.prepareStatement("insert into " + name
094: + " values('pk3', ?)");
095: pStmt.setDate(1, Date.valueOf("1970-01-03"));
096: pStmt.executeUpdate();
097: pStmt.close();
098: pStmt = conn.prepareStatement("insert into " + name
099: + " values('pk4', ?)");
100: pStmt.setDate(1, Date.valueOf("1970-01-04"));
101: pStmt.executeUpdate();
102: pStmt.close();
103: pStmt = conn.prepareStatement("insert into " + name
104: + " values('pk5', ?)");
105: pStmt.setDate(1, Date.valueOf("1970-01-05"));
106: pStmt.executeUpdate();
107: pStmt.close();
108: pStmt = conn.prepareStatement("insert into " + name
109: + " values('pk5bis', ?)");
110: pStmt.setDate(1, Date.valueOf("1970-01-05"));
111: pStmt.executeUpdate();
112: pStmt.close();
113: pStmt = conn.prepareStatement("insert into " + name
114: + " values('pktoremove', ?)");
115: pStmt.setDate(1, Date.valueOf("1970-01-12"));
116: pStmt.executeUpdate();
117: pStmt.close();
118: pStmt = conn.prepareStatement("insert into " + name
119: + " values('pknull', NULL)");
120: pStmt.executeUpdate();
121: pStmt.close();
122: pStmt = conn.prepareStatement("insert into " + name
123: + " values('pkchangenull', ?)");
124: pStmt.setDate(1, Date.valueOf("1970-01-12"));
125: pStmt.executeUpdate();
126: pStmt.close();
127: conn.close(); // release connection
128: } catch (Exception e) {
129: logger.log(BasicLevel.ERROR, "Exception in createTable : "
130: + e);
131: throw new RemoteException("Exception in createTable : " + e);
132: }
133: logger.log(BasicLevel.INFO, "Table " + name + " created");
134: }
135:
136: }
|