|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjp.sf.amateras.mirage.updater.SchemaUpdater
public class SchemaUpdater
Execute SQL files which located a specific package to update database schema. You can use this to update database schema automatically with application updating.
By the default, you have to locate SQLs within META-INF as follows:
/META-INF mysql_1.sql mysql_2.sql mysql_3.sql ...
You can change a package where locate SQL files by setPackageName(String).
SQLs will be executed in the order of version number which contained in the filename. The version number (a part of filename) have to be a continued integer value. Filename can contain the database type such as "mysql" also. It is omittable. For examples, if the schema updater can not find a "mysql_1.sql", uses "1.sql" instead of it.
| Field Summary | |
|---|---|
protected String |
packageName
|
protected SqlManager |
sqlManager
|
protected String |
tableName
|
| Constructor Summary | |
|---|---|
SchemaUpdater()
|
|
| Method Summary | |
|---|---|
protected void |
createTable()
Creates table which manages schema version and insert an initial record as version 0. |
protected boolean |
existsTable()
Checks the table which manages a schema version exists or not exisis. |
protected int |
getCurrentVersion()
Returns the current version number. |
protected String |
getSql(int version)
Returns the SQL which located within a package specified by the packageName as "dialectname_version.sql" or "version.sql". |
void |
setPackageName(String packageName)
Sets the package name where locate SQL files. |
void |
setSqlManager(SqlManager sqlManager)
Sets the SqlManager to use for schema updating. |
void |
setTableName(String tableName)
Sets the table name which manages the schema version. |
void |
update()
Updates database schema to the latest state. |
protected void |
updateVersion(int version)
Updates the version number by the given value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected SqlManager sqlManager
protected String tableName
protected String packageName
| Constructor Detail |
|---|
public SchemaUpdater()
| Method Detail |
|---|
public void setSqlManager(SqlManager sqlManager)
sqlManager - the SqlManagerpublic void setTableName(String tableName)
tableName - the table namepublic void setPackageName(String packageName)
packageName - the package namepublic void update()
Note: Before calling this method, Connection might have to be auto-commit mode.
protected String getSql(int version)
version - the version number
protected boolean existsTable()
protected void createTable()
protected int getCurrentVersion()
protected void updateVersion(int version)
version - the version number
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||