Example #1
0
 /** Load data. */
 private ArrayList loadData() {
   try {
     ArrayList vos = new ArrayList();
     BufferedReader br =
         new BufferedReader(new InputStreamReader(new FileInputStream("orders.txt")));
     String line = null;
     SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
     OrdersVO vo = null;
     String[] t = null;
     while ((line = br.readLine()) != null) {
       t = line.split(";");
       vo = new OrdersVO();
       vos.add(vo);
       vo.setOrderDate(sdf.parse(t[0]));
       vo.setCategory(t[1]);
       vo.setSubCategory(t[2]);
       vo.setCountry(t[3]);
       vo.setZone(t[4]);
       vo.setAgent(t[5]);
       vo.setItem(t[6]);
       vo.setSellQty(new BigDecimal(t[7]));
       vo.setSellAmount(new BigDecimal(t[8]));
     }
     br.close();
     return vos;
   } catch (Exception ex) {
     ex.printStackTrace();
     return new ArrayList();
   }
 }
Example #2
0
  // 일사용량(7일)
  public ArrayList<ArrayList<String>> get7dayUsage(String umdong) {

    ArrayList<ArrayList<String>> datas = new ArrayList<ArrayList<String>>();

    String sql =
        "select sum(CONSUMED), sum(PREDICTED) from CONSUMPTION where CODE in(select CODE from USER where UMDONG = \'"
            + umdong
            + "\') and DATE between '2015-02-22' and '2015-02-28' group by DATE order by DATE DESC;";

    try {
      pstmt = conn.prepareStatement(sql);
      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) {
        ArrayList<String> usage = new ArrayList<String>();

        usage.add(rs.getString("sum(CONSUMED)"));
        usage.add(rs.getString("sum(PREDICTED)"));
        datas.add(usage);
      }
      rs.close();
    } catch (SQLException e) {
      e.printStackTrace();
    }
    return datas;
  }
 public int[] executeBatch() throws SQLException {
   if (batch == null) {
     return new int[0];
   }
   int[] ret;
   if (args.length == 0) {
     ret = new int[batch.size()];
   } else {
     ret = new int[batch.size() / args.length];
   }
   for (int i = 0; i < ret.length; i++) {
     ret[i] = EXECUTE_FAILED;
   }
   int errs = 0;
   int index = 0;
   for (int i = 0; i < ret.length; i++) {
     for (int k = 0; k < args.length; k++) {
       BatchArg b = (BatchArg) batch.get(index++);
       args[k] = b.arg;
       blobs[k] = b.blob;
     }
     try {
       ret[i] = executeUpdate();
     } catch (SQLException e) {
       ++errs;
     }
   }
   if (errs > 0) {
     throw new BatchUpdateException("batch failed", ret);
   }
   return ret;
 }
 // metoda za pretragu po broju stanovnika
 public ArrayList<Country> SearchCountryPopulation(long Population) {
   ArrayList<Country> countries = new ArrayList<Country>();
   try {
     Connection connection = getConnected("world");
     PreparedStatement statement =
         connection.prepareStatement(
             "SELECT * FROM country WHERE Population <= " + Population + ";");
     ResultSet result = statement.executeQuery();
     while (result.next()) {
       countries.add(
           new Country(
               result.getString("Code"),
               result.getString("Name"),
               result.getString("Continent"),
               result.getString("Region"),
               result.getDouble("SurfaceArea"),
               result.getInt("IndepYear"),
               result.getLong("Population"),
               result.getDouble("LifeExpectancy"),
               result.getDouble("GNP"),
               result.getDouble("GNPOld"),
               result.getString("LocalName"),
               result.getString("GovernmentForm"),
               result.getString("HeadOfState"),
               result.getInt("Capital"),
               result.getString("Code2")));
     }
     connection.close();
   } catch (Exception e) {
     System.out.println(e.toString());
     return null;
   }
   return countries;
 }
