You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DbUpgrader.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright 2004-2011 H2 Group.
  3. * Copyright 2011 James Moger.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package com.iciql;
  18. import com.iciql.Iciql.IQDatabase;
  19. /**
  20. * Interface which defines a class to handle table changes based on model
  21. * versions. An implementation of <i>DbUpgrader</i> must be annotated with the
  22. * <i>IQDatabase</i> annotation, which defines the expected database version
  23. * number.
  24. */
  25. public interface DbUpgrader {
  26. /**
  27. * Defines method interface to handle database upgrades. This method is only
  28. * called if your <i>DbUpgrader</i> implementation is annotated with
  29. * IQDatabase.
  30. *
  31. * @param db
  32. * the database
  33. * @param fromVersion
  34. * the old version
  35. * @param toVersion
  36. * the new version
  37. * @return true for successful upgrade. If the upgrade is successful, the
  38. * version registry is automatically updated.
  39. */
  40. boolean upgradeDatabase(Db db, int fromVersion, int toVersion);
  41. /**
  42. * Defines method interface to handle table upgrades.
  43. *
  44. * @param db
  45. * the database
  46. * @param schema
  47. * the schema
  48. * @param table
  49. * the table
  50. * @param fromVersion
  51. * the old version
  52. * @param toVersion
  53. * the new version
  54. * @return true for successful upgrade. If the upgrade is successful, the
  55. * version registry is automatically updated.
  56. */
  57. boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion);
  58. /**
  59. * The default database upgrader. It throws runtime exception instead of
  60. * handling upgrade requests.
  61. */
  62. @IQDatabase(version = 0)
  63. public static class DefaultDbUpgrader implements DbUpgrader {
  64. public boolean upgradeDatabase(Db db, int fromVersion, int toVersion) {
  65. throw new IciqlException("Please provide your own DbUpgrader implementation.");
  66. }
  67. public boolean upgradeTable(Db db, String schema, String table, int fromVersion, int toVersion) {
  68. throw new IciqlException("Please provide your own DbUpgrader implementation.");
  69. }
  70. }
  71. }