@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);
  }
  public void runSQLTemplate(String path, boolean failOnError)
      throws IOException, NamingException, SQLException {

    DB db = DBFactoryUtil.getDB();

    db.runSQLTemplate(path, failOnError);
  }
  protected boolean isMySQL() {
    DB db = DBManagerUtil.getDB();

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

    return false;
  }
  protected void verifyOracleNewLine() throws Exception {
    DB db = DBFactoryUtil.getDB();

    String dbType = db.getType();

    if (!dbType.equals(DB.TYPE_ORACLE)) {
      return;
    }

    // This is a workaround for a limitation in Oracle sqlldr's inability
    // insert new line characters for long varchar columns. See
    // http://forums.liferay.com/index.php?showtopic=2761&hl=oracle for more
    // information. Check several articles because some articles may not
    // have new lines.

    boolean checkNewLine = false;

    List<JournalArticle> articles =
        JournalArticleLocalServiceUtil.getArticles(DEFAULT_GROUP_ID, 0, NUM_OF_ARTICLES);

    for (JournalArticle article : articles) {
      String content = article.getContent();

      if ((content != null) && content.contains("\\n")) {
        articles = JournalArticleLocalServiceUtil.getArticles(DEFAULT_GROUP_ID);

        for (int j = 0; j < articles.size(); j++) {
          article = articles.get(j);

          JournalArticleLocalServiceUtil.checkNewLine(
              article.getGroupId(), article.getArticleId(), article.getVersion());
        }

        checkNewLine = true;

        break;
      }
    }

    // Only process this once

    if (!checkNewLine) {
      if (_log.isInfoEnabled()) {
        _log.info("Do not fix oracle new line");
      }

      return;
    } else {
      if (_log.isInfoEnabled()) {
        _log.info("Fix oracle new line");
      }
    }
  }
  private void _reloadSQLTransformer() {
    if (_transformedSqls == null) {
      _transformedSqls = new ConcurrentHashMap<String, String>();
    } else {
      _transformedSqls.clear();
    }

    _vendorDB2 = false;
    _vendorDerby = false;
    _vendorFirebird = false;
    // _vendorHypersonic = false;
    _vendorInformix = false;
    _vendorIngres = false;
    _vendorInterbase = false;
    _vendorMySQL = false;
    _vendorOracle = false;
    _vendorPostgreSQL = false;
    _vendorSQLServer = false;
    _vendorSybase = false;

    DB db = DBFactoryUtil.getDB();

    String dbType = db.getType();

    _db = db;

    if (dbType.equals(DB.TYPE_DB2)) {
      _vendorDB2 = true;
    } else if (dbType.equals(DB.TYPE_DERBY)) {
      _vendorDerby = true;
    } else if (dbType.equals(DB.TYPE_FIREBIRD)) {
      _vendorFirebird = true;
    } else if (dbType.equals(DB.TYPE_HYPERSONIC)) {
      // _vendorHypersonic = true;
    } else if (dbType.equals(DB.TYPE_INFORMIX)) {
      _vendorInformix = true;
    } else if (dbType.equals(DB.TYPE_INGRES)) {
      _vendorIngres = true;
    } else if (dbType.equals(DB.TYPE_INTERBASE)) {
      _vendorInterbase = true;
    } else if (dbType.equals(DB.TYPE_MYSQL)) {
      _vendorMySQL = true;
    } else if (db.getType().equals(DB.TYPE_ORACLE)) {
      _vendorOracle = true;
    } else if (dbType.equals(DB.TYPE_POSTGRESQL)) {
      _vendorPostgreSQL = true;
    } else if (dbType.equals(DB.TYPE_SQLSERVER)) {
      _vendorSQLServer = true;
    } else if (dbType.equals(DB.TYPE_SYBASE)) {
      _vendorSybase = true;
    }
  }
  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 = 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);
    }
  }
  /**
   * 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 = ratingsStatsPersistence.getDataSource();

      DB db = DBFactoryUtil.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);
    }
  }
Exemple #11
0
  private String _transform(String sql) {
    if (sql == null) {
      return sql;
    }

    String newSQL = sql;

    newSQL = _replaceBitwiseCheck(newSQL);
    newSQL = _replaceBoolean(newSQL);
    newSQL = _replaceCastLong(newSQL);
    newSQL = _replaceCastText(newSQL);
    newSQL = _replaceIntegerDivision(newSQL);

    if (_vendorDB2) {
      newSQL = _replaceLike(newSQL);
    } else if (_vendorDerby) {
      newSQL = _replaceUnion(newSQL);
    } else if (_vendorMySQL) {
      DB db = DBFactoryUtil.getDB();

      if (!db.isSupportsStringCaseSensitiveQuery()) {
        newSQL = _removeLower(newSQL);
      }
    } else if (_vendorPostgreSQL) {
      newSQL = _replaceNegativeComparison(newSQL);
    } else if (_vendorSQLServer) {
      newSQL = _replaceMod(newSQL);
    } else if (_vendorSybase) {
      newSQL = _replaceMod(newSQL);
      newSQL = _replaceReplace(newSQL);
    }

    if (_log.isDebugEnabled()) {
      _log.debug("Original SQL " + sql);
      _log.debug("Modified SQL " + newSQL);
    }

    return newSQL;
  }
  protected void migrateTable(
      DB db, Connection connection, String tableName, Object[][] columns, String sqlCreate)
      throws Exception {

    Table table = new Table(tableName, columns);

    String tempFileName = table.generateTempFile();

    db.runSQL(connection, sqlCreate);

    if (tempFileName != null) {
      table.populateTable(tempFileName, connection);
    }
  }
  protected Scheduler initializeScheduler(String propertiesPrefix, boolean useQuartzCluster)
      throws Exception {

    StdSchedulerFactory schedulerFactory = new StdSchedulerFactory();

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

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

      String dbType = db.getType();

      if (dbType.equals(DB.TYPE_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.equals(DB.TYPE_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 boolean isSupportsAlterColumnName() {
    DB db = DBManagerUtil.getDB();

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

    return db.increment(name, size);
  }
  protected boolean isSupportsStringCaseSensitiveQuery() {
    DB db = DBFactoryUtil.getDB();

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

    return db.isSupportsUpdateWithInnerJoin();
  }
  protected long increment(String name) {
    DB db = DBFactoryUtil.getDB();

    return db.increment(name);
  }
  protected boolean isSupportsAlterColumnType() {
    DB db = DBFactoryUtil.getDB();

    return db.isSupportsAlterColumnType();
  }
  private static long _increment() {
    DB db = DBManagerUtil.getDB();

    return db.increment();
  }
  public void runSQL(String[] templates) throws IOException, SQLException {
    DB db = DBFactoryUtil.getDB();

    db.runSQL(templates);
  }
  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();
  }
  protected void runSQL(String template) throws IOException, SQLException {
    DB db = DBFactoryUtil.getDB();

    db.runSQL(template);
  }
  protected void runSQL(String[] sqls) throws Exception {
    DB db = DBFactoryUtil.getDB();

    db.runSQL(sqls);
  }
  private static void _deleteTempImages() throws Exception {
    DB db = DBFactoryUtil.getDB();

    db.runSQL(_DELETE_TEMP_IMAGES_1);
    db.runSQL(_DELETE_TEMP_IMAGES_2);
  }
  private static void _updateCompanyKey() throws Exception {
    DB db = DBFactoryUtil.getDB();

    db.runSQL("update Company set key_ = null");
  }
  protected long increment() {
    DB db = DBManagerUtil.getDB();

    return db.increment();
  }
  protected long increment() {
    DB db = DBFactoryUtil.getDB();

    return db.increment();
  }
Exemple #29
0
  protected void executeDB(String sql) throws Exception {
    DB db = DBManagerUtil.getDB();

    db.runSQL(sql);
  }
  public void runSQLTemplate(String path) throws IOException, NamingException, SQLException {

    DB db = DBFactoryUtil.getDB();

    db.runSQLTemplate(path);
  }