Example #5
0
 /**
  * Get Accessible Goals
  *
  * @param ctx context
  * @return array of goals
  */
 public static MGoal[] getGoals(Ctx ctx) {
   ArrayList<MGoal> list = new ArrayList<MGoal>();
   String sql = "SELECT * FROM PA_Goal WHERE IsActive='Y' " + "ORDER BY SeqNo";
   sql =
       MRole.getDefault(ctx, false)
           .addAccessSQL(sql, "PA_Goal", false, true); // 	RW to restrict Access
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, (Trx) null);
     rs = pstmt.executeQuery();
     while (rs.next()) {
       MGoal goal = new MGoal(ctx, rs, null);
       goal.updateGoal(false);
       list.add(goal);
     }
   } catch (Exception e) {
     s_log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeStatement(pstmt);
     DB.closeResultSet(rs);
   }
   MGoal[] retValue = new MGoal[list.size()];
   list.toArray(retValue);
   return retValue;
 } //	getGoals
Example #6
0
  public ArrayList<VentasBean> obtenerMensajes() {
    Connection cn = null;
    ArrayList<VentasBean> mensaje = null;
    Statement st;
    ResultSet rs;
    try {
      cn = getConnection();
      st = cn.createStatement();
      String tsql;
      tsql = "select * from ventas";
      rs = st.executeQuery(tsql);
      mensaje = new ArrayList<VentasBean>();
      while (rs.next()) {
        VentasBean m =
            new VentasBean(
                rs.getInt("id_venta"),
                rs.getInt("id_linea"),
                rs.getString("fecha_venta"),
                rs.getString("descripcion"));
        mensaje.add(m);
      }
      cn.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return (mensaje);
  }
Example #7
0
  public List getEntries(int startIndex, int endIndex) {
    // User code starts here
    if (agentName.initTopo()) {
      ArrayList arrayList = new ArrayList();
      int noOfObj = getCount();
      String[] name = {""}; // No I18N

      for (int i = 0; i < noOfObj; i++) {
        if (name[0].trim().equals("")) // No I18N
        {
          getFirstMo(name);
        } else {
          getNextMo(name);
        }

        if ((i + 1 >= startIndex) && (i + 1 <= endIndex)) {
          Object[] indx = new Object[] {name[0]};
          arrayList.add(indx);
          if (i + 1 == endIndex) break;
        }
      }
      return arrayList;
    }

    // User code ends here
    return null;
  }
Example #8
0
  public static ArrayList getFjList(String sid) {
    ArrayList result = new ArrayList();
    String strSql =
        "select SID,File_Name,Ext_Name,File_Size from  t_docs_fj where state='1' and parent_sid="
            + sid;
    CommonDao dao = CommonDao.GetOldDatabaseDao();
    List lst = dao.fetchAll(strSql);
    if (lst != null && lst.size() > 0) {
      for (int i = 0; i < lst.size(); i++) {
        Object[] arr = (Object[]) lst.get(i);
        result.add(arr[1]);
        result.add(arr[2]);
        if (arr[3] != null) {
          Float fileSize = Float.parseFloat(arr[3].toString()) * 1000;
          result.add(fileSize);
        } else {
          result.add(0);
        }
        result.add(arr[0]);
      }
    }
    dao.getSessionFactory().close();
    return result;
    /*Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;
    ArrayList result = new ArrayList();
    String strSql = "select * from  t_docs_fj where state='1' and parent_sid="
    		+ sid;
    try {
    	conn = DataManager.getConnection();
    	stmt = conn.createStatement();
    	rs = stmt.executeQuery(strSql);
    	while (rs.next()) {
    		result.add(rs.getString("File_Name"));
    		result.add(rs.getString("Ext_Name"));
    		result.add(""
    				+ Float.valueOf(rs.getString("File_Size")).floatValue()
    				* 1000.0);
    		result.add(rs.getString("SID"));
    		result.add(FileUtil.getDocumentPath());
    	}
    } catch (Exception ex) {
    	ex.printStackTrace();
    }

    finally {
    	try {
    		if (rs != null)
    			rs.close();
    		if (stmt != null)
    			stmt.close();
    		if (conn != null)
    			conn.close();
    	} catch (Exception ex) {
    		ex.printStackTrace();
    	}
    }*/

  }
 /** Expand the current node and return the list of leaves (MaterialVO objects). */
 private ArrayList getComponents(DefaultMutableTreeNode node) {
   ArrayList list = new ArrayList();
   for (int i = 0; i < node.getChildCount(); i++)
     list.addAll(getComponents((DefaultMutableTreeNode) node.getChildAt(i)));
   if (node.isLeaf()) list.add(node.getUserObject());
   return list;
 }
 // 根据推荐的movie的ID,获得movie的详细信息
 public ArrayList<MovieInfo> getMovieByMovieId(List<RecommendedItem> recommendations) {
   ArrayList<MovieInfo> movieList = new ArrayList<MovieInfo>();
   try {
     String sql = "";
     conn = ConnectToMySQL.getConnection();
     for (int i = 0; i < recommendations.size(); i++) {
       sql =
           "select m.name,m.published_year,m.type from movies m where m.id="
               + recommendations.get(i).getItemID()
               + "";
       ps = conn.prepareStatement(sql);
       rs = ps.executeQuery();
       while (rs.next()) {
         MovieInfo movieInfo = new MovieInfo();
         movieInfo.setName(rs.getString(1));
         movieInfo.setPublishedYear(rs.getString(2));
         movieInfo.setType(rs.getString(3));
         movieInfo.setPreference(recommendations.get(i).getValue());
         movieList.add(movieInfo);
       }
     }
   } catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
   } finally {
     closeAll();
   }
   return movieList;
 }
  public Connection getConnection() throws SQLException {
    synchronized (pool) {
      if (!pool.isEmpty()) {
        int last = pool.size() - 1;
        Connection pooled = (Connection) pool.remove(last);

        boolean conn_ok = true;
        String test_table = prop.getProperty("test_table");
        if (test_table != null) {
          Statement stmt = null;
          try {
            stmt = pooled.createStatement();
            stmt.executeQuery("select * from " + prop.getProperty("test_table"));
          } catch (SQLException ex) {
            conn_ok = false; // 连接不可用
          } finally {
            if (stmt != null) {
              stmt.close();
            }
          }
        }
        if (conn_ok == true) {
          return pooled;
        } else {
          pooled.close();
        }
      }
    }
    Connection conn =
        DriverManager.getConnection(
            prop.getProperty("url"), prop.getProperty("username"), prop.getProperty("password"));
    return conn;
  }
