コード例 #1
0
ファイル: DBCleanerTool.java プロジェクト: pkdevbox/jcr
  /**
   * Execute script on database. Set auto commit mode if needed.
   *
   * @param scripts the scripts for execution
   * @throws SQLException
   */
  protected void execute(List<String> scripts) throws SQLException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    // set needed auto commit mode
    boolean autoCommit = connection.getAutoCommit();
    if (autoCommit != this.autoCommit) {
      connection.setAutoCommit(this.autoCommit);
    }

    Statement st = connection.createStatement();
    try {
      for (String scr : scripts) {
        String sql = JDBCUtils.cleanWhitespaces(scr.trim());
        if (!sql.isEmpty()) {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Execute script: \n[" + sql + "]");
          }

          executeQuery(st, sql);
        }
      }
    } finally {
      try {
        st.close();
      } catch (SQLException e) {
        LOG.error("Can't close the Statement." + e.getMessage());
      }

      // restore previous auto commit mode
      if (autoCommit != this.autoCommit) {
        connection.setAutoCommit(autoCommit);
      }
    }
  }
コード例 #2
0
ファイル: DBCleanService.java プロジェクト: pkdevbox/jcr
  /**
   * Cleans repository data from database.
   *
   * @param rEntry the repository configuration
   * @throws DBCleanException
   */
  public static void cleanRepositoryData(RepositoryEntry rEntry) throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);

    boolean multiDB = getMultiDbParameter(wsEntry);
    if (multiDB) {
      for (WorkspaceEntry entry : rEntry.getWorkspaceEntries()) {
        cleanWorkspaceData(entry);
      }
    } else {
      Connection jdbcConn = getConnection(wsEntry);
      String dialect = resolveDialect(jdbcConn, wsEntry);
      boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

      try {
        jdbcConn.setAutoCommit(autoCommit);

        DBCleanerTool dbCleaner = getRepositoryDBCleaner(jdbcConn, rEntry);
        doClean(dbCleaner);
      } catch (SQLException e) {
        throw new DBCleanException(e);
      } finally {
        try {
          jdbcConn.close();
        } catch (SQLException e) {
          LOG.error("Can not close connection", e);
        }
      }
    }
  }
コード例 #3
0
ファイル: DBCleanService.java プロジェクト: pkdevbox/jcr
  /**
   * Returns database cleaner for workspace.
   *
   * @param jdbcConn database connection which need to use
   * @param wsEntry workspace configuration
   * @return DBCleanerTool
   * @throws DBCleanException
   */
  public static DBCleanerTool getWorkspaceDBCleaner(Connection jdbcConn, WorkspaceEntry wsEntry)
      throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    String dialect = resolveDialect(jdbcConn, wsEntry);
    boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

    DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, wsEntry);

    return new DBCleanerTool(
        jdbcConn,
        autoCommit,
        scripts.getCleaningScripts(),
        scripts.getCommittingScripts(),
        scripts.getRollbackingScripts());
  }
コード例 #4
0
ファイル: DBCleanService.java プロジェクト: pkdevbox/jcr
  /**
   * Cleans workspace data from database.
   *
   * @param wsEntry workspace configuration
   * @throws DBCleanException
   */
  public static void cleanWorkspaceData(WorkspaceEntry wsEntry) throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    Connection jdbcConn = getConnection(wsEntry);
    String dialect = resolveDialect(jdbcConn, wsEntry);
    boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

    try {
      jdbcConn.setAutoCommit(autoCommit);

      DBCleanerTool dbCleaner = getWorkspaceDBCleaner(jdbcConn, wsEntry);
      doClean(dbCleaner);
    } catch (SQLException e) {
      throw new DBCleanException(e);
    } finally {
      try {
        jdbcConn.close();
      } catch (SQLException e) {
        LOG.error("Can not close connection", e);
      }
    }
  }
コード例 #5
0
ファイル: DBCleanService.java プロジェクト: pkdevbox/jcr
  /**
   * Returns database cleaner for repository.
   *
   * @param jdbcConn database connection which need to use
   * @param rEntry repository configuration
   * @return DBCleanerTool
   * @throws DBCleanException
   */
  public static DBCleanerTool getRepositoryDBCleaner(Connection jdbcConn, RepositoryEntry rEntry)
      throws DBCleanException {
    SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

    WorkspaceEntry wsEntry = rEntry.getWorkspaceEntries().get(0);

    boolean multiDb = getMultiDbParameter(wsEntry);
    if (multiDb) {
      throw new DBCleanException(
          "It is not possible to create cleaner with common connection for multi database repository configuration");
    }

    String dialect = resolveDialect(jdbcConn, wsEntry);
    boolean autoCommit = dialect.startsWith(DialectConstants.DB_DIALECT_SYBASE);

    DBCleaningScripts scripts = DBCleaningScriptsFactory.prepareScripts(dialect, rEntry);

    return new DBCleanerTool(
        jdbcConn,
        autoCommit,
        scripts.getCleaningScripts(),
        scripts.getCommittingScripts(),
        scripts.getRollbackingScripts());
  }
コード例 #6
0
ファイル: MembershipDAOImpl.java プロジェクト: aheritier/core
 /** {@inheritDoc} */
 public void removeMembershipEventListener(MembershipEventListener listener) {
   SecurityHelper.validateSecurityPermission(PermissionConstants.MANAGE_LISTENERS);
   listeners_.remove(listener);
 }