Package ru.vassaev.core.exception

Examples of ru.vassaev.core.exception.SysException


    private boolean isClose = true;

    public synchronized void prepare(String query)
            throws SysException {
        if (!isClose) {
            throw new SysException("The statement is not closed");
        }
        int i = 0;
        int l = query.length();
        StringBuffer sql = new StringBuffer();
        int c = 0;
        int len = 0;
        while (i < l) {
            int j = query.indexOf(idf, i);
            if (j >= 0) {
                sql.append(query.substring(i, j));
                i = j + idf.length();
                len = Strings.chooseIdentifier(query, i);
                if (len > 0) {
                    i += len;
                    String name = query.substring(i - len, i);

                    ParamInfo pi = prmsh.get(name);
                    if (pi == null) {
                        pi = new ParamInfo();
                        pi.NAME = name;
                        prmsh.put(name, pi);
                    }
                    c++;
                    pi.links.add(new Integer(c));
                    prmsi.add(pi);
                    sql.append('?');
                } else {
                    sql.append(idf);
                }
            } else {
                sql.append(query.substring(i));
                i = l;
            }
        }
        this.sql = sql.toString();
        try {
            st = con.prepareStatement(this.sql);
        } catch (SQLException ex1) {
            throw new SysException(ex1);
        }
        try {
            prms = tp.getParams(st);
        } catch (Throwable ex) {
            prms = new RsParam[prmsi.size()];
View Full Code Here


  public R takeResponseWithWait(String key, long timeout, long th, ITaskAPI ta, long id_processor) throws SysException {
    Q q;
    synchronized (qt) {
      q = qt.get(key);
      if (q == null)
        throw new SysException("There is no query for this response");
    }
    R r = null;
    try {
      long to = timeout / 10;
      long from = System.currentTimeMillis();
      Date dt_to = new Date(System.currentTimeMillis() + timeout);
      //long from = System.currentTimeMillis();
      synchronized (q) {
        ta.log(id_processor, th, "from = " + new Date(from) + " - " + key);
        ta.log(id_processor, th, "from + timeout = " + new Date(from + timeout) + " - " + key);
        //from + timeout > System.currentTimeMillis()
        synchronized (rt) {
          r = rt.remove(key);
          if (r != null) {
            ta.log(id_processor, th, "-----0-----" + key + " - " + new Date());
            return r;
          }
        }
        while (dt_to.after(new Date())) {
          try {
            q.wait(to);
            ta.log(id_processor, th, "-----3-----" + key + " - " + new Date());
          } catch (InterruptedException ex) {
            throw new SysException(ex);
          }
          if (qt.get(key) == null) {
            ta.log(id_processor, th, "-----1-----" + key + " - " + new Date());
            return null;
          }
View Full Code Here

        try {
            st.clearBatch();
            st.clearWarnings();
            st.clearParameters();
        } catch (SQLException ex) {
            throw new SysException(ex);
        }
    }
View Full Code Here

    public void close() throws SysException {
        try {
            st.close();
        } catch (SQLException ex) {
            throw new SysException(ex);
        }
        isClose = true;
    }
View Full Code Here

    try {
      st.clearBatch();
      st.clearWarnings();
      st.clearParameters();
    } catch (SQLException ex) {
      throw new SysException(ex);
    }
  }
View Full Code Here

  protected Map<String, ParamInfo> prmsh = new TreeMap<String, ParamInfo>();

  public synchronized void prepare(String alias, String query)
          throws SysException {
    if (this.alias != null)
      throw new SysException("The statement is not closed");
    if (alias == null)
      throw new SysException("The database's alias can't be null");
    int i = 0;
    int l = query.length();
    StringBuffer sql = new StringBuffer();
    int c = 0;
    int len;
    while (i  < l) {
      int j = query.indexOf(idf, i);
      if (j >= 0) {
        sql.append(query.substring(i, j));
        i = j + idf.length();
        len = Strings.chooseIdentifier(query, i);
        if (len > 0) {
          i += len;
          String name = query.substring(i - len, i);

          ParamInfo pi = prmsh.get(name);
          if (pi == null) {
            pi = new StatementNew.ParamInfo();
            pi.NAME = name;
            prmsh.put(name, pi);
          }
          c++;
          pi.links.add(c);
          prmsi.add(pi);
          sql.append('?');
        } else {
          sql.append(idf);
        }
      } else {
        sql.append(query.substring(i));
        i = l;
      }
    }
    this.sql = sql.toString();
    Connection con = null;
    try {
      con = Manager.getConnection(alias);
      tp = Manager.getTypes(con);
      PreparedStatement st = null;
      try {
        st = con.prepareStatement(this.sql);
        try {
          prms = tp.getParams(st);
        } catch (Throwable ex) {
          prms = new RsParam[prmsi.size()];
        }
      } catch (SQLException ex) {
        throw new SysException(ex);
      } finally {
        if (st != null)
          try {
            st.close();
          } catch (SQLException e) {
View Full Code Here

          }
  }
  public CallableStatement getCallStatement(Connection con) throws SysException {
    try {
      if (!alias.equals(Manager.getAlias(con)))
        throw new SysException("The connection is had another alias : "
                               + alias + " != " + Manager.getAlias(con));
      CallableStatement st = (CallableStatement)con_st.get(con);
      if (st == null) {
          st = con.prepareCall(sql);
          con_st.put(con, st);
        }
      for (int p = prmsi.size() - 1; p >= 0; p--) {
        ParamInfo pi = prmsi.get(p);
        for (int i = pi.links.size() - 1; i >= 0; i--) {
          int j = pi.links.get(i);
          if (pi.value == null) {
//                        st.setNull(j, (pi.prm == null) ? pi.type : pi.type);
          } else {
            st.setObject(j, pi.value, pi.type);
          }
        }
      }
      stmts.add(st);
      return st;
    } catch (SQLException ex) {
      throw new SysException(ex);
    }
  }
View Full Code Here

  }

  public PreparedStatement getStatement(Connection con) throws SysException {
    try {
      if (!alias.equals(Manager.getAlias(con)))
        throw new SysException("The connection is had another alias : "
                               + alias + " != " + Manager.getAlias(con));
      PreparedStatement st = con_st.get(con);
      if (st == null)
        synchronized (con) {
          st = con.prepareStatement(sql);
          con_st.put(con, st);
        }
      for (int p = prmsi.size() - 1; p >= 0; p--) {
        ParamInfo pi = prmsi.get(p);
        for (int i = pi.links.size() - 1; i >= 0; i--) {
          int j = pi.links.get(i);
          if (pi.value == null) {
//                        st.setNull(j, (pi.prm == null) ? pi.type : pi.type);
          } else {
            st.setObject(j, pi.value, pi.type);
          }
        }
      }
      stmts.add(st);
      return st;
    } catch (SQLException ex) {
      throw new SysException(ex);
    }
  }
View Full Code Here

        } catch (SQLException e) {
          e.printStackTrace();
        }
      while (st.getMoreResults());
    } catch (SQLException e) {
      throw new SysException(e);
    }
  }
View Full Code Here

              st.setObject(j, value);
          }
        }
      }
    } catch (SQLException e) {
      throw new SysException(e);
    }
  }
View Full Code Here

TOP

Related Classes of ru.vassaev.core.exception.SysException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.