@Activate
  protected void activate(final BundleContext bundleContext, Map<String, Object> properties) {

    _logger = new Logger(bundleContext);

    DB db = DBManagerUtil.getDB();

    ServiceTrackerMapListener<String, UpgradeInfo, List<UpgradeInfo>> serviceTrackerMapListener =
        null;

    _releaseManagerConfiguration =
        ConfigurableUtil.createConfigurable(ReleaseManagerConfiguration.class, properties);

    if (_releaseManagerConfiguration.autoUpgrade()) {
      serviceTrackerMapListener = new UpgradeInfoServiceTrackerMapListener();
    }

    _serviceTrackerMap =
        ServiceTrackerMapFactory.openMultiValueMap(
            bundleContext,
            UpgradeStep.class,
            "(&(upgrade.bundle.symbolic.name=*)(|(upgrade.db.type=any)"
                + "(upgrade.db.type="
                + db.getDBType()
                + ")))",
            new PropertyServiceReferenceMapper<String, UpgradeStep>("upgrade.bundle.symbolic.name"),
            new UpgradeServiceTrackerCustomizer(bundleContext),
            Collections.reverseOrder(
                new PropertyServiceReferenceComparator<UpgradeStep>("upgrade.from.schema.version")),
            serviceTrackerMapListener);
  }
  protected boolean isMySQL() {
    DB db = DBManagerUtil.getDB();

    if (db.getDBType() == DBType.MYSQL) {
      return true;
    }

    return false;
  }
  protected void deleteTempImages() throws Exception {
    if (_log.isDebugEnabled()) {
      _log.debug("Delete temporary images");
    }

    DB db = DBManagerUtil.getDB();

    db.runSQL(
        "delete from Image where imageId IN (SELECT articleImageId FROM "
            + "JournalArticleImage where tempImage = TRUE)");

    db.runSQL("delete from JournalArticleImage where tempImage = TRUE");
  }
  /**
   * Performs a SQL query.
   *
   * @param sql the sql query
   */
  protected void runSQL(String sql) {
    try {
      DataSource dataSource = resourcePermissionPersistence.getDataSource();

      DB db = DBManagerUtil.getDB();

      sql = db.buildSQL(sql);
      sql = PortalUtil.transformSQL(sql);

      SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql);

      sqlUpdate.update();
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  /**
   * Performs a SQL query.
   *
   * @param sql the sql query
   */
  protected void runSQL(String sql) {
    try {
      DataSource dataSource = InfrastructureUtil.getDataSource();

      DB db = DBManagerUtil.getDB();

      sql = db.buildSQL(sql);
      sql = PortalUtil.transformSQL(sql);

      SqlUpdate sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(dataSource, sql, new int[0]);

      sqlUpdate.update();
    } catch (Exception e) {
      throw new SystemException(e);
    }
  }
  @Override
  protected void doVerify() throws Exception {
    DB db = DBManagerUtil.getDB();

    if (db.getDBType() != DBType.DB2) {
      return;
    }

    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
      StringBundler sb = new StringBundler(4);

      sb.append("select tbname, name, coltype, length from ");
      sb.append("sysibm.syscolumns where tbcreator = (select distinct ");
      sb.append("current schema from sysibm.sysschemata) AND coltype = ");
      sb.append("'VARCHAR' and length = 500");

      ps = connection.prepareStatement(sb.toString());

      rs = ps.executeQuery();

      while (rs.next()) {
        String tableName = rs.getString(1);

        if (!isPortalTableName(tableName)) {
          continue;
        }

        String columnName = rs.getString(2);

        runSQL(
            "alter table "
                + tableName
                + " alter column "
                + columnName
                + " set data type varchar(600)");
      }
    } finally {
      DataAccess.cleanUp(ps, rs);
    }
  }
  protected Scheduler initializeScheduler(String propertiesPrefix, boolean useQuartzCluster)
      throws Exception {

    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();

    Properties properties = _props.getProperties(propertiesPrefix, true);

    if (useQuartzCluster) {
      DB db = DBManagerUtil.getDB();

      DBType dbType = db.getDBType();

      if (dbType == DBType.SQLSERVER) {
        String lockHandlerClassName =
            properties.getProperty("org.quartz.jobStore.lockHandler.class");

        if (Validator.isNull(lockHandlerClassName)) {
          properties.setProperty(
              "org.quartz.jobStore.lockHandler.class", UpdateLockRowSemaphore.class.getName());
        }
      }

      if (GetterUtil.getBoolean(_props.get(PropsKeys.CLUSTER_LINK_ENABLED))) {

        if (dbType == DBType.HYPERSONIC) {
          _log.error("Unable to cluster scheduler on Hypersonic");
        } else {
          properties.put("org.quartz.jobStore.isClustered", Boolean.TRUE.toString());
        }
      }
    }

    schedulerFactory.initialize(properties);

    return schedulerFactory.getScheduler();
  }
  protected void executeDB(String sql) throws Exception {
    DB db = DBManagerUtil.getDB();

    db.runSQL(sql);
  }
  protected void processStartupEvents() throws Exception {

    // Print release information

    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    try (InputStream inputStream =
        classLoader.getResourceAsStream("com/liferay/portal/events/dependencies/startup.txt")) {

      System.out.println(_toString(inputStream));
    }

    System.out.println("Starting " + ReleaseInfo.getReleaseInfo() + "\n");

    if (_log.isDebugEnabled()) {
      _log.debug("Portal Resiliency - NOT SUPPORTED");
    }

    // Shutdown hook

    if (_log.isDebugEnabled()) {
      _log.debug("Add shutdown hook");
    }

    Runtime runtime = Runtime.getRuntime();

    runtime.addShutdownHook(new Thread(new ShutdownHook()));

    // MySQL version

    DB db = DBManagerUtil.getDB();

    if ((db.getDBType() == DBType.MYSQL) && GetterUtil.getFloat(db.getVersionString()) < 5.6F) {

      throw new ServletException(
          "Please upgrade to at least MySQL 5.6.4. The portal no "
              + "longer supports older versions of MySQL.");
    }

    // Check required build number

    if (_log.isDebugEnabled()) {
      _log.debug("Check required build number");
    }

    DBUpgrader.checkRequiredBuildNumber(ReleaseInfo.getParentBuildNumber());

    Registry registry = RegistryUtil.getRegistry();

    Map<String, Object> properties = new HashMap<>();

    properties.put("module.service.lifecycle", "database.initialized");
    properties.put("service.vendor", ReleaseInfo.getVendor());
    properties.put("service.version", ReleaseInfo.getVersion());

    _dbModuleServiceLifecycleServiceRegistration =
        registry.registerService(
            ModuleServiceLifecycle.class, new ModuleServiceLifecycle() {}, properties);

    // Check class names

    if (_log.isDebugEnabled()) {
      _log.debug("Check class names");
    }

    ClassNameLocalServiceUtil.checkClassNames();
  }
  private static long _increment() {
    DB db = DBManagerUtil.getDB();

    return db.increment();
  }
  protected boolean isSupportsUpdateWithInnerJoin() {
    DB db = DBManagerUtil.getDB();

    return db.isSupportsUpdateWithInnerJoin();
  }
  protected boolean isSupportsStringCaseSensitiveQuery() {
    DB db = DBManagerUtil.getDB();

    return db.isSupportsStringCaseSensitiveQuery();
  }
  protected boolean isSupportsAlterColumnType() {
    DB db = DBManagerUtil.getDB();

    return db.isSupportsAlterColumnType();
  }
  protected long increment(String name, int size) {
    DB db = DBManagerUtil.getDB();

    return db.increment(name, size);
  }
  protected long increment() {
    DB db = DBManagerUtil.getDB();

    return db.increment();
  }