コード例 #1
0
  @Override
  public ResultMessage updateOrderPO(OrderPO order) throws RemoteException {
    // TODO Auto-generated method stub
    String sql =
        "update orderpo set receivetime='"
            + order.getReceivetime()
            + "', timeOfsend='"
            + order.getTimeOfSend()
            + "', dueOfReceive='"
            + order.getDueOfReceive()
            + "', nameOfCourier='"
            + order.getNameOfCourier()
            + "', DocumentCondition='"
            + order.getdCondition()
            + ", Receiver=?,sender=?,bill=?,goods=? where orderNumber='"
            + order.getOrdernumber()
            + "';";

    try {
      Helper.pStatement = Helper.conn.prepareStatement(sql);
      Helper.pStatement.setObject(1, IOObject.toByteArray(order.getReceiver()));
      Helper.pStatement.setObject(2, IOObject.toByteArray(order.getSender()));
      Helper.pStatement.setObject(3, IOObject.toByteArray(order.getBill()));
      Helper.pStatement.setObject(4, IOObject.toByteArray(order.getGoods()));
      Helper.pStatement.executeUpdate();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return ResultMessage.FAIL;
    }

    return ResultMessage.SUCCESS;
  }
コード例 #2
0
  @Override
  public ResultMessage insertOrderPO(OrderPO order) {
    // TODO Auto-generated method stub
    String sql =
        "insert into orderpo values(?,?,?,?,'"
            + order.getTimeOfSend()
            + "','"
            + order.getDueOfReceive()
            + "','"
            + order.getOrdernumber()
            + "','"
            + order.getNameOfCourier()
            + "','"
            + order.getReceivetime()
            + "','"
            + order.getdCondition()
            + "');";
    try {
      Helper.pStatement = Helper.conn.prepareStatement(sql);
      Helper.pStatement.setObject(1, IOObject.toByteArray(order.getReceiver()));
      Helper.pStatement.setObject(2, IOObject.toByteArray(order.getSender()));
      Helper.pStatement.setObject(3, IOObject.toByteArray(order.getBill()));
      Helper.pStatement.setObject(4, IOObject.toByteArray(order.getGoods()));
      Helper.pStatement.executeUpdate();
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return ResultMessage.FAIL;
    }

    return ResultMessage.SUCCESS;
  }
