Ejemplo n.º 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);
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  @RequiredPermission(Permission.MANAGE_SETTINGS)
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public long vacuum(Subject whoami, String[] tableNames) {
    long duration = 0;
    Connection conn = null;
    DatabaseType dbtype = null;
    try {
      conn = dataSource.getConnection();
      dbtype = DatabaseTypeFactory.getDatabaseType(conn);
      if (!DatabaseTypeFactory.isPostgres(dbtype)) {
        return -1;
      }

      if (tableNames == null) // no names given -> operate on all tables.
      {
        tableNames = new String[1];
        tableNames[0] = null;
      }

      for (String tableName : tableNames) {
        duration += doCommand(dbtype, conn, SQL_VACUUM, tableName);
      }

      return duration;
    } catch (Exception e) {
      LOG.error("Error vacuuming database: " + e.getMessage(), e);
      return duration;
    } finally {
      if (dbtype != null) {
        dbtype.closeConnection(conn);
      }
    }
  }
Ejemplo n.º 3
0
  @Override
  @RequiredPermission(Permission.MANAGE_SETTINGS)
  @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
  public long analyze(Subject whoami) {
    Connection conn = null;
    DatabaseType dbtype = null;
    try {
      conn = dataSource.getConnection();
      dbtype = DatabaseTypeFactory.getDatabaseType(conn);
      if (!DatabaseTypeFactory.isPostgres(dbtype)) {
        return -1;
      }

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