DATACASS-482 - Polishing.
Reduce method visibility on protected types. Remove deprecated methods. Formatting, reorder methods, Javadoc. Introduce CqlIdentifier.of(…) and KeyspaceIdentifier.of(…) methods and deprecate CqlIdentifier.cqlId(…) and KeyspaceIdentifier.ksId(…) methods.
This commit is contained in:
@@ -220,5 +220,4 @@ public abstract class AbstractCassandraConfiguration extends AbstractClusterConf
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.NONE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -221,7 +221,7 @@ public abstract class AbstractClusterConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Cassandra port. Defaults to {@code 9042}
|
||||
* Returns the Cassandra port. Defaults to {@code 9042}.
|
||||
*
|
||||
* @return the Cassandra port
|
||||
* @see CassandraClusterFactoryBean#DEFAULT_PORT
|
||||
@@ -231,7 +231,7 @@ public abstract class AbstractClusterConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the {@link ProtocolVersion}. Defaults to {@link ProtocolVersion#NEWEST_SUPPORTED}
|
||||
* Returns the {@link ProtocolVersion}. Defaults to {@link ProtocolVersion#NEWEST_SUPPORTED}.
|
||||
*
|
||||
* @return the {@link ProtocolVersion}.
|
||||
* @see ProtocolVersion#NEWEST_SUPPORTED.
|
||||
|
||||
@@ -24,10 +24,7 @@ import org.springframework.data.cassandra.core.cql.CqlTemplate;
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @see AbstractClusterConfiguration
|
||||
* @see AbstractSessionConfiguration
|
||||
* @see com.datastax.driver.core.Session
|
||||
* @see com.datastax.driver.core.Cluster
|
||||
* @see CqlTemplate
|
||||
*/
|
||||
public abstract class AbstractCqlTemplateConfiguration extends AbstractSessionConfiguration {
|
||||
|
||||
@@ -66,7 +66,7 @@ public abstract class AbstractReactiveCassandraConfiguration extends AbstractCas
|
||||
/**
|
||||
* Creates a {@link CassandraAdminTemplate}.
|
||||
*
|
||||
* @return
|
||||
* @return the {@link ReactiveCassandraOperations}.
|
||||
* @see #reactiveSessionFactory()
|
||||
* @see #cassandraConverter()
|
||||
*/
|
||||
@@ -78,7 +78,7 @@ public abstract class AbstractReactiveCassandraConfiguration extends AbstractCas
|
||||
/**
|
||||
* Creates a {@link ReactiveCqlTemplate} using the configured {@link ReactiveSessionFactory}.
|
||||
*
|
||||
* @return
|
||||
* @return the {@link ReactiveCqlOperations}.
|
||||
* @see #reactiveSessionFactory()
|
||||
*/
|
||||
@Bean
|
||||
|
||||
@@ -89,5 +89,4 @@ public abstract class AbstractSessionConfiguration extends AbstractClusterConfig
|
||||
* @return must not be {@literal null}.
|
||||
*/
|
||||
protected abstract String getKeyspaceName();
|
||||
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ class BeanDefinitionUtils {
|
||||
* @param type The required {@link BeanDefinition}'s type.
|
||||
* @param includeNonSingletons Whether to include beans with scope other than {@code singleton}
|
||||
* @param allowEagerInit Whether to allow eager initialization of beans.
|
||||
* @param required Whether to allow the return of null if none were found.
|
||||
* @return The {@link BeanDefinitionHolder}s -- never returns null.
|
||||
* @see BeanFactoryUtils#beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)
|
||||
*/
|
||||
|
||||
@@ -164,11 +164,8 @@ class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
builder.addPropertyValue("keyspaceSpecifications",
|
||||
newKeyspaceSetFlattenerBeanDefinition(element, parserContext, keyspaceActionSpecificationBeanDefinitions));
|
||||
|
||||
builder.addPropertyValue("keyspaceActions", keyspaceActionSpecificationBeanDefinitions);
|
||||
builder.addPropertyValue("poolingOptions", getSourceBeanDefinition(poolingOptionsBuilder, parserContext, element));
|
||||
|
||||
builder.addPropertyValue("startupScripts", startupScripts);
|
||||
builder.addPropertyValue("shutdownScripts", shutdownScripts);
|
||||
}
|
||||
@@ -229,26 +226,6 @@ class CassandraCqlClusterParser extends AbstractBeanDefinitionParser {
|
||||
builder.addPropertyValue("networkTopologyReplicationFactors", networkTopologyReplicationFactors);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the Single Factory Bean that will flatten all Set<Set<KeyspaceActionSpecificationFactoryBean>>
|
||||
*
|
||||
* @param element {@link Element} to parse.
|
||||
* @param parserContext XML parser context and state.
|
||||
* @param keyspaceActionSpecificationBeanDefinitions The List of Definitions to flatten
|
||||
* @return A single level List of KeyspaceActionSpecifications
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses local pooling options.
|
||||
*
|
||||
|
||||
@@ -59,7 +59,8 @@ public class CassandraCqlSessionFactoryBean
|
||||
implements FactoryBean<Session>, InitializingBean, DisposableBean, PersistenceExceptionTranslator {
|
||||
|
||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
|
||||
|
||||
private final PersistenceExceptionTranslator exceptionTranslator = new CassandraExceptionTranslator();
|
||||
|
||||
private @Nullable Cluster cluster;
|
||||
|
||||
@@ -140,10 +141,6 @@ public class CassandraCqlSessionFactoryBean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param session
|
||||
* @return
|
||||
*/
|
||||
CqlOperations newCqlOperations(Session session) {
|
||||
return new CqlTemplate(session);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.w3c.dom.NamedNodeMap;
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
||||
@@ -52,28 +53,10 @@ class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
throws BeanDefinitionStoreException {
|
||||
|
||||
String id = super.resolveId(element, definition, parserContext);
|
||||
|
||||
return StringUtils.hasText(id) ? id : DefaultCqlBeanNames.SESSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given element. This method is intended to be overridden by subclasses so that any elements not known to
|
||||
* this class can be properly parsed. The default implementation throws {@link IllegalStateException}.
|
||||
*/
|
||||
protected void parseUnhandledElement(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
throw new IllegalStateException(String.format("encountered unhandled element [%s]", element.getLocalName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given session element attribute. This method is intended to be overridden by subclasses so that any
|
||||
* attributes not known to this class can be properly parsed. The default implementation throws
|
||||
* {@link IllegalStateException}.
|
||||
*/
|
||||
protected void parseUnhandledSessionElementAttribute(Attr attribute, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
throw new IllegalStateException(
|
||||
String.format("encountered unhandled session element attribute [%s]", attribute.getName()));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser#doParse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext, org.springframework.beans.factory.support.BeanDefinitionBuilder)
|
||||
*/
|
||||
@@ -90,7 +73,7 @@ class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
addRequiredPropertyReference(builder, "cluster", DefaultCqlBeanNames.CLUSTER);
|
||||
}
|
||||
|
||||
protected void parseSessionAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
private void parseSessionAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
NamedNodeMap attributes = element.getAttributes();
|
||||
int length = attributes.getLength();
|
||||
@@ -114,8 +97,7 @@ class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
}
|
||||
}
|
||||
|
||||
protected void parseSessionChildElements(Element element, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
private void parseSessionChildElements(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
|
||||
for (Element child : DomUtils.getChildElements(element)) {
|
||||
|
||||
@@ -124,8 +106,20 @@ class CassandraCqlSessionParser extends AbstractSingleBeanDefinitionParser {
|
||||
} else if ("shutdown-cql".equals(child.getLocalName())) {
|
||||
builder.addPropertyValue("shutdownScripts", DomUtils.getTextValue(child));
|
||||
} else {
|
||||
parseUnhandledElement(child, parserContext, builder);
|
||||
throw new IllegalStateException(String.format("encountered unhandled element [%s]", child.getLocalName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given session element attribute. This method is intended to be overridden by subclasses so that any
|
||||
* attributes not known to this class can be properly parsed. The default implementation throws
|
||||
* {@link IllegalStateException}.
|
||||
*/
|
||||
protected void parseUnhandledSessionElementAttribute(Attr attribute, ParserContext parserContext,
|
||||
BeanDefinitionBuilder builder) {
|
||||
|
||||
throw new IllegalStateException(
|
||||
String.format("encountered unhandled session element attribute [%s]", attribute.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,14 +44,16 @@ import org.springframework.util.StringUtils;
|
||||
public class CassandraEntityClassScanner {
|
||||
|
||||
private Set<String> entityBasePackages = new HashSet<>();
|
||||
|
||||
private Set<Class<?>> entityBasePackageClasses = new HashSet<>();
|
||||
|
||||
private @Nullable ClassLoader beanClassLoader;
|
||||
|
||||
/**
|
||||
* Scan one or more base packages for entity classes. Classes are loaded using the current class loader.
|
||||
*
|
||||
* @param entityBasePackages must not be {@literal null}.
|
||||
* @return
|
||||
* @return {@link Set} containing all discovered entity classes.
|
||||
* @throws ClassNotFoundException
|
||||
*/
|
||||
public static Set<Class<?>> scan(String... entityBasePackages) throws ClassNotFoundException {
|
||||
@@ -62,8 +64,8 @@ public class CassandraEntityClassScanner {
|
||||
* Scan one or more base packages for entity classes. Classes are loaded using the current class loader.
|
||||
*
|
||||
* @param entityBasePackageClasses must not be {@literal null}.
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
* @return {@link Set} containing all discovered entity classes.
|
||||
* @throws ClassNotFoundException if a discovered class could not be loaded via.
|
||||
*/
|
||||
public static Set<Class<?>> scan(Class<?>... entityBasePackageClasses) throws ClassNotFoundException {
|
||||
return new CassandraEntityClassScanner(entityBasePackageClasses).scanForEntityClasses();
|
||||
@@ -73,8 +75,8 @@ public class CassandraEntityClassScanner {
|
||||
* Scan one or more base packages for entity classes. Classes are loaded using the current class loader.
|
||||
*
|
||||
* @param entityBasePackages must not be {@literal null}.
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
* @return {@link Set} containing all discovered entity classes.
|
||||
* @throws ClassNotFoundException if a discovered class could not be loaded via.
|
||||
*/
|
||||
public static Set<Class<?>> scan(Collection<String> entityBasePackages) throws ClassNotFoundException {
|
||||
return new CassandraEntityClassScanner(entityBasePackages).scanForEntityClasses();
|
||||
@@ -85,8 +87,8 @@ public class CassandraEntityClassScanner {
|
||||
*
|
||||
* @param entityBasePackages must not be {@literal null}.
|
||||
* @param entityBasePackageClasses must not be {@literal null}.
|
||||
* @return
|
||||
* @throws ClassNotFoundException
|
||||
* @return {@link Set} containing all discovered entity classes.
|
||||
* @throws ClassNotFoundException if a discovered class could not be loaded via.
|
||||
*/
|
||||
public static Set<Class<?>> scan(Collection<String> entityBasePackages, Collection<Class<?>> entityBasePackageClasses)
|
||||
throws ClassNotFoundException {
|
||||
@@ -185,7 +187,7 @@ public class CassandraEntityClassScanner {
|
||||
*
|
||||
* @see #getEntityBasePackages()
|
||||
* @return {@code Set<Class<?>>} representing the annotated entity classes found.
|
||||
* @throws ClassNotFoundException
|
||||
* @throws ClassNotFoundException if a discovered class could not be loaded via.
|
||||
*/
|
||||
public Set<Class<?>> scanForEntityClasses() throws ClassNotFoundException {
|
||||
|
||||
|
||||
@@ -173,7 +173,7 @@ public class CassandraMappingBeanFactoryPostProcessor implements BeanFactoryPost
|
||||
return converter;
|
||||
}
|
||||
|
||||
private BeanDefinitionHolder registerDefaultTemplate(BeanDefinitionRegistry registry, String sessionBeanName,
|
||||
private void registerDefaultTemplate(BeanDefinitionRegistry registry, String sessionBeanName,
|
||||
String converterBeanName) {
|
||||
|
||||
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(CassandraTemplate.class) //
|
||||
@@ -183,8 +183,6 @@ public class CassandraMappingBeanFactoryPostProcessor implements BeanFactoryPost
|
||||
|
||||
BeanDefinitionHolder template = new BeanDefinitionHolder(beanDefinition, DefaultBeanNames.DATA_TEMPLATE);
|
||||
registry.registerBeanDefinition(template.getBeanName(), template.getBeanDefinition());
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
private Collection<String> getNames(Class<?>[] types) {
|
||||
|
||||
@@ -76,7 +76,7 @@ class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
parseMapping(element, builder);
|
||||
}
|
||||
|
||||
protected void parseMapping(Element element, BeanDefinitionBuilder builder) {
|
||||
private void parseMapping(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
String packages = element.getAttribute("entity-base-packages");
|
||||
|
||||
@@ -119,7 +119,7 @@ class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
builder.addPropertyValue("mapping", mapping);
|
||||
}
|
||||
|
||||
protected EntityMapping parseEntity(Element entity) {
|
||||
private EntityMapping parseEntity(Element entity) {
|
||||
|
||||
String className = entity.getAttribute("class");
|
||||
|
||||
@@ -136,8 +136,6 @@ class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
forceQuote = String.valueOf(Boolean.parseBoolean(table.getAttribute("force-quote")));
|
||||
}
|
||||
|
||||
// TODO: parse future entity mappings here, like table options
|
||||
|
||||
Map<String, PropertyMapping> propertyMappings = parsePropertyMappings(entity);
|
||||
|
||||
EntityMapping entityMapping = new EntityMapping(className, tableName, forceQuote);
|
||||
@@ -146,7 +144,7 @@ class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
return entityMapping;
|
||||
}
|
||||
|
||||
protected BeanDefinition parseUserTypeResolver(Element entity) {
|
||||
private BeanDefinition parseUserTypeResolver(Element entity) {
|
||||
|
||||
String keyspaceName = entity.getAttribute("keyspace-name");
|
||||
|
||||
@@ -161,7 +159,7 @@ class CassandraMappingContextParser extends AbstractSingleBeanDefinitionParser {
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
protected Map<String, PropertyMapping> parsePropertyMappings(Element entity) {
|
||||
private Map<String, PropertyMapping> parsePropertyMappings(Element entity) {
|
||||
|
||||
Map<String, PropertyMapping> propertyMappings = new HashMap<>();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
|
||||
super.afterPropertiesSet();
|
||||
|
||||
this.admin = new CassandraAdminTemplate(getObject(), this.converter);
|
||||
this.admin = new CassandraAdminTemplate(getSession(), this.converter);
|
||||
|
||||
performSchemaAction();
|
||||
}
|
||||
@@ -116,9 +116,13 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
/**
|
||||
* @return the {@link CassandraMappingContext}.
|
||||
*/
|
||||
@Nullable
|
||||
protected CassandraMappingContext getMappingContext() {
|
||||
return getConverter().getMappingContext();
|
||||
|
||||
CassandraConverter converter = getConverter();
|
||||
|
||||
Assert.state(converter != null, "CassandraConverter was not properly initialized");
|
||||
|
||||
return converter.getMappingContext();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -154,8 +158,8 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
|
||||
private void performSchemaActions(boolean drop, boolean dropUnused, boolean ifNotExists) {
|
||||
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator =
|
||||
new CassandraPersistentEntitySchemaCreator(getMappingContext(), getCassandraAdminOperations());
|
||||
CassandraPersistentEntitySchemaCreator schemaCreator = new CassandraPersistentEntitySchemaCreator(
|
||||
getMappingContext(), getCassandraAdminOperations());
|
||||
|
||||
if (drop) {
|
||||
|
||||
@@ -175,6 +179,9 @@ public class CassandraSessionFactoryBean extends CassandraCqlSessionFactoryBean
|
||||
* @return the {@link CassandraAdminOperations}.
|
||||
*/
|
||||
protected CassandraAdminOperations getCassandraAdminOperations() {
|
||||
|
||||
Assert.state(this.admin != null, "CassandraAdminOperations was not properly initialized");
|
||||
|
||||
return this.admin;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.springframework.util.Assert;
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "WeakerAccess" })
|
||||
public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<KeyspaceActions>, InitializingBean {
|
||||
|
||||
private KeyspaceAction action = KeyspaceAction.NONE;
|
||||
@@ -236,5 +237,4 @@ public class KeyspaceActionSpecificationFactoryBean implements FactoryBean<Keysp
|
||||
public void setReplicationFactor(int replicationFactor) {
|
||||
this.replicationFactor = replicationFactor;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,15 +33,6 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
abstract class ParsingUtils {
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyReference(BeanDefinitionBuilder builder, String propertyName, Attr attribute) {
|
||||
|
||||
addProperty(builder, propertyName, attribute.getValue(), null, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
@@ -72,34 +63,6 @@ abstract class ParsingUtils {
|
||||
addProperty(builder, propertyName, element.getAttribute(attributeName), defaultValue, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link ParsingUtils#addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyReference(BeanDefinitionBuilder builder, String propertyName, String value) {
|
||||
|
||||
addProperty(builder, propertyName, value, null, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link ParsingUtils#addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyReference(BeanDefinitionBuilder builder, String propertyName, String value,
|
||||
String defaultValue) {
|
||||
|
||||
addProperty(builder, propertyName, value, defaultValue, false, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyValue(BeanDefinitionBuilder builder, String propertyName, Attr attribute) {
|
||||
|
||||
addProperty(builder, propertyName, attribute.getValue(), null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
@@ -130,34 +93,6 @@ abstract class ParsingUtils {
|
||||
addProperty(builder, propertyName, element.getAttribute(attributeName), defaultValue, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyValue(BeanDefinitionBuilder builder, String propertyName, String value) {
|
||||
|
||||
addProperty(builder, propertyName, value, null, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addOptionalPropertyValue(BeanDefinitionBuilder builder, String propertyName, String value,
|
||||
String defaultValue) {
|
||||
|
||||
addProperty(builder, propertyName, value, defaultValue, false, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
*/
|
||||
public static void addRequiredPropertyReference(BeanDefinitionBuilder builder, String propertyName, Attr attribute) {
|
||||
|
||||
addProperty(builder, propertyName, attribute.getValue(), null, true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method delegating to
|
||||
* {@link #addProperty(BeanDefinitionBuilder, String, String, String, boolean, boolean)}.
|
||||
|
||||
@@ -114,7 +114,7 @@ public class PoolingOptionsFactoryBean implements FactoryBean<PoolingOptions>, I
|
||||
return GET_MAX_QUEUE_SIZE.map(method -> {
|
||||
|
||||
Integer defaultMaxQueueSize = (Integer) invokeMethod(method, poolingOptions);
|
||||
return defaultMaxQueueSize.intValue() == maxQueueSize;
|
||||
return defaultMaxQueueSize != null && defaultMaxQueueSize == maxQueueSize;
|
||||
}).orElse(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.config;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
@@ -27,17 +28,25 @@ import com.datastax.driver.core.SocketOptions;
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SuppressWarnings({ "unused", "WeakerAccess" })
|
||||
public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, InitializingBean, DisposableBean {
|
||||
public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, InitializingBean {
|
||||
|
||||
private @Nullable Integer connectTimeoutMillis;
|
||||
|
||||
private @Nullable Boolean keepAlive;
|
||||
|
||||
private @Nullable Integer readTimeoutMillis;
|
||||
|
||||
private @Nullable Boolean reuseAddress;
|
||||
|
||||
private @Nullable Integer soLinger;
|
||||
|
||||
private @Nullable Boolean tcpNoDelay;
|
||||
|
||||
private @Nullable Integer receiveBufferSize;
|
||||
|
||||
private @Nullable Integer sendBufferSize;
|
||||
|
||||
private @Nullable SocketOptions socketOptions;
|
||||
@@ -58,70 +67,22 @@ public class SocketOptionsFactoryBean implements FactoryBean<SocketOptions>, Ini
|
||||
return SocketOptions.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.DisposableBean#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() throws Exception {
|
||||
|
||||
connectTimeoutMillis = null;
|
||||
keepAlive = null;
|
||||
readTimeoutMillis = null;
|
||||
reuseAddress = null;
|
||||
soLinger = null;
|
||||
tcpNoDelay = null;
|
||||
receiveBufferSize = null;
|
||||
sendBufferSize = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
socketOptions = new SocketOptions();
|
||||
this.socketOptions = new SocketOptions();
|
||||
|
||||
if (connectTimeoutMillis != null) {
|
||||
socketOptions.setConnectTimeoutMillis(connectTimeoutMillis);
|
||||
}
|
||||
|
||||
if (keepAlive != null) {
|
||||
socketOptions.setKeepAlive(keepAlive);
|
||||
}
|
||||
|
||||
if (readTimeoutMillis != null) {
|
||||
socketOptions.setReadTimeoutMillis(readTimeoutMillis);
|
||||
}
|
||||
|
||||
if (reuseAddress != null) {
|
||||
socketOptions.setReuseAddress(reuseAddress);
|
||||
}
|
||||
|
||||
if (soLinger != null) {
|
||||
socketOptions.setSoLinger(soLinger);
|
||||
}
|
||||
|
||||
if (tcpNoDelay != null) {
|
||||
socketOptions.setTcpNoDelay(tcpNoDelay);
|
||||
}
|
||||
|
||||
if (receiveBufferSize != null) {
|
||||
socketOptions.setReceiveBufferSize(receiveBufferSize);
|
||||
}
|
||||
|
||||
if (sendBufferSize != null) {
|
||||
socketOptions.setSendBufferSize(sendBufferSize);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
Optional.ofNullable(this.connectTimeoutMillis).ifPresent(this.socketOptions::setConnectTimeoutMillis);
|
||||
Optional.ofNullable(this.readTimeoutMillis).ifPresent(this.socketOptions::setReadTimeoutMillis);
|
||||
Optional.ofNullable(this.keepAlive).ifPresent(this.socketOptions::setKeepAlive);
|
||||
Optional.ofNullable(this.reuseAddress).ifPresent(this.socketOptions::setReuseAddress);
|
||||
Optional.ofNullable(this.soLinger).ifPresent(this.socketOptions::setSoLinger);
|
||||
Optional.ofNullable(this.tcpNoDelay).ifPresent(this.socketOptions::setTcpNoDelay);
|
||||
Optional.ofNullable(this.receiveBufferSize).ifPresent(this.socketOptions::setReceiveBufferSize);
|
||||
Optional.ofNullable(this.sendBufferSize).ifPresent(this.socketOptions::setSendBufferSize);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -68,7 +68,7 @@ public class CassandraPersistentEntitySchemaDropper {
|
||||
this.cassandraAdminOperations.getKeyspaceMetadata().getTables()
|
||||
.stream()
|
||||
.map(AbstractTableMetadata::getName)
|
||||
.map(CqlIdentifier::cqlId)
|
||||
.map(CqlIdentifier::of)
|
||||
.filter(table -> dropUnused || this.mappingContext.usesTable(table))
|
||||
.forEach(this.cassandraAdminOperations::dropTable);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class CassandraPersistentEntitySchemaDropper {
|
||||
|
||||
this.cassandraAdminOperations.getKeyspaceMetadata().getUserTypes().forEach(userType -> {
|
||||
|
||||
CqlIdentifier typeName = CqlIdentifier.cqlId(userType.getTypeName());
|
||||
CqlIdentifier typeName = CqlIdentifier.of(userType.getTypeName());
|
||||
|
||||
if (canRecreate.contains(typeName)) {
|
||||
this.cassandraAdminOperations.dropUserType(typeName);
|
||||
|
||||
@@ -60,7 +60,7 @@ public interface CassandraConverter
|
||||
*
|
||||
* @param object must not be {@literal null}.
|
||||
* @param entity must not be {@literal null}.
|
||||
* @return
|
||||
* @return the id value or {@literal null}, if the id is not set.
|
||||
*/
|
||||
@Nullable
|
||||
Object getId(Object object, CassandraPersistentEntity<?> entity);
|
||||
|
||||
@@ -50,7 +50,7 @@ abstract class CassandraConverters {
|
||||
/**
|
||||
* Returns the converters to be registered.
|
||||
*/
|
||||
public static Collection<Object> getConvertersToRegister() {
|
||||
static Collection<Object> getConvertersToRegister() {
|
||||
|
||||
List<Object> converters = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -18,12 +18,9 @@ package org.springframework.data.cassandra.core.convert;
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.convert.Jsr310Converters;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Helper class to register JodaTime specific {@link Converter} implementations in case the library is present on the
|
||||
@@ -32,12 +29,8 @@ import org.springframework.util.ClassUtils;
|
||||
* @author Mark Paluch
|
||||
* @since 1.5
|
||||
*/
|
||||
@SuppressWarnings("Since15")
|
||||
public abstract class CassandraJsr310Converters {
|
||||
|
||||
private static final boolean JAVA_8_IS_PRESENT = ClassUtils.isPresent("java.time.LocalDateTime",
|
||||
Jsr310Converters.class.getClassLoader());
|
||||
|
||||
private CassandraJsr310Converters() {}
|
||||
|
||||
/**
|
||||
@@ -47,10 +40,6 @@ public abstract class CassandraJsr310Converters {
|
||||
*/
|
||||
public static Collection<Converter<?, ?>> getConvertersToRegister() {
|
||||
|
||||
if (!JAVA_8_IS_PRESENT) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
List<Converter<?, ?>> converters = new ArrayList<>();
|
||||
|
||||
converters.add(CassandraLocalDateToLocalDateConverter.INSTANCE);
|
||||
|
||||
@@ -36,8 +36,8 @@ import com.datastax.driver.core.TypeCodec;
|
||||
*/
|
||||
public class ColumnReader {
|
||||
|
||||
protected Row row;
|
||||
protected ColumnDefinitions columns;
|
||||
private final Row row;
|
||||
private final ColumnDefinitions columns;
|
||||
private final CodecRegistry codecRegistry;
|
||||
|
||||
public ColumnReader(Row row) {
|
||||
@@ -60,8 +60,7 @@ public class ColumnReader {
|
||||
*/
|
||||
@Nullable
|
||||
public Object get(String name) {
|
||||
int indexOf = getColumnIndex(name);
|
||||
return get(indexOf);
|
||||
return get(getColumnIndex(name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +94,7 @@ public class ColumnReader {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Object getCollection(int i, DataType type) {
|
||||
private Object getCollection(int i, DataType type) {
|
||||
|
||||
List<DataType> collectionTypes = type.getTypeArguments();
|
||||
|
||||
@@ -111,7 +110,6 @@ public class ColumnReader {
|
||||
if (type.equals(DataType.set(valueType))) {
|
||||
return row.getSet(i, typeCodec.getJavaType().getRawType());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Map
|
||||
@@ -158,7 +156,6 @@ public class ColumnReader {
|
||||
* @throws ClassCastException if the value cannot be converted to the requested type.
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(int i, Class<T> requestedType) {
|
||||
|
||||
Object o = get(i);
|
||||
@@ -167,7 +164,7 @@ public class ColumnReader {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (T) o;
|
||||
return requestedType.cast(o);
|
||||
}
|
||||
|
||||
private int getColumnIndex(String name) {
|
||||
@@ -178,5 +175,4 @@ public class ColumnReader {
|
||||
}
|
||||
return indexOf;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,7 +152,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
* @param row must not be {@literal null}.
|
||||
* @return the converted valued.
|
||||
*/
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public <R> R readRow(Class<R> type, Row row) {
|
||||
|
||||
@@ -268,7 +267,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
propertyAccessor.setProperty(property, getReadValue(valueProvider, property));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
protected Object instantiatePrimaryKey(CassandraPersistentEntity<?> entity, CassandraPersistentProperty keyProperty,
|
||||
CassandraValueProvider propertyProvider) {
|
||||
|
||||
@@ -293,7 +291,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
* @see org.springframework.data.cassandra.core.convert.CassandraConverter#convertToColumnType(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object convertToColumnType(Object obj) {
|
||||
return convertToColumnType(obj, ClassTypeInformation.from(obj.getClass()));
|
||||
}
|
||||
@@ -358,7 +355,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
}
|
||||
|
||||
protected void writeInsertFromObject(Object object, Insert insert, CassandraPersistentEntity<?> entity) {
|
||||
private void writeInsertFromObject(Object object, Insert insert, CassandraPersistentEntity<?> entity) {
|
||||
writeInsertFromWrapper(getConvertingAccessor(object, entity), insert, entity);
|
||||
}
|
||||
|
||||
@@ -498,7 +495,6 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Collection<Clause> getWhereClauses(Object source, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
Assert.notNull(source, "Id source must not be null");
|
||||
@@ -547,6 +543,7 @@ public class MappingCassandraConverter extends AbstractCassandraConverter
|
||||
QueryBuilder.eq(idProperty.getColumnName().toCql(), getPotentiallyConvertedSimpleValue(id, targetType)));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Object extractId(Object source, CassandraPersistentEntity<?> entity) {
|
||||
|
||||
if (ClassUtils.isAssignableValue(entity.getType(), source)) {
|
||||
|
||||
@@ -314,7 +314,7 @@ public class QueryMapper {
|
||||
}
|
||||
|
||||
if (column.getColumnName().isPresent()) {
|
||||
return column.getColumnName().map(CqlIdentifier::cqlId);
|
||||
return column.getColumnName().map(CqlIdentifier::of);
|
||||
}
|
||||
|
||||
return column.getCqlIdentifier();
|
||||
@@ -324,7 +324,7 @@ public class QueryMapper {
|
||||
}
|
||||
}
|
||||
|
||||
protected Field createPropertyField(CassandraPersistentEntity<?> entity, ColumnName key) {
|
||||
Field createPropertyField(CassandraPersistentEntity<?> entity, ColumnName key) {
|
||||
return Optional.of(entity).<Field> map(e -> new MetadataBackedField(key, e, getMappingContext()))
|
||||
.orElseGet(() -> new Field(key));
|
||||
}
|
||||
@@ -397,9 +397,13 @@ public class QueryMapper {
|
||||
protected static class MetadataBackedField extends Field {
|
||||
|
||||
private final CassandraPersistentEntity<?> entity;
|
||||
|
||||
private final MappingContext<? extends CassandraPersistentEntity<?>, CassandraPersistentProperty> mappingContext;
|
||||
|
||||
private final Optional<PersistentPropertyPath<CassandraPersistentProperty>> path;
|
||||
|
||||
private final @Nullable CassandraPersistentProperty property;
|
||||
|
||||
private final Optional<CassandraPersistentProperty> optionalProperty;
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,7 +36,7 @@ public class ArgumentPreparedStatementBinder implements PreparedStatementBinder
|
||||
*
|
||||
* @param args the arguments to set. May be empty or {@link null} if no arguments are provided.
|
||||
*/
|
||||
public ArgumentPreparedStatementBinder(@Nullable Object[] args) {
|
||||
public ArgumentPreparedStatementBinder(@Nullable Object... args) {
|
||||
this.args = args;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
/**
|
||||
* Create a new {@link CqlIdentifier} without force-quoting it. It may end up quoted, depending on its value.
|
||||
*
|
||||
* @see #cqlId(CharSequence)
|
||||
* @see #of(CharSequence)
|
||||
*/
|
||||
private CqlIdentifier(CharSequence identifier) {
|
||||
this(identifier, false);
|
||||
@@ -74,8 +74,8 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* <li>If the given identifier is illegal, an {@link IllegalArgumentException} is thrown.</li>
|
||||
* </ul>
|
||||
*
|
||||
* @see #cqlId(CharSequence, boolean)
|
||||
* @see #quotedCqlId(CharSequence)
|
||||
* @see #of(CharSequence, boolean)
|
||||
* @see #quoted(CharSequence)
|
||||
*/
|
||||
private CqlIdentifier(CharSequence identifier, boolean forceQuote) {
|
||||
|
||||
@@ -102,7 +102,9 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* Factory method for {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence)
|
||||
* @deprecated since 2.0, use {@link #of(CharSequence)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static CqlIdentifier cqlId(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier);
|
||||
}
|
||||
@@ -111,20 +113,50 @@ public final class CqlIdentifier implements Comparable<CqlIdentifier>, Serializa
|
||||
* Factory method for {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence, boolean)
|
||||
* @deprecated since 2.0, use {@link #of(CharSequence, boolean)}
|
||||
*/
|
||||
@Deprecated
|
||||
public static CqlIdentifier cqlId(CharSequence identifier, boolean forceQuote) {
|
||||
return new CqlIdentifier(identifier, forceQuote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for {@link CqlIdentifier}.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static CqlIdentifier of(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for {@link CqlIdentifier}.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public static CqlIdentifier of(CharSequence identifier, boolean forceQuote) {
|
||||
return new CqlIdentifier(identifier, forceQuote);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for a force-quoted {@link CqlIdentifier}. Convenient if imported statically.
|
||||
*
|
||||
* @see #CqlIdentifier(CharSequence, boolean)
|
||||
* @deprecated since 2.0, use {@link #quoted(CharSequence)}.
|
||||
*/
|
||||
public static CqlIdentifier quotedCqlId(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method for a force-quoted {@link CqlIdentifier}.
|
||||
*
|
||||
* @since 2.0.
|
||||
*/
|
||||
public static CqlIdentifier quoted(CharSequence identifier) {
|
||||
return new CqlIdentifier(identifier, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the given {@link CharSequence} is a legal unquoted identifier.
|
||||
*/
|
||||
|
||||
@@ -370,7 +370,6 @@ public interface CqlOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
* @see #queryForObject(String, Class, Object[])
|
||||
*/
|
||||
@Nullable
|
||||
<T> T queryForObject(String cql, Class<T> requiredType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -390,7 +389,6 @@ public interface CqlOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
* @see #queryForObject(String, Class)
|
||||
*/
|
||||
@Nullable
|
||||
<T> T queryForObject(String cql, Class<T> requiredType, Object... args) throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -614,7 +612,6 @@ public interface CqlOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
* @see #queryForObject(String, Class, Object[])
|
||||
*/
|
||||
@Nullable
|
||||
<T> T queryForObject(Statement statement, Class<T> requiredType) throws DataAccessException;
|
||||
|
||||
/**
|
||||
@@ -631,7 +628,6 @@ public interface CqlOperations {
|
||||
* @throws DataAccessException if there is any problem executing the query.
|
||||
* @see #queryForObject(String, RowMapper, Object[])
|
||||
*/
|
||||
@Nullable
|
||||
<T> T queryForObject(Statement statement, RowMapper<T> rowMapper) throws DataAccessException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by objects that can provide CQL strings.
|
||||
* <p>
|
||||
@@ -35,8 +33,7 @@ public interface CqlProvider {
|
||||
/**
|
||||
* Return the CQL string for this object, i.e. typically the CQL used for creating statements.
|
||||
*
|
||||
* @return the CQL string, or {@literal null}.
|
||||
* @return the CQL string.
|
||||
*/
|
||||
@Nullable
|
||||
String getCql();
|
||||
}
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/*
|
||||
* 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.data.cassandra.core.cql;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
public class CqlStringUtils {
|
||||
|
||||
private static final String DOUBLE_QUOTE = "\"";
|
||||
private static final String DOUBLE_DOUBLE_QUOTE = "\"\"";
|
||||
private static final String DOUBLE_SINGLE_QUOTE = "\'\'";
|
||||
private static final String SINGLE_QUOTE = "\'";
|
||||
private static final String EMPTY_STRING = "";
|
||||
private static final String TYPE_PARAMETER_PREFIX = "<";
|
||||
private static final String TYPE_PARAMETER_SUFFIX = ">";
|
||||
|
||||
/**
|
||||
* 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 {@literal null}, returns <code>null</code>.
|
||||
*/
|
||||
@Nullable
|
||||
public static String valuize(@Nullable String candidate) {
|
||||
return (candidate != null ? singleQuote(escapeSingle(candidate)) : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles single quote characters (' -> ''). Given {@literal null}, returns <code>null</code>.
|
||||
*/
|
||||
@Nullable
|
||||
public static String escapeSingle(@Nullable Object thing) {
|
||||
return (thing == null ? null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Doubles double quote characters (" -> ""). Given {@literal null}, returns <code>null</code>.
|
||||
*/
|
||||
@Nullable
|
||||
public static String escapeDouble(@Nullable Object thing) {
|
||||
return (thing == null ? null : thing.toString().replace(DOUBLE_QUOTE, DOUBLE_DOUBLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given {@literal null}, returns
|
||||
* {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static String singleQuote(@Nullable Object thing) {
|
||||
return (thing == null ? null : SINGLE_QUOTE.concat(thing.toString()).concat(SINGLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with double quotes. Given {@literal null}, returns
|
||||
* {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static String doubleQuote(@Nullable Object thing) {
|
||||
return (thing == null ? null : DOUBLE_QUOTE.concat(thing.toString()).concat(DOUBLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed single quotes from quoted String option values
|
||||
*/
|
||||
@Nullable
|
||||
public static String removeSingleQuotes(@Nullable Object thing) {
|
||||
return (thing == null ? null : thing.toString().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) {
|
||||
|
||||
if (dataType.getTypeArguments().isEmpty()) {
|
||||
return dataType.getName().name();
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.append(dataType.getName().name()).append(TYPE_PARAMETER_PREFIX);
|
||||
|
||||
boolean first = true;
|
||||
|
||||
for (DataType argDataType : dataType.getTypeArguments()) {
|
||||
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
builder.append(',');
|
||||
}
|
||||
|
||||
builder.append(argDataType.getName().name());
|
||||
}
|
||||
|
||||
return builder.append(TYPE_PARAMETER_SUFFIX).toString();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String unquote(@Nullable String value) {
|
||||
return unquote(value, "\"");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String unquote(@Nullable String value, String quoteChar) {
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!value.startsWith(quoteChar) || !value.endsWith(quoteChar)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (value.length() <= 2) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value.substring(1, value.length() - 1);
|
||||
}
|
||||
}
|
||||
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
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}.
|
||||
* Enum for Cassandra primary key column ordering.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public enum Ordering implements Comparator<Ordering> {
|
||||
public enum Ordering {
|
||||
|
||||
/**
|
||||
* Ascending Cassandra column ordering.
|
||||
@@ -47,18 +45,4 @@ public enum Ordering implements Comparator<Ordering> {
|
||||
public String cql() {
|
||||
return cql;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(Ordering l, Ordering r) {
|
||||
if (l == r) {
|
||||
return 0;
|
||||
}
|
||||
if (l == null) {
|
||||
return 1;
|
||||
}
|
||||
if (r == null) {
|
||||
return -1;
|
||||
}
|
||||
return (l == ASCENDING && r == DESCENDING) ? 1 : -1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,16 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Values representing primary key column types. Implements {@link Comparator} in that
|
||||
* {@link PrimaryKeyType#PARTITIONED} is ordered before {@link PrimaryKeyType#CLUSTERED}.
|
||||
* Values representing primary key column types.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Alex Shvid
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public enum PrimaryKeyType implements Comparator<PrimaryKeyType> {
|
||||
public enum PrimaryKeyType {
|
||||
|
||||
/**
|
||||
* Used for a column that is part of the partition key.
|
||||
@@ -34,19 +32,5 @@ public enum PrimaryKeyType implements Comparator<PrimaryKeyType> {
|
||||
/**
|
||||
* Used for a column that is clustered key.
|
||||
*/
|
||||
CLUSTERED;
|
||||
|
||||
@Override
|
||||
public int compare(PrimaryKeyType l, PrimaryKeyType r) {
|
||||
if (l == r) {
|
||||
return 0;
|
||||
}
|
||||
if (l == null) {
|
||||
return 1;
|
||||
}
|
||||
if (r == null) {
|
||||
return -1;
|
||||
}
|
||||
return l == PARTITIONED && r == CLUSTERED ? 1 : -1;
|
||||
}
|
||||
CLUSTERED
|
||||
}
|
||||
|
||||
@@ -35,6 +35,8 @@ import com.datastax.driver.core.UDTValue;
|
||||
*/
|
||||
public abstract class RowUtils {
|
||||
|
||||
private RowUtils() {}
|
||||
|
||||
/**
|
||||
* Retrieve a CQL column value from a {@link Row}, using the specified value type.
|
||||
* <p>
|
||||
|
||||
@@ -22,13 +22,14 @@ import org.springframework.util.Assert;
|
||||
* Base class for column change CQL generators.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Mark Paluch
|
||||
* @param <T> The corresponding {@link ColumnChangeSpecification} type for this CQL generator.
|
||||
*/
|
||||
public abstract class ColumnChangeCqlGenerator<T extends ColumnChangeSpecification> {
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
private ColumnChangeSpecification specification;
|
||||
private final ColumnChangeSpecification specification;
|
||||
|
||||
public ColumnChangeCqlGenerator(ColumnChangeSpecification specification) {
|
||||
|
||||
@@ -36,12 +37,6 @@ public abstract class ColumnChangeCqlGenerator<T extends ColumnChangeSpecificati
|
||||
this.specification = specification;
|
||||
}
|
||||
|
||||
protected void setSpecification(ColumnChangeSpecification specification) {
|
||||
|
||||
Assert.notNull(specification, "ColumnChangeSpecification must not be null");
|
||||
this.specification = specification;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getSpecification() {
|
||||
return (T) specification;
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlStringUtils;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CreateIndexSpecification.ColumnFunction;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class IndexNameCqlGenerator<T extends IndexNameSpecification<T>> {
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
private final IndexNameSpecification<T> specification;
|
||||
|
||||
public IndexNameCqlGenerator(IndexNameSpecification<T> specification) {
|
||||
@@ -51,4 +49,6 @@ public abstract class IndexNameCqlGenerator<T extends IndexNameSpecification<T>>
|
||||
public String toCql() {
|
||||
return toCql(new StringBuilder()).toString();
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,6 @@ import org.springframework.util.Assert;
|
||||
*/
|
||||
public abstract class KeyspaceNameCqlGenerator<T extends KeyspaceActionSpecification> {
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
private final KeyspaceActionSpecification specification;
|
||||
|
||||
public KeyspaceNameCqlGenerator(KeyspaceActionSpecification specification) {
|
||||
@@ -51,4 +49,6 @@ public abstract class KeyspaceNameCqlGenerator<T extends KeyspaceActionSpecifica
|
||||
public String toCql() {
|
||||
return toCql(new StringBuilder()).toString();
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.generator;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -23,8 +23,9 @@ import org.springframework.data.cassandra.core.cql.keyspace.Option;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
* @since 2.0
|
||||
*/
|
||||
public class OptionRenderUtil {
|
||||
class OptionRenderUtil {
|
||||
|
||||
static String render(Map<Option, Object> valueMap) {
|
||||
|
||||
|
||||
@@ -34,8 +34,6 @@ public abstract class TableNameCqlGenerator<T extends TableNameSpecification> {
|
||||
this.specification = specification;
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getSpecification() {
|
||||
return (T) specification;
|
||||
@@ -51,4 +49,6 @@ public abstract class TableNameCqlGenerator<T extends TableNameSpecification> {
|
||||
public String toCql() {
|
||||
return toCql(new StringBuilder()).toString();
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
}
|
||||
|
||||
@@ -43,8 +43,6 @@ public abstract class UserTypeNameCqlGenerator<T extends UserTypeNameSpecificati
|
||||
this.specification = specification;
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public T getSpecification() {
|
||||
return (T) specification;
|
||||
@@ -60,4 +58,6 @@ public abstract class UserTypeNameCqlGenerator<T extends UserTypeNameSpecificati
|
||||
public String toCql() {
|
||||
return toCql(new StringBuilder()).toString();
|
||||
}
|
||||
|
||||
public abstract StringBuilder toCql(StringBuilder cql);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class AddColumnSpecification extends ColumnTypeChangeSpecification {
|
||||
* @return a new {@link AddColumnSpecification}.
|
||||
*/
|
||||
public static AddColumnSpecification addColumn(String name, DataType type) {
|
||||
return addColumn(CqlIdentifier.cqlId(name), type);
|
||||
return addColumn(CqlIdentifier.of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AlterColumnSpecification extends ColumnTypeChangeSpecification {
|
||||
* @return a new {@link AlterColumnSpecification}.
|
||||
*/
|
||||
public static AlterColumnSpecification alterColumn(String name, DataType type) {
|
||||
return alterColumn(CqlIdentifier.cqlId(name), type);
|
||||
return alterColumn(CqlIdentifier.of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -56,7 +56,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
* @return a new {@link AlterTableSpecification}.
|
||||
*/
|
||||
public static AlterTableSpecification alterTable(String tableName) {
|
||||
return alterTable(CqlIdentifier.cqlId(tableName));
|
||||
return alterTable(CqlIdentifier.of(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,7 +78,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
* @return {@literal this} {@link AlterTableSpecification}.
|
||||
*/
|
||||
public AlterTableSpecification add(String column, DataType type) {
|
||||
return add(CqlIdentifier.cqlId(column), type);
|
||||
return add(CqlIdentifier.of(column), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +100,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
* @return {@literal this} {@link AlterTableSpecification}.
|
||||
*/
|
||||
public AlterTableSpecification drop(String column) {
|
||||
return drop(CqlIdentifier.cqlId(column));
|
||||
return drop(CqlIdentifier.of(column));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,7 +122,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
* @return {@literal this} {@link AlterTableSpecification}.
|
||||
*/
|
||||
public AlterTableSpecification rename(String from, String to) {
|
||||
return rename(CqlIdentifier.cqlId(from), CqlIdentifier.cqlId(to));
|
||||
return rename(CqlIdentifier.of(from), CqlIdentifier.of(to));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +145,7 @@ public class AlterTableSpecification extends TableOptionsSpecification<AlterTabl
|
||||
* @return {@literal this} {@link AlterTableSpecification}.
|
||||
*/
|
||||
public AlterTableSpecification alter(String column, DataType type) {
|
||||
return alter(CqlIdentifier.cqlId(column), type);
|
||||
return alter(CqlIdentifier.of(column), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
|
||||
* @return a new {@link AlterUserTypeSpecification}.
|
||||
*/
|
||||
public static AlterUserTypeSpecification alterType(String typeName) {
|
||||
return alterType(CqlIdentifier.cqlId(typeName));
|
||||
return alterType(CqlIdentifier.of(typeName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +69,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
|
||||
* @return {@code this} {@link AlterUserTypeSpecification}.
|
||||
*/
|
||||
public AlterUserTypeSpecification add(String field, DataType type) {
|
||||
return add(CqlIdentifier.cqlId(field), type);
|
||||
return add(CqlIdentifier.of(field), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,7 +91,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
|
||||
* @return {@code this} {@link AlterUserTypeSpecification}.
|
||||
*/
|
||||
public AlterUserTypeSpecification alter(String field, DataType type) {
|
||||
return alter(CqlIdentifier.cqlId(field), type);
|
||||
return alter(CqlIdentifier.of(field), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +113,7 @@ public class AlterUserTypeSpecification extends UserTypeNameSpecification {
|
||||
* @return {@code this} {@link AlterUserTypeSpecification}.
|
||||
*/
|
||||
public AlterUserTypeSpecification rename(String from, String to) {
|
||||
return rename(CqlIdentifier.cqlId(from), CqlIdentifier.cqlId(to));
|
||||
return rename(CqlIdentifier.of(from), CqlIdentifier.of(to));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,7 +65,7 @@ public class ColumnSpecification {
|
||||
* @return a new {@link ColumnSpecification} for {@code name}.
|
||||
*/
|
||||
public static ColumnSpecification name(String name) {
|
||||
return name(cqlId(name));
|
||||
return name(of(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
public class CqlStringUtils {
|
||||
|
||||
private static final String DOUBLE_SINGLE_QUOTE = "\'\'";
|
||||
private static final String SINGLE_QUOTE = "\'";
|
||||
|
||||
/**
|
||||
* Doubles single quote characters (' -> ''). Given {@literal null}, returns <code>null</code>.
|
||||
*/
|
||||
@Nullable
|
||||
public static String escapeSingle(@Nullable Object thing) {
|
||||
return (thing == null ? null : thing.toString().replace(SINGLE_QUOTE, DOUBLE_SINGLE_QUOTE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Surrounds given object's {@link Object#toString()} with single quotes. Given {@literal null}, returns
|
||||
* {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static String singleQuote(@Nullable Object thing) {
|
||||
return (thing == null ? null : SINGLE_QUOTE.concat(thing.toString()).concat(SINGLE_QUOTE));
|
||||
}
|
||||
}
|
||||
@@ -37,18 +37,18 @@ import org.springframework.util.StringUtils;
|
||||
public class CreateIndexSpecification extends IndexNameSpecification<CreateIndexSpecification>
|
||||
implements IndexDescriptor {
|
||||
|
||||
private boolean ifNotExists = false;
|
||||
|
||||
private boolean custom = false;
|
||||
|
||||
private @Nullable CqlIdentifier tableName;
|
||||
|
||||
private @Nullable CqlIdentifier columnName;
|
||||
|
||||
private boolean ifNotExists = false;
|
||||
|
||||
private ColumnFunction columnFunction = ColumnFunction.NONE;
|
||||
|
||||
private @Nullable String using;
|
||||
|
||||
private boolean custom = false;
|
||||
|
||||
private final Map<String, String> options = new LinkedHashMap<>();
|
||||
|
||||
private CreateIndexSpecification() {}
|
||||
@@ -73,7 +73,7 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
* @return a new {@link CreateIndexSpecification}.
|
||||
*/
|
||||
public static CreateIndexSpecification createIndex(String indexName) {
|
||||
return createIndex(CqlIdentifier.cqlId(indexName));
|
||||
return createIndex(CqlIdentifier.of(indexName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +87,72 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
return new CreateIndexSpecification(indexName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name.
|
||||
*
|
||||
* @param tableName must not be {@literal null} or empty.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification tableName(String tableName) {
|
||||
return tableName(of(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name.
|
||||
*
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification tableName(CqlIdentifier tableName) {
|
||||
|
||||
Assert.notNull(tableName, "CqlIdentifier must not be null");
|
||||
|
||||
this.tableName = tableName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.cql.keyspace.IndexDescriptor#getTableName()
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getTableName() {
|
||||
return this.tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column name.
|
||||
*
|
||||
* @param columnName must not be {@literal null} or empty.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification columnName(String columnName) {
|
||||
return columnName(of(columnName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column name.
|
||||
*
|
||||
* @param columnName must not be {@literal null}.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification columnName(CqlIdentifier columnName) {
|
||||
|
||||
Assert.notNull(columnName, "CqlIdentifier must not be null");
|
||||
|
||||
this.columnName = columnName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.cql.keyspace.IndexDescriptor#getColumnName()
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getColumnName() {
|
||||
return this.columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an {@code IF NOT EXISTS} clause.
|
||||
*
|
||||
@@ -142,14 +208,6 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
return this.using;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.cql.keyspace.IndexDescriptor#getColumnName()
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getColumnName() {
|
||||
return this.columnName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the inclusion of an {@code KEYS} clause.
|
||||
*
|
||||
@@ -232,64 +290,6 @@ public class CreateIndexSpecification extends IndexNameSpecification<CreateIndex
|
||||
return Collections.unmodifiableMap(this.options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name.
|
||||
*
|
||||
* @param tableName must not be {@literal null} or empty.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification tableName(String tableName) {
|
||||
return tableName(cqlId(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the table name.
|
||||
*
|
||||
* @param tableName must not be {@literal null}.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification tableName(CqlIdentifier tableName) {
|
||||
|
||||
Assert.notNull(tableName, "CqlIdentifier must not be null");
|
||||
|
||||
this.tableName = tableName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.data.cassandra.core.cql.keyspace.IndexDescriptor#getTableName()
|
||||
*/
|
||||
@Override
|
||||
public CqlIdentifier getTableName() {
|
||||
return this.tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column name.
|
||||
*
|
||||
* @param columnName must not be {@literal null} or empty.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification columnName(String columnName) {
|
||||
return columnName(cqlId(columnName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column name.
|
||||
*
|
||||
* @param columnName must not be {@literal null}.
|
||||
* @return this
|
||||
*/
|
||||
public CreateIndexSpecification columnName(CqlIdentifier columnName) {
|
||||
|
||||
Assert.notNull(columnName, "CqlIdentifier must not be null");
|
||||
|
||||
this.columnName = columnName;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Column functions to specify indexing behavior.
|
||||
*
|
||||
|
||||
@@ -40,7 +40,7 @@ public class CreateTableSpecification extends TableSpecification<CreateTableSpec
|
||||
* @return a new {@link CreateTableSpecification}.
|
||||
*/
|
||||
public static CreateTableSpecification createTable(String tableName) {
|
||||
return new CreateTableSpecification(CqlIdentifier.cqlId(tableName));
|
||||
return new CreateTableSpecification(CqlIdentifier.of(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ public class CreateUserTypeSpecification extends UserTypeSpecification<CreateUse
|
||||
* @return a new {@link CreateUserTypeSpecification}.
|
||||
*/
|
||||
public static CreateUserTypeSpecification createType(String name) {
|
||||
return new CreateUserTypeSpecification(CqlIdentifier.cqlId(name));
|
||||
return new CreateUserTypeSpecification(CqlIdentifier.of(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils.*;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class DropColumnSpecification extends ColumnChangeSpecification {
|
||||
* @param name must not be {@literal null} or empty.
|
||||
*/
|
||||
public static DropColumnSpecification dropColumn(String name) {
|
||||
return dropColumn(CqlIdentifier.cqlId(name));
|
||||
return dropColumn(CqlIdentifier.of(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DropIndexSpecification extends IndexNameSpecification<DropIndexSpec
|
||||
* @return a new {@link DropIndexSpecification}.
|
||||
*/
|
||||
public static DropIndexSpecification dropIndex(String indexName) {
|
||||
return dropIndex(CqlIdentifier.cqlId(indexName));
|
||||
return dropIndex(CqlIdentifier.of(indexName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ public class DropTableSpecification extends TableNameSpecification {
|
||||
* @return a new {@link DropTableSpecification}.
|
||||
*/
|
||||
public static DropTableSpecification dropTable(String tableName) {
|
||||
return dropTable(CqlIdentifier.cqlId(tableName));
|
||||
return dropTable(CqlIdentifier.of(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DropUserTypeSpecification extends UserTypeNameSpecification {
|
||||
* @return a new {@link DropUserTypeSpecification}.
|
||||
*/
|
||||
public static DropUserTypeSpecification dropType(String name) {
|
||||
return new DropUserTypeSpecification(CqlIdentifier.cqlId(name));
|
||||
return new DropUserTypeSpecification(CqlIdentifier.of(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,7 @@ public class FieldSpecification {
|
||||
* @param type must not be {@literal null}.
|
||||
*/
|
||||
public static FieldSpecification of(String name, DataType type) {
|
||||
return new FieldSpecification(CqlIdentifier.cqlId(name), type);
|
||||
return new FieldSpecification(CqlIdentifier.of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.KeyspaceOption.ReplicationStrategy;
|
||||
@@ -34,6 +33,10 @@ public class KeyspaceAttributes {
|
||||
public static final long DEFAULT_REPLICATION_FACTOR = 1;
|
||||
public static final boolean DEFAULT_DURABLE_WRITES = true;
|
||||
|
||||
private ReplicationStrategy replicationStrategy = DEFAULT_REPLICATION_STRATEGY;
|
||||
private long replicationFactor = DEFAULT_REPLICATION_FACTOR;
|
||||
private boolean durableWrites = DEFAULT_DURABLE_WRITES;
|
||||
|
||||
/**
|
||||
* Returns a map of {@link Option}s suitable as the value of a {@link KeyspaceOption#REPLICATION} option with
|
||||
* replication strategy class "SimpleStrategy" and with a replication factor of one.
|
||||
@@ -47,6 +50,7 @@ public class KeyspaceAttributes {
|
||||
* replication strategy class "SimpleStrategy" and with a replication factor equal to that given.
|
||||
*/
|
||||
public static Map<Option, Object> newSimpleReplication(long replicationFactor) {
|
||||
|
||||
return MapBuilder.map(Option.class, Object.class)
|
||||
.entry(new DefaultOption("class", String.class, true, false, true),
|
||||
ReplicationStrategy.SIMPLE_STRATEGY.getValue())
|
||||
@@ -71,11 +75,6 @@ public class KeyspaceAttributes {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
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<>();
|
||||
|
||||
public ReplicationStrategy getReplicationStrategy() {
|
||||
return replicationStrategy;
|
||||
}
|
||||
@@ -99,8 +98,4 @@ public class KeyspaceAttributes {
|
||||
public void setDurableWrites(boolean durableWrites) {
|
||||
this.durableWrites = durableWrites;
|
||||
}
|
||||
|
||||
public void addReplicasPerNode(String dataCenter, long replicasPerNode) {
|
||||
replicasPerNodeByDataCenter.put(dataCenter, replicasPerNode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
public enum KeyspaceOption implements Option {
|
||||
|
||||
REPLICATION("replication", Map.class, true, false, false),
|
||||
@@ -65,7 +67,7 @@ public enum KeyspaceOption implements Option {
|
||||
return delegate.toString();
|
||||
}
|
||||
|
||||
public String toString(Object value) {
|
||||
public String toString(@Nullable Object value) {
|
||||
return delegate.toString(value);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils.*;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -23,7 +23,6 @@ import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlStringUtils;
|
||||
import org.springframework.data.cassandra.core.cql.KeyspaceIdentifier;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlIdentifier.*;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -31,16 +29,6 @@ public class RenameColumnSpecification extends ColumnChangeSpecification {
|
||||
|
||||
private final CqlIdentifier targetName;
|
||||
|
||||
/**
|
||||
* Create a new {@link ColumnChangeSpecification}.
|
||||
*
|
||||
* @param from must not be {@literal null} or empty.
|
||||
* @param to must not be {@literal null} or empty.
|
||||
*/
|
||||
RenameColumnSpecification(String from, String to) {
|
||||
this(cqlId(from), cqlId(to));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ColumnChangeSpecification}.
|
||||
*
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -124,7 +126,7 @@ public enum TableOption implements Option {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
public String toString(@Nullable Object value) {
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
|
||||
@@ -219,7 +221,7 @@ public enum TableOption implements Option {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
public String toString(@Nullable Object value) {
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
|
||||
@@ -321,7 +323,7 @@ public enum TableOption implements Option {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
public String toString(@Nullable Object value) {
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
}
|
||||
@@ -398,7 +400,7 @@ public enum TableOption implements Option {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(Object value) {
|
||||
public String toString(@Nullable Object value) {
|
||||
return this.delegate.toString(value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.cql.keyspace;
|
||||
|
||||
import static org.springframework.data.cassandra.core.cql.CqlStringUtils.*;
|
||||
import static org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.cassandra.core.cql.CqlStringUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,7 +72,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
* @param type The data type of the column, must not be {@literal null}.
|
||||
*/
|
||||
public T column(String name, DataType type) {
|
||||
return column(cqlId(name), type);
|
||||
return column(of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,7 +95,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
* @return this
|
||||
*/
|
||||
public T partitionKeyColumn(String name, DataType type) {
|
||||
return partitionKeyColumn(cqlId(name), type);
|
||||
return partitionKeyColumn(of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
* @return this
|
||||
*/
|
||||
public T clusteredKeyColumn(String name, DataType type) {
|
||||
return clusteredKeyColumn(cqlId(name), type);
|
||||
return clusteredKeyColumn(of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -198,7 +198,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
Assert.notNull(keyType, "PrimaryKeyType must not be null");
|
||||
Assert.notNull(ordering, "Ordering must not be null");
|
||||
|
||||
return column(cqlId(name), type, Optional.of(keyType), Optional.of(ordering));
|
||||
return column(of(name), type, Optional.of(keyType), Optional.of(ordering));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -218,7 +218,7 @@ public class TableSpecification<T> extends TableOptionsSpecification<TableSpecif
|
||||
Assert.notNull(keyType, "PrimaryKeyType must not be null");
|
||||
Assert.notNull(ordering, "Ordering must not be null");
|
||||
|
||||
return column(cqlId(name), type, Optional.of(keyType), ordering);
|
||||
return column(of(name), type, Optional.of(keyType), ordering);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -50,7 +50,7 @@ public class UserTypeSpecification<T extends UserTypeSpecification<T>> extends U
|
||||
* @return {@code this} specification.
|
||||
*/
|
||||
public T field(String name, DataType type) {
|
||||
return field(cqlId(name), type);
|
||||
return field(of(name), type);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -91,20 +91,20 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
|
||||
return determineName(annotation.value(), annotation.forceQuote());
|
||||
}
|
||||
|
||||
return cqlId(getType().getSimpleName(), false);
|
||||
return of(getType().getSimpleName(), false);
|
||||
}
|
||||
|
||||
CqlIdentifier determineName(String value, boolean forceQuote) {
|
||||
|
||||
if (!StringUtils.hasText(value)) {
|
||||
return cqlId(getType().getSimpleName(), forceQuote);
|
||||
return of(getType().getSimpleName(), forceQuote);
|
||||
}
|
||||
|
||||
String name = spelContext == null ? value : SpelUtils.evaluate(value, spelContext);
|
||||
|
||||
Assert.state(name != null, () -> String.format("Cannot determine default name for %s", this));
|
||||
|
||||
return cqlId(name, forceQuote);
|
||||
return of(name, forceQuote);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -171,7 +171,7 @@ public class BasicCassandraPersistentEntity<T> extends BasicPersistentEntity<T,
|
||||
this.forceQuote = Optional.of(forceQuote);
|
||||
|
||||
if (changed) {
|
||||
setTableName(cqlId(getTableName().getUnquoted(), forceQuote));
|
||||
setTableName(of(getTableName().getUnquoted(), forceQuote));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -249,7 +249,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
|
||||
Assert.state(this.userTypeResolver != null, "UserTypeResolver is null");
|
||||
|
||||
CqlIdentifier identifier = CqlIdentifier.cqlId(annotation.userTypeName());
|
||||
CqlIdentifier identifier = CqlIdentifier.of(annotation.userTypeName());
|
||||
|
||||
UserType userType = this.userTypeResolver.resolveType(identifier);
|
||||
|
||||
@@ -371,7 +371,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
name = (this.spelContext != null ? SpelUtils.evaluate(overriddenName, this.spelContext) : overriddenName);
|
||||
}
|
||||
|
||||
return name == null ? null : cqlId(name, forceQuote);
|
||||
return name == null ? null : of(name, forceQuote);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -398,7 +398,7 @@ public class BasicCassandraPersistentProperty extends AnnotationBasedPersistentP
|
||||
if (changed) {
|
||||
|
||||
CqlIdentifier columnName = getColumnName();
|
||||
setColumnName(cqlId(columnName.getUnquoted(), forceQuote));
|
||||
setColumnName(of(columnName.getUnquoted(), forceQuote));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,13 +28,7 @@ public enum CassandraColumnAnnotationComparator implements Comparator<Column> {
|
||||
/**
|
||||
* Comparator instance.
|
||||
*/
|
||||
INSTANCE,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #INSTANCE}
|
||||
*/
|
||||
@Deprecated
|
||||
IT;
|
||||
INSTANCE;
|
||||
|
||||
@Override
|
||||
public int compare(Column left, Column right) {
|
||||
|
||||
@@ -119,7 +119,7 @@ public class CassandraMappingContext
|
||||
String entityTableName = entityMapping.getTableName();
|
||||
|
||||
if (StringUtils.hasText(entityTableName)) {
|
||||
entity.setTableName(cqlId(entityTableName, Boolean.valueOf(entityMapping.getForceQuote())));
|
||||
entity.setTableName(of(entityTableName, Boolean.valueOf(entityMapping.getForceQuote())));
|
||||
}
|
||||
|
||||
processMappingOverrides(entity, entityMapping);
|
||||
@@ -150,7 +150,7 @@ public class CassandraMappingContext
|
||||
property.setForceQuote(forceQuote);
|
||||
|
||||
if (StringUtils.hasText(mapping.getColumnName())) {
|
||||
property.setColumnName(cqlId(mapping.getColumnName(), forceQuote));
|
||||
property.setColumnName(of(mapping.getColumnName(), forceQuote));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ public class CassandraMappingContext
|
||||
|
||||
return getPersistentEntities().stream().flatMap(entity -> StreamSupport.stream(entity.spliterator(), false))
|
||||
.flatMap(it -> Optionals.toStream(Optional.ofNullable(it.findAnnotation(CassandraType.class))))
|
||||
.map(CassandraType::userTypeName).filter(StringUtils::hasText).map(CqlIdentifier::cqlId)
|
||||
.map(CassandraType::userTypeName).filter(StringUtils::hasText).map(CqlIdentifier::of)
|
||||
.anyMatch(identifier::equals);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,13 +42,7 @@ public enum CassandraPersistentPropertyComparator implements Comparator<Cassandr
|
||||
/**
|
||||
* Comparator instance.
|
||||
*/
|
||||
INSTANCE,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #INSTANCE}
|
||||
*/
|
||||
@Deprecated
|
||||
IT;
|
||||
INSTANCE;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
|
||||
@@ -17,9 +17,6 @@ package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.data.cassandra.core.cql.Ordering;
|
||||
import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
|
||||
|
||||
/**
|
||||
* {@link Comparator} implementation that uses, in order, the...
|
||||
* <ul>
|
||||
@@ -32,9 +29,6 @@ import org.springframework.data.cassandra.core.cql.PrimaryKeyType;
|
||||
* @author Matthew T. Adams
|
||||
* @author John Blum
|
||||
* @author Mark Paluch
|
||||
* @see PrimaryKeyType#compare(PrimaryKeyType, PrimaryKeyType)
|
||||
* @see Ordering#compare(Ordering, Ordering)
|
||||
* @see java.util.Comparator
|
||||
* @see org.springframework.data.cassandra.core.mapping.PrimaryKeyColumn
|
||||
*/
|
||||
public enum CassandraPrimaryKeyColumnAnnotationComparator implements Comparator<PrimaryKeyColumn> {
|
||||
@@ -42,13 +36,7 @@ public enum CassandraPrimaryKeyColumnAnnotationComparator implements Comparator<
|
||||
/**
|
||||
* Comparator instance.
|
||||
*/
|
||||
INSTANCE,
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, use {@link #INSTANCE}
|
||||
*/
|
||||
@Deprecated
|
||||
IT;
|
||||
INSTANCE;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
|
||||
@@ -58,7 +46,7 @@ public enum CassandraPrimaryKeyColumnAnnotationComparator implements Comparator<
|
||||
|
||||
int comparison = left.type().compareTo(right.type());
|
||||
|
||||
comparison = (comparison != 0 ? comparison : Integer.valueOf(left.ordinal()).compareTo(right.ordinal()));
|
||||
comparison = (comparison != 0 ? comparison : Integer.compare(left.ordinal(), right.ordinal()));
|
||||
comparison = (comparison != 0 ? comparison : left.name().compareTo(right.name()));
|
||||
comparison = (comparison != 0 ? comparison : left.ordering().compareTo(right.ordering()));
|
||||
|
||||
|
||||
@@ -44,9 +44,13 @@ import com.google.common.reflect.TypeToken;
|
||||
*/
|
||||
public class CassandraSimpleTypeHolder extends SimpleTypeHolder {
|
||||
|
||||
/**
|
||||
* Set of Cassandra simple types.
|
||||
*/
|
||||
public static final Set<Class<?>> CASSANDRA_SIMPLE_TYPES;
|
||||
|
||||
private static final Map<Class<?>, DataType> classToDataType;
|
||||
|
||||
private static final Map<DataType.Name, DataType> nameToDataType;
|
||||
|
||||
static {
|
||||
@@ -146,17 +150,18 @@ public class CassandraSimpleTypeHolder extends SimpleTypeHolder {
|
||||
* Returns the {@link DataType} for a {@link DataType.Name}.
|
||||
*
|
||||
* @param name must not be {@literal null}.
|
||||
* @return
|
||||
* @return the {@link DataType} for {@link DataType.Name}.
|
||||
*/
|
||||
public static DataType getDataTypeFor(DataType.Name name) {
|
||||
return nameToDataType.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default {@link DataType} for a {@link Class}.
|
||||
* Returns the default {@link DataType} for a {@link Class}. This method resolves only simple types to a Cassandra
|
||||
* {@link DataType}. Other types are resolved to {@literal null}.
|
||||
*
|
||||
* @param javaClass must not be {@literal null}.
|
||||
* @return
|
||||
* @return the {@link DataType} for {@code javaClass} if resolvable, otherwise {@literal null}.
|
||||
*/
|
||||
@Nullable
|
||||
public static DataType getDataTypeFor(Class<?> javaClass) {
|
||||
|
||||
@@ -15,9 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Mapping between a persistent entity's property and its column.
|
||||
@@ -25,6 +26,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Matthew T. Adams
|
||||
* @author John Blum
|
||||
*/
|
||||
@EqualsAndHashCode
|
||||
public class PropertyMapping {
|
||||
|
||||
private @Nullable String columnName;
|
||||
@@ -77,39 +79,6 @@ public class PropertyMapping {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof PropertyMapping)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
PropertyMapping that = (PropertyMapping) obj;
|
||||
|
||||
return ObjectUtils.nullSafeEquals(this.getPropertyName(), that.getPropertyName())
|
||||
&& ObjectUtils.nullSafeEquals(this.getColumnName(), that.getColumnName())
|
||||
&& ObjectUtils.nullSafeEquals(this.getForceQuote(), that.getForceQuote());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int hashValue = 17;
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(this.getPropertyName());
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(this.getColumnName());
|
||||
hashValue = 37 * hashValue + ObjectUtils.nullSafeHashCode(this.getForceQuote());
|
||||
return hashValue;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
|
||||
@@ -33,6 +33,7 @@ import com.datastax.driver.core.UserType;
|
||||
public class SimpleUserTypeResolver implements UserTypeResolver {
|
||||
|
||||
private final String keyspaceName;
|
||||
|
||||
private final Cluster cluster;
|
||||
|
||||
/**
|
||||
|
||||
@@ -85,10 +85,10 @@ class UserTypeUtil {
|
||||
private static CqlIdentifier getTypeName(DataType dataType) {
|
||||
|
||||
if (dataType instanceof UserType) {
|
||||
return CqlIdentifier.cqlId(((UserType) dataType).getTypeName());
|
||||
return CqlIdentifier.of(((UserType) dataType).getTypeName());
|
||||
}
|
||||
|
||||
return cqlId(dataType.asFunctionParameterString());
|
||||
return of(dataType.asFunctionParameterString());
|
||||
}
|
||||
|
||||
private static boolean isNonFrozenUdt(DataType dataType) {
|
||||
|
||||
@@ -355,7 +355,7 @@ public class Columns implements Iterable<ColumnName> {
|
||||
* @return the aliased {@link ColumnSelector}.
|
||||
*/
|
||||
public ColumnSelector as(String alias) {
|
||||
return as(CqlIdentifier.cqlId(alias));
|
||||
return as(CqlIdentifier.of(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -421,7 +421,7 @@ public class Columns implements Iterable<ColumnName> {
|
||||
* @return the aliased {@link ColumnSelector}.
|
||||
*/
|
||||
public FunctionCall as(String alias) {
|
||||
return as(CqlIdentifier.cqlId(alias));
|
||||
return as(CqlIdentifier.of(alias));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,21 +17,12 @@ package org.springframework.data.cassandra.repository.query;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraConverter;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.CollectionExecution;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.ResultProcessingConverter;
|
||||
import org.springframework.data.cassandra.repository.query.CassandraQueryExecution.ResultProcessingExecution;
|
||||
@@ -48,8 +39,6 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Statement;
|
||||
|
||||
/**
|
||||
@@ -85,27 +74,8 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
|
||||
this.instantiators = new EntityInstantiators();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
|
||||
* conversion.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setConversionService(ConversionService conversionService) {
|
||||
throw new UnsupportedOperationException("setConversionService(ConversionService) is not supported anymore. "
|
||||
+ "Please use CassandraMappingContext instead");
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
|
||||
* conversion.
|
||||
*/
|
||||
@Deprecated
|
||||
public ConversionService getConversionService() {
|
||||
return getOperations().getConverter().getConversionService();
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
protected EntityInstantiators getEntityInstantiators() {
|
||||
private EntityInstantiators getEntityInstantiators() {
|
||||
return this.instantiators;
|
||||
}
|
||||
|
||||
@@ -169,84 +139,6 @@ public abstract class AbstractCassandraQuery implements RepositoryQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a string query using the given {@link ParameterAccessor}.
|
||||
*
|
||||
* @param resultSet
|
||||
* @param declaredReturnType
|
||||
* @param returnedUnwrappedObjectType
|
||||
* @return
|
||||
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
|
||||
* conversion.
|
||||
*/
|
||||
@Deprecated
|
||||
public Object getCollectionOfEntity(ResultSet resultSet, Class<?> declaredReturnType,
|
||||
Class<?> returnedUnwrappedObjectType) {
|
||||
|
||||
Collection<Object> results;
|
||||
|
||||
if (ClassUtils.isAssignable(SortedSet.class, declaredReturnType)) {
|
||||
results = new TreeSet<>();
|
||||
} else if (ClassUtils.isAssignable(Set.class, declaredReturnType)) {
|
||||
results = new HashSet<>();
|
||||
} else { // List.class, Collection.class, or array
|
||||
results = new ArrayList<>();
|
||||
}
|
||||
|
||||
CassandraConverter converter = getOperations().getConverter();
|
||||
|
||||
for (Row row : resultSet) {
|
||||
results.add(converter.read(returnedUnwrappedObjectType, row));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resultSet
|
||||
* @param type
|
||||
* @return
|
||||
* @deprecated as of 1.5, {@link org.springframework.data.cassandra.core.mapping.CassandraMappingContext} handles type
|
||||
* conversion.
|
||||
*/
|
||||
@Deprecated
|
||||
public Object getSingleEntity(ResultSet resultSet, Class<?> type) {
|
||||
|
||||
Object result = (resultSet.isExhausted() ? null : getOperations().getConverter().read(type, resultSet.one()));
|
||||
|
||||
warnIfMoreResults(resultSet);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void warnIfMoreResults(ResultSet resultSet) {
|
||||
|
||||
if (log.isWarnEnabled() && !resultSet.isExhausted()) {
|
||||
int count = 0;
|
||||
|
||||
while (resultSet.one() != null) {
|
||||
count++;
|
||||
}
|
||||
|
||||
log.warn("ignoring extra {} row{}", count, count == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
protected void warnIfMoreResults(Iterator<Row> iterator) {
|
||||
|
||||
if (log.isWarnEnabled() && iterator.hasNext()) {
|
||||
int count = 0;
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
count++;
|
||||
iterator.next();
|
||||
}
|
||||
|
||||
log.warn("ignoring extra {} row{}", count, count == 1 ? "" : "s");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Statement} using the given {@link ParameterAccessor}
|
||||
*
|
||||
|
||||
@@ -64,24 +64,24 @@ public class CassandraAdminTemplateIntegrationTests extends AbstractKeyspaceCrea
|
||||
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
|
||||
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.of("users"), User.class, null);
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
|
||||
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.of("users"), User.class, null);
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDropTable() {
|
||||
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.of("users"), User.class, null);
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(1);
|
||||
|
||||
cassandraAdminTemplate.dropTable(User.class);
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
|
||||
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.cqlId("users"), User.class, null);
|
||||
cassandraAdminTemplate.dropTable(CqlIdentifier.cqlId("users"));
|
||||
cassandraAdminTemplate.createTable(true, CqlIdentifier.of("users"), User.class, null);
|
||||
cassandraAdminTemplate.dropTable(CqlIdentifier.of("users"));
|
||||
|
||||
assertThat(getKeyspaceMetadata().getTables()).hasSize(0);
|
||||
}
|
||||
|
||||
@@ -84,9 +84,9 @@ public class CassandraPersistentEntitySchemaDropperUnitTests {
|
||||
|
||||
schemaDropper.dropUserTypes(true);
|
||||
|
||||
verify(operations).dropUserType(CqlIdentifier.cqlId("universetype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.cqlId("moontype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.cqlId("planettype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.of("universetype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.of("moontype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.of("planettype"));
|
||||
verify(operations).getKeyspaceMetadata();
|
||||
verifyNoMoreInteractions(operations);
|
||||
}
|
||||
@@ -104,8 +104,8 @@ public class CassandraPersistentEntitySchemaDropperUnitTests {
|
||||
|
||||
schemaDropper.dropUserTypes(false);
|
||||
|
||||
verify(operations).dropUserType(CqlIdentifier.cqlId("universetype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.cqlId("moontype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.of("universetype"));
|
||||
verify(operations).dropUserType(CqlIdentifier.of("moontype"));
|
||||
verify(operations).getKeyspaceMetadata();
|
||||
verifyNoMoreInteractions(operations);
|
||||
}
|
||||
@@ -123,8 +123,8 @@ public class CassandraPersistentEntitySchemaDropperUnitTests {
|
||||
|
||||
schemaDropper.dropTables(true);
|
||||
|
||||
verify(operations).dropTable(CqlIdentifier.cqlId("person"));
|
||||
verify(operations).dropTable(CqlIdentifier.cqlId("contact"));
|
||||
verify(operations).dropTable(CqlIdentifier.of("person"));
|
||||
verify(operations).dropTable(CqlIdentifier.of("contact"));
|
||||
verify(operations).getKeyspaceMetadata();
|
||||
verifyNoMoreInteractions(operations);
|
||||
}
|
||||
@@ -142,7 +142,7 @@ public class CassandraPersistentEntitySchemaDropperUnitTests {
|
||||
|
||||
schemaDropper.dropTables(false);
|
||||
|
||||
verify(operations).dropTable(CqlIdentifier.cqlId("person"));
|
||||
verify(operations).dropTable(CqlIdentifier.of("person"));
|
||||
verify(operations).getKeyspaceMetadata();
|
||||
verifyNoMoreInteractions(operations);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ColumnReaderUnitTests {
|
||||
when(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
underTest.get(CqlIdentifier.cqlId(NON_EXISTENT_COLUMN));
|
||||
underTest.get(CqlIdentifier.of(NON_EXISTENT_COLUMN));
|
||||
fail("Expected illegal argument exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage()).isEqualTo("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN);
|
||||
@@ -84,7 +84,7 @@ public class ColumnReaderUnitTests {
|
||||
when(columnDefinitions.getIndexOf(NON_EXISTENT_COLUMN)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
underTest.get(CqlIdentifier.cqlId(NON_EXISTENT_COLUMN), String.class);
|
||||
underTest.get(CqlIdentifier.of(NON_EXISTENT_COLUMN), String.class);
|
||||
fail("Expected illegal argument exception");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertThat(e.getMessage()).isEqualTo("Column does not exist in Cassandra table: " + NON_EXISTENT_COLUMN);
|
||||
|
||||
@@ -492,7 +492,7 @@ public class MappingCassandraConverterUDTIntegrationTests extends AbstractSpring
|
||||
|
||||
@Override
|
||||
public UDTValue convert(Currency source) {
|
||||
UserType userType = userTypeResolver.resolveType(CqlIdentifier.cqlId("currency"));
|
||||
UserType userType = userTypeResolver.resolveType(CqlIdentifier.of("currency"));
|
||||
UDTValue udtValue = userType.newValue();
|
||||
udtValue.setString("currency", source.getCurrencyCode());
|
||||
return udtValue;
|
||||
|
||||
@@ -221,7 +221,7 @@ public class QueryMapperUnitTests {
|
||||
|
||||
CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
|
||||
|
||||
assertThat(mappedCriteriaDefinition.getColumnName()).isEqualTo(ColumnName.from(CqlIdentifier.cqlId("first_name")));
|
||||
assertThat(mappedCriteriaDefinition.getColumnName()).isEqualTo(ColumnName.from(CqlIdentifier.of("first_name")));
|
||||
assertThat(mappedCriteriaDefinition.getColumnName().toString()).isEqualTo("first_name");
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class CqlIdentifierUnitTests {
|
||||
String[] ids = new String[] { "foo", "Foo", "FOO", "a_", "a1" };
|
||||
|
||||
for (String id : ids) {
|
||||
CqlIdentifier cqlId = cqlId(id);
|
||||
CqlIdentifier cqlId = of(id);
|
||||
assertThat(cqlId.isQuoted()).isFalse();
|
||||
assertThat(cqlId.toCql()).isEqualTo(id.toLowerCase());
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class CqlIdentifierUnitTests {
|
||||
String[] ids = new String[] { "foo", "Foo", "FOO", "a_", "a1" };
|
||||
|
||||
for (String id : ids) {
|
||||
CqlIdentifier cqlId = quotedCqlId(id);
|
||||
CqlIdentifier cqlId = quoted(id);
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id + "\"");
|
||||
}
|
||||
@@ -56,11 +56,11 @@ public class CqlIdentifierUnitTests {
|
||||
public void testReservedWordsEndUpQuoted() {
|
||||
|
||||
for (ReservedKeyword id : ReservedKeyword.values()) {
|
||||
CqlIdentifier cqlId = cqlId(id.name());
|
||||
CqlIdentifier cqlId = of(id.name());
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id.name() + "\"");
|
||||
|
||||
cqlId = cqlId(id.name().toLowerCase());
|
||||
cqlId = of(id.name().toLowerCase());
|
||||
assertThat(cqlId.isQuoted()).isTrue();
|
||||
assertThat(cqlId.toCql()).isEqualTo("\"" + id.name().toLowerCase() + "\"");
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class CqlIdentifierUnitTests {
|
||||
String[] illegals = new String[] { null, "", "a ", "a a", "a\"", "a'", "a''", "\"\"", "''", "-", "a-", "_", "_a" };
|
||||
for (String illegal : illegals) {
|
||||
try {
|
||||
cqlId(illegal);
|
||||
of(illegal);
|
||||
fail(String.format("identifier [%s] should have caused IllegalArgumentException", illegal));
|
||||
} catch (IllegalArgumentException x) {
|
||||
// :)
|
||||
|
||||
@@ -22,8 +22,8 @@ import java.util.Map;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.cassandra.core.cql.CqlStringUtils;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.ColumnSpecification;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.CqlStringUtils;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.DropTableSpecification;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.TableDescriptor;
|
||||
import org.springframework.data.cassandra.core.cql.keyspace.TableOption;
|
||||
|
||||
@@ -120,9 +120,9 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
|
||||
public static class BasicTest extends CreateTableTest {
|
||||
|
||||
public CqlIdentifier name = cqlId("mytable");
|
||||
public CqlIdentifier name = of("mytable");
|
||||
public DataType partitionKeyType0 = DataType.text();
|
||||
public CqlIdentifier partitionKey0 = cqlId("partitionKey0");
|
||||
public CqlIdentifier partitionKey0 = of("partitionKey0");
|
||||
public DataType columnType1 = DataType.text();
|
||||
public String column1 = "column1";
|
||||
|
||||
@@ -144,12 +144,12 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
|
||||
public static class CompositePartitionKeyTest extends CreateTableTest {
|
||||
|
||||
public CqlIdentifier name = cqlId("composite_partition_key_table");
|
||||
public CqlIdentifier name = of("composite_partition_key_table");
|
||||
public DataType partKeyType0 = DataType.text();
|
||||
public CqlIdentifier partKey0 = cqlId("partKey0");
|
||||
public CqlIdentifier partKey0 = of("partKey0");
|
||||
public DataType partKeyType1 = DataType.text();
|
||||
public CqlIdentifier partKey1 = cqlId("partKey1");
|
||||
public CqlIdentifier column0 = cqlId("column0");
|
||||
public CqlIdentifier partKey1 = of("partKey1");
|
||||
public CqlIdentifier column0 = of("column0");
|
||||
public DataType columnType0 = DataType.text();
|
||||
|
||||
@Override
|
||||
@@ -177,13 +177,13 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public static class ReadRepairChanceTest extends CreateTableTest {
|
||||
|
||||
public CqlIdentifier name = cqlId("mytable");
|
||||
public CqlIdentifier name = of("mytable");
|
||||
public DataType partitionKeyType0 = DataType.text();
|
||||
public CqlIdentifier partitionKey0 = cqlId("partitionKey0");
|
||||
public CqlIdentifier partitionKey0 = of("partitionKey0");
|
||||
public DataType partitionKeyType1 = DataType.timestamp();
|
||||
public CqlIdentifier partitionKey1 = cqlId("create_timestamp");
|
||||
public CqlIdentifier partitionKey1 = of("create_timestamp");
|
||||
public DataType columnType1 = DataType.text();
|
||||
public CqlIdentifier column1 = cqlId("column1");
|
||||
public CqlIdentifier column1 = of("column1");
|
||||
public Double readRepairChance = 0.5;
|
||||
|
||||
@Override
|
||||
@@ -212,13 +212,13 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public static class MultipleOptionsTest extends CreateTableTest {
|
||||
|
||||
public CqlIdentifier name = cqlId("timeseries_table");
|
||||
public CqlIdentifier name = of("timeseries_table");
|
||||
public DataType partitionKeyType0 = DataType.timeuuid();
|
||||
public CqlIdentifier partitionKey0 = cqlId("tid");
|
||||
public CqlIdentifier partitionKey0 = of("tid");
|
||||
public DataType partitionKeyType1 = DataType.timestamp();
|
||||
public CqlIdentifier partitionKey1 = cqlId("create_timestamp");
|
||||
public CqlIdentifier partitionKey1 = of("create_timestamp");
|
||||
public DataType columnType1 = DataType.text();
|
||||
public CqlIdentifier column1 = cqlId("data_point");
|
||||
public CqlIdentifier column1 = of("data_point");
|
||||
public Double readRepairChance = 0.5;
|
||||
public Double dcLocalReadRepairChance = 0.7;
|
||||
public Double bloomFilterFpChance = 0.001;
|
||||
@@ -306,7 +306,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
|
||||
@Override
|
||||
public CreateTableSpecification specification() {
|
||||
return CreateTableSpecification.createTable(tableName).partitionKeyColumn(cqlId("pk"), DataType.text());
|
||||
return CreateTableSpecification.createTable(tableName).partitionKeyColumn(of("pk"), DataType.text());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -315,7 +315,7 @@ public class CreateTableCqlGeneratorUnitTests {
|
||||
*/
|
||||
public void test() {
|
||||
prepare();
|
||||
assertPreamble(cqlId(tableName), cql);
|
||||
assertPreamble(of(tableName), cql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class BasicCassandraPersistentEntityUnitTests {
|
||||
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(entitySpy);
|
||||
|
||||
entitySpy.setTableName(CqlIdentifier.cqlId("Messages", false));
|
||||
entitySpy.setTableName(CqlIdentifier.of("Messages", false));
|
||||
|
||||
assertThat((Optional) dfa.getPropertyValue("forceQuote")).isNotPresent();
|
||||
|
||||
@@ -129,7 +129,7 @@ public class BasicCassandraPersistentEntityUnitTests {
|
||||
BasicCassandraPersistentEntity<TableWithComposedAnnotation> entity = new BasicCassandraPersistentEntity<>(
|
||||
ClassTypeInformation.from(TableWithComposedAnnotation.class));
|
||||
|
||||
assertThat(entity.getTableName()).isEqualTo(CqlIdentifier.cqlId("mytable", true));
|
||||
assertThat(entity.getTableName()).isEqualTo(CqlIdentifier.of("mytable", true));
|
||||
}
|
||||
|
||||
@Test // DATACASS-259
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -24,7 +24,6 @@ import java.util.Date;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
import org.springframework.data.mapping.model.Property;
|
||||
@@ -64,7 +63,7 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
|
||||
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedColumnAnnotation.class, "column");
|
||||
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("mycolumn", true));
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.of("mycolumn", true));
|
||||
}
|
||||
|
||||
@Test // DATACASS-259
|
||||
@@ -73,7 +72,7 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedPrimaryKeyAnnotation.class,
|
||||
"column");
|
||||
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("primary-key", true));
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.of("primary-key", true));
|
||||
assertThat(persistentProperty.isIdProperty()).isTrue();
|
||||
}
|
||||
|
||||
@@ -83,7 +82,7 @@ public class BasicCassandraPersistentPropertyUnitTests {
|
||||
CassandraPersistentProperty persistentProperty = getPropertyFor(TypeWithComposedPrimaryKeyColumnAnnotation.class,
|
||||
"column");
|
||||
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.cqlId("mycolumn", true));
|
||||
assertThat(persistentProperty.getColumnName()).isEqualTo(CqlIdentifier.of("mycolumn", true));
|
||||
assertThat(persistentProperty.isPrimaryKeyColumn()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ public class CassandraMappingContextUnitTests {
|
||||
assertThat(mappingContext.getUserDefinedTypeEntities()).isEmpty();
|
||||
assertThat(mappingContext.getTableEntities()).hasSize(1);
|
||||
assertThat(mappingContext.getPersistentEntities()).hasSize(1);
|
||||
assertThat(mappingContext.usesTable(CqlIdentifier.cqlId(tableMetadata.getName()))).isTrue();
|
||||
assertThat(mappingContext.usesTable(CqlIdentifier.of(tableMetadata.getName()))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACASS-248
|
||||
@@ -309,15 +309,15 @@ public class CassandraMappingContextUnitTests {
|
||||
|
||||
CreateIndexSpecification firstname = getSpecificationFor("first_name", specifications);
|
||||
|
||||
assertThat(firstname.getColumnName()).isEqualTo(CqlIdentifier.cqlId("first_name"));
|
||||
assertThat(firstname.getTableName()).isEqualTo(CqlIdentifier.cqlId("indexedtype"));
|
||||
assertThat(firstname.getName()).isEqualTo(CqlIdentifier.cqlId("my_index"));
|
||||
assertThat(firstname.getColumnName()).isEqualTo(CqlIdentifier.of("first_name"));
|
||||
assertThat(firstname.getTableName()).isEqualTo(CqlIdentifier.of("indexedtype"));
|
||||
assertThat(firstname.getName()).isEqualTo(CqlIdentifier.of("my_index"));
|
||||
assertThat(firstname.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
|
||||
CreateIndexSpecification phoneNumbers = getSpecificationFor("phoneNumbers", specifications);
|
||||
|
||||
assertThat(phoneNumbers.getColumnName()).isEqualTo(CqlIdentifier.cqlId("phoneNumbers"));
|
||||
assertThat(phoneNumbers.getTableName()).isEqualTo(CqlIdentifier.cqlId("indexedtype"));
|
||||
assertThat(phoneNumbers.getColumnName()).isEqualTo(CqlIdentifier.of("phoneNumbers"));
|
||||
assertThat(phoneNumbers.getTableName()).isEqualTo(CqlIdentifier.of("indexedtype"));
|
||||
assertThat(phoneNumbers.getName()).isNull();
|
||||
assertThat(phoneNumbers.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
}
|
||||
@@ -330,16 +330,16 @@ public class CassandraMappingContextUnitTests {
|
||||
|
||||
CreateIndexSpecification entries = getSpecificationFor("last_name", specifications);
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("last_name"));
|
||||
assertThat(entries.getTableName()).isEqualTo(CqlIdentifier.cqlId("compositekeyentity"));
|
||||
assertThat(entries.getName()).isEqualTo(CqlIdentifier.cqlId("my_index"));
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.of("last_name"));
|
||||
assertThat(entries.getTableName()).isEqualTo(CqlIdentifier.of("compositekeyentity"));
|
||||
assertThat(entries.getName()).isEqualTo(CqlIdentifier.of("my_index"));
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
}
|
||||
|
||||
private static CreateIndexSpecification getSpecificationFor(String column,
|
||||
List<CreateIndexSpecification> specifications) {
|
||||
|
||||
return specifications.stream().filter(it -> it.getColumnName().equals(CqlIdentifier.cqlId(column))).findFirst()
|
||||
return specifications.stream().filter(it -> it.getColumnName().equals(CqlIdentifier.of(column))).findFirst()
|
||||
.orElseThrow(() -> new NoSuchElementException(column));
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ public class CassandraMappingContextUnitTests {
|
||||
|
||||
@Test // DATACASS-172, DATACASS-455
|
||||
public void usesTypeShouldNotReportTypeUsage() {
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.cqlId("mappedudt"))).isFalse();
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.of("mappedudt"))).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACASS-172, DATACASS-455
|
||||
@@ -458,7 +458,7 @@ public class CassandraMappingContextUnitTests {
|
||||
|
||||
mappingContext.getRequiredPersistentEntity(WithUdt.class);
|
||||
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.cqlId("mappedudt"))).isTrue();
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.of("mappedudt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACASS-172, DATACASS-455
|
||||
@@ -470,7 +470,7 @@ public class CassandraMappingContextUnitTests {
|
||||
|
||||
mappingContext.getRequiredPersistentEntity(MappedUdt.class);
|
||||
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.cqlId("mappedudt"))).isTrue();
|
||||
assertThat(mappingContext.usesUserType(CqlIdentifier.of("mappedudt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACASS-172
|
||||
@@ -518,7 +518,7 @@ public class CassandraMappingContextUnitTests {
|
||||
assertThat(mappingContext.getUserDefinedTypeEntities()).isEmpty();
|
||||
assertThat(mappingContext.getTableEntities()).isEmpty();
|
||||
assertThat(mappingContext.getPersistentEntities()).isEmpty();
|
||||
assertThat(mappingContext.usesTable(CqlIdentifier.cqlId(tableMetadata.getName()))).isFalse();
|
||||
assertThat(mappingContext.usesTable(CqlIdentifier.of(tableMetadata.getName()))).isFalse();
|
||||
}
|
||||
|
||||
@Table
|
||||
|
||||
@@ -160,8 +160,8 @@ public class CassandraPersistentPropertyComparatorUnitTests {
|
||||
when(left.isPrimaryKeyColumn()).thenReturn(true);
|
||||
when(right.isCompositePrimaryKey()).thenReturn(true);
|
||||
when(right.isPrimaryKeyColumn()).thenReturn(false);
|
||||
when(left.getColumnName()).thenReturn(CqlIdentifier.cqlId("left"));
|
||||
when(right.getColumnName()).thenReturn(CqlIdentifier.cqlId("right"));
|
||||
when(left.getColumnName()).thenReturn(CqlIdentifier.of("left"));
|
||||
when(right.getColumnName()).thenReturn(CqlIdentifier.of("right"));
|
||||
|
||||
assertThat(INSTANCE.compare(left, right)).isLessThan(0);
|
||||
|
||||
|
||||
@@ -53,8 +53,8 @@ public class CassandraUserTypePersistentEntityUnitTests {
|
||||
|
||||
CassandraUserTypePersistentEntity<MappedUdt> type = getEntity(MappedUdt.class);
|
||||
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("mappedudt"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("Mappedudt"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("mappedudt"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("Mappedudt"));
|
||||
}
|
||||
|
||||
@Test // DATACASS-172
|
||||
@@ -62,8 +62,8 @@ public class CassandraUserTypePersistentEntityUnitTests {
|
||||
|
||||
CassandraUserTypePersistentEntity<WithName> type = getEntity(WithName.class);
|
||||
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("withname"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("Withname"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("withname"));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("Withname"));
|
||||
}
|
||||
|
||||
@Test // DATACASS-172
|
||||
@@ -71,8 +71,8 @@ public class CassandraUserTypePersistentEntityUnitTests {
|
||||
|
||||
CassandraUserTypePersistentEntity<WithForceQuote> type = getEntity(WithForceQuote.class);
|
||||
|
||||
assertThat(type.getTableName()).isNotEqualTo(CqlIdentifier.cqlId("upperCase", true));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("UpperCase", true));
|
||||
assertThat(type.getTableName()).isNotEqualTo(CqlIdentifier.of("upperCase", true));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("UpperCase", true));
|
||||
}
|
||||
|
||||
@Test // DATACASS-259
|
||||
@@ -80,7 +80,7 @@ public class CassandraUserTypePersistentEntityUnitTests {
|
||||
|
||||
CassandraUserTypePersistentEntity<TypeWithComposedAnnotation> type = getEntity(TypeWithComposedAnnotation.class);
|
||||
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.cqlId("mytype", true));
|
||||
assertThat(type.getTableName()).isEqualTo(CqlIdentifier.of("mytype", true));
|
||||
}
|
||||
|
||||
private <T> CassandraUserTypePersistentEntity<T> getEntity(Class<T> entityClass) {
|
||||
|
||||
@@ -312,7 +312,7 @@ public class CreateTableSpecificationBasicCassandraMappingContextUnitTests {
|
||||
private ColumnSpecification getColumn(String columnName, CreateTableSpecification specification) {
|
||||
|
||||
for (ColumnSpecification columnSpecification : specification.getColumns()) {
|
||||
if (columnSpecification.getName().equals(CqlIdentifier.cqlId(columnName))) {
|
||||
if (columnSpecification.getName().equals(CqlIdentifier.of(columnName))) {
|
||||
return columnSpecification;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,9 +108,9 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringOne = key.getRequiredPersistentProperty("stringOne");
|
||||
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"stringZero\"");
|
||||
assertThat(stringZero.getColumnName()).isEqualTo(quotedCqlId("stringZero"));
|
||||
assertThat(stringZero.getColumnName()).isEqualTo(quoted("stringZero"));
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"stringOne\"");
|
||||
assertThat(stringOne.getColumnName()).isEqualTo(quotedCqlId("stringOne"));
|
||||
assertThat(stringOne.getColumnName()).isEqualTo(quoted("stringOne"));
|
||||
}
|
||||
|
||||
@PrimaryKeyClass
|
||||
@@ -139,8 +139,8 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringZero = key.getRequiredPersistentProperty("stringZero");
|
||||
CassandraPersistentProperty stringOne = key.getRequiredPersistentProperty("stringOne");
|
||||
|
||||
assertThat(stringZero.getColumnName()).isEqualTo(CqlIdentifier.cqlId("stringZero"));
|
||||
assertThat(stringOne.getColumnName()).isEqualTo(CqlIdentifier.cqlId("stringOne"));
|
||||
assertThat(stringZero.getColumnName()).isEqualTo(CqlIdentifier.of("stringZero"));
|
||||
assertThat(stringOne.getColumnName()).isEqualTo(CqlIdentifier.of("stringOne"));
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("stringzero");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("stringone");
|
||||
}
|
||||
@@ -172,8 +172,8 @@ public class ForceQuotedPropertiesSimpleUnitTests {
|
||||
CassandraPersistentProperty stringOne = key.getRequiredPersistentProperty("stringOne");
|
||||
|
||||
assertThat(stringZero.getColumnName()) //
|
||||
.isEqualTo(CqlIdentifier.cqlId("TheFirstKeyField", true)) //
|
||||
.isNotEqualTo(CqlIdentifier.cqlId("TheFirstKeyField"));
|
||||
.isEqualTo(CqlIdentifier.of("TheFirstKeyField", true)) //
|
||||
.isNotEqualTo(CqlIdentifier.of("TheFirstKeyField"));
|
||||
|
||||
assertThat(stringZero.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_0 + "\"");
|
||||
assertThat(stringOne.getColumnName().toCql()).isEqualTo("\"" + EXPLICIT_KEY_1 + "\"");
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.data.cassandra.core.mapping;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.data.annotation.AccessType;
|
||||
import org.springframework.data.annotation.AccessType.Type;
|
||||
import org.springframework.data.cassandra.core.cql.CqlIdentifier;
|
||||
@@ -45,14 +44,14 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification firstname = createIndexFor(IndexedType.class, "firstname");
|
||||
|
||||
assertThat(firstname.getColumnName()).isEqualTo(CqlIdentifier.cqlId("first_name"));
|
||||
assertThat(firstname.getColumnName()).isEqualTo(CqlIdentifier.of("first_name"));
|
||||
assertThat(firstname.getTableName()).isNull();
|
||||
assertThat(firstname.getName()).isEqualTo(CqlIdentifier.cqlId("my_index"));
|
||||
assertThat(firstname.getName()).isEqualTo(CqlIdentifier.of("my_index"));
|
||||
assertThat(firstname.getColumnFunction()).isEqualTo(ColumnFunction.NONE);
|
||||
|
||||
CreateIndexSpecification entries = createIndexFor(IndexedType.class, "entries");
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("entries"));
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.of("entries"));
|
||||
assertThat(entries.getTableName()).isNull();
|
||||
assertThat(entries.getName()).isNull();
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.ENTRIES);
|
||||
@@ -63,7 +62,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification entries = createIndexFor(IndexedMapKeyProperty.class, "entries");
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("entries"));
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.of("entries"));
|
||||
assertThat(entries.getTableName()).isNull();
|
||||
assertThat(entries.getName()).isNull();
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.KEYS);
|
||||
@@ -74,7 +73,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification entries = createIndexFor(MapValueIndexProperty.class, "entries");
|
||||
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.cqlId("entries"));
|
||||
assertThat(entries.getColumnName()).isEqualTo(CqlIdentifier.of("entries"));
|
||||
assertThat(entries.getTableName()).isNull();
|
||||
assertThat(entries.getName()).isNull();
|
||||
assertThat(entries.getColumnFunction()).isEqualTo(ColumnFunction.VALUES);
|
||||
@@ -85,7 +84,7 @@ public class IndexSpecificationFactoryUnitTests {
|
||||
|
||||
CreateIndexSpecification simpleSasi = createIndexFor(IndexedType.class, "simpleSasi");
|
||||
|
||||
assertThat(simpleSasi.getColumnName()).isEqualTo(CqlIdentifier.cqlId("simplesasi"));
|
||||
assertThat(simpleSasi.getColumnName()).isEqualTo(CqlIdentifier.of("simplesasi"));
|
||||
assertThat(simpleSasi.getTableName()).isNull();
|
||||
assertThat(simpleSasi.isCustom()).isTrue();
|
||||
assertThat(simpleSasi.getUsing()).isEqualTo("org.apache.cassandra.index.sasi.SASIIndex");
|
||||
|
||||
@@ -46,10 +46,10 @@ public class ColumnNameUnitTests {
|
||||
@Test // DATACASS-343
|
||||
public void cqlBasedShouldEqual() {
|
||||
|
||||
ColumnName first = ColumnName.from(CqlIdentifier.cqlId("foo"));
|
||||
ColumnName second = ColumnName.from(CqlIdentifier.cqlId("Foo"));
|
||||
ColumnName first = ColumnName.from(CqlIdentifier.of("foo"));
|
||||
ColumnName second = ColumnName.from(CqlIdentifier.of("Foo"));
|
||||
|
||||
ColumnName different = ColumnName.from(CqlIdentifier.cqlId("Foo", true));
|
||||
ColumnName different = ColumnName.from(CqlIdentifier.of("Foo", true));
|
||||
|
||||
assertThat(first).isEqualTo(second);
|
||||
assertThat(first.equals(second)).isTrue();
|
||||
@@ -64,8 +64,8 @@ public class ColumnNameUnitTests {
|
||||
public void stringAndCqlComparisonShouldEqual() {
|
||||
|
||||
ColumnName first = ColumnName.from("foo");
|
||||
ColumnName second = ColumnName.from(CqlIdentifier.cqlId("foo"));
|
||||
ColumnName different = ColumnName.from(CqlIdentifier.cqlId("one", true));
|
||||
ColumnName second = ColumnName.from(CqlIdentifier.of("foo"));
|
||||
ColumnName different = ColumnName.from(CqlIdentifier.of("one", true));
|
||||
|
||||
assertThat(first).isEqualTo(second);
|
||||
assertThat(first.equals(second)).isTrue();
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ColumnsUnitTests {
|
||||
@Test // DATACASS-343
|
||||
public void shouldCreateFromCqlIdentifiers() {
|
||||
|
||||
Columns columns = Columns.from(CqlIdentifier.cqlId("Foo", true), CqlIdentifier.cqlId("bar"));
|
||||
Columns columns = Columns.from(CqlIdentifier.of("Foo", true), CqlIdentifier.of("bar"));
|
||||
|
||||
assertThat(columns.toString()).contains("\"Foo\"").contains("bar");
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ abstract class ParameterConversionTestSupport extends AbstractSpringDataEmbedded
|
||||
|
||||
public UDTValue convert(Phone source) {
|
||||
|
||||
UserType userType = userTypeResolver.resolveType(CqlIdentifier.cqlId("phone"));
|
||||
UserType userType = userTypeResolver.resolveType(CqlIdentifier.of("phone"));
|
||||
UDTValue udtValue = userType.newValue();
|
||||
udtValue.setString("number", source.getNumber());
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ public class PartTreeCassandraQueryUnitTests {
|
||||
@Test // DATACASS-172
|
||||
public void shouldDeriveSimpleQueryWithMappedUDT() {
|
||||
|
||||
when(userTypeResolverMock.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(userTypeMock);
|
||||
when(userTypeResolverMock.resolveType(CqlIdentifier.of("address"))).thenReturn(userTypeMock);
|
||||
when(userTypeMock.newValue()).thenReturn(udtValueMock);
|
||||
|
||||
String query = deriveQueryFromMethod("findByMainAddress", new AddressType());
|
||||
|
||||
@@ -310,7 +310,7 @@ public class StringBasedCassandraQueryUnitTests {
|
||||
UserType addressType = UserTypeBuilder.forName("address").withField("city", DataType.varchar())
|
||||
.withField("country", DataType.varchar()).build();
|
||||
|
||||
when(userTypeResolver.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(addressType);
|
||||
when(userTypeResolver.resolveType(CqlIdentifier.of("address"))).thenReturn(addressType);
|
||||
|
||||
StringBasedCassandraQuery cassandraQuery = getQueryMethod("findByMainAddress", AddressType.class);
|
||||
CassandraParameterAccessor accessor = new ConvertingParameterAccessor(converter,
|
||||
|
||||
@@ -70,7 +70,7 @@ public class SimpleCassandraRepositoryUnitTests {
|
||||
|
||||
when(cassandraOperations.getConverter()).thenReturn(converter);
|
||||
when(cassandraOperations.getCqlOperations()).thenReturn(cqlOperations);
|
||||
when(userTypeResolver.resolveType(CqlIdentifier.cqlId("address"))).thenReturn(userType);
|
||||
when(userTypeResolver.resolveType(CqlIdentifier.of("address"))).thenReturn(userType);
|
||||
}
|
||||
|
||||
@Test // DATACASS-428
|
||||
|
||||
@@ -41,7 +41,7 @@ public class UserTypeBuilder {
|
||||
}
|
||||
|
||||
public static UserTypeBuilder forName(String typeName) {
|
||||
return forName(CqlIdentifier.cqlId(typeName));
|
||||
return forName(CqlIdentifier.of(typeName));
|
||||
}
|
||||
|
||||
public static UserTypeBuilder forName(CqlIdentifier typeName) {
|
||||
|
||||
Reference in New Issue
Block a user