Example #12
0
  private synchronized void init() throws SQLException {
    if (isClosed) return;

    // do tables exists?
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery(TABLE_NAMES_SELECT_STMT);

    ArrayList<String> missingTables = new ArrayList(TABLES.keySet());
    while (rs.next()) {
      String tableName = rs.getString("name");
      missingTables.remove(tableName);
    }

    for (String missingTable : missingTables) {
      try {
        Statement createStmt = conn.createStatement();
        // System.out.println("Adding table "+ missingTable);
        createStmt.executeUpdate(TABLES.get(missingTable));
        createStmt.close();

      } catch (Exception e) {
        System.err.println(e.getClass().getName() + ": " + e.getMessage());
      }
    }
  }
 public List<ICFAccTaxObj> readAllTax(boolean forceRead) {
   final String S_ProcName = "readAllTax";
   if ((allTax == null) || forceRead) {
     Map<CFAccTaxPKey, ICFAccTaxObj> map = new HashMap<CFAccTaxPKey, ICFAccTaxObj>();
     allTax = map;
     CFAccTaxBuff[] buffList =
         ((ICFAccSchema) schema.getBackingStore())
             .getTableTax()
             .readAllDerived(schema.getAuthorization());
     CFAccTaxBuff buff;
     ICFAccTaxObj obj;
     for (int idx = 0; idx < buffList.length; idx++) {
       buff = buffList[idx];
       obj = newInstance();
       obj.setPKey(((ICFAccSchema) schema.getBackingStore()).getFactoryTax().newPKey());
       obj.setBuff(buff);
       ICFAccTaxObj realized = (ICFAccTaxObj) obj.realize();
     }
   }
   Comparator<ICFAccTaxObj> cmp =
       new Comparator<ICFAccTaxObj>() {
         public int compare(ICFAccTaxObj lhs, ICFAccTaxObj rhs) {
           if (lhs == null) {
             if (rhs == null) {
               return (0);
             } else {
               return (-1);
             }
           } else if (rhs == null) {
             return (1);
           } else {
             CFAccTaxPKey lhsPKey = lhs.getPKey();
             CFAccTaxPKey rhsPKey = rhs.getPKey();
             int ret = lhsPKey.compareTo(rhsPKey);
             return (ret);
           }
         }
       };
   int len = allTax.size();
   ICFAccTaxObj arr[] = new ICFAccTaxObj[len];
   Iterator<ICFAccTaxObj> valIter = allTax.values().iterator();
   int idx = 0;
   while ((idx < len) && valIter.hasNext()) {
     arr[idx++] = valIter.next();
   }
   if (idx < len) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   } else if (valIter.hasNext()) {
     throw CFLib.getDefaultExceptionFactory()
         .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len);
   }
   Arrays.sort(arr, cmp);
   ArrayList<ICFAccTaxObj> arrayList = new ArrayList<ICFAccTaxObj>(len);
   for (idx = 0; idx < len; idx++) {
     arrayList.add(arr[idx]);
   }
   List<ICFAccTaxObj> sortedList = arrayList;
   return (sortedList);
 }
  protected synchronized String getProcedureName(Connection dConn, Connection gConn) {
    /// avoid #42569
    ResultSet rs = null;

    try {
      rs = gConn.getMetaData().getProcedures(null, null, null);
      List procNames = ResultSetHelper.asList(rs, false);
      Log.getLogWriter().info("procedure names are " + ResultSetHelper.listToString(procNames));
      rs.close();
    } catch (SQLException se) {
      SQLHelper.handleSQLException(se);
    }

    try {
      rs = gConn.getMetaData().getFunctions(null, null, null);
    } catch (SQLException se) {
      SQLHelper.handleSQLException(se);
    }
    List funcNames = ResultSetHelper.asList(rs, false);
    Log.getLogWriter().info("function names are " + ResultSetHelper.listToString(funcNames));

    if (procedureNames == null) {
      ArrayList<String> procs = new ArrayList<String>();
      procs.addAll(ProcedureDDLStmt.modifyProcNameList);
      procs.addAll(ProcedureDDLStmt.nonModifyProcNameList);
      procedureNames = new ArrayList<String>(procs);
    }

    return procedureNames.get(SQLTest.random.nextInt(procedureNames.size()));
  }
