Пример #1
0
  @Override
  @RequiredPermission(Permission.MANAGE_SETTINGS)
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public long reindex(Subject whoami) {
    Connection conn = null;
    DatabaseType dbtype = null;
    try {
      conn = dataSource.getConnection();
      dbtype = DatabaseTypeFactory.getDatabaseType(conn);
      long duration = 0;
      if (DatabaseTypeFactory.isPostgres(dbtype)) {
        for (String table : TABLES_TO_REINDEX) {
          duration += doCommand(dbtype, conn, SQL_REINDEX, table);
        }
      } else if (DatabaseTypeFactory.isOracle(dbtype)) {
        for (String index : ORA_INDEXES_TO_REBUILD) {
          duration += doCommand(dbtype, conn, SQL_REBUILD, index);
        }
      } else {
        return -1;
      }

      return duration;
    } catch (Exception e) {
      LOG.error("Error reindexing database", e);
      throw new RuntimeException("Error reindexing database", e);
    } finally {
      if (dbtype != null) {
        dbtype.closeConnection(conn);
      }
    }
  }