KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > sybase > SybaseVersionedDatabaseSchema


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: SybaseVersionedDatabaseSchema.java,v 1.6 2007/01/07 06:14:45 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.sybase;
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.DatabaseImpl;
32 import org.opensubsystems.core.persist.db.VersionedDatabaseSchema;
33 import org.opensubsystems.core.util.DatabaseUtils;
34 import org.opensubsystems.core.util.Log;
35
36 /**
37  * MS SQL Server versioned database schema provide functionality of creating
38  * and upgrading of Sybase database schemas in the database based on
39  * their versions.
40  * This class keeps track of existing and current versiones of Sybase
41  * database schemas and upgrades them as necesary
42  *
43  * @version $Id: SybaseVersionedDatabaseSchema.java,v 1.6 2007/01/07 06:14:45 bastafidli Exp $
44  * @author Julo Legeny
45  * @code.reviewer Miro Halas
46  * @code.reviewed 1.4 2005/10/10 09:00:30 bastafidli
47  */

48 public class SybaseVersionedDatabaseSchema extends VersionedDatabaseSchema
49 {
50
51    // Cached values ////////////////////////////////////////////////////////////
52

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

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

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

63    public SybaseVersionedDatabaseSchema(
64    ) throws OSSException
65    {
66       super();
67    }
68
69
70    /**
71     * Create the schema.
72     *
73     * @param cntDBConnection - valid connection to database
74     * @param strUserName - name of user who will be accessing this table
75     * @throws SQLException - problem creating the schema
76     */

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

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