KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opensubsystems > core > persist > db > mysql > MySQLVersionedDatabaseSchema


1 /*
2  * Copyright (c) 2003 - 2007 OpenSubsystems s.r.o. Slovak Republic. All rights reserved.
3  *
4  * Project: OpenSubsystems
5  *
6  * $Id: MySQLVersionedDatabaseSchema.java,v 1.6 2007/01/07 06:14:27 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.mysql;
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  * MySQL versioned database schema provide functionality of creating
37  * and upgrading of MySQL database schemas in the database based on
38  * their versions.
39  * This class keeps track of existing and current versiones of MYSQL
40  * database schemas and upgrades them as necesary
41  *
42  * @version $Id: MySQLVersionedDatabaseSchema.java,v 1.6 2007/01/07 06:14:27 bastafidli Exp $
43  * @author Julo Legeny
44  * @code.reviewer Miro Halas
45  * @code.reviewed 1.4 2005/10/10 09:00:32 bastafidli
46  */

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

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

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

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

61    public MySQLVersionedDatabaseSchema(
62    ) throws OSSException
63    {
64       super();
65    }
66    
67    /**
68     * {@inheritDoc}
69     */

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

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