Quantcast
Channel: Liquibase Forums
Viewing all articles
Browse latest Browse all 2993

Liquibase java not applying changesets

$
0
0
Hi,

I'm using Liquibase directly from Java 8, after adding the Maven dependency for Liquibase 3.4.0.
My project includes some database interactions with an Oracle 11g database (I included ojdbc6.jar in the build path and liquibase-oracle-3.0.0.jar as a maven dependency). My changelog is composed with a single changeset of creating a table if it doesn't exist (precondition with onSQLOutput="TEST"). When I run this changelog with the command line, everything works fine, but when I launch it with my Java application, something goes wrong (my simplified java code is written down below).
With the update action, this task simply does nothing. With updateSQL or futureRollbackSQL, it generates a file creating the tables of Liquibase (databasechangelog and databasechangeloglock), but does not include my changeset.
I'm 100% sure that the table does not exist on the given database.

I'm a little lost now, I don't know what to do or what's wrong. I checked at some examples from other topics, but I can't see any error in my code in my code (well... there should be one, obviously). Even posted this question on stackoverflow and didn't get any answer.

So I would be very grateful if you could help me point out my mistake(s) on this application !

Tell me if you need more details.

Thank you for your answers.

Java Code
  1. Connection c = null;
  2. Database database = null;
  3. PrintWriter pw = null;
  4. File file = null;
  5. liquibase.Liquibase liquibase = null;
  6. contexts = db+"."+user;
  7. try {
  8.     pw = new PrintWriter(new FileWriter(file));
  9.     // Get connection
  10.     c = SQLManager.getInstance().getConnection(db, user, passwd);
  11.     // Get liquibase connection
  12.     database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(c));
  13.     liquibase = new liquibase.Liquibase(new DatabaseChangeLog(fsource), new FileSystemResourceAccessor(),
  14.             database);
  15.     // Run liquibase action
  16.     switch (realAction) {
  17.         case Constants.LIQUIBASE_ACTION_FUTUREROLLBACKSQL:
  18.             liquibase.futureRollbackSQL(pw);
  19.             break;
  20.         case Constants.LIQUIBASE_ACTION_UPDATESQL:
  21.             liquibase.update(contexts, pw);
  22.             break;
  23.         case Constants.LIQUIBASE_ACTION_UPDATE:
  24.             liquibase.update(contexts);
  25.             if (!c.getAutoCommit())
  26.                 c.commit();
  27.             break;
  28.         default:
  29.             throw new RuntimeException("Action not implemented");
  30.     }
  31.     pw.close();
  32.     database.close();
  33.     c.close();
  34. } catch (IOException | SQLException | LiquibaseException e) {
  35.     throw new Exception(e.getMessage());
  36. } finally {
  37.     if (c != null) {
  38.         try {
  39.             c.close();
  40.         } catch (SQLException e) {
  41.             throw new RuntimeException(e.getClass() + ": " + e.getMessage());
  42.         }
  43.     }
  44. }

Viewing all articles
Browse latest Browse all 2993

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>