Java Code Examples for org.hsqldb.jdbc.JDBCClob

The following examples show how to use org.hsqldb.jdbc.JDBCClob. 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: zap-extensions   Source File: MessageTable.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void insert(ClientMessage cmsg) throws SQLException {
    psInsert.setTimestamp(1, new Timestamp(cmsg.getReceived().getTime()));
    psInsert.setString(2, cmsg.getClientId());
    psInsert.setInt(3, cmsg.getState().ordinal());
    psInsert.setClob(4, new JDBCClob(cmsg.getJson().toString()));
    psInsert.setBoolean(5, cmsg.isChanged());

    psInsert.executeUpdate();

    ResultSet rs = psGetIdLastInsert.executeQuery();
    rs.next();
    cmsg.setIndex(rs.getLong(1));
    rs.close();
}
 
Example 2
Source Project: zap-extensions   Source File: MessageTable.java    License: Apache License 2.0 5 votes vote down vote up
public synchronized void update(ClientMessage cmsg) throws SQLException {
    psUpdate.setClob(1, new JDBCClob(cmsg.getJson().toString()));
    psUpdate.setInt(2, cmsg.getState().ordinal());
    psUpdate.setLong(3, cmsg.getIndex());

    psUpdate.executeUpdate();
}
 
Example 3
Source Project: olingo-odata2   Source File: OnDBWriteContent.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Clob getJPAClob(final char[] characterData) throws ODataJPARuntimeException {
  try {
    return new JDBCClob(new String(characterData));
  } catch (SQLException e) {
    ODataJPARuntimeException.throwException(ODataJPARuntimeException.INNER_EXCEPTION, e);
  }
  return null;
}
 
Example 4
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);
    }
}
 
Example 5
Source Project: zap-extensions   Source File: TableEventStream.java    License: Apache License 2.0 4 votes vote down vote up
public void insertEvent(ServerSentEvent event) throws DatabaseException {
    // synchronize on whole object to avoid race conditions with insertOrUpdateStreams()
    synchronized (this) {
        try {
            if (getConnection().isClosed()) {
                // temporarily buffer events and write them the next time
                eventBuffer.offer(event);
                return;
            }

            do {
                while (!streamIds.contains(event.getStreamId())) {
                    // maybe stream is buffered
                    if (streamBuffer.size() > 0) {
                        insertOrUpdateStream(streamBuffer.poll());
                        continue;
                    }
                    throw new DatabaseException("stream not inserted: " + event.getStreamId());
                }

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

                psInsertEvent.setInt(1, event.getId());
                psInsertEvent.setInt(2, event.getStreamId());
                psInsertEvent.setTimestamp(3, new Timestamp(event.getTimestamp()));
                psInsertEvent.setString(4, event.getLastEventId());
                psInsertEvent.setClob(5, new JDBCClob(event.getData()));
                psInsertEvent.setString(6, event.getEventType());

                Integer time;
                if ((time = event.getReconnectionTime()) == null) {
                    psInsertEvent.setNull(7, java.sql.Types.INTEGER);
                } else {
                    psInsertEvent.setInt(7, time);
                }
                psInsertEvent.setClob(8, new JDBCClob(event.getRawEvent()));
                psInsertEvent.execute();

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