KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > webdocwf > util > loader > test > CreateDatabaseOperation


1 /*
2
3      Loader - tool for transfering data from one JDBC source to another and
4      doing transformations during copy.
5
6     Copyright (C) 2002 Together
7
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Lesser General Public
10     License as published by the Free Software Foundation; either
11     version 2.1 of the License, or (at your option) any later version.
12
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16     Lesser General Public License for more details.
17
18     You should have received a copy of the GNU Lesser General Public
19     License along with this library; if not, write to the Free Software
20     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22 /*
23  * CreateDatabaseOperation.java Aug 30, 2002
24  * Author: Sinisa Milosevic sinisami@eunet.yu
25  *
26  */

27
28
29 package org.webdocwf.util.loader.test;
30
31 import java.sql.Connection JavaDoc;
32 import java.sql.Statement JavaDoc;
33 import org.webdocwf.util.loader.test.DatabaseOperation;
34 import org.webdocwf.util.loader.Loader;
35 import org.webdocwf.util.loader.LoaderException;
36
37 import java.sql.SQLException JavaDoc;
38
39 /**
40  * Creates new database using sql command (CREATE DATABASE) or specified loader job.
41  *
42  * @author Sinisa Milosevic
43  * @version $Revision: 1.1 $
44  */

45 public class CreateDatabaseOperation extends DatabaseOperation
46 {
47     
48     private String JavaDoc databaseName=null;
49     
50     CreateDatabaseOperation()
51     {
52     }
53
54
55     public CreateDatabaseOperation(String JavaDoc name)
56     {
57         databaseName=name;
58     }
59
60     ////////////////////////////////////////////////////////////////////////////
61
// DatabaseOperation class
62

63     /**
64      * Executes this operation on the specified database using the specified
65      * connection to the database.
66      *
67      * @param conn the database connection.
68      */

69
70     public void execute(Connection JavaDoc conn) throws SQLException JavaDoc
71     {
72         Statement JavaDoc stmt = conn.createStatement();
73         if(databaseName!=null){
74             try
75             {
76            stmt.execute("CREATE DATABASE "+databaseName);
77             }
78             finally
79             {
80             stmt.close();
81             }
82         }
83     }
84
85     
86     /**
87      * Returns type of database operation
88      *
89      */

90     public String JavaDoc getDatabaseOperationType()
91     {
92         return DatabaseOperation.CREATE;
93     }
94
95
96 }
97
98
99
100
101
102
103
104
Popular Tags