Example #15
0
 public void listerArticles() {
   Connection con = null;
   Statement st = null;
   ResultSet rs = null;
   try {
     Class.forName(driver).newInstance();
     con = DriverManager.getConnection(url, usr, passwd);
     st = con.createStatement();
     rs = st.executeQuery("SELECT id, nom, quantite FROM articles");
     // remise à 0 de la liste - utile pour les mises à jour
     list.clear();
     // Stocker les enregistrements dans la liste
     while (rs.next()) {
       int id = rs.getInt(1);
       String nom = new String(rs.getString(2));
       int quantite = rs.getInt(3);
       list.add(new ElementBDD(nom, quantite)); // ajout
       System.out.println(nom + "          " + quantite);
     }
   } catch (Exception e) {
     System.err.println("Exception: " + e.getMessage());
   } finally {
     try {
       if (rs != null) rs.close();
       if (st != null) st.close();
       if (con != null) con.close();
     } catch (SQLException e) {
     }
   }
 }
Example #16
0
 /**
  * ************************************************************************ Lineas de Remesa
  *
  * @param whereClause where clause or null (starting with AND)
  * @return lines
  */
 public MRemesaLine[] getLines(String whereClause, String orderClause) {
   ArrayList list = new ArrayList();
   StringBuffer sql = new StringBuffer("SELECT * FROM C_RemesaLine WHERE C_Remesa_ID=? ");
   if (whereClause != null) sql.append(whereClause);
   if (orderClause != null) sql.append(" ").append(orderClause);
   PreparedStatement pstmt = null;
   try {
     pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
     pstmt.setInt(1, getC_Remesa_ID());
     ResultSet rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MRemesaLine(getCtx(), rs));
     rs.close();
     pstmt.close();
     pstmt = null;
   } catch (Exception e) {
     log.saveError("getLines - " + sql, e);
   } finally {
     try {
       if (pstmt != null) pstmt.close();
     } catch (Exception e) {
     }
     pstmt = null;
   }
   //
   MRemesaLine[] lines = new MRemesaLine[list.size()];
   list.toArray(lines);
   return lines;
 } //	getLines
