package org.jboss.aerogear.unifiedpush.cassandra.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.jboss.aerogear.unifiedpush.cassandra.CassandraConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.InsertOptions;
import org.springframework.data.cassandra.core.cql.CassandraAccessor;
import org.springframework.data.cassandra.repository.query.CassandraEntityInformation;
import org.springframework.data.cassandra.repository.support.SimpleCassandraRepository;

import com.datastax.driver.core.ConsistencyLevel;

public abstract class CassandraBaseDao<T, ID extends Serializable> extends SimpleCassandraRepository<T, ID> {
	private final Logger logger = LoggerFactory.getLogger(CassandraBaseDao.class);

	@Autowired
	protected CassandraOperations operations;
	protected String tableName;
	protected final Class<T> domainClass;
	private CassandraConfig config;

	public CassandraBaseDao(Class<T> domainClass, CassandraEntityInformation<T, ID> metadata,
			CassandraOperations operations, CassandraConfig configuraion) {
		super(metadata, operations);

		this.domainClass = domainClass;
		this.tableName = metadata.getTableName().getUnquoted();
		this.config = configuraion;

		if (CassandraAccessor.class.isAssignableFrom(operations.getCqlOperations().getClass())) {
			// Used for Select Queries
			((CassandraAccessor) operations.getCqlOperations()).setConsistencyLevel(getConsistencyLevel());
		}

		if (getConsistencyLevel() != ConsistencyLevel.QUORUM)
			logger.warn("Using ConsistencyLevel ({}) lower then QUORUM might lead to inconsistency read/write",
					getConsistencyLevel());
	}
	
	public <S extends T> S save(S entity, int ttl) {
		operations.insert(entity, InsertOptions.builder().ttl(ttl).build());
		return entity;
	}
	
	@Override
	public <S extends T> S insert(S entity) {
		throw new UnsupportedOperationException(
				"TypedIdCassandraRepository is @Deprecated, use CassandraRepository.save");
	}

	@Override
	public <S extends T> List<S> insert(Iterable<S> entities) {
		throw new UnsupportedOperationException(
				"TypedIdCassandraRepository is @Deprecated, use CassandraRepository.save");
	}

	protected ConsistencyLevel getConsistencyLevel() {
		return ConsistencyLevel.valueOf(config.getConsistencyLevel());
	}
}
@@ -363,70 +363,8 @@
 ns;%0A
-import org.springframework.data.cassandra.core.InsertOptions;%0A
 impo
@@ -1740,151 +1740,8 @@
 %7D%0A%09%0A
-%09public %3CS extends T%3E S save(S entity, int ttl) %7B%0A%09%09operations.insert(entity, InsertOptions.builder().ttl(ttl).build());%0A%09%09return entity;%0A%09%7D%0A%09%0A
 %09@Ov

Remove unused code