Java Code Examples for com.datastax.driver.core.BoundStatement#setBytesUnsafe()

The following examples show how to use com.datastax.driver.core.BoundStatement#setBytesUnsafe() . 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 File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public void insertRanges(final byte[][] ids, final double value) throws DataAccessLayerException {
	/*
	 * insert in CF_RN_SP_O
	 */
	final BoundStatement nspoStatement = _insertNSPOStatement.bind();
	nspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	nspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	nspoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
	nspoStatement.setDouble(3, value);
	_batchStatements.get().add(nspoStatement);

	/*
	 * insert in CF_RN_P_OS
	 */
	final BoundStatement nposStatement = _insertNPOSStatement.bind();
	nposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	nposStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	nposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));
	nposStatement.setDouble(3, value);
	_batchStatements.get().add(nposStatement);
}
 
Example 2
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
@Override
public void insertRanges(final byte[][] ids, final long value) throws DataAccessLayerException {
	/*
	 * insert in: CF_RDT_SP_O
	 */
	// row key: subject + predicate
	final BoundStatement dspoStatement = _insertDSPOStatement.bind();
	dspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	dspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	dspoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
	dspoStatement.setLong(3, value);
	_batchStatements.get().add(dspoStatement);

	/*
	 * insert in: CF_RDT_P_OS
	 */
	final BoundStatement dposStatement = _insertDPOSStatement.bind();
	dposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	dposStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	dposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));
	dposStatement.setLong(3, value);
	_batchStatements.get().add(dposStatement);

}
 
Example 3
Source File: Cassandra2xDefaultMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link BoundStatement} to insert the given key/value pair.
 * @param key The key.
 * @param value The value.
 * @return A BoundStatement to insert the given key/value pair.
 */
private BoundStatement getInsertStatement(final K key, final V value) {
	BoundStatement insertStatement = _insertStatement.bind();
	insertStatement.setBytesUnsafe(0, _keySerializer.serialize(key));
	insertStatement.setBytesUnsafe(1, _valueSerializer.serialize(value));

	return insertStatement;
}
 
Example 4
Source File: Cassandra2xBidirectionalMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(final K key) {
	BoundStatement getValueStatement = _getValueStatement.bind();
	getValueStatement.setBytesUnsafe(0, _keySerializer.serialize(key));

	return _session.execute(getValueStatement).getAvailableWithoutFetching() > 0;
}
 
Example 5
Source File: Cassandra2xBidirectionalMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public V get(final K key) {
	BoundStatement getValueStatement = _getValueStatement.bind();
	getValueStatement.setBytesUnsafe(0, _keySerializer.serialize(key));

	ByteBuffer result = _session.execute(getValueStatement).one().getBytesUnsafe(0);

	if (result != null) {
		return _valueSerializer.deserialize(result);
	} else {
		return null;
	}
}
 
Example 6
Source File: Cassandra2xBidirectionalMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void delete(final K... keys) {
	BatchStatement batchStatement = new BatchStatement();
	
	for (K key : keys) {
		BoundStatement deleteStatement = _deleteStatement.bind();
		deleteStatement.setBytesUnsafe(0, _keySerializer.serialize(key));
		batchStatement.add(deleteStatement);
	}
	
	_session.execute(batchStatement);
}
 
Example 7
Source File: Cassandra2xBidirectionalMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void set(final K key, final V value) {
	BoundStatement insertStatement = _insertStatement.bind();
	insertStatement.setBytesUnsafe(0, _keySerializer.serialize(key));
	insertStatement.setLong(1, getValueHash(value));
	insertStatement.setBytesUnsafe(2, _valueSerializer.serialize(value));
	_session.execute(insertStatement);
}
 
Example 8
Source File: Cassandra2xQuadIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void insertTriple(final byte[][] ids) throws DataAccessLayerException {
	super.insertTriple(ids);

	// Insert in OC_PS
	final BoundStatement ocpsStatement = _insertOCPSStatement.bind();
	ocpsStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[2]));
	ocpsStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[3]));
	ocpsStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[1]));
	ocpsStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[0]));
	ocpsStatement.setBytesUnsafe(4, ID_SERIALIZER.serialize(ids[3]));

	_batchStatements.get().add(ocpsStatement);

	// Insert in SC_OP
	final BoundStatement scopStatement = _insertSCOPStatement.bind();
	scopStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	scopStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[3]));
	scopStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
	scopStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[1]));

	_batchStatements.get().add(scopStatement);

	// Insert in SPC_O
	final BoundStatement spcoStatement = _insertSPCOStatement.bind();
	spcoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	spcoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	spcoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[3]));
	spcoStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[2]));
	spcoStatement.setBytesUnsafe(4, ID_SERIALIZER.serialize(_dictionary.compose(ids[1], ids[3])));

	_batchStatements.get().add(spcoStatement);
}
 
Example 9
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<byte[][]> numericRangeQuery(
		final Value[] query, 
		final double lowerBound, 
		final boolean equalsLower, 
		final double upperBound, 
		final boolean equalsUpper, 
		final boolean reverse, 
		final int limit) throws DataAccessLayerException {
	
	final byte[] s = _dictionary.getID(query[0], false);
	final byte[] p = _dictionary.getID(query[1], true);

	final boolean subjectIsVariable = isVariable(s);
	final BoundStatement statement = _rangeQueries[getRangeQueryIndex(reverse, subjectIsVariable, true, !equalsUpper, !equalsLower)].bind();
	int queryParameterIndex = 0;

	if (!subjectIsVariable) {
		statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(s));
	}

	statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(p));
	statement.setDouble(queryParameterIndex++, lowerBound);
	statement.setDouble(queryParameterIndex++, upperBound);
	statement.setInt(queryParameterIndex, limit);

	return new SPOCResultIterator(_session.executeAsync(statement), false);
}
 
Example 10
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public Iterator<byte[][]> dateRangeQuery(
		final Value[] query, 
		final long lowerBound, 
		final boolean equalsLower, 
		final long upperBound, 
		final boolean equalsUpper, 
		final boolean reverse, 
		final int limit) throws DataAccessLayerException {
	final byte[] s = _dictionary.getID(query[0], false);
	final byte[] p = _dictionary.getID(query[1], true);
	final boolean subjectIsVariable = isVariable(s);
	
	final BoundStatement statement = _rangeQueries[getRangeQueryIndex(reverse, subjectIsVariable, false, !equalsUpper, !equalsLower)].bind();

	int queryParameterIndex = 0;

	if (!subjectIsVariable) {
		statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(s));
	}

	statement.setBytesUnsafe(queryParameterIndex++, ID_SERIALIZER.serialize(p));
	statement.setDouble(queryParameterIndex++, lowerBound);
	statement.setDouble(queryParameterIndex++, upperBound);
	statement.setInt(queryParameterIndex, limit);

	return new SPOCResultIterator(_session.executeAsync(statement), false);
}
 
Example 11
Source File: Cassandra2xQuadIndexDAO.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
@Override
public List<byte[][]> deleteTriples(
		final Iterator<byte[][]> nodes,
		final int batchSize,
		final boolean rangesEnabled) throws DataAccessLayerException {
	final List<byte[][]> deleted = new ArrayList<byte[][]>(batchSize);

	while (nodes.hasNext()) {
		for (int i = 0; i < batchSize && nodes.hasNext(); i++) {

			final byte[][] ids = nodes.next();

			// check if valid triple or quad
			if (ids == null || ids.length < 3) {
				continue;
			}

			internalDelete(ids, rangesEnabled);

			// Delete from OC_PS index
			final BoundStatement ocpsStatement = _deleteOCPSStatement.bind();
			ocpsStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[2]));
			ocpsStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[3]));
			ocpsStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[1]));
			ocpsStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[0]));

			_batchStatements.get().add(ocpsStatement);

			// Delete from SC_OP index
			final BoundStatement scopStatement = _deleteSCOPStatement.bind();
			scopStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			scopStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[3]));
			scopStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));
			scopStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[1]));

			_batchStatements.get().add(scopStatement);

			// Delete from SPC_O
			final BoundStatement spcoStatement = _deleteSPCOStatement.bind();
			spcoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			spcoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
			spcoStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[3]));
			spcoStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[2]));

			_batchStatements.get().add(spcoStatement);
			deleted.add(ids);

			executePendingMutations();
		}
	}

	return deleted;
}
 