コード例 #3
0
  @Override
  public ArrayList<OrderPO> findWithdCondition(String nameOfCourier, DocumentCondition dCondition)
      throws RemoteException {
    // TODO Auto-generated method stub
    String sql =
        "select* from orderpo where documentcondition='"
            + dCondition
            + "' and nameofcourier='"
            + nameOfCourier
            + "';";
    ResultSet result = null;
    OrderPO po = null;
    ArrayList<OrderPO> pos = new ArrayList<OrderPO>();
    ReceiverPO receiver = null;
    SenderPO sender = null;
    BillPO bill = null;
    GoodsPO goods = null;

    try {
      result = Helper.find(sql);
      while (result.next()) {

        try {
          // ObjectInputStream oips = new ObjectInputStream(result.getBinaryStream("receiver"));
          receiver = (ReceiverPO) IOObject.getArray(result.getBytes("receiver"));
          // oips = new ObjectInputStream(result.getBinaryStream("sender"));
          sender = (SenderPO) IOObject.getArray(result.getBytes("sender"));
          // oips = new ObjectInputStream(result.getBinaryStream("bill"));
          bill = (BillPO) IOObject.getArray(result.getBytes("bill"));
          // oips = new ObjectInputStream(result.getBinaryStream("goods"));
          goods = (GoodsPO) IOObject.getArray(result.getBytes("goods"));
        } catch (Exception e) {
          // TODO: handle exception
          e.printStackTrace();
        }

        po =
            new OrderPO(
                receiver,
                sender,
                bill,
                goods,
                result.getString(5),
                result.getString(6),
                result.getString(7),
                result.getString(8),
                result.getString(9),
                DocumentCondition.valueOf(result.getString(10)));
        pos.add(po);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return pos;
  }
コード例 #4
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  @Override
  public void in_event() {

    //  If still handshaking, receive and process the greeting message.
    if (handshaking) if (!handshake()) return;

    assert (decoder != null);
    boolean disconnection = false;

    //  If there's no data to process in the buffer...
    if (insize == 0) {

      //  Retrieve the buffer and read as much data as possible.
      //  Note that buffer can be arbitrarily large. However, we assume
      //  the underlying TCP layer has fixed buffer size and thus the
      //  number of bytes read will be always limited.
      inbuf = decoder.get_buffer();
      insize = read(inbuf);
      inbuf.flip();

      //  Check whether the peer has closed the connection.
      if (insize == -1) {
        insize = 0;
        disconnection = true;
      }
    }

    //  Push the data to the decoder.
    int processed = decoder.process_buffer(inbuf, insize);

    if (processed == -1) {
      disconnection = true;
    } else {

      //  Stop polling for input if we got stuck.
      if (processed < insize) io_object.reset_pollin(handle);

      //  Adjust the buffer.
      insize -= processed;
    }

    //  Flush all messages the decoder may have produced.
    session.flush();

    //  An input error has occurred. If the last decoded message
    //  has already been accepted, we terminate the engine immediately.
    //  Otherwise, we stop waiting for socket events and postpone
    //  the termination until after the message is accepted.
    if (disconnection) {
      if (decoder.stalled()) {
        io_object.rm_fd(handle);
        io_enabled = false;
      } else error();
    }
  }
コード例 #5
0
 @Override
 public ResultMessage insertReceiptsPO(ReceiptsPO receipts) {
   // TODO Auto-generated method stub
   String sql =
       "insert into receiptspo values('"
           + receipts.getDate()
           + "',"
           + receipts.getFee()
           + ",'"
           + receipts.getCourier()
           + "',?,'"
           + receipts.getOffice()
           + "','"
           + receipts.getdCondition()
           + "');";
   try {
     Helper.pStatement = Helper.conn.prepareStatement(sql);
     Helper.pStatement.setObject(1, IOObject.toByteArray(receipts.getOrdernumbers()));
     Helper.pStatement.executeUpdate();
   } catch (Exception e) {
     e.printStackTrace();
     return ResultMessage.FAIL;
   }
   return ResultMessage.SUCCESS;
 }
コード例 #6
0
  @Override
  public ReceiptsPO findReceipt(String date, String courier) throws RemoteException {
    // TODO Auto-generated method stub
    String sql = "select*from receiptspo where data='" + date + "' and courier='" + courier + "';";
    ReceiptsPO receiptsPO = null;
    ResultSet resultSet = null;

    try {
      resultSet = Helper.find(sql);
      while (resultSet.next()) {
        ArrayList<String> orderNumber =
            (ArrayList<String>) IOObject.getArray(resultSet.getBytes("orderNumber"));
        receiptsPO =
            new ReceiptsPO(
                resultSet.getString(1),
                resultSet.getDouble(2),
                resultSet.getString(3),
                orderNumber,
                resultSet.getString(5),
                DocumentCondition.valueOf(resultSet.getString(6)));
      }

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // TODO Auto-generated method stub
    return receiptsPO;
  }
コード例 #7
0
  @Override
  public ArrayList<ReceiptsPO> findReceipts(String date, String office) throws RemoteException {
    String sql = "select*from receiptspo where data='" + date + "' and office='" + office + "';";
    ArrayList<ReceiptsPO> receiptsPOs = new ArrayList<ReceiptsPO>();
    ResultSet resultSet = null;

    try {
      resultSet = Helper.find(sql);
      while (resultSet.next()) {
        ArrayList<String> orderNumber =
            (ArrayList<String>) IOObject.getArray(resultSet.getBytes("ordernumbers"));
        ReceiptsPO po =
            new ReceiptsPO(
                resultSet.getString(1),
                resultSet.getDouble(2),
                resultSet.getString(3),
                orderNumber,
                resultSet.getString(5),
                DocumentCondition.valueOf(resultSet.getString(6)));
        receiptsPOs.add(po);
      }

    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // TODO Auto-generated method stub
    return receiptsPOs;
  }
コード例 #8
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  @Override
  public void activate_in() {
    if (!io_enabled) {
      //  There was an input error but the engine could not
      //  be terminated (due to the stalled decoder).
      //  Flush the pending message and terminate the engine now.
      decoder.process_buffer(inbuf, 0);
      assert (!decoder.stalled());
      session.flush();
      error();
      return;
    }

    io_object.set_pollin(handle);

    //  Speculative read.
    io_object.in_event();
  }
コード例 #9
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  private void unplug() {
    assert (plugged);
    plugged = false;

    //  Cancel all fd subscriptions.
    if (io_enabled) {
      io_object.rm_fd(handle);
      io_enabled = false;
    }

    //  Disconnect from I/O threads poller object.
    io_object.unplug();

    //  Disconnect from session object.
    if (encoder != null) encoder.set_msg_source(null);
    if (decoder != null) decoder.set_msg_sink(null);
    session = null;
  }
コード例 #10
0
 @Override
 public String toString() {
   StringBuffer result =
       new StringBuffer(
           "IOContainer (" + ioObjects.size() + " objects):" + Tools.getLineSeparator());
   Iterator i = ioObjects.iterator();
   while (i.hasNext()) {
     IOObject current = (IOObject) i.next();
     if (current != null) {
       result.append(
           current.toString()
               + Tools.getLineSeparator()
               + (current.getSource() != null
                   ? "(created by " + current.getSource() + ")" + Tools.getLineSeparator()
                   : ""));
     }
   }
   return result.toString();
 }
コード例 #11
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  @Override
  public void activate_out() {
    io_object.set_pollout(handle);

    //  Speculative write: The assumption is that at the moment new message
    //  was sent by the user the socket is probably available for writing.
    //  Thus we try to write the data to socket avoiding polling for POLLOUT.
    //  Consequently, the latency should be better in request/reply scenarios.
    out_event();
  }
コード例 #12
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  public void plug(IOThread io_thread_, SessionBase session_) {
    assert (!plugged);
    plugged = true;

    //  Connect to session object.
    assert (session == null);
    assert (session_ != null);
    session = session_;
    socket = session.get_soket();

    io_object = new IOObject(null);
    io_object.set_handler(this);
    //  Connect to I/O threads poller object.
    io_object.plug(io_thread_);
    io_object.add_fd(handle);
    io_enabled = true;

    //  Send the 'length' and 'flags' fields of the identity message.
    //  The 'length' field is encoded in the long format.
    greeting_output_buffer.put((byte) 0xff);
    greeting_output_buffer.putLong(options.identity_size + 1);
    greeting_output_buffer.put((byte) 0x7f);

    io_object.set_pollin(handle);
    //  When there's a raw custom encoder, we don't send 10 bytes frame
    boolean custom = false;
    try {
      custom = options.encoder != null && options.encoder.getDeclaredField("RAW_ENCODER") != null;
    } catch (SecurityException e) {
    } catch (NoSuchFieldException e) {
    }

    if (!custom) {
      outsize = greeting_output_buffer.position();
      outbuf = new Transfer.ByteBufferTransfer((ByteBuffer) greeting_output_buffer.flip());
      io_object.set_pollout(handle);
    }

    //  Flush all the data that may have been already received downstream.
    in_event();
  }
コード例 #13
0
  @Override
  public ArrayList<OrderPO> findReceived() throws RemoteException {
    // TODO Auto-generated method stub
    String sql = "select*from orderpo where receivetime != 'null';";
    ArrayList<OrderPO> orderPOs = new ArrayList<OrderPO>();
    ResultSet result = null;
    ReceiverPO receiver = null;
    SenderPO sender = null;
    BillPO bill = null;
    GoodsPO goods = null;

    try {
      result = Helper.find(sql);
      while (result.next()) {
        receiver = (ReceiverPO) IOObject.getArray(result.getBytes("receiver"));
        // oips = new ObjectInputStream(result.getBinaryStream("sender"));
        sender = (SenderPO) IOObject.getArray(result.getBytes("sender"));
        // oips = new ObjectInputStream(result.getBinaryStream("bill"));
        bill = (BillPO) IOObject.getArray(result.getBytes("bill"));
        // oips = new ObjectInputStream(result.getBinaryStream("goods"));
        goods = (GoodsPO) IOObject.getArray(result.getBytes("goods"));
        OrderPO po =
            new OrderPO(
                receiver,
                sender,
                bill,
                goods,
                result.getString(5),
                result.getString(6),
                result.getString(7),
                result.getString(8),
                result.getString(9),
                DocumentCondition.valueOf(result.getString(10)));
        orderPOs.add(po);
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return orderPOs;
  }
コード例 #14
0
  @Override
  public OrderPO findLatest() throws RemoteException {
    // TODO Auto-generated method stub

    String sql = "select * from orderpo order by ordernumber desc;";
    OrderPO po = null;
    ResultSet result = null;
    ReceiverPO receiver = null;
    SenderPO sender = null;
    BillPO bill = null;
    GoodsPO goods = null;

    try {
      result = Helper.find(sql);
      if (result.next()) {
        receiver = (ReceiverPO) IOObject.getArray(result.getBytes("receiver"));
        // oips = new ObjectInputStream(result.getBinaryStream("sender"));
        sender = (SenderPO) IOObject.getArray(result.getBytes("sender"));
        // oips = new ObjectInputStream(result.getBinaryStream("bill"));
        bill = (BillPO) IOObject.getArray(result.getBytes("bill"));
        // oips = new ObjectInputStream(result.getBinaryStream("goods"));
        goods = (GoodsPO) IOObject.getArray(result.getBytes("goods"));
        po =
            new OrderPO(
                receiver,
                sender,
                bill,
                goods,
                result.getString(5),
                result.getString(6),
                result.getString(7),
                result.getString(8),
                result.getString(9),
                DocumentCondition.valueOf(result.getString(10)));
      }
    } catch (SQLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return po;
  }
コード例 #15
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  private boolean handshake() {
    assert (handshaking);

    //  Receive the greeting.
    while (greeting.position() < GREETING_SIZE) {
      final int n = read(greeting);
      if (n == -1) {
        error();
        return false;
      }

      if (n == 0) return false;

      //  We have received at least one byte from the peer.
      //  If the first byte is not 0xff, we know that the
      //  peer is using unversioned protocol.
      if (greeting.array()[0] != -1) break;

      if (greeting.position() < 10) continue;
      //  Inspect the right-most bit of the 10th byte (which coincides
      //  with the 'flags' field if a regular message was sent).
      //  Zero indicates this is a header of identity message
      //  (i.e. the peer is using the unversioned protocol).
      if ((greeting.array()[9] & 0x01) == 0) break;

      //  The peer is using versioned protocol.
      //  Send the rest of the greeting, if necessary.
      if (greeting_output_buffer.limit() < GREETING_SIZE) {
        if (outsize == 0) io_object.set_pollout(handle);
        int pos = greeting_output_buffer.position();
        greeting_output_buffer.position(10).limit(GREETING_SIZE);
        greeting_output_buffer.put((byte) 1); // Protocol version
        greeting_output_buffer.put((byte) options.type); // Socket type
        greeting_output_buffer.position(pos);
        outsize += 2;
      }
    }

    //  Position of the version field in the greeting.
    final int version_pos = 10;

    //  Is the peer using the unversioned protocol?
    //  If so, we send and receive rests of identity
    //  messages.
    if (greeting.array()[0] != -1 || (greeting.array()[9] & 0x01) == 0) {
      encoder = new_encoder(Config.out_batch_size.getValue(), null, 0);
      encoder.set_msg_source(session);

      decoder = new_decoder(Config.in_batch_size.getValue(), options.maxmsgsize, null, 0);
      decoder.set_msg_sink(session);

      //  We have already sent the message header.
      //  Since there is no way to tell the encoder to
      //  skip the message header, we simply throw that
      //  header data away.
      final int header_size = options.identity_size + 1 >= 255 ? 10 : 2;
      ByteBuffer tmp = ByteBuffer.allocate(header_size);
      encoder.get_data(tmp);
      assert (tmp.remaining() == header_size);

      //  Make sure the decoder sees the data we have already received.
      inbuf = greeting;
      greeting.flip();
      insize = greeting.remaining();

      //  To allow for interoperability with peers that do not forward
      //  their subscriptions, we inject a phony subsription
      //  message into the incomming message stream. To put this
      //  message right after the identity message, we temporarily
      //  divert the message stream from session to ourselves.
      if (options.type == ZMQ.ZMQ_PUB || options.type == ZMQ.ZMQ_XPUB) decoder.set_msg_sink(this);
    } else if (greeting.array()[version_pos] == 0) {
      //  ZMTP/1.0 framing.
      encoder = new_encoder(Config.out_batch_size.getValue(), null, 0);
      encoder.set_msg_source(session);

      decoder = new_decoder(Config.in_batch_size.getValue(), options.maxmsgsize, null, 0);
      decoder.set_msg_sink(session);
    } else {
      //  v1 framing protocol.
      encoder = new_encoder(Config.out_batch_size.getValue(), session, V1Protocol.VERSION);

      decoder =
          new_decoder(
              Config.in_batch_size.getValue(), options.maxmsgsize, session, V1Protocol.VERSION);
    }
    // Start polling for output if necessary.
    if (outsize == 0) io_object.set_pollout(handle);

    //  Handshaking was successful.
    //  Switch into the normal message flow.
    handshaking = false;

    return true;
  }
コード例 #16
0
ファイル: StreamEngine.java プロジェクト: Gank/jeromq
  @Override
  public void out_event() {
    //  If write buffer is empty, try to read new data from the encoder.
    if (outsize == 0) {

      //  Even when we stop polling as soon as there is no
      //  data to send, the poller may invoke out_event one
      //  more time due to 'speculative write' optimisation.
      if (encoder == null) {
        assert (handshaking);
        return;
      }

      outbuf = encoder.get_data(null);
      outsize = outbuf.remaining();
      //  If there is no data to send, stop polling for output.
      if (outbuf.remaining() == 0) {
        io_object.reset_pollout(handle);

        // when we use custom encoder, we might want to close
        if (encoder.is_error()) {
          error();
        }

        return;
      }
    }

    //  If there are any data to write in write buffer, write as much as
    //  possible to the socket. Note that amount of data to write can be
    //  arbitratily large. However, we assume that underlying TCP layer has
    //  limited transmission buffer and thus the actual number of bytes
    //  written should be reasonably modest.
    int nbytes = write(outbuf);

    //  IO error has occurred. We stop waiting for output events.
    //  The engine is not terminated until we detect input error;
    //  this is necessary to prevent losing incomming messages.
    if (nbytes == -1) {
      io_object.reset_pollout(handle);

      if (terminating) terminate();

      return;
    }

    outsize -= nbytes;

    //  If we are still handshaking and there are no data
    //  to send, stop polling for output.
    if (handshaking) if (outsize == 0) io_object.reset_pollout(handle);

    // when we use custom encoder, we might want to close after sending a response
    if (outsize == 0) {
      if (encoder != null && encoder.is_error()) {
        error();
        return;
      }
      if (terminating) terminate();
    }
  }