001package com.avaje.ebean.dbmigration;
002
003import com.avaje.ebean.config.dbplatform.DbPlatformName;
004import org.slf4j.Logger;
005import org.slf4j.LoggerFactory;
006
007/**
008 * Helper to indicate that an EbeanServer should come up offline
009 * typically for DDL generation purposes.
010 */
011public class DbOffline {
012
013  private static final Logger logger = LoggerFactory.getLogger(DbOffline.class);
014
015  private static final String KEY = "ebean.dboffline";
016
017  private static boolean generateMigration;
018
019  /**
020   * Set the platform to use when creating the next EbeanServer instance.
021   */
022  public static void setPlatform(DbPlatformName dbPlatform) {
023    System.setProperty(KEY, dbPlatform.name());
024  }
025
026  /**
027   * Set the platform to use when creating the next EbeanServer instance.
028   */
029  public static void setPlatform(String platformName) {
030    System.setProperty(KEY, platformName);
031  }
032
033  /**
034   * Return the platform to use when creating the next EbeanServer instance.
035   */
036  public static String getPlatform() {
037    return System.getProperty(KEY);
038  }
039
040  /**
041   * Bring up the next EbeanServer instance using the H2 platform.
042   */
043  public static void asH2() {
044    setPlatform(DbPlatformName.H2);
045  }
046
047  /**
048   * Return true if the offline platform has been set.
049   */
050  public static boolean isSet() {
051    return getPlatform() != null;
052  }
053
054  /**
055   * Return true if the migration is running. This typically means don't run the
056   * plugins like full DDL generation.
057   */
058  public static boolean isGenerateMigration() {
059    return generateMigration;
060  }
061
062  /**
063   * Called when the migration is running is order to stop other plugins
064   * like the full DDL generation from executing.
065   */
066  public static void setGenerateMigration() {
067    generateMigration = true;
068  }
069
070  /**
071   * Reset the offline platform and runningMigration flag.
072   */
073  public static void reset() {
074    generateMigration = false;
075    System.clearProperty(KEY);
076    logger.debug("reset");
077  }
078
079}