Example 12
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
@Override
public void insertTriple(final byte[][] ids) throws DataAccessLayerException {
	// insert in CF_PO_SC
	final BoundStatement poscStatement = _insertPOSCStatement.bind();

	poscStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	poscStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	poscStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

	if (ids.length == 4) {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	poscStatement.setBytesUnsafe(4, ID_SERIALIZER.serialize(ids[1]));

	_batchStatements.get().add(poscStatement);

	// insert in CF_S_POC
	BoundStatement spocStatement = _insertSPOCStatement.bind();

	spocStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	spocStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	spocStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));

	if (ids.length == 4) {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(spocStatement);

	// insert in CF_O_SPC
	final BoundStatement ospcStatement = _insertOSPCStatement.bind();

	ospcStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[2]));
	ospcStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[0]));
	ospcStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[1]));

	if (ids.length == 4) {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}
	
	_batchStatements.get().add(ospcStatement);
}
 
Example 13
Source File: Cassandra2xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 4 votes vote down vote up
/**
 * Internal method used for reuse delete stuff.
 * 
 * @param ids the triple identifiers.
 * @param rangesEnabled if ranges have been enabled on the current store.
 * @throws DataAccessLayerException in case of data access failure.
 */
void internalDelete(final byte [][]ids, final boolean rangesEnabled) throws DataAccessLayerException {
	// delete in CF_PO_SC
	final BoundStatement poscStatement = _deletePOSCStatement.bind();
	poscStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
	poscStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[2]));
	poscStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

	if (ids.length == 4) {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		poscStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(poscStatement);

	// delete in CF_S_POC
	final BoundStatement spocStatement = _deleteSPOCStatement.bind();
	spocStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
	spocStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
	spocStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[2]));

	if (ids.length == 4) {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		spocStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(spocStatement);

	// delete in CF_O_SPC
	final BoundStatement ospcStatement = _deleteOSPCStatement.bind();
	ospcStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[2]));
	ospcStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[0]));
	ospcStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[1]));

	if (ids.length == 4) {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(ids[3]));
	} else {
		ospcStatement.setBytesUnsafe(3, ID_SERIALIZER.serialize(EMPTY_VAL));
	}

	_batchStatements.get().add(ospcStatement);

	/*
	 * delete in: CF_RN_SP_O + CF_RN_PO_S
	 */
	if (rangesEnabled && _dictionary.isLiteral(ids[2])) {
		final Literal lit = (Literal) _dictionary.getValue(ids[2], false);
		final URI dt = lit.getDatatype();

		if (Environment.NUMERIC_RANGETYPES.contains(dt)) {

			double number = Double.parseDouble(lit.getLabel());

			// delete in CF_RN_SP_O
			final BoundStatement nspoStatement = _deleteNSPOStatement.bind();
			nspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			nspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
			nspoStatement.setDouble(2, number);

			_batchStatements.get().add(nspoStatement);

			// delete in CF_RN_PO_S
			final BoundStatement nposStatement = _deleteNPOSStatement.bind();
			nposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
			nposStatement.setDouble(1, number);
			nposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

			_batchStatements.get().add(nposStatement);

		} else if (Environment.DATETIME_RANGETYPES.contains(dt)) {

			long ms = parseXMLSchemaDateTimeAsMSecs(lit);

			// delete in CF_RN_SP_O
			final BoundStatement dspoStatement = _deleteDSPOStatement.bind();
			dspoStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[0]));
			dspoStatement.setBytesUnsafe(1, ID_SERIALIZER.serialize(ids[1]));
			dspoStatement.setLong(2, ms);

			_batchStatements.get().add(dspoStatement);

			// delete in CF_RN_PO_S
			final BoundStatement dposStatement = _deleteDPOSStatement.bind();
			dposStatement.setBytesUnsafe(0, ID_SERIALIZER.serialize(ids[1]));
			dposStatement.setLong(1, ms);
			dposStatement.setBytesUnsafe(2, ID_SERIALIZER.serialize(ids[0]));

			_batchStatements.get().add(dposStatement);
		}		
	}
}