code: private static void orientBySlope(Statement st,
                                        TableLocation nodesName,
                                        TableLocation edgesName) throws SQLException {
          LOGGER.info("Orienting edges by slope...");
          st.execute("UPDATE " + edgesName + " c " +
                      "SET START_NODE=END_NODE, " +
                      "    END_NODE=START_NODE " +
                      "WHERE (SELECT ST_Z(A.THE_GEOM) < ST_Z(B.THE_GEOM) " +
                              "FROM " + nodesName + " A, " + nodesName + " B " +
                              "WHERE C.START_NODE=A.NODE_ID AND C.END_NODE=B.NODE_ID);");
      }
docs: Edges direction according the slope (start and end z)
  @param st
  @param nodesName
  @param edgesName
  @throws SQLException