Java Code Examples for org.hsqldb.jdbc.JDBCBlob

The following examples show how to use org.hsqldb.jdbc.JDBCBlob. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: olingo-odata2   Source File: BlobToByteConverter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Blob convertToEntityAttribute(final byte[] arg0) {
  try {
    if (arg0 == null) {
      return null;
    }
    return new JDBCBlob(arg0);
  } catch (SQLException e) {
    e.printStackTrace();
  }
  return null;
}
 
Example 2
Source Project: zap-extensions   Source File: TableWebSocket.java    License: Apache License 2.0 4 votes vote down vote up
public void insertMessage(WebSocketMessageDTO message) throws DatabaseException {
    try {
        // synchronize on whole object to avoid race conditions with insertOrUpdateChannel()
        synchronized (this) {
            if (getConnection().isClosed()) {
                // temporarily buffer messages and write them the next time
                messagesBuffer.offer(message);
                return;
            }

            do {
                if (!channelIds.contains(message.channel.id)) {
                    // maybe channel is buffered
                    if (channelsBuffer.size() > 0) {
                        insertOrUpdateChannel(channelsBuffer.poll());
                    }
                    throw new SQLException("channel not inserted: " + message.channel.id);
                }

                if (logger.isDebugEnabled()) {
                    logger.debug("insert message: " + message.toString());
                }

                psInsertMessage.setInt(1, message.id);
                psInsertMessage.setInt(2, message.channel.id);
                psInsertMessage.setTimestamp(3, new Timestamp(message.timestamp));
                psInsertMessage.setInt(4, message.opcode);

                // write payload
                if (message.payload instanceof String) {
                    psInsertMessage.setClob(5, new JDBCClob((String) message.payload));
                    psInsertMessage.setNull(6, Types.BLOB);
                } else if (message.payload instanceof byte[]) {
                    psInsertMessage.setNull(5, Types.CLOB);
                    psInsertMessage.setBlob(6, new JDBCBlob((byte[]) message.payload));
                } else {
                    throw new SQLException(
                            "Attribute 'payload' of class WebSocketMessageDTO has got wrong type!");
                }

                psInsertMessage.setInt(7, message.payloadLength);
                psInsertMessage.setBoolean(8, message.isOutgoing);
                psInsertMessage.execute();

                if (message instanceof WebSocketFuzzMessageDTO) {
                    WebSocketFuzzMessageDTO fuzzMessage = (WebSocketFuzzMessageDTO) message;
                    psInsertFuzz.setInt(1, fuzzMessage.fuzzId);
                    psInsertFuzz.setInt(2, fuzzMessage.id);
                    psInsertFuzz.setInt(3, fuzzMessage.channel.id);
                    psInsertFuzz.setString(4, fuzzMessage.state.toString());
                    psInsertFuzz.setString(5, fuzzMessage.fuzz);
                    psInsertFuzz.execute();
                }

                message = messagesBuffer.poll();
            } while (message != null);
        }
    } catch (SQLException e) {
        throw new DatabaseException(e);
    }
}