Example #17
0
  public static ArrayList<String> getPasser_zone(String zone) throws SQLException {
    ArrayList<String> passerArray = new ArrayList<String>();
    Connection conn = DBConn.GetConnection();
    PreparedStatement st =
        conn.prepareStatement(
            "SELECT * FROM cs_conversion LEFT JOIN cs_user ON cs_user.username=cs_conversion.username WHERE cs_conversion.isstart=? AND cs_user.zone=? ");
    st.setInt(1, 0);
    st.setString(2, zone);

    ResultSet rs = st.executeQuery();
    while (rs.next()) {
      if (rs.getString("username").length() != 0) {
        if (passerArray.size() == 0) {
          passerArray.add(rs.getString("username"));
        } else {
          if (!passerArray.contains(rs.getString("username"))) {
            passerArray.add(rs.getString("username"));
          }
        }
      }
    }
    rs.close();
    st.close();
    conn.close();
    return passerArray;
  }
 public ArrayList<Empleado> listarEmpleado() {
   ArrayList<Empleado> emple = new ArrayList<Empleado>();
   try {
     cn = Conexion.realizarConexion();
     st = cn.createStatement();
     String sql = "select * from empleado";
     rs = st.executeQuery(sql);
     while (rs.next()) {
       emple.add(
           new Empleado(
               rs.getString(1),
               rs.getString(2),
               rs.getString(3),
               rs.getString(4),
               rs.getString(5),
               rs.getString(6),
               rs.getString(7),
               rs.getString(8)));
     }
   } catch (ClassNotFoundException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } catch (SQLException ex) {
     showMessageDialog(null, ex.getMessage(), "Excepción", 0);
   } finally {
     try {
       rs.close();
       st.close();
       cn.close();
     } catch (Exception ex) {
       showMessageDialog(null, ex.getMessage(), "Excepción", 0);
     }
   }
   return emple;
 }
 // 根据用户的id,获得用户的所有电影
 public ArrayList<MovieInfo> getMovieByUserId(long userID) {
   ArrayList<MovieInfo> movieList = new ArrayList<MovieInfo>();
   try {
     String sql =
         "select m.name,m.published_year,m.type,mp.preference from movie_preferences mp,movies m where mp.movieID=m.id and mp.userID="
             + userID
             + " order by preference desc";
     conn = ConnectToMySQL.getConnection();
     ps = conn.prepareStatement(sql);
     rs = ps.executeQuery();
     while (rs.next()) {
       MovieInfo movieInfo = new MovieInfo();
       movieInfo.setName(rs.getString(1));
       movieInfo.setPublishedYear(rs.getString(2));
       movieInfo.setType(rs.getString(3));
       movieInfo.setPreference(rs.getInt(4));
       movieList.add(movieInfo);
     }
   } catch (Exception e) {
     // TODO: handle exception
     e.printStackTrace();
   } finally {
     closeAll();
   }
   return movieList;
 }
