Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. public void applySchema(DataBaseSchema new_schema, byte[] version)
  2. throws DBStorageException, DBSavepointException
  3. {
  4. if (new_schema == null)
  5. {
  6. throw new MigrationException("schema must be not null");
  7. }
  8.  
  9. if (!hasValidDB())
  10. {
  11. throw new DBStorageException("db '" + name_ + "' is invalid");
  12. }
  13.  
  14. if (!version_mgr_.requiresUpdate(version))
  15. {
  16. DBLog.info("schema for DB '" + name_ + "' is already newest");
  17. return;
  18. }
  19. else
  20. {
  21. try
  22. {
  23. beginTransaction();
  24.  
  25. final DataBaseSchema curr_db_schema = SQLSchemaReader.readDBSchema(this);
  26.  
  27. createAndChangeTables(curr_db_schema, new_schema);
  28. removeOldTables(curr_db_schema, new_schema);
  29.  
  30. if (!setActiveTransactionSuccessful())
  31. {
  32. throw new DBStorageException("failed to set transaction as successful");
  33. }
  34. }
  35. catch (DBSchemaException ex)
  36. {
  37. throw new MigrationException("failed migration for db schema '" + new_schema.getName() + "'", ex);
  38. }
  39. finally
  40. {
  41. endTransaction();
  42. }
  43.  
  44. version_mgr_.saveSchemaVersion(version);
  45. }
  46.  
  47. curr_schema_ = new_schema;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement