コード例 #1
0
ファイル: DialectPostgreSQL.java プロジェクト: beno/apricot
 @Override
 public void existingTableDetected(
     Connection connection, Table table, Model model, Database database) throws SQLException {
   if (Model.ANCESTORS_TABLE_NAME.equals(table.getKey())) {
     if (!pathOptimizationsEnabled) {
       log.info("Path optimizations disabled");
       return;
     }
     // check if we want to initialize the descendants table now, or log
     // a warning if the hierarchy table is too big
     String sql = "SELECT id FROM ancestors LIMIT 1";
     Statement s = connection.createStatement();
     ResultSet rs = s.executeQuery(sql);
     boolean empty = !rs.next();
     rs.close();
     s.close();
     if (empty) {
       pathOptimizationsEnabled = false;
       log.error(
           "Table ANCESTORS empty, must be upgraded by hand by calling: "
               + "SELECT nx_init_ancestors()");
       log.info("Path optimizations disabled");
     }
   }
 }
コード例 #2
0
ファイル: DialectPostgreSQL.java プロジェクト: beno/apricot
 @Override
 public boolean preCreateTable(Connection connection, Table table, Model model, Database database)
     throws SQLException {
   String tableKey = table.getKey();
   if (model.HIER_TABLE_NAME.equals(tableKey)) {
     hierarchyCreated = true;
     return true;
   }
   if (model.ANCESTORS_TABLE_NAME.equals(tableKey)) {
     if (hierarchyCreated) {
       // database initialization
       return true;
     }
     // upgrade of an existing database
     // check hierarchy size
     String sql = "SELECT COUNT(*) FROM hierarchy WHERE NOT isproperty";
     Statement s = connection.createStatement();
     ResultSet rs = s.executeQuery(sql);
     rs.next();
     long count = rs.getLong(1);
     rs.close();
     s.close();
     if (count > 100000) {
       // if the hierarchy table is too big, tell the admin to do the
       // init by hand
       pathOptimizationsEnabled = false;
       log.error(
           "Table ANCESTORS not initialized automatically because table HIERARCHY is too big. "
               + "Upgrade by hand by calling: SELECT nx_init_ancestors()");
     }
     return true;
   }
   return true;
 }
コード例 #3
0
ファイル: DialectPostgreSQL.java プロジェクト: beno/apricot
 @Override
 public List<String> getPostCreateTableSqls(Table table, Model model, Database database) {
   if (Model.ANCESTORS_TABLE_NAME.equals(table.getKey())) {
     List<String> sqls = new ArrayList<String>();
     if (pathOptimizationsEnabled) {
       sqls.add("SELECT nx_init_ancestors()");
     } else {
       log.info("Path optimizations disabled");
     }
     return sqls;
   }
   return Collections.emptyList();
 }