Example #20
0
 /**
  * Get Restriction Lines
  *
  * @param reload reload data
  * @return array of lines
  */
 public MGoalRestriction[] getRestrictions(boolean reload) {
   if (m_restrictions != null && !reload) return m_restrictions;
   ArrayList<MGoalRestriction> list = new ArrayList<MGoalRestriction>();
   //
   String sql =
       "SELECT * FROM PA_GoalRestriction "
           + "WHERE PA_Goal_ID=? AND IsActive='Y' "
           + "ORDER BY Org_ID, C_BPartner_ID, M_Product_ID";
   PreparedStatement pstmt = null;
   ResultSet rs = null;
   try {
     pstmt = DB.prepareStatement(sql, get_Trx());
     pstmt.setInt(1, getPA_Goal_ID());
     rs = pstmt.executeQuery();
     while (rs.next()) list.add(new MGoalRestriction(getCtx(), rs, get_Trx()));
   } catch (Exception e) {
     log.log(Level.SEVERE, sql, e);
   } finally {
     DB.closeStatement(pstmt);
     DB.closeResultSet(rs);
   }
   //
   m_restrictions = new MGoalRestriction[list.size()];
   list.toArray(m_restrictions);
   return m_restrictions;
 } //	getRestrictions
  private double[] getSparkModelInfoFromHDFS(Path location, Configuration conf) throws Exception {

    FileSystem fileSystem = FileSystem.get(location.toUri(), conf);
    FileStatus[] files = fileSystem.listStatus(location);

    if (files == null) throw new Exception("Couldn't find Spark Truck ML weights at: " + location);

    ArrayList<Double> modelInfo = new ArrayList<Double>();
    for (FileStatus file : files) {

      if (file.getPath().getName().startsWith("_")) {
        continue;
      }

      InputStream stream = fileSystem.open(file.getPath());

      StringWriter writer = new StringWriter();
      IOUtils.copy(stream, writer, "UTF-8");
      String raw = writer.toString();
      for (String str : raw.split("\n")) {
        modelInfo.add(Double.valueOf(str));
      }
    }

    return Doubles.toArray(modelInfo);
  }
 public void close() throws SQLException {
   Iterator<Connection> it = pool.iterator();
   while (it.hasNext()) {
     Connection conn = it.next();
     conn.close();
   }
   pool.clear();
 }
Example #23
0
 /**
  * Returnerar en lista över namnen på användarens kortsamlingar.
  *
  * @return stränglista innehållande namnen på användarens kortsamlingar
  */
 @Override
 public ArrayList<String> getUserCollections() {
   ArrayList<String> userTables = new ArrayList<String>();
   for (CardCollection cc : cardCollections) {
     userTables.add(cc.getCollectionName()); // lägg till samling i namnlista
   }
   return userTables; // return namnlista över kortsamlingar
 }
Example #24
0
 /**
  * 事实表和关联报表属于当前传入数组的交叉报表
  *
  * @param request
  * @return elements are ArrayList, first is cxtab id, second is cxtab name
  */
 public List getCxtabs(HttpServletRequest request, int tableCategoryId) {
   List tables = getChildrenOfTableCategory(request, tableCategoryId, false);
   ArrayList<Integer> al = new ArrayList();
   for (int i = 0; i < tables.size(); i++) {
     al.add(((Table) tables.get(i)).getId());
   }
   return getCxtabs(request, al);
 }
Example #25
0
  /**
   * @param request
   * @param tableCategoryId
   * @paqram includeAction if true, will load webactions also
   * @return elements are Table or WebAction
   */
  public List getChildrenOfTableCategory(
      HttpServletRequest request, int tableCategoryId, boolean includeAction) {
    TableManager manager = TableManager.getInstance();

    WebAction action;
    ArrayList cats = new ArrayList();
    Connection conn = null;
    HashMap webActionEnv = null;
    Table table;
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));

    TableCategory tc = manager.getTableCategory(tableCategoryId);
    List children = tc.children();
    ArrayList catschild = new ArrayList();
    try {
      if (includeAction) {
        conn = QueryEngine.getInstance().getConnection();
        webActionEnv = new HashMap();
        webActionEnv.put("connection", conn);
        webActionEnv.put("httpservletrequest", request);
        webActionEnv.put("userweb", userWeb);
      }
      for (int j = 0; j < children.size(); j++) {
        if (children.get(j) instanceof Table) {
          table = (Table) children.get(j);
          if (!table.isMenuObject()) {
            continue;
          }
          try {
            WebUtils.checkTableQueryPermission(table.getName(), request);
          } catch (NDSSecurityException e) {
            continue;
          }
          // table is ok for current user to list
          catschild.add(table);
        } else if (children.get(j) instanceof WebAction) {
          if (includeAction) {
            action = (WebAction) children.get(j);
            if (action.canDisplay(webActionEnv)) catschild.add(action);
          }
        } else {
          throw new NDSRuntimeException(
              "Unsupported element in TableCategory children:" + children.get(j).getClass());
        }
      }
    } catch (Throwable t) {
      logger.error("Fail to load subsystem tree", t);
    } finally {
      try {
        if (conn != null) conn.close();
      } catch (Throwable e) {
      }
    }
    return catschild;
  }
