Ejemplo n.º 1
0
 /**
  * Revision操作记录列表 为了避免由于权限配置不严格,导致未授权的Controller数据操作访问,父类提供protected基础实现,子类根据需要覆写public然后调用基类方法
  *
  * @return JSON集合数据
  */
 @MetaData(value = "版本数据列表")
 protected HttpHeaders revisionList() {
   String property = this.getParameter("property");
   Boolean hasChanged = null;
   String changed = this.getParameter("changed");
   if (StringUtils.isNotBlank(changed)) {
     hasChanged = BooleanUtils.toBooleanObject(changed);
   }
   List<EntityRevision> entityRevisions =
       getEntityService().findEntityRevisions(this.getId(), property, hasChanged);
   for (EntityRevision entityRevision : entityRevisions) {
     Object entity = entityRevision.getEntity();
     ExtDefaultRevisionEntity revEntity = entityRevision.getRevisionEntity();
     if (entity instanceof OperationAuditable) {
       OperationAuditable aae = (OperationAuditable) entity;
       revEntity.setOldStateDisplay(aae.convertStateToDisplay(revEntity.getOldState()));
       revEntity.setNewStateDisplay(aae.convertStateToDisplay(revEntity.getNewState()));
       revEntity.setOperationEventDisplay(
           aae.convertEventToDisplay(revEntity.getOperationEvent()));
     }
   }
   setModel(buildPageResultFromList(entityRevisions));
   return buildDefaultHttpHeaders();
 }
Ejemplo n.º 2
0
  public static void main(String[] args) throws SQLException, IOException {
    String host = "localhost";
    String database = null;
    String user = null;
    String password = null;
    int minTuples = 1000;
    Boolean dropIndices = null;
    Boolean dropConstraints = null;
    Boolean createIndices = null;
    boolean showHelp = false;

    for (String arg : args) {
      if (arg.startsWith("--host=")) {
        host = arg.substring(7);
      } else if (arg.startsWith("--database=")) {
        database = arg.substring(11);
      } else if (arg.startsWith("--user="******"--password="******"--min-tuples=")) {
        minTuples = Integer.valueOf(arg.substring(13));
      } else if (arg.startsWith("--drop-indices=")) {
        dropIndices = BooleanUtils.toBooleanObject(arg.substring(15));
      } else if (arg.startsWith("--drop-constraints=")) {
        dropConstraints = BooleanUtils.toBooleanObject(arg.substring(19));
      } else if (arg.startsWith("--create-indices=")) {
        createIndices = BooleanUtils.toBooleanObject(arg.substring(17));
      } else if (arg.startsWith("--help")) {
        showHelp = true;
      }
    }

    Properties props = new Properties();
    props.load(ClassLoader.getSystemResourceAsStream("default.index.properties"));
    try {
      props.load(new FileInputStream(getJarPath() + File.separator + "index.properties"));
    } catch (Exception e) {
      System.err.println("Couldn't locate index.properties -- ignoring.");
    }
    for (Entry<Object, Object> prop : props.entrySet()) {
      String indexName = prop.getKey().toString();
      String[] tableAndColumn = prop.getValue().toString().split("\\.");
      if (tableAndColumn.length == 2) {
        indexMap.put(
            indexName, new ImmutablePair<String, String>(tableAndColumn[0], tableAndColumn[1]));
      }
    }

    if (showHelp
        || database == null
        || user == null
        || password == null
        || (dropIndices == null && dropConstraints == null && createIndices == null)) {
      System.out.println(
          "Usage: java -jar AutoFKIndexDB.jar\nOptions:\n"
              + "\t--host=["
              + host
              + "]\n"
              + "\t--database=["
              + database
              + "]\n"
              + "\t--user=["
              + user
              + "]\n"
              + "\t--password=["
              + password
              + "]\n"
              + "\t--min-tuples=["
              + minTuples
              + "]\n"
              + "\t--drop-indices="
              + (dropIndices != null ? "[" + dropIndices + "]" : "true|false")
              + "\n"
              + "\t--drop-constraints="
              + (dropConstraints != null ? "[" + dropConstraints + "]" : "true|false")
              + "\n"
              + "\t--create-indices="
              + (createIndices != null ? "[" + createIndices + "]" : "true|false")
              + "\n"
              + "\t--help");
      System.exit(1);
    }

    Connection conn = null;
    try {
      String url = "jdbc:postgresql://" + host + ":5432/" + database;
      conn = DriverManager.getConnection(url, user, password);

      AutoFKIndexDB autoFK = new AutoFKIndexDB();

      if (BooleanUtils.isTrue(dropIndices)) {
        autoFK.dropForeignKeyIndices(conn);
      }

      if (BooleanUtils.isTrue(dropConstraints)) {
        autoFK.dropForeignKeyConstraints(conn);
      }

      if (BooleanUtils.isTrue(createIndices)) {
        autoFK.createForeignKeyIndices(conn, minTuples);
      }
    } catch (Exception e) {
      System.err.println("Got an exception: " + e.getMessage());
      e.printStackTrace();
    } finally {
      if (conn != null) {
        conn.close();
      }
    }
  }