DATACASS-389 - Java 8 cleanup.
Add deprecations. Remove unused classes. Replace explicit type arguments with diamond operator. Replace imperative for-loops with stream/forEach (functional approach). Replace anonymous inner classes with lambdas. Replace <code>…</code> with {@code}.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,25 +32,14 @@ import org.springframework.cassandra.core.cql.generator.DropKeyspaceCqlGenerator
|
||||
import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceActionSpecification;
|
||||
import org.springframework.cassandra.core.util.CollectionUtils;
|
||||
import org.springframework.cassandra.support.CassandraExceptionTranslator;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.AuthProvider;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Host;
|
||||
import com.datastax.driver.core.LatencyTracker;
|
||||
import com.datastax.driver.core.NettyOptions;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import com.datastax.driver.core.ProtocolVersion;
|
||||
import com.datastax.driver.core.QueryOptions;
|
||||
import com.datastax.driver.core.SSLOptions;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.SocketOptions;
|
||||
import com.datastax.driver.core.TimestampGenerator;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.Cluster.Builder;
|
||||
import com.datastax.driver.core.ProtocolOptions.Compression;
|
||||
import com.datastax.driver.core.policies.AddressTranslator;
|
||||
@@ -76,8 +65,8 @@ import com.datastax.driver.core.policies.SpeculativeExecutionPolicy;
|
||||
* @see com.datastax.driver.core.Cluster
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, InitializingBean, DisposableBean,
|
||||
BeanNameAware, PersistenceExceptionTranslator {
|
||||
public class CassandraCqlClusterFactoryBean
|
||||
implements FactoryBean<Cluster>, InitializingBean, DisposableBean, BeanNameAware, PersistenceExceptionTranslator {
|
||||
|
||||
public static final boolean DEFAULT_JMX_REPORTING_ENABLED = true;
|
||||
public static final boolean DEFAULT_METRICS_ENABLED = true;
|
||||
@@ -108,12 +97,12 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
private Host.StateListener hostStateListener;
|
||||
private LatencyTracker latencyTracker;
|
||||
|
||||
private List<CreateKeyspaceSpecification> keyspaceCreations = new ArrayList<CreateKeyspaceSpecification>();
|
||||
private List<DropKeyspaceSpecification> keyspaceDrops = new ArrayList<DropKeyspaceSpecification>();
|
||||
private Set<KeyspaceActionSpecification<?>> keyspaceSpecifications = new HashSet<KeyspaceActionSpecification<?>>();
|
||||
private List<CreateKeyspaceSpecification> keyspaceCreations = new ArrayList<>();
|
||||
private List<DropKeyspaceSpecification> keyspaceDrops = new ArrayList<>();
|
||||
private Set<KeyspaceActionSpecification<?>> keyspaceSpecifications = new HashSet<>();
|
||||
|
||||
private List<String> startupScripts = new ArrayList<String>();
|
||||
private List<String> shutdownScripts = new ArrayList<String>();
|
||||
private List<String> startupScripts = new ArrayList<>();
|
||||
private List<String> shutdownScripts = new ArrayList<>();
|
||||
|
||||
private LoadBalancingPolicy loadBalancingPolicy;
|
||||
private NettyOptions nettyOptions;
|
||||
@@ -307,16 +296,15 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
*/
|
||||
private void generateSpecificationsFromFactoryBeans() {
|
||||
|
||||
for (KeyspaceActionSpecification<?> keyspaceSpecification : keyspaceSpecifications) {
|
||||
|
||||
if (keyspaceSpecification instanceof CreateKeyspaceSpecification) {
|
||||
keyspaceCreations.add((CreateKeyspaceSpecification) keyspaceSpecification);
|
||||
keyspaceSpecifications.forEach(keyspaceActionSpecification -> {
|
||||
if (keyspaceActionSpecification instanceof CreateKeyspaceSpecification) {
|
||||
keyspaceCreations.add((CreateKeyspaceSpecification) keyspaceActionSpecification);
|
||||
}
|
||||
|
||||
if (keyspaceSpecification instanceof DropKeyspaceSpecification) {
|
||||
keyspaceDrops.add((DropKeyspaceSpecification) keyspaceSpecification);
|
||||
if (keyspaceActionSpecification instanceof DropKeyspaceSpecification) {
|
||||
keyspaceDrops.add((DropKeyspaceSpecification) keyspaceActionSpecification);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void executeSpecsAndScripts(List<? extends KeyspaceActionSpecification<?>> kepspaceActionSpecifications,
|
||||
@@ -329,13 +317,10 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
try {
|
||||
CqlTemplate template = new CqlTemplate(session);
|
||||
|
||||
for (KeyspaceActionSpecification<?> keyspaceActionSpecification : kepspaceActionSpecifications) {
|
||||
template.execute(toCql(keyspaceActionSpecification));
|
||||
}
|
||||
kepspaceActionSpecifications
|
||||
.forEach(keyspaceActionSpecification -> template.execute(toCql(keyspaceActionSpecification)));
|
||||
|
||||
for (String script : scripts) {
|
||||
template.execute(script);
|
||||
}
|
||||
scripts.forEach(template::execute);
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
@@ -347,8 +332,8 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
private String toCql(KeyspaceActionSpecification<?> keyspaceActionSpecification) {
|
||||
|
||||
return (keyspaceActionSpecification instanceof CreateKeyspaceSpecification
|
||||
? new CreateKeyspaceCqlGenerator((CreateKeyspaceSpecification) keyspaceActionSpecification).toCql()
|
||||
: new DropKeyspaceCqlGenerator((DropKeyspaceSpecification) keyspaceActionSpecification).toCql());
|
||||
? new CreateKeyspaceCqlGenerator((CreateKeyspaceSpecification) keyspaceActionSpecification).toCql()
|
||||
: new DropKeyspaceCqlGenerator((DropKeyspaceSpecification) keyspaceActionSpecification).toCql());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -362,8 +347,8 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a comma-delimited string of the contact points (hosts) to connect to. Default is {@code localhost};
|
||||
* see {@link #DEFAULT_CONTACT_POINTS}.
|
||||
* Set a comma-delimited string of the contact points (hosts) to connect to. Default is {@code localhost}; see
|
||||
* {@link #DEFAULT_CONTACT_POINTS}.
|
||||
*
|
||||
* @param contactPoints the contact points used by the new cluster.
|
||||
*/
|
||||
@@ -528,7 +513,6 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the startup scripts
|
||||
*/
|
||||
public List<String> getStartupScripts() {
|
||||
@@ -547,7 +531,6 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the shutdown scripts
|
||||
*/
|
||||
public List<String> getShutdownScripts() {
|
||||
@@ -626,8 +609,8 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the address translator used by the new cluster to translate IP addresses received
|
||||
* from Cassandra nodes into locally query-able addresses.
|
||||
* Configures the address translator used by the new cluster to translate IP addresses received from Cassandra nodes
|
||||
* into locally query-able addresses.
|
||||
*
|
||||
* @param addressTranslator {@link AddressTranslator} used by the new cluster.
|
||||
* @see com.datastax.driver.core.Cluster.Builder#withAddressTranslator(AddressTranslator)
|
||||
@@ -664,8 +647,8 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum time to wait for schema agreement before returning from a DDL query. The timeout is used
|
||||
* to wait for all currently up hosts in the cluster to agree on the schema.
|
||||
* Sets the maximum time to wait for schema agreement before returning from a DDL query. The timeout is used to wait
|
||||
* for all currently up hosts in the cluster to agree on the schema.
|
||||
*
|
||||
* @param seconds max schema agreement wait in seconds.
|
||||
* @see com.datastax.driver.core.Cluster.Builder#withMaxSchemaAgreementWaitSeconds(int)
|
||||
@@ -690,8 +673,7 @@ public class CassandraCqlClusterFactoryBean implements FactoryBean<Cluster>, Ini
|
||||
/**
|
||||
* Configures the generator that will produce the client-side timestamp sent with each query.
|
||||
*
|
||||
* @param timestampGenerator {@link TimestampGenerator} used to produce a client-side timestamp
|
||||
* sent with each query.
|
||||
* @param timestampGenerator {@link TimestampGenerator} used to produce a client-side timestamp sent with each query.
|
||||
* @see com.datastax.driver.core.Cluster.Builder#withTimestampGenerator(TimestampGenerator)
|
||||
* @see com.datastax.driver.core.TimestampGenerator
|
||||
* @since 1.5
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -38,8 +38,8 @@ import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* Factory for creating and configuring a Cassandra {@link Session}, which is a thread-safe singleton.
|
||||
* As such, it is sufficient to have one {@link Session} per application and keyspace.
|
||||
* Factory for creating and configuring a Cassandra {@link Session}, which is a thread-safe singleton. As such, it is
|
||||
* sufficient to have one {@link Session} per application and keyspace.
|
||||
*
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
@@ -53,80 +53,98 @@ import com.datastax.driver.core.Session;
|
||||
* @see com.datastax.driver.core.Cluster
|
||||
* @see com.datastax.driver.core.Session
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, InitializingBean, DisposableBean,
|
||||
PersistenceExceptionTranslator {
|
||||
public class CassandraCqlSessionFactoryBean
|
||||
implements FactoryBean<Session>, InitializingBean, DisposableBean, PersistenceExceptionTranslator {
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
|
||||
|
||||
private Cluster cluster;
|
||||
|
||||
private List<String> startupScripts = Collections.emptyList();
|
||||
|
||||
private List<String> shutdownScripts = Collections.emptyList();
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
protected final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
|
||||
|
||||
private Session session;
|
||||
|
||||
private String keyspaceName;
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public Session getObject() {
|
||||
return this.session;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
*/
|
||||
@Override
|
||||
public Class<? extends Session> getObjectType() {
|
||||
return (this.session != null ? this.session.getClass() : Session.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
this.session = connect(getKeyspaceName());
|
||||
executeScripts(getStartupScripts());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Session connect(String keyspaceName) {
|
||||
|
||||
return (StringUtils.hasText(keyspaceName) ? getCluster().connect(keyspaceName) : getCluster().connect());
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
executeScripts(getShutdownScripts());
|
||||
getSession().close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the given Cassandra CQL scripts. The {@link Session} must be connected when this method is called.
|
||||
* Executes the given Cassandra CQL scripts. The {@link Session} must be connected when this method is called.
|
||||
*/
|
||||
protected void executeScripts(List<String> scripts) {
|
||||
|
||||
if (!CollectionUtils.isEmpty(scripts)) {
|
||||
|
||||
CqlOperations template = newCqlOperations(getSession());
|
||||
|
||||
for (String script : scripts) {
|
||||
scripts.forEach(script -> {
|
||||
logger.info("executing raw CQL [{}]", script);
|
||||
template.execute(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/**
|
||||
* @param session
|
||||
* @return
|
||||
*/
|
||||
CqlOperations newCqlOperations(Session session) {
|
||||
return new CqlTemplate(session);
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.dao.support.PersistenceExceptionTranslator#translateExceptionIfPossible(java.lang.RuntimeException)
|
||||
*/
|
||||
@Override
|
||||
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
|
||||
return this.exceptionTranslator.translateExceptionIfPossible(e);
|
||||
@@ -140,6 +158,7 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* @see #getObject()
|
||||
*/
|
||||
public boolean isConnected() {
|
||||
|
||||
Session session = getObject();
|
||||
return !(session == null || session.isClosed());
|
||||
}
|
||||
@@ -153,6 +172,7 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* @see #getCluster()
|
||||
*/
|
||||
public void setCluster(Cluster cluster) {
|
||||
|
||||
Assert.notNull(cluster, "Cluster must not be null");
|
||||
this.cluster = cluster;
|
||||
}
|
||||
@@ -166,13 +186,14 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* @see #setCluster(Cluster)
|
||||
*/
|
||||
protected Cluster getCluster() {
|
||||
|
||||
Assert.state(this.cluster != null, "Cluster was not properly initialized");
|
||||
return this.cluster;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the Cassandra Keyspace to connect to. Passing <code>null</code>, an empty String,
|
||||
* or whitespace will cause the Cassandra System Keyspace to be used.
|
||||
* Sets the name of the Cassandra Keyspace to connect to. Passing {@code null}, an empty String, or whitespace will
|
||||
* cause the Cassandra System Keyspace to be used.
|
||||
*
|
||||
* @param keyspaceName a String indicating the name of the Keyspace in which to connect.
|
||||
* @see #getKeyspaceName()
|
||||
@@ -199,6 +220,7 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* @see com.datastax.driver.core.Session
|
||||
*/
|
||||
protected Session getSession() {
|
||||
|
||||
Session session = getObject();
|
||||
Assert.state(session != null, "Session was not properly initialized");
|
||||
return session;
|
||||
@@ -208,7 +230,7 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* Sets CQL scripts to be executed immediately after the session is connected.
|
||||
*/
|
||||
public void setStartupScripts(List<String> scripts) {
|
||||
this.startupScripts = (scripts != null ? new ArrayList<String>(scripts) : Collections.<String>emptyList());
|
||||
this.startupScripts = (scripts != null ? new ArrayList<>(scripts) : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +244,7 @@ public class CassandraCqlSessionFactoryBean implements FactoryBean<Session>, Ini
|
||||
* Sets CQL scripts to be executed immediately before the session is shutdown.
|
||||
*/
|
||||
public void setShutdownScripts(List<String> scripts) {
|
||||
this.shutdownScripts = (scripts != null ? new ArrayList<String>(scripts) : Collections.<String>emptyList());
|
||||
this.shutdownScripts = (scripts != null ? new ArrayList<>(scripts) : Collections.emptyList());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -24,7 +24,7 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* Factory for configuring a {@link CqlTemplate}.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@@ -33,8 +33,7 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
private CqlTemplate template;
|
||||
private Session session;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
@@ -42,8 +41,7 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
return template;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
*/
|
||||
@Override
|
||||
@@ -51,8 +49,7 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
return CqlTemplate.class;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
@@ -60,8 +57,7 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
@@ -76,7 +72,7 @@ public class CassandraCqlTemplateFactoryBean implements FactoryBean<CqlTemplate>
|
||||
* Sets the Cassandra {@link Session} to use. The {@link CqlTemplate} will use the logged keyspace of the underlying
|
||||
* {@link Session}. Don't change the keyspace using CQL but use multiple {@link Session} and
|
||||
* {@link CqlTemplate} beans.
|
||||
*
|
||||
*
|
||||
* @param session must not be {@literal null}.
|
||||
*/
|
||||
public void setSession(Session session) {
|
||||
|
||||
@@ -20,19 +20,48 @@ package org.springframework.cassandra.config;
|
||||
*/
|
||||
public class DataCenterReplication {
|
||||
|
||||
public static DataCenterReplication[] dcrs(DataCenterReplication... dcrs) {
|
||||
return dcrs;
|
||||
}
|
||||
|
||||
public static DataCenterReplication dcr(String dataCenter, long replicationFactor) {
|
||||
/**
|
||||
* Creates a new {@link DataCenterReplication} given {@code dataCenter} and {@code replicationFactor}.
|
||||
*
|
||||
* @param dataCenter must not be {@literal null}.
|
||||
* @param replicationFactor
|
||||
* @return
|
||||
*/
|
||||
public static DataCenterReplication of(String dataCenter, long replicationFactor) {
|
||||
return new DataCenterReplication(dataCenter, replicationFactor);
|
||||
}
|
||||
|
||||
public String dataCenter;
|
||||
public long replicationFactor;
|
||||
private final String dataCenter;
|
||||
private final long replicationFactor;
|
||||
|
||||
private DataCenterReplication(String dataCenter, long replicationFactor) {
|
||||
|
||||
public DataCenterReplication(String dataCenter, long replicationFactor) {
|
||||
this.dataCenter = dataCenter;
|
||||
this.replicationFactor = replicationFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the data center.
|
||||
*/
|
||||
public String getDataCenter() {
|
||||
return dataCenter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the replication factor.
|
||||
*/
|
||||
public long getReplicationFactor() {
|
||||
return replicationFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [dataCenter='").append(dataCenter).append('\'');
|
||||
sb.append(", replicationFactor=").append(replicationFactor);
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -17,9 +17,9 @@ package org.springframework.cassandra.config;
|
||||
|
||||
/**
|
||||
* Available actions for Keyspace Specifications
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
*/
|
||||
public enum KeyspaceAction {
|
||||
CREATE, CREATE_DROP, ALTER;
|
||||
CREATE, CREATE_DROP, ALTER
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -41,17 +41,16 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author David Webb
|
||||
*/
|
||||
public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<KeyspaceActionSpecification<?>>>,
|
||||
InitializingBean, DisposableBean {
|
||||
public class KeyspaceActionSpecificationFactoryBean
|
||||
implements FactoryBean<Set<KeyspaceActionSpecification<?>>>, InitializingBean, DisposableBean {
|
||||
|
||||
private KeyspaceAction action;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<String> networkTopologyDataCenters = new LinkedList<String>();
|
||||
|
||||
private List<String> networkTopologyReplicationFactors = new LinkedList<String>();
|
||||
private List<String> networkTopologyDataCenters = new LinkedList<>();
|
||||
|
||||
private List<String> networkTopologyReplicationFactors = new LinkedList<>();
|
||||
private ReplicationStrategy replicationStrategy;
|
||||
|
||||
private long replicationFactor;
|
||||
@@ -60,11 +59,13 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
|
||||
|
||||
private boolean ifNotExists = false;
|
||||
|
||||
private Set<KeyspaceActionSpecification<?>> specs = new HashSet<KeyspaceActionSpecification<?>>();
|
||||
private Set<KeyspaceActionSpecification<?>> specs = new HashSet<>();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
public void destroy() {
|
||||
action = null;
|
||||
name = null;
|
||||
networkTopologyDataCenters = null;
|
||||
@@ -73,8 +74,11 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
|
||||
specs = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
|
||||
Assert.hasText(name, "Keyspace Name is required for a Keyspace Action");
|
||||
Assert.notNull(action, "Keyspace Action is required for a Keyspace Action");
|
||||
@@ -89,7 +93,6 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
|
||||
case ALTER:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +105,7 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
|
||||
CreateKeyspaceSpecification create = new CreateKeyspaceSpecification();
|
||||
create.name(name).ifNotExists(ifNotExists).with(KeyspaceOption.DURABLE_WRITES, durableWrites);
|
||||
|
||||
Map<Option, Object> replicationStrategyMap = new HashMap<Option, Object>();
|
||||
Map<Option, Object> replicationStrategyMap = new HashMap<>();
|
||||
replicationStrategyMap.put(new DefaultOption("class", String.class, true, false, true),
|
||||
replicationStrategy.getValue());
|
||||
|
||||
@@ -135,16 +138,25 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Set<K
|
||||
return drop;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public Set<KeyspaceActionSpecification<?>> getObject() throws Exception {
|
||||
return specs;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return Set.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return false;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -26,9 +26,10 @@ import org.springframework.cassandra.core.util.MapBuilder;
|
||||
|
||||
/**
|
||||
* Keyspace attributes.
|
||||
*
|
||||
*
|
||||
* @author Alex Shvid
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class KeyspaceAttributes {
|
||||
|
||||
@@ -68,7 +69,7 @@ public class KeyspaceAttributes {
|
||||
ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getValue());
|
||||
|
||||
for (DataCenterReplication dcr : dataCenterReplications) {
|
||||
builder.entry(new DefaultOption(dcr.dataCenter, Long.class, true, false, false), dcr.replicationFactor);
|
||||
builder.entry(new DefaultOption(dcr.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor());
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
@@ -77,7 +78,7 @@ public class KeyspaceAttributes {
|
||||
private ReplicationStrategy replicationStrategy = DEFAULT_REPLICATION_STRATEGY;
|
||||
private long replicationFactor = DEFAULT_REPLICATION_FACTOR;
|
||||
private boolean durableWrites = DEFAULT_DURABLE_WRITES;
|
||||
private Map<String, Long> replicasPerNodeByDataCenter = new HashMap<String, Long>();
|
||||
private Map<String, Long> replicasPerNodeByDataCenter = new HashMap<>();
|
||||
|
||||
public ReplicationStrategy getReplicationStrategy() {
|
||||
return replicationStrategy;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,14 +15,15 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* Given List of Lists where all child Lists contain the same class, then a single level List of <T> is generated.
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
* @param <T>
|
||||
*/
|
||||
@@ -32,15 +33,7 @@ public class MultiLevelListFlattenerFactoryBean<T> implements FactoryBean<List<T
|
||||
|
||||
@Override
|
||||
public List<T> getObject() throws Exception {
|
||||
List<T> list = new ArrayList<T>();
|
||||
|
||||
for (List<T> topList : multiLevelList) {
|
||||
for (T t : topList) {
|
||||
list.add(t);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return multiLevelList.stream().flatMap(Collection::stream).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -24,9 +25,9 @@ import org.springframework.beans.factory.FactoryBean;
|
||||
|
||||
/**
|
||||
* Given Set of Sets where all child Sets contain the same class, then a single level Set of <T> is generated.
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
* @param <T>
|
||||
* @param <T> TODO: Remove me
|
||||
*/
|
||||
public class MultiLevelSetFlattenerFactoryBean<T> implements FactoryBean<Set<T>> {
|
||||
|
||||
@@ -36,15 +37,13 @@ public class MultiLevelSetFlattenerFactoryBean<T> implements FactoryBean<Set<T>>
|
||||
|
||||
@Override
|
||||
public Set<T> getObject() throws Exception {
|
||||
Set<T> set = new HashSet<T>();
|
||||
Set<T> set = new HashSet<>();
|
||||
|
||||
for (Set<T> topSet : multiLevelSet) {
|
||||
for (T t : topSet) {
|
||||
log.debug(t.toString());
|
||||
log.debug("Set contains -> " + set.contains(t));
|
||||
set.add(t);
|
||||
}
|
||||
}
|
||||
multiLevelSet.stream().flatMap(Collection::stream).forEach(t -> {
|
||||
log.debug(t.toString());
|
||||
log.debug("Set contains -> " + set.contains(t));
|
||||
set.add(t);
|
||||
});
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
*/
|
||||
package org.springframework.cassandra.config;
|
||||
|
||||
|
||||
import static org.springframework.util.ReflectionUtils.invokeMethod;
|
||||
import static org.springframework.util.ReflectionUtils.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.datastax.driver.core.HostDistance;
|
||||
import com.datastax.driver.core.PoolingOptions;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Spring {@link FactoryBean} for the Cassandra Java driver {@link PoolingOptions}.
|
||||
@@ -44,14 +44,16 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
|
||||
private static final PoolingOptions DEFAULT = new PoolingOptions();
|
||||
|
||||
private static final Method SET_MAX_QUEUE_SIZE;
|
||||
private static final Method GET_MAX_QUEUE_SIZE;
|
||||
// Compatibility between 3.1.1 and earlier Cassandra driver versions
|
||||
private static final Optional<Method> SET_MAX_QUEUE_SIZE;
|
||||
|
||||
// Compatibility between 3.1.1 and earlier Cassandra driver versions
|
||||
private static final Optional<Method> GET_MAX_QUEUE_SIZE;
|
||||
|
||||
static {
|
||||
SET_MAX_QUEUE_SIZE = ReflectionUtils
|
||||
.findMethod(PoolingOptions.class, "setMaxQueueSize", int.class);
|
||||
GET_MAX_QUEUE_SIZE = ReflectionUtils
|
||||
.findMethod(PoolingOptions.class, "getMaxQueueSize");
|
||||
SET_MAX_QUEUE_SIZE = Optional
|
||||
.ofNullable(ReflectionUtils.findMethod(PoolingOptions.class, "setMaxQueueSize", int.class));
|
||||
GET_MAX_QUEUE_SIZE = Optional.ofNullable(ReflectionUtils.findMethod(PoolingOptions.class, "getMaxQueueSize"));
|
||||
}
|
||||
|
||||
private Executor initializationExecutor;
|
||||
@@ -83,7 +85,7 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
poolingOptions = configureRemoteHostDistancePoolingOptions(
|
||||
configureLocalHostDistancePoolingOptions(newPoolingOptions()));
|
||||
configureLocalHostDistancePoolingOptions(newPoolingOptions()));
|
||||
|
||||
if (heartbeatIntervalSeconds != DEFAULT.getHeartbeatIntervalSeconds()) {
|
||||
poolingOptions.setHeartbeatIntervalSeconds(heartbeatIntervalSeconds);
|
||||
@@ -101,22 +103,18 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
poolingOptions.setPoolTimeoutMillis(poolTimeoutMilliseconds);
|
||||
}
|
||||
|
||||
if (!isDefaultMaxQueueSize() && SET_MAX_QUEUE_SIZE != null) {
|
||||
invokeMethod(SET_MAX_QUEUE_SIZE, poolingOptions, maxQueueSize);
|
||||
if (!isDefaultMaxQueueSize()) {
|
||||
SET_MAX_QUEUE_SIZE.ifPresent(method -> invokeMethod(method, poolingOptions, maxQueueSize));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDefaultMaxQueueSize() {
|
||||
|
||||
if(GET_MAX_QUEUE_SIZE != null){
|
||||
return GET_MAX_QUEUE_SIZE.map(method -> {
|
||||
|
||||
Integer defaultMaxQueueSize = (Integer) invokeMethod(GET_MAX_QUEUE_SIZE, poolingOptions);
|
||||
if(defaultMaxQueueSize.intValue() == maxQueueSize){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
Integer defaultMaxQueueSize = (Integer) invokeMethod(method, poolingOptions);
|
||||
return defaultMaxQueueSize.intValue() == maxQueueSize;
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -128,12 +126,11 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} instance initialized
|
||||
* with the {@link HostDistance#LOCAL}-based {@link PoolingOptions} as configured on this
|
||||
* {@link PoolingOptionsFactoryBean}.
|
||||
* Constructs and returns a {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} instance initialized with the
|
||||
* {@link HostDistance#LOCAL}-based {@link PoolingOptions} as configured on this {@link PoolingOptionsFactoryBean}.
|
||||
*
|
||||
* @return {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} initialized with this
|
||||
* {@link PoolingOptionsFactoryBean}'s {@link HostDistance#LOCAL}-based {@link PoolingOptions}.
|
||||
* {@link PoolingOptionsFactoryBean}'s {@link HostDistance#LOCAL}-based {@link PoolingOptions}.
|
||||
* @see com.datastax.driver.core.HostDistance#LOCAL
|
||||
* @see com.datastax.driver.core.PoolingOptions
|
||||
* @see org.springframework.cassandra.config.PoolingOptionsFactoryBean.HostDistancePoolingOptions
|
||||
@@ -141,16 +138,15 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
*/
|
||||
protected HostDistancePoolingOptions newLocalHostDistancePoolingOptions() {
|
||||
return LocalHostDistancePoolingOptions.create(getLocalCoreConnections(), getLocalMaxConnections(),
|
||||
getLocalMaxSimultaneousRequests(), getLocalMinSimultaneousRequests());
|
||||
getLocalMaxSimultaneousRequests(), getLocalMinSimultaneousRequests());
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs and returns a {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} instance initialized
|
||||
* with the {@link HostDistance#REMOTE}-based {@link PoolingOptions} as configured on this
|
||||
* {@link PoolingOptionsFactoryBean}.
|
||||
* Constructs and returns a {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} instance initialized with the
|
||||
* {@link HostDistance#REMOTE}-based {@link PoolingOptions} as configured on this {@link PoolingOptionsFactoryBean}.
|
||||
*
|
||||
* @return {@link PoolingOptionsFactoryBean.HostDistancePoolingOptions} initialized with this
|
||||
* {@link PoolingOptionsFactoryBean}'s {@link HostDistance#REMOTE}-based {@link PoolingOptions}.
|
||||
* {@link PoolingOptionsFactoryBean}'s {@link HostDistance#REMOTE}-based {@link PoolingOptions}.
|
||||
* @see com.datastax.driver.core.HostDistance#REMOTE
|
||||
* @see com.datastax.driver.core.PoolingOptions
|
||||
* @see org.springframework.cassandra.config.PoolingOptionsFactoryBean.HostDistancePoolingOptions
|
||||
@@ -158,7 +154,7 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
*/
|
||||
protected HostDistancePoolingOptions newRemoteHostDistancePoolingOptions() {
|
||||
return RemoteHostDistancePoolingOptions.create(getRemoteCoreConnections(), getRemoteMaxConnections(),
|
||||
getRemoteMaxSimultaneousRequests(), getRemoteMinSimultaneousRequests());
|
||||
getRemoteMaxSimultaneousRequests(), getRemoteMinSimultaneousRequests());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -359,8 +355,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the threshold that triggers the creation of a new connection to a host
|
||||
* for the {@link HostDistance#LOCAL} scope.
|
||||
* Sets the threshold that triggers the creation of a new connection to a host for the {@link HostDistance#LOCAL}
|
||||
* scope.
|
||||
*
|
||||
* @param localMinSimultaneousRequests threshold triggering the creation of local connections to a host.
|
||||
*/
|
||||
@@ -369,8 +365,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold that triggers the creation of a new connection to a host
|
||||
* for the {@link HostDistance#LOCAL} scope.
|
||||
* Gets the threshold that triggers the creation of a new connection to a host for the {@link HostDistance#LOCAL}
|
||||
* scope.
|
||||
*
|
||||
* @return the {@code localMinSimultaneousRequests}.
|
||||
*/
|
||||
@@ -433,8 +429,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the threshold that triggers the creation of a new connection to a host
|
||||
* for the {@link HostDistance#REMOTE} scope.
|
||||
* Sets the threshold that triggers the creation of a new connection to a host for the {@link HostDistance#REMOTE}
|
||||
* scope.
|
||||
*
|
||||
* @param remoteMinSimultaneousRequests threshold triggering the creation of remote connections to a host.
|
||||
*/
|
||||
@@ -443,8 +439,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the threshold that triggers the creation of a new connection to a host
|
||||
* for the {@link HostDistance#REMOTE} scope.
|
||||
* Gets the threshold that triggers the creation of a new connection to a host for the {@link HostDistance#REMOTE}
|
||||
* scope.
|
||||
*
|
||||
* @return the {@code remoteMinSimultaneousRequests}.
|
||||
*/
|
||||
@@ -476,7 +472,7 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
* @param newConnectionThreshold threshold that triggers the creation of a new connection to a host.
|
||||
*/
|
||||
protected HostDistancePoolingOptions(Integer coreConnectionsPerHost, Integer maxConnectionsPerHost,
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
|
||||
this.coreConnectionsPerHost = coreConnectionsPerHost;
|
||||
this.maxConnectionsPerHost = maxConnectionsPerHost;
|
||||
@@ -616,8 +612,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
static class LocalHostDistancePoolingOptions extends HostDistancePoolingOptions {
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link LocalHostDistancePoolingOptions} initialized with {@link PoolingOptions}
|
||||
* based on {@link HostDistance#LOCAL}.
|
||||
* Creates an instance of {@link LocalHostDistancePoolingOptions} initialized with {@link PoolingOptions} based on
|
||||
* {@link HostDistance#LOCAL}.
|
||||
*
|
||||
* @param coreConnectionsPerHost core number of connections per host.
|
||||
* @param maxConnectionsPerHost maximum number of connections per host.
|
||||
@@ -628,12 +624,12 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
|
||||
return new LocalHostDistancePoolingOptions(coreConnectionsPerHost, maxConnectionsPerHost,
|
||||
maxRequestsPerConnection, newConnectionThreshold);
|
||||
maxRequestsPerConnection, newConnectionThreshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of {@link LocalHostDistancePoolingOptions} initialized with {@link PoolingOptions}
|
||||
* based on {@link HostDistance#LOCAL}.
|
||||
* Constructs an instance of {@link LocalHostDistancePoolingOptions} initialized with {@link PoolingOptions} based
|
||||
* on {@link HostDistance#LOCAL}.
|
||||
*
|
||||
* @param coreConnectionsPerHost core number of connections per host.
|
||||
* @param maxConnectionsPerHost maximum number of connections per host.
|
||||
@@ -667,8 +663,8 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
static class RemoteHostDistancePoolingOptions extends HostDistancePoolingOptions {
|
||||
|
||||
/**
|
||||
* Creates an instance of {@link RemoteHostDistancePoolingOptions} initialized with {@link PoolingOptions}
|
||||
* based on {@link HostDistance#REMOTE}.
|
||||
* Creates an instance of {@link RemoteHostDistancePoolingOptions} initialized with {@link PoolingOptions} based on
|
||||
* {@link HostDistance#REMOTE}.
|
||||
*
|
||||
* @param coreConnectionsPerHost core number of connections per host.
|
||||
* @param maxConnectionsPerHost maximum number of connections per host.
|
||||
@@ -676,15 +672,15 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
* @param newConnectionThreshold threshold that triggers the creation of a new connection to a host.
|
||||
*/
|
||||
static RemoteHostDistancePoolingOptions create(Integer coreConnectionsPerHost, Integer maxConnectionsPerHost,
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
|
||||
return new RemoteHostDistancePoolingOptions(coreConnectionsPerHost, maxConnectionsPerHost,
|
||||
maxRequestsPerConnection, newConnectionThreshold);
|
||||
maxRequestsPerConnection, newConnectionThreshold);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of {@link RemoteHostDistancePoolingOptions} initialized with {@link PoolingOptions}
|
||||
* based on {@link HostDistance#REMOTE}.
|
||||
* Constructs an instance of {@link RemoteHostDistancePoolingOptions} initialized with {@link PoolingOptions} based
|
||||
* on {@link HostDistance#REMOTE}.
|
||||
*
|
||||
* @param coreConnectionsPerHost core number of connections per host.
|
||||
* @param maxConnectionsPerHost maximum number of connections per host.
|
||||
@@ -692,7 +688,7 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
* @param newConnectionThreshold threshold that triggers the creation of a new connection to a host.
|
||||
*/
|
||||
RemoteHostDistancePoolingOptions(Integer coreConnectionsPerHost, Integer maxConnectionsPerHost,
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
Integer maxRequestsPerConnection, Integer newConnectionThreshold) {
|
||||
|
||||
super(coreConnectionsPerHost, maxConnectionsPerHost, maxRequestsPerConnection, newConnectionThreshold);
|
||||
}
|
||||
|
||||
@@ -38,20 +38,30 @@ public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, Ini
|
||||
private Integer receiveBufferSize;
|
||||
private Integer sendBufferSize;
|
||||
|
||||
SocketOptions socketOptions;
|
||||
private SocketOptions socketOptions;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public SocketOptions getObject() throws Exception {
|
||||
return socketOptions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return SocketOptions.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
connectTimeoutMillis = null;
|
||||
keepAlive = null;
|
||||
readTimeoutMillis = null;
|
||||
@@ -62,6 +72,9 @@ public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, Ini
|
||||
sendBufferSize = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
@@ -101,6 +114,9 @@ public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, Ini
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,7 +61,7 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
|
||||
return (StringUtils.hasText(id) ? id : DefaultCqlBeanNames.CLUSTER);
|
||||
return StringUtils.hasText(id) ? id : DefaultCqlBeanNames.CLUSTER;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -131,10 +131,10 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
*/
|
||||
protected void parseChildElements(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
ManagedSet<BeanDefinition> keyspaceActionSpecificationBeanDefinitions = new ManagedSet<BeanDefinition>();
|
||||
ManagedSet<BeanDefinition> keyspaceActionSpecificationBeanDefinitions = new ManagedSet<>();
|
||||
|
||||
List<String> startupScripts = new ArrayList<String>();
|
||||
List<String> shutdownScripts = new ArrayList<String>();
|
||||
List<String> startupScripts = new ArrayList<>();
|
||||
List<String> shutdownScripts = new ArrayList<>();
|
||||
|
||||
BeanDefinitionBuilder poolingOptionsBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(PoolingOptionsFactoryBean.class);
|
||||
@@ -184,7 +184,7 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
* @param parserContext XML parser context and state.
|
||||
* @return the {@link BeanDefinition} or {@literal null} if action is not given.
|
||||
*/
|
||||
BeanDefinition newKeyspaceActionSpecificationBeanDefinition(Element element, ParserContext parserContext) {
|
||||
private BeanDefinition newKeyspaceActionSpecificationBeanDefinition(Element element, ParserContext parserContext) {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(KeyspaceActionSpecificationFactoryBean.class);
|
||||
@@ -210,10 +210,10 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
* @param element {@link Element} to parse.
|
||||
* @param builder The {@link BeanDefinitionBuilder} to add the replication to
|
||||
*/
|
||||
void parseReplication(Element element, BeanDefinitionBuilder builder) {
|
||||
private void parseReplication(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
ManagedList<String> networkTopologyDataCenters = new ManagedList<String>();
|
||||
ManagedList<String> networkTopologyReplicationFactors = new ManagedList<String>();
|
||||
ManagedList<String> networkTopologyDataCenters = new ManagedList<>();
|
||||
ManagedList<String> networkTopologyReplicationFactors = new ManagedList<>();
|
||||
|
||||
if (element != null) {
|
||||
addOptionalPropertyValue(builder, "replicationStrategy", element, "class",
|
||||
@@ -241,12 +241,13 @@ public class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
* @param keyspaceActionSpecificationBeanDefinitions The List of Definitions to flatten
|
||||
* @return A single level List of KeyspaceActionSpecifications
|
||||
*/
|
||||
Object newKeyspaceSetFlattenerBeanDefinition(Element element, ParserContext parserContext,
|
||||
private Object newKeyspaceSetFlattenerBeanDefinition(Element element, ParserContext parserContext,
|
||||
ManagedSet<BeanDefinition> keyspaceActionSpecificationBeanDefinitions) {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(MultiLevelSetFlattenerFactoryBean.class);
|
||||
|
||||
// TODO: introduce a typed reference instead of Set of Sets.
|
||||
builder.addPropertyValue("multiLevelSet", keyspaceActionSpecificationBeanDefinitions);
|
||||
|
||||
return getSourceBeanDefinition(builder, parserContext, element);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import org.w3c.dom.Element;
|
||||
* Utility class for parsing Cassandra XML namespace configuration meta-data.
|
||||
*
|
||||
* @author John Blum
|
||||
* @author Mark Paluch
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
@@ -209,26 +210,25 @@ public abstract class ParsingUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the named property and value, or reference to the given {@link BeanDefinitionBuilder} with an optional
|
||||
* default value if the value has not been specified.
|
||||
* Adds the named property and value, or reference to the given {@link BeanDefinitionBuilder} with an optional default
|
||||
* value if the value has not been specified.
|
||||
* <p/>
|
||||
* If <code>required</code> is <code>false</code>, <code>value</code> is null or empty,
|
||||
* and <code>defaultValue</code> is null or empty, then no property is added to the bean definition
|
||||
* and this method silently returns.
|
||||
* If {@code required} is <code>false</code>, <code>value</code> is null or empty, and {@code defaultValue} is null or
|
||||
* empty, then no property is added to the bean definition and this method silently returns.
|
||||
*
|
||||
* @param builder {@link BeanDefinitionBuilder} used to build the {@link BeanDefinition}.
|
||||
* @param propertyName name of the property to add.
|
||||
* @param value value for the property being added.
|
||||
* @param defaultValue default value for the property if value is null or empty.
|
||||
* @param required If <code>true</code>, then <code>value</code> must not be null or empty. If <code>false</code>,
|
||||
* then <code>value</code> may be null and the <code>defaultValue</code> will be used. If <code>required</code> is
|
||||
* <code>false</code>, <code>value</code> is null or empty, and <code>defaultValue</code> is null or empty,
|
||||
* then no property is added to the bean definition and this method silently returns.
|
||||
* @param reference If <code>true</code>, then the <code>value</code>value for the named property is
|
||||
* considered a reference to another bean in the Spring context.
|
||||
* @param required If {@code true}, then <code>value</code> must not be null or empty. If <code>false</code>, then
|
||||
* {@code value} may be null and the <code>defaultValue</code> will be used. If <code>required</code> is
|
||||
* {@code false}, <code>value</code> is null or empty, and <code>defaultValue</code> is null or empty, then
|
||||
* no property is added to the bean definition and this method silently returns.
|
||||
* @param reference If {@code true}, then the <code>value</code>value for the named property is considered a reference
|
||||
* to another bean in the Spring context.
|
||||
* @return the given {@link BeanDefinitionBuilder}.
|
||||
* @throws IllegalArgumentException if either the {@link BeanDefinitionBuilder} is null
|
||||
* or the <code>propertyName</code> has not been specified.
|
||||
* @throws IllegalArgumentException if either the {@link BeanDefinitionBuilder} is null or the {@code propertyName}
|
||||
* has not been specified.
|
||||
* @see BeanDefinitionBuilder#addPropertyReference(String, String)
|
||||
* @see BeanDefinitionBuilder#addPropertyValue(String, Object)
|
||||
*/
|
||||
|
||||
@@ -38,6 +38,9 @@ public class ArgumentPreparedStatementBinder implements PreparedStatementBinder
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.PreparedStatementBinder#bindValues(com.datastax.driver.core.PreparedStatement)
|
||||
*/
|
||||
@Override
|
||||
public BoundStatement bindValues(PreparedStatement ps) throws DriverException {
|
||||
return args != null ? ps.bind(args) : ps.bind();
|
||||
|
||||
@@ -80,7 +80,7 @@ import com.google.common.util.concurrent.Futures;
|
||||
public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOperations {
|
||||
|
||||
/**
|
||||
* Constructs a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before
|
||||
* Create a new, uninitialized {@link AsyncCqlTemplate}. Note: The {@link SessionFactory} has to be set before
|
||||
* using the instance.
|
||||
*
|
||||
* @see #setSessionFactory(SessionFactory)
|
||||
@@ -88,7 +88,7 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
public AsyncCqlTemplate() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link AsyncCqlTemplate} with the given {@link Session}.
|
||||
* Create a new {@link AsyncCqlTemplate} with the given {@link Session}.
|
||||
*
|
||||
* @param session the active Cassandra {@link Session}, must not be {@literal null}.
|
||||
* @throws IllegalStateException if {@link Session} is {@literal null}.
|
||||
@@ -450,17 +450,15 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
logger.debug("Preparing statement [{}] using {}", toCql(preparedStatementCreator), preparedStatementCreator);
|
||||
}
|
||||
|
||||
Session currentSession = getCurrentSession();
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
preparedStatementCreator.createPreparedStatement(currentSession), preparedStatement -> {
|
||||
try {
|
||||
return action.doInPreparedStatement(currentSession,
|
||||
applyStatementSettings(preparedStatement));
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", preparedStatement.toString(), e);
|
||||
}
|
||||
}), getExceptionTranslator());
|
||||
Session currentSession = getCurrentSession();return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(preparedStatementCreator.createPreparedStatement(currentSession),
|
||||
preparedStatement -> {
|
||||
try {
|
||||
return action.doInPreparedStatement(currentSession,applyStatementSettings(preparedStatement));
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", preparedStatement.toString(), e);
|
||||
}
|
||||
}), getExceptionTranslator());
|
||||
|
||||
} catch (DriverException e) {
|
||||
throw translateException("PreparedStatementCallback", toCql(preparedStatementCreator), e);
|
||||
@@ -588,8 +586,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(preparedStatementCreator, preparedStatementBinder,
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -625,8 +623,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args),
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -663,8 +661,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<?> results = query(newAsyncPreparedStatementCreator(cql), preparedStatementBinder,
|
||||
newResultSetExtractor(rowCallbackHandler));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, o -> null), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, o -> null), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -733,8 +731,8 @@ public class AsyncCqlTemplate extends CassandraAccessor implements AsyncCqlOpera
|
||||
ListenableFuture<List<T>> results = query(newAsyncPreparedStatementCreator(cql), newPreparedStatementBinder(args),
|
||||
newResultSetExtractor(rowMapper, 1));
|
||||
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(
|
||||
new MappingListenableFutureAdapter<>(results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
return new ExceptionTranslatingListenableFutureAdapter<>(new MappingListenableFutureAdapter<>(
|
||||
results, DataAccessUtils::requiredSingleResult), getExceptionTranslator());
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -19,7 +19,7 @@ import com.datastax.driver.core.ResultSetFuture;
|
||||
|
||||
/**
|
||||
* Interface used to give an implementation access to a {@link ResultSetFuture} after the query has completed.
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
@@ -27,8 +27,8 @@ public interface AsynchronousQueryListener {
|
||||
|
||||
/**
|
||||
* Called upon query completion.
|
||||
*
|
||||
*
|
||||
* @param rsf The {@link ResultSetFuture}. Called when the query operation is completed.
|
||||
*/
|
||||
public void onQueryComplete(ResultSetFuture rsf);
|
||||
void onQueryComplete(ResultSetFuture rsf);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -33,13 +33,13 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
* <p>
|
||||
* {@link CachedPreparedStatementCreator} is thread-safe and does not require external synchronization when used by
|
||||
* concurrent threads.
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class CachedPreparedStatementCreator implements PreparedStatementCreator {
|
||||
|
||||
private static final Map<Session, Map<String, PreparedStatement>> CACHE = new ConcurrentHashMap<Session, Map<String, PreparedStatement>>();
|
||||
private static final Map<Session, Map<String, PreparedStatement>> CACHE = new ConcurrentHashMap<>();
|
||||
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@@ -47,7 +47,7 @@ public class CachedPreparedStatementCreator implements PreparedStatementCreator
|
||||
|
||||
/**
|
||||
* Create a {@link PreparedStatementCreator} from the provided CQL.
|
||||
*
|
||||
*
|
||||
* @param cql must not be empty or {@literal null}.
|
||||
*/
|
||||
public CachedPreparedStatementCreator(String cql) {
|
||||
|
||||
@@ -41,6 +41,9 @@ import com.datastax.driver.core.Row;
|
||||
*/
|
||||
public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.RowMapper#mapRow(com.datastax.driver.core.Row, int)
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> mapRow(Row rs, int rowNum) {
|
||||
|
||||
@@ -62,7 +65,8 @@ public class ColumnMapRowMapper implements RowMapper<Map<String, Object>> {
|
||||
* <p>
|
||||
* By default, a linked case-insensitive Map will be created.
|
||||
*
|
||||
* @param columnCount the column count, to be used as initial capacity for the {@link Map}, must not be {@literal null}.
|
||||
* @param columnCount the column count, to be used as initial capacity for the {@link Map}, must not be
|
||||
* {@literal null}.
|
||||
* @return the new Map instance.
|
||||
* @see org.springframework.util.LinkedCaseInsensitiveMap
|
||||
*/
|
||||
|
||||
@@ -80,7 +80,7 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
|
||||
/**
|
||||
* Constructs a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using
|
||||
* Create a new, uninitialized {@link CqlTemplate}. Note: The {@link SessionFactory} has to be set before using
|
||||
* the instance.
|
||||
*
|
||||
* @see #setSessionFactory(SessionFactory)
|
||||
@@ -88,7 +88,7 @@ public class CqlTemplate extends CassandraAccessor implements CqlOperations {
|
||||
public CqlTemplate() {}
|
||||
|
||||
/**
|
||||
* Constructs a new {@link CqlTemplate} initialized with the given {@link Session}.
|
||||
* Create a new {@link CqlTemplate} initialized with the given {@link Session}.
|
||||
*
|
||||
* @param session the active Cassandra {@link Session}.
|
||||
* @throws IllegalStateException if {@link Session} is {@literal null}.
|
||||
|
||||
@@ -97,8 +97,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
future.addCallback(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.util.concurrent.ListenableFuture#addCallback(org.springframework.util.concurrent.SuccessCallback, org.springframework.util.concurrent.FailureCallback)
|
||||
*/
|
||||
@Override
|
||||
@@ -106,8 +105,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
future.addCallback(successCallback, failureCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#cancel(boolean)
|
||||
*/
|
||||
@Override
|
||||
@@ -115,8 +113,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
return adaptee.cancel(mayInterruptIfRunning);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#isCancelled()
|
||||
*/
|
||||
@Override
|
||||
@@ -124,8 +121,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
return adaptee.isCancelled();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#isDone()
|
||||
*/
|
||||
@Override
|
||||
@@ -133,8 +129,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
return future.isDone();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#get()
|
||||
*/
|
||||
@Override
|
||||
@@ -142,8 +137,7 @@ class ExceptionTranslatingListenableFutureAdapter<T> implements ListenableFuture
|
||||
return future.get();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -91,8 +91,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
return settableFuture;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.util.concurrent.ListenableFuture#addCallback(org.springframework.util.concurrent.ListenableFutureCallback)
|
||||
*/
|
||||
@Override
|
||||
@@ -100,8 +99,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
future.addCallback(callback);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.util.concurrent.ListenableFuture#addCallback(org.springframework.util.concurrent.SuccessCallback, org.springframework.util.concurrent.FailureCallback)
|
||||
*/
|
||||
@Override
|
||||
@@ -109,8 +107,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
future.addCallback(successCallback, failureCallback);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#cancel(boolean)
|
||||
*/
|
||||
@Override
|
||||
@@ -118,8 +115,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
return adaptee.cancel(mayInterruptIfRunning);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#isCancelled()
|
||||
*/
|
||||
@Override
|
||||
@@ -127,8 +123,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
return adaptee.isCancelled();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#isDone()
|
||||
*/
|
||||
@Override
|
||||
@@ -136,8 +131,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
return future.isDone();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#get()
|
||||
*/
|
||||
@Override
|
||||
@@ -145,8 +139,7 @@ public class GuavaListenableFutureAdapter<T> implements ListenableFuture<T> {
|
||||
return future.get();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Future#get(long, java.util.concurrent.TimeUnit)
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -20,7 +20,7 @@ import java.util.Comparator;
|
||||
/**
|
||||
* Enum for Cassandra primary key column ordering. Implements {@link Comparator} in that {@link Ordering#ASCENDING} is
|
||||
* ordered before {@link Ordering#DESCENDING}.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public enum Ordering implements Comparator<Ordering> {
|
||||
@@ -37,7 +37,7 @@ public enum Ordering implements Comparator<Ordering> {
|
||||
|
||||
private String cql;
|
||||
|
||||
private Ordering(String cql) {
|
||||
Ordering(String cql) {
|
||||
this.cql = cql;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ public enum Ordering implements Comparator<Ordering> {
|
||||
if (l == r) {
|
||||
return 0;
|
||||
}
|
||||
if (l == null && r != null) {
|
||||
if (l == null) {
|
||||
return 1;
|
||||
}
|
||||
if (l != null && r == null) {
|
||||
if (r == null) {
|
||||
return -1;
|
||||
}
|
||||
return (l == ASCENDING && r == DESCENDING) ? 1 : -1;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -35,14 +35,15 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
* @see CqlTemplate#query(String, PreparedStatementBinder, ResultSetExtractor)
|
||||
* @see AsyncCqlTemplate#query(AsyncPreparedStatementCreator, PreparedStatementBinder, ResultSetExtractor)
|
||||
* @see ReactiveCqlTemplate#query(String, PreparedStatementBinder, ReactiveResultSetExtractor)
|
||||
*/
|
||||
public interface PreparedStatementBinder {
|
||||
|
||||
/**
|
||||
* Bind parameter values on the given {@link PreparedStatement}.
|
||||
*
|
||||
* @param ps the PreparedStatement to invoke setter methods on
|
||||
*
|
||||
* @param ps the PreparedStatement to invoke setter methods on.
|
||||
* @throws DriverException if a {@link DriverException} is encountered (i.e. there is no need to catch
|
||||
* {@link DriverException})
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,8 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
* @see AsyncCqlTemplate#execute(String, PreparedStatementCallback)
|
||||
* @see AsyncCqlTemplate#execute(PreparedStatementCreator, PreparedStatementCallback)
|
||||
* @see CqlTemplate#execute(String, PreparedStatementCallback)
|
||||
* @see CqlTemplate#execute(PreparedStatementCreator, PreparedStatementCallback)
|
||||
*/
|
||||
@@ -54,10 +56,11 @@ public interface PreparedStatementCallback<T> {
|
||||
* @return a result object publisher.
|
||||
* @throws DriverException if thrown by a session method, to be auto-converted to a DataAccessException.
|
||||
* @throws DataAccessException in case of custom exceptions.
|
||||
* @see AsyncCqlTemplate#queryForObject(String, Class, Object...)
|
||||
* @see AsyncCqlTemplate#queryForList(String, Class, Object...)
|
||||
* @see CqlTemplate#queryForObject(String, Class, Object...)
|
||||
* @see CqlTemplate#queryForList(String, Object...)
|
||||
*/
|
||||
T doInPreparedStatement(Session session, PreparedStatement preparedStatement)
|
||||
throws DriverException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -43,5 +43,4 @@ public interface PreparedStatementCreator {
|
||||
* of this method. The {@link CqlTemplate} class will handle them.
|
||||
*/
|
||||
PreparedStatement createPreparedStatement(Session session) throws DriverException;
|
||||
|
||||
}
|
||||
|
||||
@@ -41,10 +41,10 @@ public enum PrimaryKeyType implements Comparator<PrimaryKeyType> {
|
||||
if (l == r) {
|
||||
return 0;
|
||||
}
|
||||
if (l == null && r != null) {
|
||||
if (l == null) {
|
||||
return 1;
|
||||
}
|
||||
if (l != null && r == null) {
|
||||
if (r == null) {
|
||||
return -1;
|
||||
}
|
||||
return l == PARTITIONED && r == CLUSTERED ? 1 : -1;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core;
|
||||
|
||||
import java.util.List;
|
||||
@@ -5,8 +20,8 @@ import java.util.List;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
/**
|
||||
* Listener used to receive asynchronous results expected as a <code>List<T></code>.
|
||||
*
|
||||
* Listener used to receive asynchronous results expected as a {@code List<T>}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,25 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Listener used to receive asynchronous results expected as a <code>List<T></code>.
|
||||
*
|
||||
* Listener used to receive asynchronous results expected as a {@code List<T>}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public interface QueryForListOfMapListener extends QueryForListListener<Map<String, Object>> {}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core;
|
||||
|
||||
import java.util.Map;
|
||||
@@ -5,8 +20,8 @@ import java.util.Map;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
/**
|
||||
* Listener used to receive asynchronous results expected as a <code>List<Map<String,Object>></code>.
|
||||
*
|
||||
* Listener used to receive asynchronous results expected as a {@code List<Map<String,Object>>}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cassandra.core;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
/**
|
||||
* Listener used to receive asynchronous results expected as an object of type <code>T</code> or an {@link Exception}.
|
||||
*
|
||||
* Listener used to receive asynchronous results expected as an object of type {@code T} or an {@link Exception}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @param <T>
|
||||
@@ -28,14 +28,14 @@ public interface QueryForObjectListener<T> {
|
||||
|
||||
/**
|
||||
* Called upon query completion.
|
||||
*
|
||||
*
|
||||
* @param result the result, can be {@literal null} for empty single-record results.
|
||||
*/
|
||||
void onQueryComplete(T result);
|
||||
|
||||
/**
|
||||
* Called if an exception is raised while getting or converting the {@link ResultSet}.
|
||||
*
|
||||
*
|
||||
* @param ex the exception that triggered the failure, never {@link null}.
|
||||
*/
|
||||
void onException(Exception ex);
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -257,7 +261,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(cql, rowMapper).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list))).next();
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -378,7 +383,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(Statement statement, RowMapper<T> rowMapper) throws DataAccessException {
|
||||
return query(statement, rowMapper).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list))).next();
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -568,7 +574,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
@Override
|
||||
public <T> Mono<T> queryForObject(String cql, RowMapper<T> rowMapper, Object... args) throws DataAccessException {
|
||||
return query(cql, rowMapper, args).buffer(2).flatMap(list ->
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list))).next();
|
||||
Mono.just(DataAccessUtils.requiredSingleResult(list)))
|
||||
.next();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -638,7 +645,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
@Override
|
||||
public Mono<Boolean> execute(String cql, PreparedStatementBinder psb) throws DataAccessException {
|
||||
return query(new SimpleReactivePreparedStatementCreator(cql), psb, resultSet ->
|
||||
Mono.just(resultSet.wasApplied())).next();
|
||||
Mono.just(resultSet.wasApplied()))
|
||||
.next();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -748,7 +756,8 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
protected <T> Function<Throwable, Mono<? extends T>> translateException(String task, String cql) {
|
||||
|
||||
return throwable -> Mono.error(
|
||||
return throwable -> Mono
|
||||
.error(
|
||||
throwable instanceof DriverException ? translate(task, cql, (DriverException) throwable) : throwable);
|
||||
}
|
||||
|
||||
@@ -852,7 +861,11 @@ public class ReactiveCqlTemplate extends ReactiveCassandraAccessor implements Re
|
||||
*/
|
||||
private static String getCql(Object cqlProvider) {
|
||||
|
||||
return (cqlProvider instanceof CqlProvider ? ((CqlProvider) cqlProvider).getCql() : null);
|
||||
return Optional.ofNullable(cqlProvider) //
|
||||
.filter(o -> o instanceof CqlProvider) //
|
||||
.map(o -> (CqlProvider) o) //
|
||||
.map(CqlProvider::getCql) //
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private class SimpleReactivePreparedStatementCreator implements ReactivePreparedStatementCreator, CqlProvider {
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
/**
|
||||
* Callback interface used by {@link CqlTemplate}'s query methods. Implementations of this interface perform the actual
|
||||
* work of extracting results from a {@link ResultSet}, but don't need to worry about exception handling.
|
||||
@@ -35,6 +35,7 @@ import org.springframework.dao.DataAccessException;
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @since April 24, 2003
|
||||
* @see AsyncCqlTemplate
|
||||
* @see CqlTemplate
|
||||
* @see RowCallbackHandler
|
||||
* @see RowMapper
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core;
|
||||
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
|
||||
/**
|
||||
* Convenient default implementation of a {@link Cancellable}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class ResultSetFutureCancellable implements Cancellable {
|
||||
|
||||
ResultSetFuture rsf;
|
||||
|
||||
public ResultSetFutureCancellable(ResultSetFuture rsf) {
|
||||
this.rsf = rsf;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
rsf.cancel(true);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -20,6 +20,10 @@ import org.springframework.dao.DataAccessException;
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
/**
|
||||
* @param <T>
|
||||
* @deprecated as of 2.0, not used anymore.
|
||||
*/
|
||||
public interface ResultSetFutureExtractor<T> {
|
||||
|
||||
T extractData(ResultSetFuture rs) throws DriverException, DataAccessException;
|
||||
|
||||
@@ -17,10 +17,15 @@ package org.springframework.cassandra.core;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.driver.core.Host;
|
||||
|
||||
/**
|
||||
* Domain object representing a Cassandra host.
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public final class RingMember implements Serializable {
|
||||
|
||||
@@ -29,16 +34,47 @@ public final class RingMember implements Serializable {
|
||||
/*
|
||||
* Ring attributes
|
||||
*/
|
||||
public String hostName;
|
||||
public String address;
|
||||
public String DC;
|
||||
public String rack;
|
||||
private final String hostName;
|
||||
|
||||
public RingMember(Host h) {
|
||||
this.hostName = h.getAddress().getHostName();
|
||||
this.address = h.getAddress().getHostAddress();
|
||||
this.DC = h.getDatacenter();
|
||||
this.rack = h.getRack();
|
||||
private final String address;
|
||||
|
||||
private final String dc;
|
||||
|
||||
private final String rack;
|
||||
|
||||
/**
|
||||
* Creates a new {@link RingMember} given {@link Host}.
|
||||
*
|
||||
* @param host
|
||||
* @return
|
||||
*/
|
||||
public static RingMember from(Host host) {
|
||||
return new RingMember(host);
|
||||
}
|
||||
|
||||
private RingMember(Host host) {
|
||||
|
||||
Assert.notNull(host, "Host must not be null");
|
||||
|
||||
this.hostName = host.getAddress().getHostName();
|
||||
this.address = host.getAddress().getHostAddress();
|
||||
this.dc = host.getDatacenter();
|
||||
this.rack = host.getRack();
|
||||
}
|
||||
|
||||
public String getHostName() {
|
||||
return hostName;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public String getDataCenter() {
|
||||
return dc;
|
||||
}
|
||||
|
||||
public String getRack() {
|
||||
return rack;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@ import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.datastax.driver.core.Host;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* {@link HostMapper} to to map hosts into {@link RingMember} objects.
|
||||
*
|
||||
@@ -43,6 +43,6 @@ public enum RingMemberHostMapper implements HostMapper<RingMember> {
|
||||
|
||||
Assert.notNull(hosts, "Hosts must not be null");
|
||||
|
||||
return StreamSupport.stream(hosts.spliterator(), false).map(RingMember::new).collect(Collectors.toList());
|
||||
return StreamSupport.stream(hosts.spliterator(), false).map(RingMember::from).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -19,11 +19,18 @@ import com.datastax.driver.core.Row;
|
||||
|
||||
/**
|
||||
* Simple internal callback to allow operations on a {@link Row}.
|
||||
*
|
||||
*
|
||||
* @author Alex Shvid
|
||||
* @deprecated as of 2.0. Superseded by {@link RowCallbackHandler}.
|
||||
*/
|
||||
|
||||
public interface RowCallback<T> {
|
||||
|
||||
/**
|
||||
* Implementations must implement this method to process each row of data in the
|
||||
* {@link com.datastax.driver.core.ResultSet}. This method is only supposed to extract values of the current row.
|
||||
*
|
||||
* @param object
|
||||
* @return
|
||||
*/
|
||||
T doWith(Row object);
|
||||
}
|
||||
|
||||
@@ -50,5 +50,4 @@ public interface RowCallbackHandler {
|
||||
* to catch {@link DriverException})
|
||||
*/
|
||||
void processRow(Row row) throws DriverException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -17,7 +17,9 @@ package org.springframework.cassandra.core;
|
||||
|
||||
/**
|
||||
* @author David Webb
|
||||
* @deprecated as of 2.0. This class is not used anymore.
|
||||
*/
|
||||
@Deprecated
|
||||
public interface RowIterator {
|
||||
|
||||
Object[] next();
|
||||
|
||||
@@ -46,5 +46,4 @@ public interface RowMapper<T> {
|
||||
* to catch {@link DriverException})
|
||||
*/
|
||||
T mapRow(Row row, int rowNum) throws DriverException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -43,7 +43,7 @@ public interface SessionCallback<T> {
|
||||
* objects. Note that there's special support for single step actions: see {@link CqlTemplate#queryForObject} etc. A
|
||||
* thrown {@link RuntimeException} is treated as application exception: it gets propagated to the caller of the
|
||||
* template.
|
||||
*
|
||||
*
|
||||
* @param session active Cassandra Session, must not be {@literal null}.
|
||||
* @return a result object, or {@code null} if none.
|
||||
* @throws DriverException if thrown by a Session method, to be auto-converted to a {@link DataAccessException}.
|
||||
@@ -52,5 +52,4 @@ public interface SessionCallback<T> {
|
||||
* @see CqlTemplate#queryForResultSet(String)
|
||||
*/
|
||||
T doInSession(Session session) throws DriverException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -22,34 +22,43 @@ import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.DriverException;
|
||||
|
||||
/**
|
||||
* This Prepared Statement Creator simply prepares a statement from the CQL string. This should not be used in
|
||||
* Production systems with high volume reads and writes. Use {@link CachedPreparedStatementCreator} When preparing
|
||||
* statements with Cassandra, each Statement should be prepared once and only once due to the overhead of preparing the
|
||||
* statement.
|
||||
*
|
||||
* Trivial implementation of {@link PreparedStatementCreator}. This prepared statement creator simply prepares a
|
||||
* statement from the CQL string.
|
||||
* <p>
|
||||
* This implementation is useful for testing. It should not be used in production systems with high volume reads and
|
||||
* writes. Use {@link CachedPreparedStatementCreator} When preparing statements with Cassandra, each Statement should be
|
||||
* prepared once and only once due to the overhead of preparing the statement.
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class SimplePreparedStatementCreator implements PreparedStatementCreator {
|
||||
public class SimplePreparedStatementCreator implements PreparedStatementCreator, CqlProvider {
|
||||
|
||||
private final String cql;
|
||||
|
||||
/**
|
||||
* Create a PreparedStatementCreator from the provided CQL.
|
||||
*
|
||||
* @param cql
|
||||
* Create a {@link SimplePreparedStatementCreator} given {@code cql}.
|
||||
*
|
||||
* @param cql must not be {@literal null}.
|
||||
*/
|
||||
public SimplePreparedStatementCreator(String cql) {
|
||||
|
||||
Assert.notNull(cql, "CQL is required to create a PreparedStatement");
|
||||
this.cql = cql;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.CqlProvider#getCql()
|
||||
*/
|
||||
public String getCql() {
|
||||
return this.cql;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.PreparedStatementCreator#createPreparedStatement(com.datastax.driver.core.Session)
|
||||
*/
|
||||
@Override
|
||||
public PreparedStatement createPreparedStatement(Session session) throws DriverException {
|
||||
return session.prepare(this.cql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,10 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
* @see AsyncCqlTemplate#queryForList(String, Class)
|
||||
* @see AsyncCqlTemplate#queryForObject(String, Class)
|
||||
* @see CqlTemplate#queryForList(String, Class)
|
||||
* @see CqlTemplate#queryForObject(String, Class)
|
||||
* @see ReactiveCqlTemplate#queryForFlux(String, Class)
|
||||
* @see ReactiveCqlTemplate#queryForObject(String, Class)
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.List;
|
||||
@@ -22,7 +37,7 @@ import com.datastax.driver.core.ResultSet;
|
||||
* <p/>
|
||||
* If the converter throws due to the inability to convert a given {@link ResultSet}, it will throw an
|
||||
* {@link IllegalArgumentException}.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
@@ -5,7 +20,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
|
||||
|
||||
/**
|
||||
* Thin wrapper that allows subclasses to delegate conversion of the given value to a {@link DefaultConversionService}.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T>
|
||||
*/
|
||||
|
||||
@@ -70,7 +70,7 @@ public class ResultSetToArrayConverter implements Converter<ResultSet, Object[]>
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Object[]> list = new ArrayList<Object[]>();
|
||||
List<Object[]> list = new ArrayList<>();
|
||||
for (Row row : resultSet) {
|
||||
list.add(rowConverter.convert(row));
|
||||
}
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class ResultSetToBigDecimalConverter extends AbstractResultSetToBasicFixedTypeConverter<BigDecimal> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected BigDecimal doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, BigDecimal.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return BigDecimal.class;
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class ResultSetToBigIntegerConverter extends AbstractResultSetToBasicFixedTypeConverter<BigInteger> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected BigInteger doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, BigInteger.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return BigInteger.class;
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
public class ResultSetToBooleanConverter extends AbstractResultSetToBasicFixedTypeConverter<Boolean> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Boolean doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Boolean.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Boolean.class;
|
||||
|
||||
@@ -1,9 +1,27 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class ResultSetToByteBufferConverter extends AbstractResultSetConverter<ByteBuffer> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected ByteBuffer doConvertSingleValue(Object object) {
|
||||
|
||||
@@ -14,6 +32,9 @@ public class ResultSetToByteBufferConverter extends AbstractResultSetConverter<B
|
||||
return (ByteBuffer) object;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return ByteBuffer.class;
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class ResultSetToDateConverter extends AbstractResultSetToBasicFixedTypeConverter<Date> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Date doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Date.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Date.class;
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
public class ResultSetToDoubleConverter extends AbstractResultSetToBasicFixedTypeConverter<Double> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Double doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Double.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Double.class;
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
public class ResultSetToFloatConverter extends AbstractResultSetToBasicFixedTypeConverter<Float> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Float doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Float.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Float.class;
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class ResultSetToInetAddressConverter extends AbstractResultSetToBasicFixedTypeConverter<InetAddress> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected InetAddress doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, InetAddress.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return InetAddress.class;
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
public class ResultSetToIntegerConverter extends AbstractResultSetToBasicFixedTypeConverter<Integer> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Integer doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Integer.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Integer.class;
|
||||
|
||||
@@ -79,7 +79,7 @@ public class ResultSetToListConverter implements Converter<ResultSet, List<Map<S
|
||||
return null;
|
||||
}
|
||||
|
||||
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (Row row : resultSet) {
|
||||
list.add(rowConverter.convert(row));
|
||||
}
|
||||
|
||||
@@ -1,44 +1,54 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class ResultSetToListOfStringConverter extends AbstractResultSetConverter<List<String>> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected List<String> doConvertSingleValue(Object object) {
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
list.add(object == null ? null : object.toString());
|
||||
return list;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleRow(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected List<String> doConvertSingleRow(Map<String, Object> row) {
|
||||
|
||||
List<String> list = new ArrayList<String>(row.size());
|
||||
|
||||
for (Object value : row.values()) {
|
||||
list.add(value == null ? null : value.toString());
|
||||
}
|
||||
|
||||
return list;
|
||||
return row.values().stream().map(value -> value == null ? null : value.toString()).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> doConvertResultSet(List<Map<String, Object>> resultSet) {
|
||||
|
||||
List<String> list = new ArrayList<String>(resultSet.size());
|
||||
|
||||
for (Map<String, Object> row : resultSet) {
|
||||
list.add(StringUtils.arrayToCommaDelimitedString(doConvertSingleRow(row).toArray()));
|
||||
}
|
||||
|
||||
return list;
|
||||
return resultSet.stream().map(row -> doConvertSingleRow(row).toArray()) //
|
||||
.map(StringUtils::arrayToCommaDelimitedString) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,33 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
public class ResultSetToLongConverter extends AbstractResultSetToBasicFixedTypeConverter<Long> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected Long doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, Long.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return Long.class;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.List;
|
||||
@@ -5,11 +20,17 @@ import java.util.Map;
|
||||
|
||||
public class ResultSetToStringConverter extends AbstractResultSetConverter<String> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected String doConvertSingleValue(Object object) {
|
||||
return object == null ? null : object.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleRow(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
protected String doConvertSingleRow(Map<String, Object> row) {
|
||||
|
||||
|
||||
@@ -1,14 +1,35 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ResultSetToUuidConverter extends AbstractResultSetToBasicFixedTypeConverter<UUID> {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#doConvertSingleValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
protected UUID doConvertSingleValue(Object object) {
|
||||
return CONVERTER.convert(object, UUID.class);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.converter.AbstractResultSetConverter#getType()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getType() {
|
||||
return UUID.class;
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.List;
|
||||
@@ -10,6 +25,9 @@ public class RowToArrayConverter implements Converter<Row, Object[]> {
|
||||
|
||||
protected RowToListConverter delegate = new RowToListConverter();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Object[] convert(Row row) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package org.springframework.cassandra.core.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.ReadingConverter;
|
||||
@@ -38,6 +39,9 @@ public class RowToListConverter implements Converter<Row, List<Object>> {
|
||||
|
||||
public final static RowToListConverter INSTANCE = new RowToListConverter();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public List<Object> convert(Row row) {
|
||||
|
||||
@@ -46,14 +50,8 @@ public class RowToListConverter implements Converter<Row, List<Object>> {
|
||||
}
|
||||
|
||||
ColumnDefinitions cols = row.getColumnDefinitions();
|
||||
List<Object> list = new ArrayList<Object>(cols.size());
|
||||
|
||||
for (Definition def : cols.asList()) {
|
||||
String name = def.getName();
|
||||
|
||||
list.add(row.isNull(name) ? null : row.getObject(name));
|
||||
}
|
||||
|
||||
return list;
|
||||
return cols.asList().stream() //
|
||||
.map(Definition::getName).map(name -> row.isNull(name) ? null : row.getObject(name)) //
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,6 +38,9 @@ public class RowToMapConverter implements Converter<Row, Map<String, Object>> {
|
||||
|
||||
public final static RowToMapConverter INSTANCE = new RowToMapConverter();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.core.convert.converter.Converter#convert(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> convert(Row row) {
|
||||
|
||||
@@ -46,14 +49,10 @@ public class RowToMapConverter implements Converter<Row, Map<String, Object>> {
|
||||
}
|
||||
|
||||
ColumnDefinitions cols = row.getColumnDefinitions();
|
||||
Map<String, Object> map = new HashMap<String, Object>(cols.size());
|
||||
Map<String, Object> map = new HashMap<>(cols.size());
|
||||
|
||||
for (Definition def : cols.asList()) {
|
||||
|
||||
String name = def.getName();
|
||||
|
||||
map.put(name, row.isNull(name) ? null : row.getObject(name));
|
||||
}
|
||||
cols.asList().stream().map(Definition::getName)
|
||||
.forEach(name -> map.put(name, row.isNull(name) ? null : row.getObject(name)));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.cql;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlConstantType.Regex.*;
|
||||
@@ -14,7 +29,7 @@ public enum CqlConstantType {
|
||||
|
||||
private Pattern pattern;
|
||||
|
||||
private CqlConstantType(Pattern pattern) {
|
||||
CqlConstantType(Pattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -69,10 +69,10 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
/**
|
||||
* Create a new CQL identifier, optionally force-quoting it. Force-quoting can be used to preserve identifier case.
|
||||
* <ul>
|
||||
* <li>If the given identifier is a legal quoted identifier or <code>forceQuote</code> is <code>true</code>,
|
||||
* {@link #isQuoted()} will return <code>true</code> and the identifier will be quoted when rendered.</li>
|
||||
* <li>If the given identifier is a legal unquoted identifier, {@link #isQuoted()} will return <code>false</code>,
|
||||
* plus the name will be converted to lower case and rendered as such.</li>
|
||||
* <li>If the given identifier is a legal quoted identifier or {@code forceQuote} is <code>true</code>,
|
||||
* {@link #isQuoted()} will return {@code true} and the identifier will be quoted when rendered.</li>
|
||||
* <li>If the given identifier is a legal unquoted identifier, {@link #isQuoted()} will return {@code false}, plus the
|
||||
* name will be converted to lower case and rendered as such.</li>
|
||||
* <li>If the given identifier is illegal, an {@link IllegalArgumentException} is thrown.</li>
|
||||
* </ul>
|
||||
*
|
||||
@@ -111,14 +111,14 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given {@link CharSequence} is a legal unquoted identifier.
|
||||
* Returns {@code true} if the given {@link CharSequence} is a legal unquoted identifier.
|
||||
*/
|
||||
public static boolean isUnquotedIdentifier(CharSequence chars) {
|
||||
return UNQUOTED.matcher(chars).matches() && !ReservedKeyword.isReserved(chars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given {@link CharSequence} is a legal unquoted identifier.
|
||||
* Returns {@code true} if the given {@link CharSequence} is a legal unquoted identifier.
|
||||
*/
|
||||
public static boolean isQuotedIdentifier(CharSequence chars) {
|
||||
return QUOTED.matcher(chars).matches() || ReservedKeyword.isReserved(chars);
|
||||
@@ -149,7 +149,7 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Returns the identifier <em>without</em> encasing quotes, regardless of the value of {@link #isQuoted()}. For
|
||||
* example, if {@link #isQuoted()} is <code>true</code>, then this value will be the same as {@link #toCql()} and
|
||||
* example, if {@link #isQuoted()} is {@code true}, then this value will be the same as {@link #toCql()} and
|
||||
* {@link #toString()}.
|
||||
* <p/>
|
||||
* This is needed, for example, to get the correct {@link TableMetadata} from
|
||||
@@ -168,8 +168,7 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
|
||||
/**
|
||||
* Appends the rendering of this identifier to the given {@link StringBuilder}, then returns that
|
||||
* {@link StringBuilder}. If <code>null</code> is given, a new {@link StringBuilder} is created, appended to, and
|
||||
* returned.
|
||||
* {@link StringBuilder}. If {@code null} is given, a new {@link StringBuilder} is created, appended to, and returned.
|
||||
*/
|
||||
public StringBuilder toCql(StringBuilder builder) {
|
||||
return (builder != null ? builder : new StringBuilder()).append(toCql());
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -33,7 +33,7 @@ public class CqlStringUtils {
|
||||
|
||||
/**
|
||||
* Renders the given string as a legal Cassandra string column or table option value, by escaping single quotes and
|
||||
* encasing the result in single quotes. Given <code>null</code>, returns <code>null</code>.
|
||||
* encasing the result in single quotes. Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String valuize(String candidate) {
|
||||
|
||||
@@ -44,34 +44,32 @@ public class CqlStringUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles single quote characters (' -> ''). Given <code>null</code>, returns <code>null</code>.
|
||||
* Doubles single quote characters (' -> ''). Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String escapeSingle(Object thing) {
|
||||
return thing == null ? (String) null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE);
|
||||
return thing == null ? null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles double quote characters (" -> ""). Given <code>null</code>, returns <code>null</code>.
|
||||
* Doubles double quote characters (" -> ""). Given {@code null}, returns <code>null</code>.
|
||||
*/
|
||||
public static String escapeDouble(Object thing) {
|
||||
return thing == null ? (String) null : thing.toString().replace(DOUBLE_QUOTE, DOUBLE_DOUBLE_QUOTE);
|
||||
return thing == null ? null : thing.toString().replace(DOUBLE_QUOTE, DOUBLE_DOUBLE_QUOTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given <code>null</code>, returns
|
||||
* <code>null</code>.
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String singleQuote(Object thing) {
|
||||
return thing == null ? (String) null : new StringBuilder().append(SINGLE_QUOTE).append(thing).append(SINGLE_QUOTE)
|
||||
return thing == null ? null : new StringBuilder().append(SINGLE_QUOTE).append(thing).append(SINGLE_QUOTE)
|
||||
.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with double quotes. Given <code>null</code>, returns
|
||||
* <code>null</code>.
|
||||
* Surrounds given object's {@link Object#toString()} with double quotes. Given {@code null}, returns {@code null}.
|
||||
*/
|
||||
public static String doubleQuote(Object thing) {
|
||||
return thing == null ? (String) null : new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE)
|
||||
return thing == null ? null : new StringBuilder().append(DOUBLE_QUOTE).append(thing).append(DOUBLE_QUOTE)
|
||||
.toString();
|
||||
}
|
||||
|
||||
@@ -79,12 +77,12 @@ public class CqlStringUtils {
|
||||
* Removed single quotes from quoted String option values
|
||||
*/
|
||||
public static String removeSingleQuotes(Object thing) {
|
||||
return thing == null ? (String) null : ((String) thing).replaceAll(SINGLE_QUOTE, EMPTY_STRING);
|
||||
return thing == null ? null : ((String) thing).replaceAll(SINGLE_QUOTE, EMPTY_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the given {@link DataType} as a CQL string.
|
||||
*
|
||||
*
|
||||
* @param dataType The {@link DataType} to render; must not be null.
|
||||
*/
|
||||
public static String toCql(DataType dataType) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public final class KeyspaceIdentifier implements Comparable<KeyspaceIdentifier>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the given {@link CharSequence} is a legal keyspace identifier.
|
||||
* Returns {@code true} if the given {@link CharSequence} is a legal keyspace identifier.
|
||||
*/
|
||||
public static boolean isIdentifier(CharSequence chars) {
|
||||
return PATTERN.matcher(chars).matches() && !ReservedKeyword.isReserved(chars);
|
||||
@@ -86,8 +86,7 @@ public final class KeyspaceIdentifier implements Comparable<KeyspaceIdentifier>
|
||||
|
||||
/**
|
||||
* Appends the rendering of this identifier to the given {@link StringBuilder}, then returns that
|
||||
* {@link StringBuilder}. If <code>null</code> is given, a new {@link StringBuilder} is created, appended to, and
|
||||
* returned.
|
||||
* {@link StringBuilder}. If {@code null} is given, a new {@link StringBuilder} is created, appended to, and returned.
|
||||
*/
|
||||
public StringBuilder toCql(StringBuilder sb) {
|
||||
sb = sb == null ? new StringBuilder() : sb;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.AlterColumnSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating an <code>ALTER</code> column clause of an <code>ALTER TABLE</code> statement.
|
||||
* CQL generator for generating an {@code ALTER} column clause of an <code>ALTER TABLE</code> statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @see AlterColumnSpecification
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -23,8 +23,8 @@ import org.springframework.cassandra.core.keyspace.AlterKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* CQL generator for generating <code>ALTER TABLE</code> statements.
|
||||
*
|
||||
* CQL generator for generating {@code ALTER TABLE} statements.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class AlterKeyspaceCqlGenerator extends KeyspaceOptionsCqlGenerator<AlterKeyspaceSpecification> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.CreateIndexSpecification;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>CREATE INDEX</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code CREATE INDEX} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -25,8 +25,8 @@ import org.springframework.cassandra.core.keyspace.KeyspaceOption;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>CREATE TABLE</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code CREATE TABLE} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,9 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.PrimaryKeyType.PARTITIONED;
|
||||
import static org.springframework.cassandra.core.PrimaryKeyType.CLUSTERED;
|
||||
import static org.springframework.cassandra.core.PrimaryKeyType.*;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -28,8 +27,8 @@ import org.springframework.cassandra.core.keyspace.CreateTableSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>CREATE TABLE</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code CREATE TABLE} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
*/
|
||||
@@ -69,8 +68,8 @@ public class CreateTableCqlGenerator extends TableCqlGenerator<CreateTableSpecif
|
||||
// begin columns
|
||||
cql.append(" (");
|
||||
|
||||
List<ColumnSpecification> partitionKeys = new ArrayList<ColumnSpecification>();
|
||||
List<ColumnSpecification> clusterKeys = new ArrayList<ColumnSpecification>();
|
||||
List<ColumnSpecification> partitionKeys = new ArrayList<>();
|
||||
List<ColumnSpecification> clusterKeys = new ArrayList<>();
|
||||
for (ColumnSpecification col : spec().getColumns()) {
|
||||
col.toCql(cql).append(", ");
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropIndexSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>DROP INDEX</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code DROP INDEX} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>DROP TABLE</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code DROP TABLE} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class DropKeyspaceCqlGenerator extends KeyspaceNameCqlGenerator<DropKeyspaceSpecification> {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.noNull;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
|
||||
/**
|
||||
* CQL generator for generating a <code>DROP TABLE</code> statement.
|
||||
*
|
||||
* CQL generator for generating a {@code DROP TABLE} statement.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class DropTableCqlGenerator extends TableNameCqlGenerator<DropTableSpecification> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,7 +66,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
/**
|
||||
* The list of column changes.
|
||||
*/
|
||||
private List<ColumnChangeSpecification> changes = new ArrayList<ColumnChangeSpecification>();
|
||||
private List<ColumnChangeSpecification> changes = new ArrayList<>();
|
||||
|
||||
/*
|
||||
* Adds a {@code DROP} to the list of column changes.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,7 @@ import com.datastax.driver.core.DataType;
|
||||
*/
|
||||
public class AlterUserTypeSpecification extends UserTypeNameSpecification<AlterUserTypeSpecification> {
|
||||
|
||||
private final List<ColumnChangeSpecification> changes = new ArrayList<ColumnChangeSpecification>();
|
||||
private final List<ColumnChangeSpecification> changes = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Entry point into the {@link AlterUserTypeSpecification}'s fluent API to alter a type. Convenient if imported
|
||||
|
||||
@@ -31,8 +31,8 @@ import com.datastax.driver.core.DataType;
|
||||
* Builder class to specify columns.
|
||||
* <p/>
|
||||
* Use {@link #name(String)} and {@link #type(String)} to set the name and type of the column, respectively. To specify
|
||||
* a clustered <code>PRIMARY KEY</code> column, use {@link #clustered()} or {@link #clustered(Ordering)}. To specify
|
||||
* that the <code>PRIMARY KEY</code> column is or is part of the partition key, use {@link #partitioned()} instead of
|
||||
* a clustered {@code PRIMARY KEY} column, use {@link #clustered()} or {@link #clustered(Ordering)}. To specify that the
|
||||
* {@code PRIMARY KEY} column is or is part of the partition key, use {@link #partitioned()} instead of
|
||||
* {@link #clustered()} or {@link #clustered(Ordering)}.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
@@ -81,7 +81,7 @@ public class ColumnSpecification {
|
||||
|
||||
/**
|
||||
* Identifies this column as a primary key column that is also part of a partition key. Sets the column's
|
||||
* {@link #keyType} to {@link PrimaryKeyType#PARTITIONED} and its {@link #ordering} to <code>null</code>.
|
||||
* {@link #keyType} to {@link PrimaryKeyType#PARTITIONED} and its {@link #ordering} to {@code null}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@@ -91,8 +91,8 @@ public class ColumnSpecification {
|
||||
|
||||
/**
|
||||
* Toggles the identification of this column as a primary key column that also is or is part of a partition key. Sets
|
||||
* {@link #ordering} to <code>null</code> and, if the given boolean is <code>true</code>, then sets the column's
|
||||
* {@link #keyType} to {@link PrimaryKeyType#PARTITIONED}, else sets it to <code>null</code>.
|
||||
* {@link #ordering} to {@code null} and, if the given boolean is <code>true</code>, then sets the column's
|
||||
* {@link #keyType} to {@link PrimaryKeyType#PARTITIONED}, else sets it to {@code null}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@@ -123,9 +123,9 @@ public class ColumnSpecification {
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the identification of this column as a clustered key column. If the given boolean is <code>true</code>,
|
||||
* then sets the column's {@link #keyType} to {@link PrimaryKeyType#PARTITIONED} and {@link #ordering} to the given
|
||||
* {@link Ordering} , else sets both {@link #keyType} and {@link #ordering} to <code>null</code>.
|
||||
* Toggles the identification of this column as a clustered key column. If the given boolean is {@code true}, then
|
||||
* sets the column's {@link #keyType} to {@link PrimaryKeyType#PARTITIONED} and {@link #ordering} to the given
|
||||
* {@link Ordering} , else sets both {@link #keyType} and {@link #ordering} to {@code null}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Builder class to construct a <code>CREATE INDEX</code> specification.
|
||||
* Builder class to construct a {@code CREATE INDEX} specification.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
@@ -61,7 +61,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
* Causes the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
* Toggles the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import org.springframework.cassandra.config.DataCenterReplication;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.cassandra.core.cql.KeyspaceIdentifier;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceOption.ReplicationStrategy;
|
||||
import org.springframework.cassandra.core.util.MapBuilder;
|
||||
@@ -60,8 +59,8 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
*
|
||||
* Causes the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public CreateKeyspaceSpecification ifNotExists() {
|
||||
@@ -69,8 +68,8 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
*
|
||||
* Toggles the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public CreateKeyspaceSpecification ifNotExists(boolean ifNotExists) {
|
||||
@@ -103,7 +102,7 @@ public class CreateKeyspaceSpecification extends KeyspaceSpecification<CreateKey
|
||||
ReplicationStrategy.NETWORK_TOPOLOGY_STRATEGY.getValue());
|
||||
|
||||
for (DataCenterReplication dcr : dcrs) {
|
||||
builder.entry(new DefaultOption(dcr.dataCenter, Long.class, true, false, false), dcr.replicationFactor);
|
||||
builder.entry(new DefaultOption(dcr.getDataCenter(), Long.class, true, false, false), dcr.getReplicationFactor());
|
||||
}
|
||||
|
||||
return with(KeyspaceOption.REPLICATION, builder.build());
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cassandra.core.keyspace;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
|
||||
/**
|
||||
* Builder class to construct a <code>CREATE TABLE</code> specification.
|
||||
*
|
||||
* Builder class to construct a {@code CREATE TABLE} specification.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CreateTableSpecification extends TableSpecification<CreateTableSpecification> {
|
||||
@@ -56,8 +56,8 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
*
|
||||
* Causes the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public CreateTableSpecification ifNotExists() {
|
||||
@@ -65,8 +65,8 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the inclusion of an <code>IF NOT EXISTS</code> clause.
|
||||
*
|
||||
* Toggles the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public CreateTableSpecification ifNotExists(boolean ifNotExists) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -16,8 +16,8 @@
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
/**
|
||||
* Builder class that supports the construction of <code>DROP INDEX</code> specifications.
|
||||
*
|
||||
* Builder class that supports the construction of {@code DROP INDEX} specifications.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -18,8 +18,8 @@ package org.springframework.cassandra.core.keyspace;
|
||||
import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
|
||||
/**
|
||||
* Builder class that supports the construction of <code>DROP TABLE</code> specifications.
|
||||
*
|
||||
* Builder class that supports the construction of {@code DROP TABLE} specifications.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class DropTableSpecification extends TableNameSpecification<DropTableSpecification> {
|
||||
@@ -51,9 +51,8 @@ public class DropTableSpecification extends TableNameSpecification<DropTableSpec
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
|
||||
* statically. This static method is shorter than the no-arg form, which would be
|
||||
* <code>dropTable().name(tableName)</code>.
|
||||
*
|
||||
* statically. This static method is shorter than the no-arg form, which would be {@code dropTable().name(tableName)}.
|
||||
*
|
||||
* @param tableName The name of the table to drop.
|
||||
*/
|
||||
public static DropTableSpecification dropTable(CqlIdentifier tableName) {
|
||||
@@ -62,9 +61,8 @@ public class DropTableSpecification extends TableNameSpecification<DropTableSpec
|
||||
|
||||
/**
|
||||
* Entry point into the {@link DropTableSpecification}'s fluent API to drop a table. Convenient if imported
|
||||
* statically. This static method is shorter than the no-arg form, which would be
|
||||
* <code>dropTable().name(tableName)</code>.
|
||||
*
|
||||
* statically. This static method is shorter than the no-arg form, which would be {@code dropTable().name(tableName)}.
|
||||
*
|
||||
* @param tableName The name of the table to drop.
|
||||
*/
|
||||
public static DropTableSpecification dropTable(String tableName) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -24,7 +24,7 @@ public enum KeyspaceOption implements Option {
|
||||
|
||||
private Option delegate;
|
||||
|
||||
private KeyspaceOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
KeyspaceOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public enum KeyspaceOption implements Option {
|
||||
|
||||
/**
|
||||
* Known Replication Strategy options.
|
||||
*
|
||||
*
|
||||
* @author John McPeek
|
||||
*/
|
||||
public enum ReplicationStrategy {
|
||||
@@ -78,7 +78,7 @@ public enum KeyspaceOption implements Option {
|
||||
|
||||
private String value;
|
||||
|
||||
private ReplicationStrategy(String value) {
|
||||
ReplicationStrategy(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.escapeSingle;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.singleQuote;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -26,21 +25,21 @@ import org.springframework.cassandra.core.cql.CqlStringUtils;
|
||||
|
||||
/**
|
||||
* Abstract builder class to support the construction of table specifications that have table options, that is, those
|
||||
* options normally specified by <code>WITH ... AND ...</code>.
|
||||
* options normally specified by {@code WITH ... AND ...}.
|
||||
* <p/>
|
||||
* It is important to note that although this class depends on {@link KeyspaceOption} for convenient and typesafe use,
|
||||
* it ultimately stores its options in a <code>Map<String,Object></code> for flexibility. This means that
|
||||
* {@link #with(KeyspaceOption)} and {@link #with(KeyspaceOption, Object)} delegate to
|
||||
* {@link #with(String, Object, boolean, boolean)}. This design allows the API to support new Cassandra options as they
|
||||
* are introduced without having to update the code immediately.
|
||||
*
|
||||
*
|
||||
* @author John McPeek
|
||||
* @param <T> The subtype of the {@link KeyspaceOptionsSpecification}.
|
||||
*/
|
||||
public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpecification<T>> extends
|
||||
KeyspaceActionSpecification<KeyspaceOptionsSpecification<T>> {
|
||||
|
||||
protected Map<String, Object> options = new LinkedHashMap<String, Object>();
|
||||
protected Map<String, Object> options = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -49,8 +48,8 @@ public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpec
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that calls <code>with(option, null)</code>.
|
||||
*
|
||||
* Convenience method that calls {@code with(option, null)}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public T with(KeyspaceOption option) {
|
||||
@@ -61,7 +60,7 @@ public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpec
|
||||
* Sets the given table option. This is a convenience method that calls
|
||||
* {@link #with(String, Object, boolean, boolean)} appropriately from the given {@link KeyspaceOption} and value for
|
||||
* that option.
|
||||
*
|
||||
*
|
||||
* @param option The option to set.
|
||||
* @param value The value of the option. Must be type-compatible with the {@link KeyspaceOption}.
|
||||
* @return this
|
||||
@@ -75,13 +74,13 @@ public abstract class KeyspaceOptionsSpecification<T extends KeyspaceOptionsSpec
|
||||
/**
|
||||
* Adds the given option by name to this keyspaces's options.
|
||||
* <p/>
|
||||
* Options that have <code>null</code> values are considered single string options where the name of the option is the
|
||||
* Options that have {@code null} values are considered single string options where the name of the option is the
|
||||
* string to be used. Otherwise, the result of {@link Object#toString()} is considered to be the value of the option
|
||||
* with the given name. The value, after conversion to string, may have embedded single quotes escaped according to
|
||||
* parameter <code>escape</code> and may be single-quoted according to parameter <code>quote</code>.
|
||||
*
|
||||
* parameter {@code escape} and may be single-quoted according to parameter <code>quote</code>.
|
||||
*
|
||||
* @param name The name of the option
|
||||
* @param value The value of the option. If <code>null</code>, the value is ignored and the option is considered to be
|
||||
* @param value The value of the option. If {@code null}, the value is ignored and the option is considered to be
|
||||
* composed of only the name, otherwise the value's {@link Object#toString()} value is used.
|
||||
* @param escape Whether to escape the value via {@link CqlStringUtils#escapeSingle(Object)}. Ignored if given value
|
||||
* is an instance of a {@link Map}.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
/**
|
||||
* Interface to represent option types.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public interface Option {
|
||||
@@ -65,10 +65,9 @@ public interface Option {
|
||||
/**
|
||||
* First ensures that the given value is coerceable into the type expected by this option, then returns the result of
|
||||
* {@link Object#toString()} called on the given value. If this option is escaping quotes ({@link #escapesValue()} is
|
||||
* <code>true</code>), then single quotes will be escaped, and if this option is quoting values (
|
||||
* {@link #quotesValue()} is <code>true</code>), then the value will be surrounded by single quotes. Given
|
||||
* <code>null</code>, returns <code>null</code>.
|
||||
*
|
||||
* {@code true}), then single quotes will be escaped, and if this option is quoting values ( {@link #quotesValue()} is
|
||||
* {@code true}), then the value will be surrounded by single quotes. Given {@code null}, returns <code>null</code>.
|
||||
*
|
||||
* @see #escapesValue()
|
||||
* @see #quotesValue()
|
||||
*/
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -22,7 +22,7 @@ import org.springframework.cassandra.core.cql.CqlIdentifier;
|
||||
|
||||
/**
|
||||
* Describes a table.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
*/
|
||||
@@ -41,22 +41,22 @@ public interface TableDescriptor {
|
||||
/**
|
||||
* Returns an unmodifiable list of all partition key columns.
|
||||
*/
|
||||
public List<ColumnSpecification> getPartitionKeyColumns();
|
||||
List<ColumnSpecification> getPartitionKeyColumns();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of all primary key columns that are not also partition key columns.
|
||||
*/
|
||||
public List<ColumnSpecification> getClusteredKeyColumns();
|
||||
List<ColumnSpecification> getClusteredKeyColumns();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of all partition and primary key columns.
|
||||
*/
|
||||
public List<ColumnSpecification> getPrimaryKeyColumns();
|
||||
List<ColumnSpecification> getPrimaryKeyColumns();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable list of all non-key columns.
|
||||
*/
|
||||
public List<ColumnSpecification> getNonKeyColumns();
|
||||
List<ColumnSpecification> getNonKeyColumns();
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable {@link Map} of table options.
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -21,7 +21,7 @@ import java.util.Map;
|
||||
* Enumeration that represents all known table options. If a table option is not listed here, but is supported by
|
||||
* Cassandra, use the method {@link CreateTableSpecification#with(String, Object, boolean, boolean)} to write the raw
|
||||
* value. Implements {@link Option} via delegation, since {@link Enum}s can't extend anything.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @see CompactionOption
|
||||
* @see CompressionOption
|
||||
@@ -29,51 +29,51 @@ import java.util.Map;
|
||||
*/
|
||||
public enum TableOption implements Option {
|
||||
/**
|
||||
* <code>comment</code>
|
||||
* {@code comment}
|
||||
*/
|
||||
COMMENT("comment", String.class, true, true, true),
|
||||
/**
|
||||
* <code>COMPACT STORAGE</code>
|
||||
* {@code COMPACT STORAGE}
|
||||
*/
|
||||
COMPACT_STORAGE("COMPACT STORAGE", null, false, false, false),
|
||||
/**
|
||||
* <code>compaction</code>. Value is a <code>Map<CompactionOption,Object></code>.
|
||||
*
|
||||
* {@code compaction}. Value is a <code>Map<CompactionOption,Object></code>.
|
||||
*
|
||||
* @see CompactionOption
|
||||
*/
|
||||
COMPACTION("compaction", Map.class, true, false, false),
|
||||
/**
|
||||
* <code>compression</code>. Value is a <code>Map<CompressionOption,Object></code>.
|
||||
*
|
||||
* {@code compression}. Value is a <code>Map<CompressionOption,Object></code>.
|
||||
*
|
||||
* @see {@link CompressionOption}
|
||||
*/
|
||||
COMPRESSION("compression", Map.class, true, false, false),
|
||||
/**
|
||||
* <code>caching</code>
|
||||
*
|
||||
* {@code caching}
|
||||
*
|
||||
* @see CachingOption
|
||||
*/
|
||||
CACHING("caching", Map.class, true, false, false),
|
||||
/**
|
||||
* <code>bloom_filter_fp_chance</code>
|
||||
* {@code bloom_filter_fp_chance}
|
||||
*/
|
||||
BLOOM_FILTER_FP_CHANCE("bloom_filter_fp_chance", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>read_repair_chance</code>
|
||||
* {@code read_repair_chance}
|
||||
*/
|
||||
READ_REPAIR_CHANCE("read_repair_chance", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>dclocal_read_repair_chance</code>
|
||||
* {@code dclocal_read_repair_chance}
|
||||
*/
|
||||
DCLOCAL_READ_REPAIR_CHANCE("dclocal_read_repair_chance", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>gc_grace_seconds</code>
|
||||
* {@code gc_grace_seconds}
|
||||
*/
|
||||
GC_GRACE_SECONDS("gc_grace_seconds", Long.class, true, false, false);
|
||||
|
||||
private Option delegate;
|
||||
|
||||
private TableOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
TableOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public enum TableOption implements Option {
|
||||
|
||||
/**
|
||||
* Known KeyCaching Options
|
||||
*
|
||||
*
|
||||
* @author David Webb
|
||||
* @since 1.2.0
|
||||
*
|
||||
@@ -140,7 +140,7 @@ public enum TableOption implements Option {
|
||||
|
||||
private String value;
|
||||
|
||||
private KeyCachingOption(String value) {
|
||||
KeyCachingOption(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public enum TableOption implements Option {
|
||||
|
||||
/**
|
||||
* Known caching options.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
* @since 1.2.0
|
||||
@@ -169,7 +169,7 @@ public enum TableOption implements Option {
|
||||
|
||||
private Option delegate;
|
||||
|
||||
private CachingOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
CachingOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue, boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
@@ -227,51 +227,51 @@ public enum TableOption implements Option {
|
||||
|
||||
/**
|
||||
* Known compaction options.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public enum CompactionOption implements Option {
|
||||
/**
|
||||
* <code>class</code>
|
||||
* {@code class}
|
||||
*/
|
||||
CLASS("class", String.class, true, false, true),
|
||||
/**
|
||||
* <code>tombstone_threshold</code>
|
||||
* {@code tombstone_threshold}
|
||||
*/
|
||||
TOMBSTONE_THRESHOLD("tombstone_threshold", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>tombstone_compaction_interval</code>
|
||||
* {@code tombstone_compaction_interval}
|
||||
*/
|
||||
TOMBSTONE_COMPACTION_INTERVAL("tombstone_compaction_interval", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>min_sstable_size</code>
|
||||
* {@code min_sstable_size}
|
||||
*/
|
||||
MIN_SSTABLE_SIZE("min_sstable_size", Long.class, true, false, false),
|
||||
/**
|
||||
* <code>min_threshold</code>
|
||||
* {@code min_threshold}
|
||||
*/
|
||||
MIN_THRESHOLD("min_threshold", Long.class, true, false, false),
|
||||
/**
|
||||
* <code>max_threshold</code>
|
||||
* {@code max_threshold}
|
||||
*/
|
||||
MAX_THRESHOLD("max_threshold", Long.class, true, false, false),
|
||||
/**
|
||||
* <code>bucket_low</code>
|
||||
* {@code bucket_low}
|
||||
*/
|
||||
BUCKET_LOW("bucket_low", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>bucket_high</code>
|
||||
* {@code bucket_high}
|
||||
*/
|
||||
BUCKET_HIGH("bucket_high", Double.class, true, false, false),
|
||||
/**
|
||||
* <code>sstable_size_in_mb</code>
|
||||
* {@code sstable_size_in_mb}
|
||||
*/
|
||||
SSTABLE_SIZE_IN_MB("sstable_size_in_mb", Long.class, true, false, false);
|
||||
|
||||
private Option delegate;
|
||||
|
||||
private CompactionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
CompactionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
@@ -328,27 +328,27 @@ public enum TableOption implements Option {
|
||||
|
||||
/**
|
||||
* Known compression options.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public enum CompressionOption implements Option {
|
||||
/**
|
||||
* <code>sstable_compression</code>
|
||||
* {@code sstable_compression}
|
||||
*/
|
||||
SSTABLE_COMPRESSION("sstable_compression", String.class, true, false, true),
|
||||
/**
|
||||
* <code>chunk_length_kb</code>
|
||||
* {@code chunk_length_kb}
|
||||
*/
|
||||
CHUNK_LENGTH_KB("chunk_length_kb", Long.class, true, false, false),
|
||||
/**
|
||||
* <code>crc_check_chance</code>
|
||||
* {@code crc_check_chance}
|
||||
*/
|
||||
CRC_CHECK_CHANCE("crc_check_chance", Double.class, true, false, false);
|
||||
|
||||
private Option delegate;
|
||||
|
||||
private CompressionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
CompressionOption(String name, Class<?> type, boolean requiresValue, boolean escapesValue,
|
||||
boolean quotesValue) {
|
||||
this.delegate = new DefaultOption(name, type, requiresValue, escapesValue, quotesValue);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.cassandra.core.keyspace;
|
||||
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.escapeSingle;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.singleQuote;
|
||||
import static org.springframework.cassandra.core.cql.CqlStringUtils.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -27,21 +26,21 @@ import org.springframework.cassandra.core.cql.CqlStringUtils;
|
||||
|
||||
/**
|
||||
* Abstract builder class to support the construction of table specifications that have table options, that is, those
|
||||
* options normally specified by <code>WITH ... AND ...</code>.
|
||||
* options normally specified by {@code WITH ... AND ...}.
|
||||
* <p/>
|
||||
* It is important to note that although this class depends on {@link TableOption} for convenient and typesafe use, it
|
||||
* ultimately stores its options in a <code>Map<String,Object></code> for flexibility. This means that
|
||||
* {@link #with(TableOption)} and {@link #with(TableOption, Object)} delegate to
|
||||
* {@link #with(String, Object, boolean, boolean)}. This design allows the API to support new Cassandra options as they
|
||||
* are introduced without having to update the code immediately.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @param <T> The subtype of the {@link TableOptionsSpecification}.
|
||||
*/
|
||||
public abstract class TableOptionsSpecification<T extends TableOptionsSpecification<T>> extends
|
||||
TableNameSpecification<TableOptionsSpecification<T>> {
|
||||
|
||||
protected Map<String, Object> options = new LinkedHashMap<String, Object>();
|
||||
protected Map<String, Object> options = new LinkedHashMap<>();
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -56,8 +55,8 @@ public abstract class TableOptionsSpecification<T extends TableOptionsSpecificat
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that calls <code>with(option, null)</code>.
|
||||
*
|
||||
* Convenience method that calls {@code with(option, null)}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public T with(TableOption option) {
|
||||
@@ -68,7 +67,7 @@ public abstract class TableOptionsSpecification<T extends TableOptionsSpecificat
|
||||
* Sets the given table option. This is a convenience method that calls
|
||||
* {@link #with(String, Object, boolean, boolean)} appropriately from the given {@link TableOption} and value for that
|
||||
* option.
|
||||
*
|
||||
*
|
||||
* @param option The option to set.
|
||||
* @param value The value of the option. Must be type-compatible with the {@link TableOption}.
|
||||
* @return this
|
||||
@@ -82,13 +81,13 @@ public abstract class TableOptionsSpecification<T extends TableOptionsSpecificat
|
||||
/**
|
||||
* Adds the given option by name to this table's options.
|
||||
* <p/>
|
||||
* Options that have <code>null</code> values are considered single string options where the name of the option is the
|
||||
* Options that have {@code null} values are considered single string options where the name of the option is the
|
||||
* string to be used. Otherwise, the result of {@link Object#toString()} is considered to be the value of the option
|
||||
* with the given name. The value, after conversion to string, may have embedded single quotes escaped according to
|
||||
* parameter <code>escape</code> and may be single-quoted according to parameter <code>quote</code>.
|
||||
*
|
||||
* parameter {@code escape} and may be single-quoted according to parameter <code>quote</code>.
|
||||
*
|
||||
* @param name The name of the option
|
||||
* @param value The value of the option. If <code>null</code>, the value is ignored and the option is considered to be
|
||||
* @param value The value of the option. If {@code null}, the value is ignored and the option is considered to be
|
||||
* composed of only the name, otherwise the value's {@link Object#toString()} value is used.
|
||||
* @param escape Whether to escape the value via {@link CqlStringUtils#escapeSingle(Object)}. Ignored if given value
|
||||
* is an instance of a {@link Map}.
|
||||
|
||||
@@ -43,22 +43,22 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
/**
|
||||
* List of all columns.
|
||||
*/
|
||||
private List<ColumnSpecification> columns = new ArrayList<ColumnSpecification>();
|
||||
private List<ColumnSpecification> columns = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of only those columns that comprise the partition key.
|
||||
*/
|
||||
private List<ColumnSpecification> partitionKeyColumns = new ArrayList<ColumnSpecification>();
|
||||
private List<ColumnSpecification> partitionKeyColumns = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of only those columns that comprise the primary key that are not also part of the partition key.
|
||||
*/
|
||||
private List<ColumnSpecification> clusteredKeyColumns = new ArrayList<ColumnSpecification>();
|
||||
private List<ColumnSpecification> clusteredKeyColumns = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of only those columns that are not partition or primary key columns.
|
||||
*/
|
||||
private List<ColumnSpecification> nonKeyColumns = new ArrayList<ColumnSpecification>();
|
||||
private List<ColumnSpecification> nonKeyColumns = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Adds the given non-key column to the table. Must be specified after all primary key columns.
|
||||
@@ -280,7 +280,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
@Override
|
||||
public List<ColumnSpecification> getPrimaryKeyColumns() {
|
||||
|
||||
ArrayList<ColumnSpecification> primaryKeyColumns = new ArrayList<ColumnSpecification>();
|
||||
ArrayList<ColumnSpecification> primaryKeyColumns = new ArrayList<>();
|
||||
primaryKeyColumns.addAll(partitionKeyColumns);
|
||||
primaryKeyColumns.addAll(clusteredKeyColumns);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,7 +36,7 @@ import com.datastax.driver.core.DataType;
|
||||
*/
|
||||
public class UserTypeSpecification<T extends UserTypeSpecification<T>> extends UserTypeNameSpecification<T> {
|
||||
|
||||
private final List<FieldSpecification> fields = new ArrayList<FieldSpecification>();
|
||||
private final List<FieldSpecification> fields = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Adds the given field to the type.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2016-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -63,7 +63,7 @@ public interface ReactiveResultSet {
|
||||
*
|
||||
* @return the columns returned in this ResultSet.
|
||||
*/
|
||||
public ColumnDefinitions getColumnDefinitions();
|
||||
ColumnDefinitions getColumnDefinitions();
|
||||
|
||||
/**
|
||||
* If the query that produced this ResultSet was a conditional update, return whether it was successfully applied.
|
||||
@@ -79,7 +79,7 @@ public interface ReactiveResultSet {
|
||||
* @return if the query was a conditional update, whether it was applied. {@code true} for other types of queries.
|
||||
* @see <a href="https://issues.apache.org/jira/browse/CASSANDRA-7337">CASSANDRA-7337</a>
|
||||
*/
|
||||
public boolean wasApplied();
|
||||
boolean wasApplied();
|
||||
|
||||
/**
|
||||
* Returns information on the execution of the last query made for this result set.
|
||||
|
||||
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.datastax.driver.core.ExecutionInfo;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
/**
|
||||
* An empty {@link com.datastax.driver.core.ResultSet} implementation
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.cassandra.core.support.ResultSetAdapter
|
||||
* @see com.datastax.driver.core.ResultSet
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class EmptyResultSet extends ResultSetAdapter {
|
||||
|
||||
protected static final EmptyResultSet INSTANCE = new EmptyResultSet();
|
||||
|
||||
/**
|
||||
* Returns the given {@link ResultSet} if not null, otherwise returns an empty {@link ResultSet}.
|
||||
*
|
||||
* @param resultSet {@link ResultSet} to evaluate for {@literal null}.
|
||||
* @return the given {@link ResultSet} if not null, otherwise return an empty {@link ResultSet}.
|
||||
* @see com.datastax.driver.core.ResultSet
|
||||
*/
|
||||
public static ResultSet nullSafeResultSet(ResultSet resultSet) {
|
||||
return (resultSet != null ? resultSet : EmptyResultSet.INSTANCE);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#isExhausted()
|
||||
*/
|
||||
@Override
|
||||
public boolean isExhausted() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#isFullyFetched()
|
||||
*/
|
||||
@Override
|
||||
public boolean isFullyFetched() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getAvailableWithoutFetching()
|
||||
*/
|
||||
@Override
|
||||
public int getAvailableWithoutFetching() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getAllExecutionInfo()
|
||||
*/
|
||||
@Override
|
||||
public List<ExecutionInfo> getAllExecutionInfo() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getExecutionInfo()
|
||||
*/
|
||||
@Override
|
||||
public ExecutionInfo getExecutionInfo() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#all()
|
||||
*/
|
||||
@Override
|
||||
public List<Row> all() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Row> iterator() {
|
||||
return Collections.emptyIterator();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#one()
|
||||
*/
|
||||
@Override
|
||||
public Row one() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.support;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.datastax.driver.core.ColumnDefinitions;
|
||||
import com.datastax.driver.core.ExecutionInfo;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
/**
|
||||
* An Adapter class to simply implementations of the {@link ResultSet} interface.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.datastax.driver.core.ResultSet
|
||||
* @since 1.5.0
|
||||
*/
|
||||
public class ResultSetAdapter implements ResultSet {
|
||||
|
||||
private static final String NOT_SUPPORTED = "Not Supported";
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#isExhausted()
|
||||
*/
|
||||
@Override
|
||||
public boolean isExhausted() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#isFullyFetched()
|
||||
*/
|
||||
@Override
|
||||
public boolean isFullyFetched() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getAvailableWithoutFetching()
|
||||
*/
|
||||
@Override
|
||||
public int getAvailableWithoutFetching() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getColumnDefinitions()
|
||||
*/
|
||||
@Override
|
||||
public ColumnDefinitions getColumnDefinitions() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getAllExecutionInfo()
|
||||
*/
|
||||
@Override
|
||||
public List<ExecutionInfo> getAllExecutionInfo() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#getExecutionInfo()
|
||||
*/
|
||||
@Override
|
||||
public ExecutionInfo getExecutionInfo() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#all()
|
||||
*/
|
||||
@Override
|
||||
public List<Row> all() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#fetchMoreResults()
|
||||
*/
|
||||
@Override
|
||||
public ListenableFuture<ResultSet> fetchMoreResults() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#iterator()
|
||||
*/
|
||||
@Override
|
||||
public Iterator<Row> iterator() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#one()
|
||||
*/
|
||||
@Override
|
||||
public Row one() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.ResultSet#wasApplied()
|
||||
*/
|
||||
@Override
|
||||
public boolean wasApplied() {
|
||||
throw new UnsupportedOperationException(NOT_SUPPORTED);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cassandra.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CollectionUtils extends org.springframework.util.CollectionUtils {
|
||||
|
||||
public static Object[] toArray(Iterable<?> iterable) {
|
||||
return toList(iterable).toArray();
|
||||
}
|
||||
|
||||
public static <T> List<T> toList(T... elements) {
|
||||
List<T> list = Collections.emptyList();
|
||||
|
||||
if (elements != null) {
|
||||
list = new ArrayList<T>(elements.length);
|
||||
Collections.addAll(list, elements);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static <T> List<T> toList(Iterable<T> iterable) {
|
||||
if (!(iterable instanceof List)) {
|
||||
List<T> list = new ArrayList<T>();
|
||||
|
||||
if (iterable != null) {
|
||||
for (T element : iterable) {
|
||||
list.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
iterable = list;
|
||||
}
|
||||
|
||||
return (List<T>) iterable;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -16,22 +16,47 @@
|
||||
package org.springframework.cassandra.core.util;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Builder for maps, which also conveniently implements {@link Map} via delegation for convenience so you don't have to
|
||||
* actually {@link #build()} it.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @param <K> The key type of the map.
|
||||
* @param <V> The value type of the map.
|
||||
*/
|
||||
public class MapBuilder<K, V> implements Map<K, V> {
|
||||
|
||||
private Map<K, V> map;
|
||||
|
||||
/**
|
||||
* Factory method to construct a new <code>MapBuilder<Object,Object></code>. Convenient if imported statically.
|
||||
* Create a new {@link MapBuilder}.
|
||||
*/
|
||||
public MapBuilder() {
|
||||
this(Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with a copy of the given map.
|
||||
*
|
||||
* @param source must not be {@literal null}
|
||||
*/
|
||||
public MapBuilder(Map<K, V> source) {
|
||||
|
||||
Assert.notNull(source, "Source map must not be null");
|
||||
|
||||
this.map = new LinkedHashMap<>(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to construct a new {@code MapBuilder<Object,Object>}. Convenient if imported statically.
|
||||
*/
|
||||
public static MapBuilder<Object, Object> map() {
|
||||
return map(Object.class, Object.class);
|
||||
@@ -41,32 +66,19 @@ public class MapBuilder<K, V> implements Map<K, V> {
|
||||
* Factory method to construct a new builder with the given key & value types. Convenient if imported statically.
|
||||
*/
|
||||
public static <K, V> MapBuilder<K, V> map(Class<K> keyType, Class<V> valueType) {
|
||||
return new MapBuilder<K, V>();
|
||||
return new MapBuilder<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method to construct a new builder with a shallow copy of the given map. Convenient if imported statically.
|
||||
*/
|
||||
public static <K, V> MapBuilder<K, V> map(Map<K, V> source) {
|
||||
return new MapBuilder<K, V>(source);
|
||||
}
|
||||
|
||||
private Map<K, V> map;
|
||||
|
||||
public MapBuilder() {
|
||||
this(new LinkedHashMap<K, V>());
|
||||
return new MapBuilder<>(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new instance with a copy of the given map.
|
||||
*/
|
||||
public MapBuilder(Map<K, V> source) {
|
||||
this.map = new LinkedHashMap<K, V>(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an entry to this map, then returns <code>this</code>.
|
||||
*
|
||||
* Add an entry to this map, then returns {@code this}.
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public MapBuilder<K, V> entry(K key, V value) {
|
||||
@@ -75,79 +87,121 @@ public class MapBuilder<K, V> implements Map<K, V> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new map based on the current state of this builder's map.
|
||||
*
|
||||
* Return a new map based on the current state of this builder's map.
|
||||
*
|
||||
* @return A new Map<K, V> with this builder's map's current content.
|
||||
*/
|
||||
public Map<K, V> build() {
|
||||
return new LinkedHashMap<K, V>(map);
|
||||
return new LinkedHashMap<>(map);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#size()
|
||||
*/
|
||||
@Override
|
||||
public int size() {
|
||||
return map.size();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#isEmpty()
|
||||
*/
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#containsKey(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean containsKey(Object key) {
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#containsValue(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return map.containsValue(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#get(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public V get(Object key) {
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public V put(K key, V value) {
|
||||
return map.put(key, value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#remove(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public V remove(Object key) {
|
||||
return map.remove(key);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#putAll(java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public void putAll(Map<? extends K, ? extends V> m) {
|
||||
map.putAll(m);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#clear()
|
||||
*/
|
||||
@Override
|
||||
public void clear() {
|
||||
map.clear();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#keySet()
|
||||
*/
|
||||
@Override
|
||||
public Set<K> keySet() {
|
||||
return map.keySet();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#values()
|
||||
*/
|
||||
@Override
|
||||
public Collection<V> values() {
|
||||
return map.values();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Map#entrySet()
|
||||
*/
|
||||
@Override
|
||||
public Set<java.util.Map.Entry<K, V>> entrySet() {
|
||||
return map.entrySet();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return map.equals(o);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return map.hashCode();
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.cassandra.support;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -377,7 +378,11 @@ public class CassandraAccessor implements InitializingBean {
|
||||
* @see CqlProvider
|
||||
*/
|
||||
protected static String toCql(Object cqlProvider) {
|
||||
return (cqlProvider instanceof CqlProvider ? ((CqlProvider) cqlProvider).getCql() : null);
|
||||
return Optional.ofNullable(cqlProvider) //
|
||||
.filter(o -> o instanceof CqlProvider) //
|
||||
.map(o -> (CqlProvider) o) //
|
||||
.map(CqlProvider::getCql) //
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected void logDebug(String logMessage, Object... array) {
|
||||
@@ -444,7 +449,8 @@ public class CassandraAccessor implements InitializingBean {
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet)
|
||||
*
|
||||
@see org.springframework.cassandra.core.ResultSetExtractor#extractData(com.datastax.driver.core.ResultSet)
|
||||
*/
|
||||
@Override
|
||||
public Object extractData(ResultSet resultSet) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
@@ -24,14 +24,14 @@ import org.springframework.dao.DataAccessResourceFailureException;
|
||||
|
||||
/**
|
||||
* Spring data access exception for Cassandra when no host is available.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CassandraConnectionFailureException extends DataAccessResourceFailureException {
|
||||
|
||||
private static final long serialVersionUID = 6299912054261646552L;
|
||||
|
||||
private final Map<InetSocketAddress, Throwable> messagesByHost = new HashMap<InetSocketAddress, Throwable>();
|
||||
private final Map<InetSocketAddress, Throwable> messagesByHost = new HashMap<>();
|
||||
|
||||
public CassandraConnectionFailureException(Map<InetSocketAddress, Throwable> map, String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Copyright 2013-2017 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
*
|
||||
* 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.
|
||||
@@ -19,7 +19,7 @@ import org.springframework.dao.NonTransientDataAccessException;
|
||||
|
||||
/**
|
||||
* Spring data access exception for when Cassandra schema element being created already exists.
|
||||
*
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class CassandraSchemaElementExistsException extends NonTransientDataAccessException {
|
||||
@@ -27,7 +27,7 @@ public class CassandraSchemaElementExistsException extends NonTransientDataAcces
|
||||
private static final long serialVersionUID = 7798361273692300162L;
|
||||
|
||||
public enum ElementType {
|
||||
KEYSPACE, TABLE, COLUMN, INDEX;
|
||||
KEYSPACE, TABLE, COLUMN, INDEX
|
||||
}
|
||||
|
||||
private String elementName;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user