All Downloads are FREE. Search and download functionalities are using the official Maven repository.

kieker.extension.cassandra.CassandraValueSerializer Maven / Gradle / Ivy

The newest version!
/***************************************************************************
 * Copyright 2022 Kieker Project (http://kieker-monitoring.net)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ***************************************************************************/
package kieker.extension.cassandra;

import com.datastax.oss.driver.api.core.cql.BoundStatement;

import kieker.common.record.io.IValueSerializer;

/**
 * @author Reiner Jung
 * @since 1.16
 */
public class CassandraValueSerializer implements IValueSerializer { // NOPMD TooManyMethods

	private final BoundStatement boundStatement;
	private int column;

	public CassandraValueSerializer(final BoundStatement boundStatement) {
		this.boundStatement = boundStatement;
		this.column = 1; // start at one, as 0 is the column of the benchmarkId
	}

	@Override
	public void putBoolean(final boolean value) {
		this.boundStatement.setBoolean(this.column++, value);
	}

	@Override
	public void putByte(final byte value) {
		this.boundStatement.setByte(this.column++, value);
	}

	@Override
	public void putChar(final char value) {
		this.boundStatement.setString(this.column++, String.valueOf(value));
	}

	@Override
	public void putShort(final short value) {
		this.boundStatement.setShort(this.column++, value);
	}

	@Override
	public void putInt(final int value) {
		this.boundStatement.setInt(this.column++, value);
	}

	@Override
	public void putLong(final long value) {
		this.boundStatement.setLong(this.column++, value);
	}

	@Override
	public void putFloat(final float value) {
		this.boundStatement.setFloat(this.column++, value);
	}

	@Override
	public void putDouble(final double value) {
		this.boundStatement.setDouble(this.column++, value);
	}

	@Override
	public > void putEnumeration(final T value) {
		this.boundStatement.setInt(this.column++, value.ordinal());
	}

	@Override
	public void putBytes(final byte[] value) {
		throw new UnsupportedOperationException("Plain byte arrays cannot be stored in Cassandra DB.");
	}

	@Override
	public void putString(final String value) {
		this.boundStatement.setString(this.column++, value);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy