KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > mssql > MSSQLVersionedDatabaseSchema


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: MSSQLVersionedDatabaseSchema.java,v 1.8 2007/01/07 06:14:54 bastafidli Exp $
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */

21
22 package org.opensubsystems.core.persist.db.mssql;
23
24 import java.sql.Connection JavaDoc;
25 import java.sql.SQLException JavaDoc;
26 import java.sql.Statement JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.util.logging.Logger JavaDoc;
29
30 import org.opensubsystems.core.error.OSSException;
31 import org.opensubsystems.core.persist.db.VersionedDatabaseSchema;
32 import org.opensubsystems.core.util.DatabaseUtils;
33 import org.opensubsystems.core.util.Log;
34
35 /**
36  * MS SQL Server versioned database schema provide functionality of creating
37  * and upgrading of MS SQL Server database schemas in the database based on
38  * their versions.
39  * This class keeps track of existing and current versiones of MS SQL Server
40  * database schemas and upgrades them as necesary
41  *
42  * @version $Id: MSSQLVersionedDatabaseSchema.java,v 1.8 2007/01/07 06:14:54 bastafidli Exp $
43  * @author Julo Legeny
44  * @code.reviewer Miro Halas
45  * @code.reviewed 1.6 2005/10/10 09:00:32 bastafidli
46  */

47 public class MSSQLVersionedDatabaseSchema extends VersionedDatabaseSchema
48 {
49
50    // Cached values ////////////////////////////////////////////////////////////
51

52    /**
53     * Logger for this class
54     */

55    private static Logger JavaDoc s_logger = Log.getInstance(MSSQLVersionedDatabaseSchema.class);
56
57    // Constructors /////////////////////////////////////////////////////////////
58

59    /**
60     * @throws OSSException - database cannot be started.
61     */

62    public MSSQLVersionedDatabaseSchema(
63    ) throws OSSException
64    {
65       super();
66    }
67    
68    // Public methods ///////////////////////////////////////////////////////////
69

70    /**
71     * {@inheritDoc}
72     */

73    public void create(
74       Connection JavaDoc cntDBConnection,
75       String JavaDoc strUserName
76    ) throws SQLException JavaDoc
77    {
78       s_logger.entering(this.getClass().getName(), "create");
79
80       try
81       {
82          Statement JavaDoc stmQuery = null;
83          try
84          {
85
86             stmQuery = cntDBConnection.createStatement();
87             if (stmQuery.execute(
88                   "create table " + SCHEMA_TABLE_NAME + NL
89                      + "(" + NL
90                      + " SCHEMA_NAME VARCHAR(50) NOT NULL," + NL
91                      + " SCHEMA_VERSION INTEGER NOT NULL," + NL
92                      + " CREATION_TIMESTAMP DATETIME NOT NULL," + NL
93                      + " MODIFICATION_TIMESTAMP DATETIME NOT NULL," + NL
94                      + " CONSTRAINT " + getSchemaPrefix() + "SCH_PK PRIMARY KEY" +
95                            " (SCHEMA_NAME)" + NL
96                      + ")"))
97             {
98                // Close any results
99
stmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS);
100             }
101             s_logger.log(Level.FINEST, "Table " + SCHEMA_TABLE_NAME + " created.");
102             /*
103             if (stmQuery.execute("grant all on " + TABLE_NAME + " to " + strUserName))
104             {
105                // Close any results
106                stmQuery.getMoreResults(Statement.CLOSE_ALL_RESULTS);
107             }
108             Log.getLogger().log(Level.FINEST, "Access for table " + TABLE_NAME + " set.");
109             */

110          }
111          catch (SQLException JavaDoc sqleExc)
112          {
113             // Catch this just so we can log the message
114
s_logger.log(Level.WARNING, "Failed to create version schema.",
115                                 sqleExc);
116             throw sqleExc;
117          }
118          finally
119          {
120             DatabaseUtils.closeStatement(stmQuery);
121          }
122       }
123       finally
124       {
125          s_logger.exiting(this.getClass().getName(), "create");
126       }
127    }
128 }
129
Popular Tags