DATACASS-721 - Apply additional code polish.

This commit is contained in:
John Blum
2020-01-31 17:15:05 -08:00
parent 461975cf1a
commit 5c7d16ef4c
3 changed files with 54 additions and 37 deletions

View File

@@ -85,8 +85,7 @@
<properties>
<build.cassandra.host>localhost</build.cassandra.host>
<build.cassandra.mode>embedded</build.cassandra.mode>
<build.cassandra.native_transport_port>19042
</build.cassandra.native_transport_port>
<build.cassandra.native_transport_port>19042</build.cassandra.native_transport_port>
<build.cassandra.rpc_port>19160</build.cassandra.rpc_port>
<build.cassandra.ssl_storage_port>17001</build.cassandra.ssl_storage_port>
<build.cassandra.storage_port>17000</build.cassandra.storage_port>

View File

@@ -121,7 +121,7 @@ public abstract class AbstractCassandraConfiguration extends AbstractSessionConf
SessionFactoryFactoryBean bean = new SessionFactoryFactoryBean();
// Initialize the CqlSession reference first since it is required, or must not be null.
// Initialize the CqlSession reference first since it is required, or must not be null!
bean.setSession(cqlSession);
bean.setConverter(requireBeanOfType(CassandraConverter.class));
@@ -153,6 +153,37 @@ public abstract class AbstractCassandraConfiguration extends AbstractSessionConf
return new CassandraCustomConversions(Collections.emptyList());
}
/**
* Configures the Java {@link ClassLoader} used to resolve Cassandra application entity {@link Class types}.
*
* @param classLoader Java {@link ClassLoader} used to resolve Cassandra application entity {@link Class types};
* may be {@literal null}.
* @see java.lang.ClassLoader
*/
@Override
public void setBeanClassLoader(@Nullable ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
/**
* Returns the configured Java {@link ClassLoader} used to resolve Cassandra application entity {@link Class types}.
*
* @return the Java {@link ClassLoader} used to resolve Cassandra application entity {@link Class types}.
* @see java.lang.ClassLoader
* @see java.util.Optional
*/
protected Optional<ClassLoader> getBeanClassLoader() {
return Optional.ofNullable(this.beanClassLoader);
}
/**
* Base packages to scan for entities annotated with {@link Table} annotations. By default, returns the package name
* of {@literal this} ({@code this.getClass().getPackage().getName()}. This method must never return {@literal null}.
*/
public String[] getEntityBasePackages() {
return new String[] { getClass().getPackage().getName() };
}
/**
* Return the {@link Set} of initial entity classes. Scans by default the class path using
* {@link #getEntityBasePackages()}. Can be overridden by subclasses to skip class path scanning and return a fixed
@@ -178,6 +209,15 @@ public abstract class AbstractCassandraConfiguration extends AbstractSessionConf
return requireBeanOfType(SessionFactory.class);
}
/**
* The {@link SchemaAction} to perform at application startup. Defaults to {@link SchemaAction#NONE}.
*
* @see org.springframework.data.cassandra.config.SchemaAction
*/
public SchemaAction getSchemaAction() {
return SchemaAction.NONE;
}
/**
* Creates a {@link KeyspacePopulator} to cleanup the keyspace.
*
@@ -200,30 +240,6 @@ public abstract class AbstractCassandraConfiguration extends AbstractSessionConf
return null;
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
protected Optional<ClassLoader> getBeanClassLoader() {
return Optional.ofNullable(this.beanClassLoader);
}
/**
* Base packages to scan for entities annotated with {@link Table} annotations. By default, returns the package name
* of {@literal this} ({@code this.getClass().getPackage().getName()}. This method must never return {@literal null}.
*/
public String[] getEntityBasePackages() {
return new String[] { getClass().getPackage().getName() };
}
/**
* The {@link SchemaAction} to perform at startup. Defaults to {@link SchemaAction#NONE}.
*/
public SchemaAction getSchemaAction() {
return SchemaAction.NONE;
}
/**
* Creates a new {@link ByteArrayResource} given {@code content}.
*

View File

@@ -225,10 +225,11 @@ public abstract class AbstractSessionConfiguration implements BeanFactoryAware {
}
/**
* Returns the list of startup scripts to be run after {@link #getKeyspaceCreations() keyspace creations} and after
* initialization in the {@code system} keyspace.
* Returns the list of CQL scripts to be run on startup after {@link #getKeyspaceCreations() Keyspace creations}
* and after initialization of the {@literal System} Keyspace.
*
* @return the list of startup scripts, may be {@link Collections#emptyList() empty} but never {@literal null}.
* @return the list of CQL scripts to be run on startup; may be {@link Collections#emptyList() empty}
* but never {@literal null}.
* @deprecated since 3.0; Declare a
* {@link org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer} bean instead.
*/
@@ -238,10 +239,11 @@ public abstract class AbstractSessionConfiguration implements BeanFactoryAware {
}
/**
* Returns the list of shutdown scripts to be run after {@link #getKeyspaceDrops() keyspace drops} and right before
* shutdown in the {@code system} keyspace.
* Returns the list of CQL scripts to be run on shutdown after {@link #getKeyspaceDrops() Keyspace drops}
* and right before shutdown of the {@code System} Keyspace.
*
* @return the list of shutdown scripts, may be {@link Collections#emptyList() empty} but never {@literal null}.
* @return the list of CQL scripts to be run on shutdown; may be {@link Collections#emptyList() empty}
* but never {@literal null}.
* @deprecated since 3.0; Declare a
* {@link org.springframework.data.cassandra.core.cql.session.init.SessionFactoryInitializer} bean instead.
*/
@@ -286,12 +288,12 @@ public abstract class AbstractSessionConfiguration implements BeanFactoryAware {
CassandraDriverOptions options = new CassandraDriverOptions();
if (StringUtils.hasText(getClusterName())) {
options.add(DefaultDriverOption.SESSION_NAME, getClusterName());
}
else if (StringUtils.hasText(getSessionName())) {
if (StringUtils.hasText(getSessionName())) {
options.add(DefaultDriverOption.SESSION_NAME, getSessionName());
}
else if (StringUtils.hasText(getClusterName())) {
options.add(DefaultDriverOption.SESSION_NAME, getClusterName());
}
CompressionType compressionType = getCompressionType();