Example #26
0
 public static ArrayList<String> getListOfSensors(String envelope) throws ParseException {
   Geometry geom = new WKTReader().read(envelope);
   List listEnvelope = geoIndex.query(geom.getEnvelopeInternal());
   ArrayList<String> sensors = new ArrayList<String>();
   for (int i = 0; i < listEnvelope.size(); i++) {
     sensors.add(searchForSensors_String((Point) listEnvelope.get(i)));
   }
   return sensors;
 }
 public void closeConnection(Connection conn) throws SQLException {
   synchronized (pool) {
     if (pool.size() < pool_size) {
       pool.add(conn);
       return;
     }
   }
   conn.close();
 }
Example #28
0
  /**
   * Get viewable subsystem list
   *
   * @param request
   * @return never null, elements are nds.schema.SubSystem
   */
  public List getSubSystems(HttpServletRequest request) {
    UserWebImpl userWeb =
        ((UserWebImpl)
            WebUtils.getSessionContextManager(request.getSession())
                .getActor(nds.util.WebKeys.USER));
    ArrayList subs = new ArrayList();
    if (userWeb.getUserId() == userWeb.GUEST_ID) {
      return subs;
    }
    List al = (List) userWeb.getProperty("subsystems"); // elements are subystem.id
    TableManager manager = TableManager.getInstance();
    if (al != null) {

      for (int i = 0; i < al.size(); i++) {
        int sid = ((Integer) al.get(i)).intValue();
        SubSystem ss = manager.getSubSystem(sid);
        if (ss != null) subs.add(ss);
      }
    } else {
      // search all tablecategoris for subsystem
      // add users subsystems param
      al = new ArrayList();
      String[] sub_list;
      try {
        String subsystems =
            (String)
                QueryEngine.getInstance()
                    .doQueryOne("SELECT subsystems from users where id=" + userWeb.getUserId());
        if (Validator.isNotNull(subsystems)) {
          sub_list = subsystems.split(",");
          for (int m = 0; m < sub_list.length; m++) {
            SubSystem usersub = manager.getSubSystem(sub_list[m].trim());

            if (usersub != null) {
              if (usersub.getId() == 10) continue;
              al.add(new Integer(usersub.getId()));
              subs.add(usersub);
            }
          }
          userWeb.setProperty("subsystems", al);
          return subs;
        }
      } catch (QueryException e) {
        logger.error("Fail to load subsystems from users", e);
      }

      for (int i = 0; i < manager.getSubSystems().size(); i++) {
        SubSystem ss = (SubSystem) manager.getSubSystems().get(i);
        if (containsViewableChildren(request, ss)) {
          al.add(new Integer(ss.getId()));
          subs.add(ss);
        }
      }
      userWeb.setProperty("subsystems", al);
    }
    return subs;
  }
Example #29
0
 private static ArrayList<PairInfo> getPairListFromStr(String str) {
   String[] nodes = str.split(":");
   ArrayList<PairInfo> pairList = new ArrayList<PairInfo>();
   for (int i = 0; i < nodes.length; i++) {
     PairInfo pair = getPairFromStr(nodes[i]);
     pairList.add(pair);
   }
   return pairList;
 }
Example #30
-8
 public ArrayList getSelectedMessages() {
   ArrayList list = new ArrayList();
   for (int i = 0; i < table.getRowCount(); i++) {
     if (((Boolean) table.getValueAt(i, 0)) == true) {
       list.add(msgID[i]);
     }
   }
   return list;
 }