Formatting
This commit is contained in:
parent
75f32eb542
commit
6e687a7e90
205 changed files with 10518 additions and 10704 deletions
|
@ -15,9 +15,10 @@
|
|||
*/
|
||||
package com.datastax.driver.core.querybuilder;
|
||||
|
||||
import com.datastax.driver.core.CodecRegistry;
|
||||
import java.util.List;
|
||||
|
||||
import com.datastax.driver.core.CodecRegistry;
|
||||
|
||||
public class IsNotNullClause extends Clause {
|
||||
|
||||
final String name;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.datastax.driver.core.schemabuilder;
|
||||
|
||||
import static com.datastax.driver.core.schemabuilder.SchemaStatement.STATEMENT_START;
|
||||
import static com.datastax.driver.core.schemabuilder.SchemaStatement.validateNotEmpty;
|
||||
import static com.datastax.driver.core.schemabuilder.SchemaStatement.validateNotKeyWord;
|
||||
import static com.datastax.driver.core.schemabuilder.SchemaStatement.*;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
|
@ -18,10 +16,8 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
CreateCustomIndex(String indexName) {
|
||||
super(indexName);
|
||||
validateNotEmpty(indexName, "Index name");
|
||||
validateNotKeyWord(
|
||||
indexName,
|
||||
String.format(
|
||||
"The index name '%s' is not allowed because it is a reserved keyword", indexName));
|
||||
validateNotKeyWord(indexName,
|
||||
String.format("The index name '%s' is not allowed because it is a reserved keyword", indexName));
|
||||
this.indexName = indexName;
|
||||
}
|
||||
|
||||
|
@ -38,22 +34,20 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
/**
|
||||
* Specify the keyspace and table to create the index on.
|
||||
*
|
||||
* @param keyspaceName the keyspace name.
|
||||
* @param tableName the table name.
|
||||
* @return a {@link CreateIndex.CreateIndexOn} that will allow the specification of the column.
|
||||
* @param keyspaceName
|
||||
* the keyspace name.
|
||||
* @param tableName
|
||||
* the table name.
|
||||
* @return a {@link CreateIndex.CreateIndexOn} that will allow the specification
|
||||
* of the column.
|
||||
*/
|
||||
public CreateIndex.CreateIndexOn onTable(String keyspaceName, String tableName) {
|
||||
validateNotEmpty(keyspaceName, "Keyspace name");
|
||||
validateNotEmpty(tableName, "Table name");
|
||||
validateNotKeyWord(
|
||||
keyspaceName,
|
||||
String.format(
|
||||
"The keyspace name '%s' is not allowed because it is a reserved keyword",
|
||||
keyspaceName));
|
||||
validateNotKeyWord(
|
||||
tableName,
|
||||
String.format(
|
||||
"The table name '%s' is not allowed because it is a reserved keyword", tableName));
|
||||
validateNotKeyWord(keyspaceName,
|
||||
String.format("The keyspace name '%s' is not allowed because it is a reserved keyword", keyspaceName));
|
||||
validateNotKeyWord(tableName,
|
||||
String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName));
|
||||
this.keyspaceName = Optional.fromNullable(keyspaceName);
|
||||
this.tableName = tableName;
|
||||
return new CreateCustomIndex.CreateIndexOn();
|
||||
|
@ -62,15 +56,15 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
/**
|
||||
* Specify the table to create the index on.
|
||||
*
|
||||
* @param tableName the table name.
|
||||
* @return a {@link CreateIndex.CreateIndexOn} that will allow the specification of the column.
|
||||
* @param tableName
|
||||
* the table name.
|
||||
* @return a {@link CreateIndex.CreateIndexOn} that will allow the specification
|
||||
* of the column.
|
||||
*/
|
||||
public CreateIndex.CreateIndexOn onTable(String tableName) {
|
||||
validateNotEmpty(tableName, "Table name");
|
||||
validateNotKeyWord(
|
||||
tableName,
|
||||
String.format(
|
||||
"The table name '%s' is not allowed because it is a reserved keyword", tableName));
|
||||
validateNotKeyWord(tableName,
|
||||
String.format("The table name '%s' is not allowed because it is a reserved keyword", tableName));
|
||||
this.tableName = tableName;
|
||||
return new CreateCustomIndex.CreateIndexOn();
|
||||
}
|
||||
|
@ -79,15 +73,14 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
/**
|
||||
* Specify the column to create the index on.
|
||||
*
|
||||
* @param columnName the column name.
|
||||
* @param columnName
|
||||
* the column name.
|
||||
* @return the final CREATE INDEX statement.
|
||||
*/
|
||||
public SchemaStatement andColumn(String columnName) {
|
||||
validateNotEmpty(columnName, "Column name");
|
||||
validateNotKeyWord(
|
||||
columnName,
|
||||
String.format(
|
||||
"The column name '%s' is not allowed because it is a reserved keyword", columnName));
|
||||
validateNotKeyWord(columnName,
|
||||
String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
}
|
||||
|
@ -95,15 +88,14 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
/**
|
||||
* Create an index on the keys of the given map column.
|
||||
*
|
||||
* @param columnName the column name.
|
||||
* @param columnName
|
||||
* the column name.
|
||||
* @return the final CREATE INDEX statement.
|
||||
*/
|
||||
public SchemaStatement andKeysOfColumn(String columnName) {
|
||||
validateNotEmpty(columnName, "Column name");
|
||||
validateNotKeyWord(
|
||||
columnName,
|
||||
String.format(
|
||||
"The column name '%s' is not allowed because it is a reserved keyword", columnName));
|
||||
validateNotKeyWord(columnName,
|
||||
String.format("The column name '%s' is not allowed because it is a reserved keyword", columnName));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
CreateCustomIndex.this.keys = true;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
|
@ -120,8 +112,7 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
|
||||
@Override
|
||||
public String buildInternal() {
|
||||
StringBuilder createStatement =
|
||||
new StringBuilder(STATEMENT_START).append("CREATE CUSTOM INDEX ");
|
||||
StringBuilder createStatement = new StringBuilder(STATEMENT_START).append("CREATE CUSTOM INDEX ");
|
||||
|
||||
if (ifNotExists) {
|
||||
createStatement.append("IF NOT EXISTS ");
|
||||
|
|
|
@ -10,11 +10,7 @@ public class CreateMaterializedView extends Create {
|
|||
private String primaryKey;
|
||||
private String clustering;
|
||||
|
||||
public CreateMaterializedView(
|
||||
String keyspaceName,
|
||||
String viewName,
|
||||
Select.Where selection,
|
||||
String primaryKey,
|
||||
public CreateMaterializedView(String keyspaceName, String viewName, Select.Where selection, String primaryKey,
|
||||
String clustering) {
|
||||
super(keyspaceName, viewName);
|
||||
this.viewName = viewName;
|
||||
|
@ -28,8 +24,7 @@ public class CreateMaterializedView extends Create {
|
|||
}
|
||||
|
||||
public String buildInternal() {
|
||||
StringBuilder createStatement =
|
||||
new StringBuilder(STATEMENT_START).append("CREATE MATERIALIZED VIEW");
|
||||
StringBuilder createStatement = new StringBuilder(STATEMENT_START).append("CREATE MATERIALIZED VIEW");
|
||||
if (ifNotExists) {
|
||||
createStatement.append(" IF NOT EXISTS");
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@ public class CreateSasiIndex extends CreateCustomIndex {
|
|||
}
|
||||
|
||||
String getOptions() {
|
||||
return "'analyzer_class': "
|
||||
+ "'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', "
|
||||
return "'analyzer_class': " + "'org.apache.cassandra.index.sasi.analyzer.NonTokenizingAnalyzer', "
|
||||
+ "'case_sensitive': 'false'";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,7 @@ import com.google.common.base.Optional;
|
|||
public class DropMaterializedView extends Drop {
|
||||
|
||||
enum DroppedItem {
|
||||
TABLE,
|
||||
TYPE,
|
||||
INDEX,
|
||||
MATERIALIZED_VIEW
|
||||
TABLE, TYPE, INDEX, MATERIALIZED_VIEW
|
||||
}
|
||||
|
||||
private Optional<String> keyspaceName = Optional.absent();
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.config;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.DslInstantiator;
|
||||
import net.helenus.core.MapperInstantiator;
|
||||
import net.helenus.core.reflect.ReflectionDslInstantiator;
|
||||
|
|
|
@ -18,6 +18,7 @@ package net.helenus.config;
|
|||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.mapping.annotation.Transient;
|
||||
|
||||
public enum GetterMethodDetector implements Function<Method, Boolean> {
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.config;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.DslInstantiator;
|
||||
import net.helenus.core.MapperInstantiator;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.helenus.core;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
|
||||
public abstract class AbstractAuditedEntityDraft<E> extends AbstractEntityDraft<E> {
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package net.helenus.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.primitives.Primitives;
|
||||
import java.util.*;
|
||||
|
||||
import net.helenus.core.reflect.DefaultPrimitiveTypes;
|
||||
import net.helenus.core.reflect.Drafted;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
|
|
|
@ -15,18 +15,21 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import brave.Tracer;
|
||||
import java.io.PrintStream;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.io.PrintStream;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import brave.Tracer;
|
||||
import net.helenus.mapping.value.ColumnValuePreparer;
|
||||
import net.helenus.mapping.value.ColumnValueProvider;
|
||||
import net.helenus.support.HelenusException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractSessionOperations {
|
||||
|
||||
|
|
|
@ -15,26 +15,27 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import com.diffplug.common.base.Errors;
|
||||
import com.google.common.collect.TreeTraverser;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.support.Either;
|
||||
|
||||
import org.ahocorasick.trie.Emit;
|
||||
import org.ahocorasick.trie.Trie;
|
||||
|
||||
import com.diffplug.common.base.Errors;
|
||||
import com.google.common.collect.TreeTraverser;
|
||||
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.support.Either;
|
||||
|
||||
/** Encapsulates the concept of a "transaction" as a unit-of-work. */
|
||||
public abstract class AbstractUnitOfWork<E extends Exception>
|
||||
implements UnitOfWork<E>, AutoCloseable {
|
||||
public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfWork<E>, AutoCloseable {
|
||||
private final List<AbstractUnitOfWork<E>> nested = new ArrayList<>();
|
||||
private final HelenusSession session;
|
||||
private final AbstractUnitOfWork<E> parent;
|
||||
private List<CommitThunk> postCommit = new ArrayList<CommitThunk>();
|
||||
private final Map<String, Either<Object, Set<Object>>> cache =
|
||||
new HashMap<String, Either<Object, Set<Object>>>();
|
||||
private Trie cacheIndex =
|
||||
Trie.builder().ignoreOverlaps().onlyWholeWordsWhiteSpaceSeparated().build();
|
||||
private final Map<String, Either<Object, Set<Object>>> cache = new HashMap<String, Either<Object, Set<Object>>>();
|
||||
private Trie cacheIndex = Trie.builder().ignoreOverlaps().build();
|
||||
private boolean aborted = false;
|
||||
private boolean committed = false;
|
||||
|
||||
|
@ -67,14 +68,13 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Optional<Either<Object, Set<Object>>> cacheLookupByFacet(Set<BoundFacet> facets) {
|
||||
public Optional<Either<Object, Set<Object>>> cacheLookupByFacet(Set<Facet> facets) {
|
||||
Optional<Either<Object, Set<Object>>> result = Optional.empty();
|
||||
Collection<Emit> emits =
|
||||
cacheIndex.parseText(
|
||||
String.join(
|
||||
" ", facets.stream().map(facet -> facet.toString()).collect(Collectors.toList())));
|
||||
Collection<Emit> emits = cacheIndex.parseText(
|
||||
String.join(" ", facets.stream().map(facet -> facet.toString()).collect(Collectors.toList())));
|
||||
for (Emit emit : emits) {
|
||||
// NOTE: rethink. should this match *all* facets? how do I know which emit keyword is the primary key?
|
||||
// NOTE: rethink. should this match *all* facets? how do I know which emit
|
||||
// keyword is the primary key?
|
||||
String key = emit.getKeyword();
|
||||
result = cacheLookup(key);
|
||||
if (result.isPresent()) {
|
||||
|
@ -98,8 +98,9 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
|
||||
@Override
|
||||
public Optional<Either<Object, Set<Object>>> cacheLookup(String key) {
|
||||
Optional<Either<Object, Set<Object>>> result =
|
||||
(cache.containsKey(key)) ? Optional.of(cache.get(key)) : Optional.empty();
|
||||
Optional<Either<Object, Set<Object>>> result = (cache.containsKey(key))
|
||||
? Optional.of(cache.get(key))
|
||||
: Optional.empty();
|
||||
|
||||
if (!result.isPresent()) {
|
||||
// Be sure to check all enclosing UnitOfWork caches as well, we may be nested.
|
||||
|
@ -111,14 +112,12 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
}
|
||||
|
||||
@Override
|
||||
public void cacheUpdate(
|
||||
Either<Object, Set<Object>> value, String[] statementKeys, Map<String, BoundFacet> facetMap) {
|
||||
public void cacheUpdate(Either<Object, Set<Object>> value, String[] statementKeys,
|
||||
Map<String, BoundFacet> facetMap) {
|
||||
String key = "CQL::" + String.join(",", statementKeys);
|
||||
cache.put(key, value);
|
||||
Trie.TrieBuilder builder =
|
||||
cacheIndex.builder().ignoreOverlaps().onlyWholeWordsWhiteSpaceSeparated();
|
||||
facetMap.forEach(
|
||||
(facetName, facet) -> {
|
||||
Trie.TrieBuilder builder = cacheIndex.builder().ignoreOverlaps();
|
||||
facetMap.forEach((facetName, facet) -> {
|
||||
builder.addKeyword(facet.toString());
|
||||
if (facetName.equals("*")) {
|
||||
cache.put(facet.toString(), value);
|
||||
|
@ -132,16 +131,19 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the work performed between calling begin and now can be committed or not.
|
||||
* Checks to see if the work performed between calling begin and now can be
|
||||
* committed or not.
|
||||
*
|
||||
* @return a function from which to chain work that only happens when commit is successful
|
||||
* @throws E when the work overlaps with other concurrent writers.
|
||||
* @return a function from which to chain work that only happens when commit is
|
||||
* successful
|
||||
* @throws E
|
||||
* when the work overlaps with other concurrent writers.
|
||||
*/
|
||||
public PostCommitFunction<Void, Void> commit() throws E {
|
||||
// All nested UnitOfWork should be committed (not aborted) before calls to commit, check.
|
||||
// All nested UnitOfWork should be committed (not aborted) before calls to
|
||||
// commit, check.
|
||||
boolean canCommit = true;
|
||||
TreeTraverser<AbstractUnitOfWork<E>> traverser =
|
||||
TreeTraverser.using(node -> node::getChildNodes);
|
||||
TreeTraverser<AbstractUnitOfWork<E>> traverser = TreeTraverser.using(node -> node::getChildNodes);
|
||||
for (AbstractUnitOfWork<E> uow : traverser.postOrderTraversal(this)) {
|
||||
if (this != uow) {
|
||||
canCommit &= (!uow.aborted && uow.committed);
|
||||
|
@ -149,15 +151,18 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
}
|
||||
|
||||
// log.record(txn::provisionalCommit)
|
||||
// examine log for conflicts in read-set and write-set between begin and provisional commit
|
||||
// examine log for conflicts in read-set and write-set between begin and
|
||||
// provisional commit
|
||||
// if (conflict) { throw new ConflictingUnitOfWorkException(this) }
|
||||
// else return function so as to enable commit.andThen(() -> { do something iff commit was successful; })
|
||||
// else return function so as to enable commit.andThen(() -> { do something iff
|
||||
// commit was successful; })
|
||||
|
||||
if (canCommit) {
|
||||
committed = true;
|
||||
aborted = false;
|
||||
|
||||
// TODO(gburd): union this cache with parent's (if there is a parent) or with the session cache for all cacheable entities we currently hold
|
||||
// TODO(gburd): union this cache with parent's (if there is a parent) or with
|
||||
// the session cache for all cacheable entities we currently hold
|
||||
|
||||
nested.forEach((uow) -> Errors.rethrow().wrap(uow::commit));
|
||||
|
||||
|
@ -168,10 +173,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
|
||||
// Apply all post-commit functions for
|
||||
if (parent == null) {
|
||||
traverser
|
||||
.postOrderTraversal(this)
|
||||
.forEach(
|
||||
uow -> {
|
||||
traverser.postOrderTraversal(this).forEach(uow -> {
|
||||
uow.applyPostCommitFunctions();
|
||||
});
|
||||
return new PostCommitFunction(this, null);
|
||||
|
@ -186,12 +188,8 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
|
||||
/* Explicitly discard the work and mark it as as such in the log. */
|
||||
public void abort() {
|
||||
TreeTraverser<AbstractUnitOfWork<E>> traverser =
|
||||
TreeTraverser.using(node -> node::getChildNodes);
|
||||
traverser
|
||||
.postOrderTraversal(this)
|
||||
.forEach(
|
||||
uow -> {
|
||||
TreeTraverser<AbstractUnitOfWork<E>> traverser = TreeTraverser.using(node -> node::getChildNodes);
|
||||
traverser.postOrderTraversal(this).forEach(uow -> {
|
||||
uow.committed = false;
|
||||
uow.aborted = true;
|
||||
});
|
||||
|
@ -199,8 +197,7 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
// cache.invalidateSince(txn::start time)
|
||||
}
|
||||
|
||||
private void assumeCache(
|
||||
Map<String, Either<Object, Set<Object>>> childCache, Trie childCacheIndex) {
|
||||
private void assumeCache(Map<String, Either<Object, Set<Object>>> childCache, Trie childCacheIndex) {
|
||||
for (String key : childCache.keySet()) {
|
||||
if (cache.containsKey(key)) {
|
||||
Either<Object, Set<Object>> value = cache.get(key);
|
||||
|
@ -237,7 +234,8 @@ public abstract class AbstractUnitOfWork<E extends Exception>
|
|||
|
||||
@Override
|
||||
public void close() throws E {
|
||||
// Closing a AbstractUnitOfWork will abort iff we've not already aborted or committed this unit of work.
|
||||
// Closing a AbstractUnitOfWork will abort iff we've not already aborted or
|
||||
// committed this unit of work.
|
||||
if (aborted == false && committed == false) {
|
||||
abort();
|
||||
}
|
||||
|
|
|
@ -16,8 +16,5 @@
|
|||
package net.helenus.core;
|
||||
|
||||
public enum AutoDdl {
|
||||
VALIDATE,
|
||||
UPDATE,
|
||||
CREATE,
|
||||
CREATE_DROP;
|
||||
VALIDATE, UPDATE, CREATE, CREATE_DROP;
|
||||
}
|
||||
|
|
|
@ -15,15 +15,13 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
|
||||
public interface DslInstantiator {
|
||||
|
||||
<E> E instantiate(
|
||||
Class<E> iface,
|
||||
ClassLoader classLoader,
|
||||
Optional<HelenusPropertyNode> parent,
|
||||
Metadata metadata);
|
||||
<E> E instantiate(Class<E> iface, ClassLoader classLoader, Optional<HelenusPropertyNode> parent, Metadata metadata);
|
||||
}
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.Clause;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.Clause;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
import net.helenus.mapping.value.ColumnValuePreparer;
|
||||
|
@ -93,8 +95,7 @@ public final class Filter<V> {
|
|||
Objects.requireNonNull(val, "empty value");
|
||||
|
||||
if (op == Operator.IN) {
|
||||
throw new IllegalArgumentException(
|
||||
"invalid usage of the 'in' operator, use Filter.in() static method");
|
||||
throw new IllegalArgumentException("invalid usage of the 'in' operator, use Filter.in() static method");
|
||||
}
|
||||
|
||||
HelenusPropertyNode node = MappingUtil.resolveMappingProperty(getter);
|
||||
|
|
|
@ -15,12 +15,17 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Metadata;
|
||||
import com.datastax.driver.core.Session;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import net.helenus.config.DefaultHelenusSettings;
|
||||
import net.helenus.config.HelenusSettings;
|
||||
import net.helenus.core.reflect.DslExportable;
|
||||
|
@ -31,14 +36,13 @@ import net.helenus.support.HelenusMappingException;
|
|||
public final class Helenus {
|
||||
|
||||
private static volatile HelenusSettings settings = new DefaultHelenusSettings();
|
||||
private static final ConcurrentMap<Class<?>, Object> dslCache =
|
||||
new ConcurrentHashMap<Class<?>, Object>();
|
||||
private static final ConcurrentMap<Class<?>, Metadata> metadataForEntity =
|
||||
new ConcurrentHashMap<Class<?>, Metadata>();
|
||||
private static final ConcurrentMap<Class<?>, Object> dslCache = new ConcurrentHashMap<Class<?>, Object>();
|
||||
private static final ConcurrentMap<Class<?>, Metadata> metadataForEntity = new ConcurrentHashMap<Class<?>, Metadata>();
|
||||
private static final Set<HelenusSession> sessions = new HashSet<HelenusSession>();
|
||||
private static volatile HelenusSession singleton;
|
||||
|
||||
private Helenus() {}
|
||||
private Helenus() {
|
||||
}
|
||||
|
||||
protected static void setSession(HelenusSession session) {
|
||||
sessions.add(session);
|
||||
|
@ -50,8 +54,7 @@ public final class Helenus {
|
|||
}
|
||||
|
||||
public static void shutdown() {
|
||||
sessions.forEach(
|
||||
(session) -> {
|
||||
sessions.forEach((session) -> {
|
||||
session.close();
|
||||
sessions.remove(session);
|
||||
});
|
||||
|
@ -103,10 +106,7 @@ public final class Helenus {
|
|||
return dsl(iface, classLoader, Optional.empty(), metadata);
|
||||
}
|
||||
|
||||
public static <E> E dsl(
|
||||
Class<E> iface,
|
||||
ClassLoader classLoader,
|
||||
Optional<HelenusPropertyNode> parent,
|
||||
public static <E> E dsl(Class<E> iface, ClassLoader classLoader, Optional<HelenusPropertyNode> parent,
|
||||
Metadata metadata) {
|
||||
|
||||
Object instance = null;
|
||||
|
|
|
@ -17,9 +17,6 @@ package net.helenus.core;
|
|||
|
||||
import static net.helenus.core.Query.eq;
|
||||
|
||||
import brave.Tracer;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import java.io.Closeable;
|
||||
import java.io.PrintStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
@ -30,6 +27,11 @@ import java.util.Optional;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
|
||||
import brave.Tracer;
|
||||
import net.helenus.core.operation.*;
|
||||
import net.helenus.core.reflect.Drafted;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
|
@ -67,25 +69,14 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
private final StatementColumnValuePreparer valuePreparer;
|
||||
private final Metadata metadata;
|
||||
|
||||
HelenusSession(
|
||||
Session session,
|
||||
String usingKeyspace,
|
||||
CodecRegistry registry,
|
||||
boolean showCql,
|
||||
PrintStream printStream,
|
||||
SessionRepositoryBuilder sessionRepositoryBuilder,
|
||||
Executor executor,
|
||||
boolean dropSchemaOnClose,
|
||||
ConsistencyLevel consistencyLevel,
|
||||
boolean defaultQueryIdempotency,
|
||||
Class<? extends UnitOfWork> unitOfWorkClass,
|
||||
MetricRegistry metricRegistry,
|
||||
Tracer tracer) {
|
||||
HelenusSession(Session session, String usingKeyspace, CodecRegistry registry, boolean showCql,
|
||||
PrintStream printStream, SessionRepositoryBuilder sessionRepositoryBuilder, Executor executor,
|
||||
boolean dropSchemaOnClose, ConsistencyLevel consistencyLevel, boolean defaultQueryIdempotency,
|
||||
Class<? extends UnitOfWork> unitOfWorkClass, MetricRegistry metricRegistry, Tracer tracer) {
|
||||
this.session = session;
|
||||
this.registry = registry == null ? CodecRegistry.DEFAULT_INSTANCE : registry;
|
||||
this.usingKeyspace =
|
||||
Objects.requireNonNull(
|
||||
usingKeyspace, "keyspace needs to be selected before creating session");
|
||||
this.usingKeyspace = Objects.requireNonNull(usingKeyspace,
|
||||
"keyspace needs to be selected before creating session");
|
||||
this.showCql = showCql;
|
||||
this.printStream = printStream;
|
||||
this.sessionRepository = sessionRepositoryBuilder.build();
|
||||
|
@ -189,35 +180,26 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
public synchronized UnitOfWork begin(UnitOfWork parent) {
|
||||
try {
|
||||
Class<? extends UnitOfWork> clazz = unitOfWorkClass;
|
||||
Constructor<? extends UnitOfWork> ctor =
|
||||
clazz.getConstructor(HelenusSession.class, UnitOfWork.class);
|
||||
Constructor<? extends UnitOfWork> ctor = clazz.getConstructor(HelenusSession.class, UnitOfWork.class);
|
||||
UnitOfWork uow = ctor.newInstance(this, parent);
|
||||
if (parent != null) {
|
||||
parent.addNestedUnitOfWork(uow);
|
||||
}
|
||||
return uow.begin();
|
||||
} catch (NoSuchMethodException
|
||||
| InvocationTargetException
|
||||
| InstantiationException
|
||||
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException
|
||||
| IllegalAccessException e) {
|
||||
throw new HelenusException(
|
||||
String.format(
|
||||
"Unable to instantiate {} as a UnitOfWork.", unitOfWorkClass.getSimpleName()),
|
||||
e);
|
||||
String.format("Unable to instantiate {} as a UnitOfWork.", unitOfWorkClass.getSimpleName()), e);
|
||||
}
|
||||
}
|
||||
|
||||
public <E> SelectOperation<E> select(E pojo) {
|
||||
Objects.requireNonNull(
|
||||
pojo, "supplied object must be a dsl for a registered entity but cannot be null");
|
||||
Objects.requireNonNull(pojo, "supplied object must be a dsl for a registered entity but cannot be null");
|
||||
ColumnValueProvider valueProvider = getValueProvider();
|
||||
HelenusEntity entity = Helenus.resolve(pojo);
|
||||
Class<?> entityClass = entity.getMappingInterface();
|
||||
|
||||
return new SelectOperation<E>(
|
||||
this,
|
||||
entity,
|
||||
(r) -> {
|
||||
return new SelectOperation<E>(this, entity, (r) -> {
|
||||
Map<String, Object> map = new ValueProviderMap(r, valueProvider, entity);
|
||||
return (E) Helenus.map(entityClass, map);
|
||||
});
|
||||
|
@ -228,10 +210,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
ColumnValueProvider valueProvider = getValueProvider();
|
||||
HelenusEntity entity = Helenus.entity(entityClass);
|
||||
|
||||
return new SelectOperation<E>(
|
||||
this,
|
||||
entity,
|
||||
(r) -> {
|
||||
return new SelectOperation<E>(this, entity, (r) -> {
|
||||
Map<String, Object> map = new ValueProviderMap(r, valueProvider, entity);
|
||||
return (E) Helenus.map(entityClass, map);
|
||||
});
|
||||
|
@ -247,8 +226,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
|
||||
public <E> SelectOperation<Row> selectAll(E pojo) {
|
||||
Objects.requireNonNull(
|
||||
pojo, "supplied object must be a dsl for a registered entity but cannot be null");
|
||||
Objects.requireNonNull(pojo, "supplied object must be a dsl for a registered entity but cannot be null");
|
||||
HelenusEntity entity = Helenus.resolve(pojo);
|
||||
return new SelectOperation<Row>(this, entity);
|
||||
}
|
||||
|
@ -263,8 +241,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
|
||||
HelenusPropertyNode p1 = MappingUtil.resolveMappingProperty(getter1);
|
||||
return new SelectOperation<Tuple1<V1>>(
|
||||
this, new Mappers.Mapper1<V1>(getValueProvider(), p1), p1);
|
||||
return new SelectOperation<Tuple1<V1>>(this, new Mappers.Mapper1<V1>(getValueProvider(), p1), p1);
|
||||
}
|
||||
|
||||
public <V1, V2> SelectOperation<Tuple2<V1, V2>> select(Getter<V1> getter1, Getter<V2> getter2) {
|
||||
|
@ -273,12 +250,12 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
|
||||
HelenusPropertyNode p1 = MappingUtil.resolveMappingProperty(getter1);
|
||||
HelenusPropertyNode p2 = MappingUtil.resolveMappingProperty(getter2);
|
||||
return new SelectOperation<Fun.Tuple2<V1, V2>>(
|
||||
this, new Mappers.Mapper2<V1, V2>(getValueProvider(), p1, p2), p1, p2);
|
||||
return new SelectOperation<Fun.Tuple2<V1, V2>>(this, new Mappers.Mapper2<V1, V2>(getValueProvider(), p1, p2),
|
||||
p1, p2);
|
||||
}
|
||||
|
||||
public <V1, V2, V3> SelectOperation<Fun.Tuple3<V1, V2, V3>> select(
|
||||
Getter<V1> getter1, Getter<V2> getter2, Getter<V3> getter3) {
|
||||
public <V1, V2, V3> SelectOperation<Fun.Tuple3<V1, V2, V3>> select(Getter<V1> getter1, Getter<V2> getter2,
|
||||
Getter<V3> getter3) {
|
||||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
Objects.requireNonNull(getter2, "field 2 is empty");
|
||||
Objects.requireNonNull(getter3, "field 3 is empty");
|
||||
|
@ -286,12 +263,12 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusPropertyNode p1 = MappingUtil.resolveMappingProperty(getter1);
|
||||
HelenusPropertyNode p2 = MappingUtil.resolveMappingProperty(getter2);
|
||||
HelenusPropertyNode p3 = MappingUtil.resolveMappingProperty(getter3);
|
||||
return new SelectOperation<Fun.Tuple3<V1, V2, V3>>(
|
||||
this, new Mappers.Mapper3<V1, V2, V3>(getValueProvider(), p1, p2, p3), p1, p2, p3);
|
||||
return new SelectOperation<Fun.Tuple3<V1, V2, V3>>(this,
|
||||
new Mappers.Mapper3<V1, V2, V3>(getValueProvider(), p1, p2, p3), p1, p2, p3);
|
||||
}
|
||||
|
||||
public <V1, V2, V3, V4> SelectOperation<Fun.Tuple4<V1, V2, V3, V4>> select(
|
||||
Getter<V1> getter1, Getter<V2> getter2, Getter<V3> getter3, Getter<V4> getter4) {
|
||||
public <V1, V2, V3, V4> SelectOperation<Fun.Tuple4<V1, V2, V3, V4>> select(Getter<V1> getter1, Getter<V2> getter2,
|
||||
Getter<V3> getter3, Getter<V4> getter4) {
|
||||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
Objects.requireNonNull(getter2, "field 2 is empty");
|
||||
Objects.requireNonNull(getter3, "field 3 is empty");
|
||||
|
@ -301,21 +278,12 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusPropertyNode p2 = MappingUtil.resolveMappingProperty(getter2);
|
||||
HelenusPropertyNode p3 = MappingUtil.resolveMappingProperty(getter3);
|
||||
HelenusPropertyNode p4 = MappingUtil.resolveMappingProperty(getter4);
|
||||
return new SelectOperation<Fun.Tuple4<V1, V2, V3, V4>>(
|
||||
this,
|
||||
new Mappers.Mapper4<V1, V2, V3, V4>(getValueProvider(), p1, p2, p3, p4),
|
||||
p1,
|
||||
p2,
|
||||
p3,
|
||||
p4);
|
||||
return new SelectOperation<Fun.Tuple4<V1, V2, V3, V4>>(this,
|
||||
new Mappers.Mapper4<V1, V2, V3, V4>(getValueProvider(), p1, p2, p3, p4), p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
public <V1, V2, V3, V4, V5> SelectOperation<Fun.Tuple5<V1, V2, V3, V4, V5>> select(
|
||||
Getter<V1> getter1,
|
||||
Getter<V2> getter2,
|
||||
Getter<V3> getter3,
|
||||
Getter<V4> getter4,
|
||||
Getter<V5> getter5) {
|
||||
public <V1, V2, V3, V4, V5> SelectOperation<Fun.Tuple5<V1, V2, V3, V4, V5>> select(Getter<V1> getter1,
|
||||
Getter<V2> getter2, Getter<V3> getter3, Getter<V4> getter4, Getter<V5> getter5) {
|
||||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
Objects.requireNonNull(getter2, "field 2 is empty");
|
||||
Objects.requireNonNull(getter3, "field 3 is empty");
|
||||
|
@ -327,23 +295,12 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusPropertyNode p3 = MappingUtil.resolveMappingProperty(getter3);
|
||||
HelenusPropertyNode p4 = MappingUtil.resolveMappingProperty(getter4);
|
||||
HelenusPropertyNode p5 = MappingUtil.resolveMappingProperty(getter5);
|
||||
return new SelectOperation<Fun.Tuple5<V1, V2, V3, V4, V5>>(
|
||||
this,
|
||||
new Mappers.Mapper5<V1, V2, V3, V4, V5>(getValueProvider(), p1, p2, p3, p4, p5),
|
||||
p1,
|
||||
p2,
|
||||
p3,
|
||||
p4,
|
||||
p5);
|
||||
return new SelectOperation<Fun.Tuple5<V1, V2, V3, V4, V5>>(this,
|
||||
new Mappers.Mapper5<V1, V2, V3, V4, V5>(getValueProvider(), p1, p2, p3, p4, p5), p1, p2, p3, p4, p5);
|
||||
}
|
||||
|
||||
public <V1, V2, V3, V4, V5, V6> SelectOperation<Fun.Tuple6<V1, V2, V3, V4, V5, V6>> select(
|
||||
Getter<V1> getter1,
|
||||
Getter<V2> getter2,
|
||||
Getter<V3> getter3,
|
||||
Getter<V4> getter4,
|
||||
Getter<V5> getter5,
|
||||
Getter<V6> getter6) {
|
||||
public <V1, V2, V3, V4, V5, V6> SelectOperation<Fun.Tuple6<V1, V2, V3, V4, V5, V6>> select(Getter<V1> getter1,
|
||||
Getter<V2> getter2, Getter<V3> getter3, Getter<V4> getter4, Getter<V5> getter5, Getter<V6> getter6) {
|
||||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
Objects.requireNonNull(getter2, "field 2 is empty");
|
||||
Objects.requireNonNull(getter3, "field 3 is empty");
|
||||
|
@ -357,26 +314,14 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusPropertyNode p4 = MappingUtil.resolveMappingProperty(getter4);
|
||||
HelenusPropertyNode p5 = MappingUtil.resolveMappingProperty(getter5);
|
||||
HelenusPropertyNode p6 = MappingUtil.resolveMappingProperty(getter6);
|
||||
return new SelectOperation<Tuple6<V1, V2, V3, V4, V5, V6>>(
|
||||
this,
|
||||
new Mappers.Mapper6<V1, V2, V3, V4, V5, V6>(getValueProvider(), p1, p2, p3, p4, p5, p6),
|
||||
p1,
|
||||
p2,
|
||||
p3,
|
||||
p4,
|
||||
p5,
|
||||
p6);
|
||||
return new SelectOperation<Tuple6<V1, V2, V3, V4, V5, V6>>(this,
|
||||
new Mappers.Mapper6<V1, V2, V3, V4, V5, V6>(getValueProvider(), p1, p2, p3, p4, p5, p6), p1, p2, p3, p4,
|
||||
p5, p6);
|
||||
}
|
||||
|
||||
public <V1, V2, V3, V4, V5, V6, V7>
|
||||
SelectOperation<Fun.Tuple7<V1, V2, V3, V4, V5, V6, V7>> select(
|
||||
Getter<V1> getter1,
|
||||
Getter<V2> getter2,
|
||||
Getter<V3> getter3,
|
||||
Getter<V4> getter4,
|
||||
Getter<V5> getter5,
|
||||
Getter<V6> getter6,
|
||||
Getter<V7> getter7) {
|
||||
public <V1, V2, V3, V4, V5, V6, V7> SelectOperation<Fun.Tuple7<V1, V2, V3, V4, V5, V6, V7>> select(
|
||||
Getter<V1> getter1, Getter<V2> getter2, Getter<V3> getter3, Getter<V4> getter4, Getter<V5> getter5,
|
||||
Getter<V6> getter6, Getter<V7> getter7) {
|
||||
Objects.requireNonNull(getter1, "field 1 is empty");
|
||||
Objects.requireNonNull(getter2, "field 2 is empty");
|
||||
Objects.requireNonNull(getter3, "field 3 is empty");
|
||||
|
@ -392,17 +337,9 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusPropertyNode p5 = MappingUtil.resolveMappingProperty(getter5);
|
||||
HelenusPropertyNode p6 = MappingUtil.resolveMappingProperty(getter6);
|
||||
HelenusPropertyNode p7 = MappingUtil.resolveMappingProperty(getter7);
|
||||
return new SelectOperation<Fun.Tuple7<V1, V2, V3, V4, V5, V6, V7>>(
|
||||
this,
|
||||
new Mappers.Mapper7<V1, V2, V3, V4, V5, V6, V7>(
|
||||
getValueProvider(), p1, p2, p3, p4, p5, p6, p7),
|
||||
p1,
|
||||
p2,
|
||||
p3,
|
||||
p4,
|
||||
p5,
|
||||
p6,
|
||||
p7);
|
||||
return new SelectOperation<Fun.Tuple7<V1, V2, V3, V4, V5, V6, V7>>(this,
|
||||
new Mappers.Mapper7<V1, V2, V3, V4, V5, V6, V7>(getValueProvider(), p1, p2, p3, p4, p5, p6, p7), p1, p2,
|
||||
p3, p4, p5, p6, p7);
|
||||
}
|
||||
|
||||
public CountOperation count() {
|
||||
|
@ -430,24 +367,19 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
HelenusEntity entity = Helenus.entity(draft.getEntityClass());
|
||||
|
||||
// Add all the mutated values contained in the draft.
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.forEach(
|
||||
property -> {
|
||||
entity.getOrderedProperties().forEach(property -> {
|
||||
switch (property.getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
String propertyName = property.getPropertyName();
|
||||
if (mutatedProperties.contains(propertyName)) {
|
||||
Object value = map.get(propertyName);
|
||||
Getter<Object> getter =
|
||||
new Getter<Object>() {
|
||||
Getter<Object> getter = new Getter<Object>() {
|
||||
@Override
|
||||
public Object get() {
|
||||
throw new DslPropertyException(
|
||||
new HelenusPropertyNode(property, Optional.empty()));
|
||||
throw new DslPropertyException(new HelenusPropertyNode(property, Optional.empty()));
|
||||
}
|
||||
};
|
||||
update.set(getter, value);
|
||||
|
@ -455,22 +387,18 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
});
|
||||
|
||||
// Add the partition and clustering keys if they were in the draft (normally the case).
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.forEach(
|
||||
property -> {
|
||||
// Add the partition and clustering keys if they were in the draft (normally the
|
||||
// case).
|
||||
entity.getOrderedProperties().forEach(property -> {
|
||||
switch (property.getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
String propertyName = property.getPropertyName();
|
||||
Object value = map.get(propertyName);
|
||||
Getter<Object> getter =
|
||||
new Getter<Object>() {
|
||||
Getter<Object> getter = new Getter<Object>() {
|
||||
@Override
|
||||
public Object get() {
|
||||
throw new DslPropertyException(
|
||||
new HelenusPropertyNode(property, Optional.empty()));
|
||||
throw new DslPropertyException(new HelenusPropertyNode(property, Optional.empty()));
|
||||
}
|
||||
};
|
||||
update.where(getter, eq(value));
|
||||
|
@ -498,8 +426,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
|
||||
public <T> InsertOperation<T> insert(T pojo) {
|
||||
Objects.requireNonNull(
|
||||
pojo,
|
||||
Objects.requireNonNull(pojo,
|
||||
"supplied object must be either an instance of the entity class or a dsl for it, but cannot be null");
|
||||
HelenusEntity entity = null;
|
||||
try {
|
||||
|
@ -539,8 +466,7 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
}
|
||||
|
||||
public <T> InsertOperation<T> upsert(T pojo) {
|
||||
Objects.requireNonNull(
|
||||
pojo,
|
||||
Objects.requireNonNull(pojo,
|
||||
"supplied object must be either an instance of the entity class or a dsl for it, but cannot be null");
|
||||
HelenusEntity entity = null;
|
||||
try {
|
||||
|
@ -610,11 +536,11 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
private void dropEntity(HelenusEntity entity) {
|
||||
|
||||
switch (entity.getType()) {
|
||||
case TABLE:
|
||||
case TABLE :
|
||||
execute(SchemaUtil.dropTable(entity), true);
|
||||
break;
|
||||
|
||||
case UDT:
|
||||
case UDT :
|
||||
execute(SchemaUtil.dropUserType(entity), true);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
package net.helenus.core;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.support.HelenusException;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
@ -35,8 +37,7 @@ public enum HelenusValidator implements PropertyValueValidator {
|
|||
try {
|
||||
valid = typeless.isValid(value, null);
|
||||
} catch (ClassCastException e) {
|
||||
throw new HelenusMappingException(
|
||||
"validator was used for wrong type '" + value + "' in " + prop, e);
|
||||
throw new HelenusMappingException("validator was used for wrong type '" + value + "' in " + prop, e);
|
||||
}
|
||||
|
||||
if (!valid) {
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.mapping.value.ColumnValueProvider;
|
||||
|
@ -24,7 +26,8 @@ import net.helenus.support.Fun;
|
|||
|
||||
public final class Mappers {
|
||||
|
||||
private Mappers() {}
|
||||
private Mappers() {
|
||||
}
|
||||
|
||||
public static final class Mapper1<A> implements Function<Row, Fun.Tuple1<A>> {
|
||||
|
||||
|
@ -56,8 +59,7 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple2<A, B> apply(Row row) {
|
||||
return new Fun.Tuple2<A, B>(
|
||||
provider.getColumnValue(row, 0, p1), provider.getColumnValue(row, 1, p2));
|
||||
return new Fun.Tuple2<A, B>(provider.getColumnValue(row, 0, p1), provider.getColumnValue(row, 1, p2));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,10 +70,7 @@ public final class Mappers {
|
|||
private final HelenusProperty p2;
|
||||
private final HelenusProperty p3;
|
||||
|
||||
public Mapper3(
|
||||
ColumnValueProvider provider,
|
||||
HelenusPropertyNode p1,
|
||||
HelenusPropertyNode p2,
|
||||
public Mapper3(ColumnValueProvider provider, HelenusPropertyNode p1, HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3) {
|
||||
this.provider = provider;
|
||||
this.p1 = p1.getProperty();
|
||||
|
@ -81,9 +80,7 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple3<A, B, C> apply(Row row) {
|
||||
return new Fun.Tuple3<A, B, C>(
|
||||
provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2),
|
||||
return new Fun.Tuple3<A, B, C>(provider.getColumnValue(row, 0, p1), provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3));
|
||||
}
|
||||
}
|
||||
|
@ -96,12 +93,8 @@ public final class Mappers {
|
|||
private final HelenusProperty p3;
|
||||
private final HelenusProperty p4;
|
||||
|
||||
public Mapper4(
|
||||
ColumnValueProvider provider,
|
||||
HelenusPropertyNode p1,
|
||||
HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3,
|
||||
HelenusPropertyNode p4) {
|
||||
public Mapper4(ColumnValueProvider provider, HelenusPropertyNode p1, HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3, HelenusPropertyNode p4) {
|
||||
this.provider = provider;
|
||||
this.p1 = p1.getProperty();
|
||||
this.p2 = p2.getProperty();
|
||||
|
@ -111,27 +104,18 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple4<A, B, C, D> apply(Row row) {
|
||||
return new Fun.Tuple4<A, B, C, D>(
|
||||
provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4));
|
||||
return new Fun.Tuple4<A, B, C, D>(provider.getColumnValue(row, 0, p1), provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3), provider.getColumnValue(row, 3, p4));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Mapper5<A, B, C, D, E>
|
||||
implements Function<Row, Fun.Tuple5<A, B, C, D, E>> {
|
||||
public static final class Mapper5<A, B, C, D, E> implements Function<Row, Fun.Tuple5<A, B, C, D, E>> {
|
||||
|
||||
private final ColumnValueProvider provider;
|
||||
private final HelenusProperty p1, p2, p3, p4, p5;
|
||||
|
||||
public Mapper5(
|
||||
ColumnValueProvider provider,
|
||||
HelenusPropertyNode p1,
|
||||
HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3,
|
||||
HelenusPropertyNode p4,
|
||||
HelenusPropertyNode p5) {
|
||||
public Mapper5(ColumnValueProvider provider, HelenusPropertyNode p1, HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3, HelenusPropertyNode p4, HelenusPropertyNode p5) {
|
||||
this.provider = provider;
|
||||
this.p1 = p1.getProperty();
|
||||
this.p2 = p2.getProperty();
|
||||
|
@ -142,29 +126,19 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple5<A, B, C, D, E> apply(Row row) {
|
||||
return new Fun.Tuple5<A, B, C, D, E>(
|
||||
provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4),
|
||||
provider.getColumnValue(row, 4, p5));
|
||||
return new Fun.Tuple5<A, B, C, D, E>(provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2), provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4), provider.getColumnValue(row, 4, p5));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Mapper6<A, B, C, D, E, F>
|
||||
implements Function<Row, Fun.Tuple6<A, B, C, D, E, F>> {
|
||||
public static final class Mapper6<A, B, C, D, E, F> implements Function<Row, Fun.Tuple6<A, B, C, D, E, F>> {
|
||||
|
||||
private final ColumnValueProvider provider;
|
||||
private final HelenusProperty p1, p2, p3, p4, p5, p6;
|
||||
|
||||
public Mapper6(
|
||||
ColumnValueProvider provider,
|
||||
HelenusPropertyNode p1,
|
||||
HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3,
|
||||
HelenusPropertyNode p4,
|
||||
HelenusPropertyNode p5,
|
||||
HelenusPropertyNode p6) {
|
||||
public Mapper6(ColumnValueProvider provider, HelenusPropertyNode p1, HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3, HelenusPropertyNode p4, HelenusPropertyNode p5, HelenusPropertyNode p6) {
|
||||
this.provider = provider;
|
||||
this.p1 = p1.getProperty();
|
||||
this.p2 = p2.getProperty();
|
||||
|
@ -176,30 +150,20 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple6<A, B, C, D, E, F> apply(Row row) {
|
||||
return new Fun.Tuple6<A, B, C, D, E, F>(
|
||||
provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4),
|
||||
provider.getColumnValue(row, 4, p5),
|
||||
return new Fun.Tuple6<A, B, C, D, E, F>(provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2), provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4), provider.getColumnValue(row, 4, p5),
|
||||
provider.getColumnValue(row, 5, p6));
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Mapper7<A, B, C, D, E, F, G>
|
||||
implements Function<Row, Fun.Tuple7<A, B, C, D, E, F, G>> {
|
||||
public static final class Mapper7<A, B, C, D, E, F, G> implements Function<Row, Fun.Tuple7<A, B, C, D, E, F, G>> {
|
||||
|
||||
private final ColumnValueProvider provider;
|
||||
private final HelenusProperty p1, p2, p3, p4, p5, p6, p7;
|
||||
|
||||
public Mapper7(
|
||||
ColumnValueProvider provider,
|
||||
HelenusPropertyNode p1,
|
||||
HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3,
|
||||
HelenusPropertyNode p4,
|
||||
HelenusPropertyNode p5,
|
||||
HelenusPropertyNode p6,
|
||||
public Mapper7(ColumnValueProvider provider, HelenusPropertyNode p1, HelenusPropertyNode p2,
|
||||
HelenusPropertyNode p3, HelenusPropertyNode p4, HelenusPropertyNode p5, HelenusPropertyNode p6,
|
||||
HelenusPropertyNode p7) {
|
||||
this.provider = provider;
|
||||
this.p1 = p1.getProperty();
|
||||
|
@ -213,14 +177,10 @@ public final class Mappers {
|
|||
|
||||
@Override
|
||||
public Fun.Tuple7<A, B, C, D, E, F, G> apply(Row row) {
|
||||
return new Fun.Tuple7<A, B, C, D, E, F, G>(
|
||||
provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2),
|
||||
provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4),
|
||||
provider.getColumnValue(row, 4, p5),
|
||||
provider.getColumnValue(row, 5, p6),
|
||||
provider.getColumnValue(row, 6, p7));
|
||||
return new Fun.Tuple7<A, B, C, D, E, F, G>(provider.getColumnValue(row, 0, p1),
|
||||
provider.getColumnValue(row, 1, p2), provider.getColumnValue(row, 2, p3),
|
||||
provider.getColumnValue(row, 3, p4), provider.getColumnValue(row, 4, p5),
|
||||
provider.getColumnValue(row, 5, p6), provider.getColumnValue(row, 6, p7));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package net.helenus.core;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.Ordering;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import java.util.Objects;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.ColumnType;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
|
@ -32,10 +34,10 @@ public final class Ordered {
|
|||
}
|
||||
|
||||
switch (direction) {
|
||||
case ASC:
|
||||
case ASC :
|
||||
return QueryBuilder.asc(propNode.getColumnName());
|
||||
|
||||
case DESC:
|
||||
case DESC :
|
||||
return QueryBuilder.desc(propNode.getColumnName());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package net.helenus.core;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class PostCommitFunction<T, R> implements java.util.function.Function<T, R> {
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.core;
|
|||
|
||||
import com.datastax.driver.core.querybuilder.Clause;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.value.ColumnValuePreparer;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
@ -38,34 +39,34 @@ public final class Postulate<V> {
|
|||
public Clause getClause(HelenusPropertyNode node, ColumnValuePreparer valuePreparer) {
|
||||
|
||||
switch (operator) {
|
||||
case EQ:
|
||||
return QueryBuilder.eq(
|
||||
node.getColumnName(), valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
case EQ :
|
||||
return QueryBuilder.eq(node.getColumnName(),
|
||||
valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
|
||||
case IN:
|
||||
case IN :
|
||||
Object[] preparedValues = new Object[values.length];
|
||||
for (int i = 0; i != values.length; ++i) {
|
||||
preparedValues[i] = valuePreparer.prepareColumnValue(values[i], node.getProperty());
|
||||
}
|
||||
return QueryBuilder.in(node.getColumnName(), preparedValues);
|
||||
|
||||
case LT:
|
||||
return QueryBuilder.lt(
|
||||
node.getColumnName(), valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
case LT :
|
||||
return QueryBuilder.lt(node.getColumnName(),
|
||||
valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
|
||||
case LTE:
|
||||
return QueryBuilder.lte(
|
||||
node.getColumnName(), valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
case LTE :
|
||||
return QueryBuilder.lte(node.getColumnName(),
|
||||
valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
|
||||
case GT:
|
||||
return QueryBuilder.gt(
|
||||
node.getColumnName(), valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
case GT :
|
||||
return QueryBuilder.gt(node.getColumnName(),
|
||||
valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
|
||||
case GTE:
|
||||
return QueryBuilder.gte(
|
||||
node.getColumnName(), valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
case GTE :
|
||||
return QueryBuilder.gte(node.getColumnName(),
|
||||
valuePreparer.prepareColumnValue(values[0], node.getProperty()));
|
||||
|
||||
default:
|
||||
default :
|
||||
throw new HelenusMappingException("unknown filter operation " + operator);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,17 +15,20 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.BindMarker;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.datastax.driver.core.querybuilder.BindMarker;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
import net.helenus.mapping.OrderingDirection;
|
||||
|
||||
/** Sugar methods for the queries */
|
||||
public final class Query {
|
||||
|
||||
private Query() {}
|
||||
private Query() {
|
||||
}
|
||||
|
||||
public static BindMarker marker() {
|
||||
return QueryBuilder.bindMarker();
|
||||
|
|
|
@ -15,15 +15,16 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
import com.datastax.driver.core.IndexMetadata;
|
||||
import com.datastax.driver.core.querybuilder.IsNotNullClause;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.schemabuilder.*;
|
||||
import com.datastax.driver.core.schemabuilder.Create.Options;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.*;
|
||||
import net.helenus.mapping.ColumnType;
|
||||
|
@ -34,7 +35,8 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class SchemaUtil {
|
||||
|
||||
private SchemaUtil() {}
|
||||
private SchemaUtil() {
|
||||
}
|
||||
|
||||
public static RegularStatement use(String keyspace, boolean forceQuote) {
|
||||
if (forceQuote) {
|
||||
|
@ -57,31 +59,23 @@ public final class SchemaUtil {
|
|||
ColumnType columnType = prop.getColumnType();
|
||||
|
||||
if (columnType == ColumnType.PARTITION_KEY || columnType == ColumnType.CLUSTERING_COLUMN) {
|
||||
throw new HelenusMappingException(
|
||||
"primary key columns are not supported in UserDefinedType for "
|
||||
+ prop.getPropertyName()
|
||||
+ " in entity "
|
||||
+ entity);
|
||||
throw new HelenusMappingException("primary key columns are not supported in UserDefinedType for "
|
||||
+ prop.getPropertyName() + " in entity " + entity);
|
||||
}
|
||||
|
||||
try {
|
||||
prop.getDataType().addColumn(create, prop.getColumnName());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new HelenusMappingException(
|
||||
"invalid column name '"
|
||||
+ prop.getColumnName()
|
||||
+ "' in entity '"
|
||||
+ entity.getName().getName()
|
||||
+ "'",
|
||||
e);
|
||||
throw new HelenusMappingException("invalid column name '" + prop.getColumnName() + "' in entity '"
|
||||
+ entity.getName().getName() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
return create;
|
||||
}
|
||||
|
||||
public static List<SchemaStatement> alterUserType(
|
||||
UserType userType, HelenusEntity entity, boolean dropUnusedColumns) {
|
||||
public static List<SchemaStatement> alterUserType(UserType userType, HelenusEntity entity,
|
||||
boolean dropUnusedColumns) {
|
||||
|
||||
if (entity.getType() != HelenusEntityType.UDT) {
|
||||
throw new HelenusMappingException("expected UDT entity " + entity);
|
||||
|
@ -90,13 +84,12 @@ public final class SchemaUtil {
|
|||
List<SchemaStatement> result = new ArrayList<SchemaStatement>();
|
||||
|
||||
/**
|
||||
* TODO: In future replace SchemaBuilder.alterTable by SchemaBuilder.alterType when it will
|
||||
* exist
|
||||
* TODO: In future replace SchemaBuilder.alterTable by SchemaBuilder.alterType
|
||||
* when it will exist
|
||||
*/
|
||||
Alter alter = SchemaBuilder.alterTable(entity.getName().toCql());
|
||||
|
||||
final Set<String> visitedColumns =
|
||||
dropUnusedColumns ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
final Set<String> visitedColumns = dropUnusedColumns ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
|
||||
for (HelenusProperty prop : entity.getOrderedProperties()) {
|
||||
|
||||
|
@ -113,9 +106,8 @@ public final class SchemaUtil {
|
|||
}
|
||||
|
||||
DataType dataType = userType.getFieldType(columnName);
|
||||
SchemaStatement stmt =
|
||||
prop.getDataType()
|
||||
.alterColumn(alter, prop.getColumnName(), optional(columnName, dataType));
|
||||
SchemaStatement stmt = prop.getDataType().alterColumn(alter, prop.getColumnName(),
|
||||
optional(columnName, dataType));
|
||||
|
||||
if (stmt != null) {
|
||||
result.add(stmt);
|
||||
|
@ -148,8 +140,7 @@ public final class SchemaUtil {
|
|||
return SchemaBuilder.dropType(type.getTypeName()).ifExists();
|
||||
}
|
||||
|
||||
public static SchemaStatement createMaterializedView(
|
||||
String keyspace, String viewName, HelenusEntity entity) {
|
||||
public static SchemaStatement createMaterializedView(String keyspace, String viewName, HelenusEntity entity) {
|
||||
if (entity.getType() != HelenusEntityType.VIEW) {
|
||||
throw new HelenusMappingException("expected view entity " + entity);
|
||||
}
|
||||
|
@ -159,10 +150,7 @@ public final class SchemaUtil {
|
|||
}
|
||||
|
||||
List<HelenusPropertyNode> props = new ArrayList<HelenusPropertyNode>();
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
.forEach(p -> props.add(p));
|
||||
|
||||
Select.Selection selection = QueryBuilder.select();
|
||||
|
@ -181,44 +169,37 @@ public final class SchemaUtil {
|
|||
for (HelenusPropertyNode prop : props) {
|
||||
String columnName = prop.getColumnName();
|
||||
switch (prop.getProperty().getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case PARTITION_KEY :
|
||||
p.add(columnName);
|
||||
where = where.and(new IsNotNullClause(columnName));
|
||||
break;
|
||||
|
||||
case CLUSTERING_COLUMN:
|
||||
case CLUSTERING_COLUMN :
|
||||
c.add(columnName);
|
||||
where = where.and(new IsNotNullClause(columnName));
|
||||
|
||||
ClusteringColumn clusteringColumn =
|
||||
prop.getProperty().getGetterMethod().getAnnotation(ClusteringColumn.class);
|
||||
ClusteringColumn clusteringColumn = prop.getProperty().getGetterMethod()
|
||||
.getAnnotation(ClusteringColumn.class);
|
||||
if (clusteringColumn != null && clusteringColumn.ordering() != null) {
|
||||
o.add(columnName + " " + clusteringColumn.ordering().cql());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String primaryKey =
|
||||
"PRIMARY KEY ("
|
||||
+ ((p.size() > 1) ? "(" + String.join(", ", p) + ")" : p.get(0))
|
||||
+ ((c.size() > 0)
|
||||
? ", " + ((c.size() > 1) ? "(" + String.join(", ", c) + ")" : c.get(0))
|
||||
: "")
|
||||
+ ")";
|
||||
String primaryKey = "PRIMARY KEY (" + ((p.size() > 1) ? "(" + String.join(", ", p) + ")" : p.get(0))
|
||||
+ ((c.size() > 0) ? ", " + ((c.size() > 1) ? "(" + String.join(", ", c) + ")" : c.get(0)) : "") + ")";
|
||||
|
||||
String clustering = "";
|
||||
if (o.size() > 0) {
|
||||
clustering = "WITH CLUSTERING ORDER BY (" + String.join(", ", o) + ")";
|
||||
}
|
||||
return new CreateMaterializedView(keyspace, viewName, where, primaryKey, clustering)
|
||||
.ifNotExists();
|
||||
return new CreateMaterializedView(keyspace, viewName, where, primaryKey, clustering).ifNotExists();
|
||||
}
|
||||
|
||||
public static SchemaStatement dropMaterializedView(
|
||||
String keyspace, String viewName, HelenusEntity entity) {
|
||||
public static SchemaStatement dropMaterializedView(String keyspace, String viewName, HelenusEntity entity) {
|
||||
return new DropMaterializedView(keyspace, viewName);
|
||||
}
|
||||
|
||||
|
@ -251,15 +232,14 @@ public final class SchemaUtil {
|
|||
|
||||
if (!clusteringColumns.isEmpty()) {
|
||||
Options options = create.withOptions();
|
||||
clusteringColumns.forEach(
|
||||
p -> options.clusteringOrder(p.getColumnName().toCql(), mapDirection(p.getOrdering())));
|
||||
clusteringColumns
|
||||
.forEach(p -> options.clusteringOrder(p.getColumnName().toCql(), mapDirection(p.getOrdering())));
|
||||
}
|
||||
|
||||
return create;
|
||||
}
|
||||
|
||||
public static List<SchemaStatement> alterTable(
|
||||
TableMetadata tmd, HelenusEntity entity, boolean dropUnusedColumns) {
|
||||
public static List<SchemaStatement> alterTable(TableMetadata tmd, HelenusEntity entity, boolean dropUnusedColumns) {
|
||||
|
||||
if (entity.getType() != HelenusEntityType.TABLE) {
|
||||
throw new HelenusMappingException("expected table entity " + entity);
|
||||
|
@ -269,8 +249,7 @@ public final class SchemaUtil {
|
|||
|
||||
Alter alter = SchemaBuilder.alterTable(entity.getName().toCql());
|
||||
|
||||
final Set<String> visitedColumns =
|
||||
dropUnusedColumns ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
final Set<String> visitedColumns = dropUnusedColumns ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
|
||||
for (HelenusProperty prop : entity.getOrderedProperties()) {
|
||||
|
||||
|
@ -287,8 +266,8 @@ public final class SchemaUtil {
|
|||
}
|
||||
|
||||
ColumnMetadata columnMetadata = tmd.getColumn(columnName);
|
||||
SchemaStatement stmt =
|
||||
prop.getDataType().alterColumn(alter, prop.getColumnName(), optional(columnMetadata));
|
||||
SchemaStatement stmt = prop.getDataType().alterColumn(alter, prop.getColumnName(),
|
||||
optional(columnMetadata));
|
||||
|
||||
if (stmt != null) {
|
||||
result.add(stmt);
|
||||
|
@ -318,42 +297,28 @@ public final class SchemaUtil {
|
|||
|
||||
public static SchemaStatement createIndex(HelenusProperty prop) {
|
||||
if (prop.caseSensitiveIndex()) {
|
||||
return SchemaBuilder.createIndex(prop.getIndexName().get().toCql())
|
||||
.ifNotExists()
|
||||
.onTable(prop.getEntity().getName().toCql())
|
||||
.andColumn(prop.getColumnName().toCql());
|
||||
return SchemaBuilder.createIndex(prop.getIndexName().get().toCql()).ifNotExists()
|
||||
.onTable(prop.getEntity().getName().toCql()).andColumn(prop.getColumnName().toCql());
|
||||
} else {
|
||||
return new CreateSasiIndex(prop.getIndexName().get().toCql())
|
||||
.ifNotExists()
|
||||
.onTable(prop.getEntity().getName().toCql())
|
||||
.andColumn(prop.getColumnName().toCql());
|
||||
return new CreateSasiIndex(prop.getIndexName().get().toCql()).ifNotExists()
|
||||
.onTable(prop.getEntity().getName().toCql()).andColumn(prop.getColumnName().toCql());
|
||||
}
|
||||
}
|
||||
|
||||
public static List<SchemaStatement> createIndexes(HelenusEntity entity) {
|
||||
|
||||
return entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.filter(p -> p.getIndexName().isPresent())
|
||||
.map(p -> SchemaUtil.createIndex(p))
|
||||
.collect(Collectors.toList());
|
||||
return entity.getOrderedProperties().stream().filter(p -> p.getIndexName().isPresent())
|
||||
.map(p -> SchemaUtil.createIndex(p)).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static List<SchemaStatement> alterIndexes(
|
||||
TableMetadata tmd, HelenusEntity entity, boolean dropUnusedIndexes) {
|
||||
public static List<SchemaStatement> alterIndexes(TableMetadata tmd, HelenusEntity entity,
|
||||
boolean dropUnusedIndexes) {
|
||||
|
||||
List<SchemaStatement> list = new ArrayList<SchemaStatement>();
|
||||
|
||||
final Set<String> visitedColumns =
|
||||
dropUnusedIndexes ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
final Set<String> visitedColumns = dropUnusedIndexes ? new HashSet<String>() : Collections.<String>emptySet();
|
||||
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.filter(p -> p.getIndexName().isPresent())
|
||||
.forEach(
|
||||
p -> {
|
||||
entity.getOrderedProperties().stream().filter(p -> p.getIndexName().isPresent()).forEach(p -> {
|
||||
String columnName = p.getColumnName().getName();
|
||||
|
||||
if (dropUnusedIndexes) {
|
||||
|
@ -374,11 +339,9 @@ public final class SchemaUtil {
|
|||
|
||||
if (dropUnusedIndexes) {
|
||||
|
||||
tmd.getColumns()
|
||||
.stream()
|
||||
tmd.getColumns().stream()
|
||||
.filter(c -> tmd.getIndex(c.getName()) != null && !visitedColumns.contains(c.getName()))
|
||||
.forEach(
|
||||
c -> {
|
||||
.forEach(c -> {
|
||||
list.add(SchemaBuilder.dropIndex(tmd.getIndex(c.getName()).getName()).ifExists());
|
||||
});
|
||||
}
|
||||
|
@ -392,9 +355,9 @@ public final class SchemaUtil {
|
|||
|
||||
private static SchemaBuilder.Direction mapDirection(OrderingDirection o) {
|
||||
switch (o) {
|
||||
case ASC:
|
||||
case ASC :
|
||||
return SchemaBuilder.Direction.ASC;
|
||||
case DESC:
|
||||
case DESC :
|
||||
return SchemaBuilder.Direction.DESC;
|
||||
}
|
||||
throw new HelenusMappingException("unknown ordering " + o);
|
||||
|
@ -404,10 +367,7 @@ public final class SchemaUtil {
|
|||
|
||||
throw new HelenusMappingException(
|
||||
"only primitive types and Set,List,Map collections and UserDefinedTypes are allowed, unknown type for property '"
|
||||
+ prop.getPropertyName()
|
||||
+ "' type is '"
|
||||
+ prop.getJavaType()
|
||||
+ "' in the entity "
|
||||
+ prop.getPropertyName() + "' type is '" + prop.getJavaType() + "' in the entity "
|
||||
+ prop.getEntity());
|
||||
}
|
||||
|
||||
|
|
|
@ -15,16 +15,18 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import brave.Tracer;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
|
||||
import brave.Tracer;
|
||||
import net.helenus.core.reflect.DslExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusEntityType;
|
||||
|
@ -181,11 +183,8 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
|
||||
public SessionInitializer addPackage(String packageName) {
|
||||
try {
|
||||
PackageUtil.getClasses(packageName)
|
||||
.stream()
|
||||
.filter(c -> c.isInterface() && !c.isAnnotation())
|
||||
.forEach(
|
||||
clazz -> {
|
||||
PackageUtil.getClasses(packageName).stream().filter(c -> c.isInterface() && !c.isAnnotation())
|
||||
.forEach(clazz -> {
|
||||
initList.add(Either.right(clazz));
|
||||
});
|
||||
} catch (IOException | ClassNotFoundException e) {
|
||||
|
@ -247,19 +246,8 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
|
||||
public synchronized HelenusSession get() {
|
||||
initialize();
|
||||
return new HelenusSession(
|
||||
session,
|
||||
usingKeyspace,
|
||||
registry,
|
||||
showCql,
|
||||
printStream,
|
||||
sessionRepository,
|
||||
executor,
|
||||
autoDdl == AutoDdl.CREATE_DROP,
|
||||
consistencyLevel,
|
||||
idempotent,
|
||||
unitOfWorkClass,
|
||||
metricRegistry,
|
||||
return new HelenusSession(session, usingKeyspace, registry, showCql, printStream, sessionRepository, executor,
|
||||
autoDdl == AutoDdl.CREATE_DROP, consistencyLevel, idempotent, unitOfWorkClass, metricRegistry,
|
||||
zipkinTracer);
|
||||
}
|
||||
|
||||
|
@ -267,8 +255,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
|
||||
Objects.requireNonNull(usingKeyspace, "please define keyspace by 'use' operator");
|
||||
|
||||
initList.forEach(
|
||||
(either) -> {
|
||||
initList.forEach((either) -> {
|
||||
Class<?> iface = null;
|
||||
if (either.isLeft()) {
|
||||
iface = MappingUtil.getMappingInterface(either.getLeft());
|
||||
|
@ -285,74 +272,53 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
UserTypeOperations userTypeOps = new UserTypeOperations(this, dropUnusedColumns);
|
||||
|
||||
switch (autoDdl) {
|
||||
case CREATE_DROP:
|
||||
case CREATE_DROP :
|
||||
|
||||
// Drop view first, otherwise a `DROP TABLE ...` will fail as the type is still referenced
|
||||
// Drop view first, otherwise a `DROP TABLE ...` will fail as the type is still
|
||||
// referenced
|
||||
// by a view.
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
.forEach(e -> tableOps.dropView(e));
|
||||
|
||||
// Drop tables second, before DROP TYPE otherwise a `DROP TYPE ...` will fail as the type is
|
||||
// Drop tables second, before DROP TYPE otherwise a `DROP TYPE ...` will fail as
|
||||
// the type is
|
||||
// still referenced by a table.
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
.forEach(e -> tableOps.dropTable(e));
|
||||
|
||||
eachUserTypeInReverseOrder(userTypeOps, e -> userTypeOps.dropUserType(e));
|
||||
|
||||
// FALLTHRU to CREATE case (read: the absence of a `break;` statement here is intentional!)
|
||||
case CREATE:
|
||||
// FALLTHRU to CREATE case (read: the absence of a `break;` statement here is
|
||||
// intentional!)
|
||||
case CREATE :
|
||||
eachUserTypeInOrder(userTypeOps, e -> userTypeOps.createUserType(e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
.forEach(e -> tableOps.createTable(e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
.forEach(e -> tableOps.createView(e));
|
||||
|
||||
break;
|
||||
|
||||
case VALIDATE:
|
||||
case VALIDATE :
|
||||
eachUserTypeInOrder(userTypeOps, e -> userTypeOps.validateUserType(getUserType(e), e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
.forEach(e -> tableOps.validateTable(getTableMetadata(e), e));
|
||||
|
||||
break;
|
||||
|
||||
case UPDATE:
|
||||
case UPDATE :
|
||||
eachUserTypeInOrder(userTypeOps, e -> userTypeOps.updateUserType(getUserType(e), e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
.forEach(e -> tableOps.dropView(e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.TABLE)
|
||||
.forEach(e -> tableOps.updateTable(getTableMetadata(e), e));
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.VIEW)
|
||||
.forEach(e -> tableOps.createView(e));
|
||||
break;
|
||||
}
|
||||
|
@ -364,41 +330,27 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
}
|
||||
}
|
||||
|
||||
private void eachUserTypeInOrder(
|
||||
UserTypeOperations userTypeOps, Consumer<? super HelenusEntity> action) {
|
||||
private void eachUserTypeInOrder(UserTypeOperations userTypeOps, Consumer<? super HelenusEntity> action) {
|
||||
|
||||
Set<HelenusEntity> processedSet = new HashSet<HelenusEntity>();
|
||||
Set<HelenusEntity> stack = new HashSet<HelenusEntity>();
|
||||
|
||||
sessionRepository
|
||||
.entities()
|
||||
.stream()
|
||||
.filter(e -> e.getType() == HelenusEntityType.UDT)
|
||||
.forEach(
|
||||
e -> {
|
||||
sessionRepository.entities().stream().filter(e -> e.getType() == HelenusEntityType.UDT).forEach(e -> {
|
||||
stack.clear();
|
||||
eachUserTypeInRecursion(e, processedSet, stack, userTypeOps, action);
|
||||
});
|
||||
}
|
||||
|
||||
private void eachUserTypeInReverseOrder(
|
||||
UserTypeOperations userTypeOps, Consumer<? super HelenusEntity> action) {
|
||||
private void eachUserTypeInReverseOrder(UserTypeOperations userTypeOps, Consumer<? super HelenusEntity> action) {
|
||||
ArrayDeque<HelenusEntity> deque = new ArrayDeque<>();
|
||||
eachUserTypeInOrder(userTypeOps, e -> deque.addFirst(e));
|
||||
deque
|
||||
.stream()
|
||||
.forEach(
|
||||
e -> {
|
||||
deque.stream().forEach(e -> {
|
||||
action.accept(e);
|
||||
});
|
||||
}
|
||||
|
||||
private void eachUserTypeInRecursion(
|
||||
HelenusEntity e,
|
||||
Set<HelenusEntity> processedSet,
|
||||
Set<HelenusEntity> stack,
|
||||
UserTypeOperations userTypeOps,
|
||||
Consumer<? super HelenusEntity> action) {
|
||||
private void eachUserTypeInRecursion(HelenusEntity e, Set<HelenusEntity> processedSet, Set<HelenusEntity> stack,
|
||||
UserTypeOperations userTypeOps, Consumer<? super HelenusEntity> action) {
|
||||
|
||||
stack.add(e);
|
||||
|
||||
|
@ -419,8 +371,7 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
|
||||
private KeyspaceMetadata getKeyspaceMetadata() {
|
||||
if (keyspaceMetadata == null) {
|
||||
keyspaceMetadata =
|
||||
session.getCluster().getMetadata().getKeyspace(usingKeyspace.toLowerCase());
|
||||
keyspaceMetadata = session.getCluster().getMetadata().getKeyspace(usingKeyspace.toLowerCase());
|
||||
}
|
||||
return keyspaceMetadata;
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import com.datastax.driver.core.UserType;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
|
||||
public final class SessionRepository {
|
||||
|
@ -30,8 +32,7 @@ public final class SessionRepository {
|
|||
|
||||
userTypeMap = ImmutableMap.<String, UserType>builder().putAll(builder.getUserTypeMap()).build();
|
||||
|
||||
entityMap =
|
||||
ImmutableMap.<Class<?>, HelenusEntity>builder().putAll(builder.getEntityMap()).build();
|
||||
entityMap = ImmutableMap.<Class<?>, HelenusEntity>builder().putAll(builder.getEntityMap()).build();
|
||||
}
|
||||
|
||||
public UserType findUserType(String name) {
|
||||
|
|
|
@ -15,15 +15,17 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
import com.datastax.driver.core.UserType;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusEntityType;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
@ -33,8 +35,7 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class SessionRepositoryBuilder {
|
||||
|
||||
private static final Optional<HelenusEntityType> OPTIONAL_UDT =
|
||||
Optional.of(HelenusEntityType.UDT);
|
||||
private static final Optional<HelenusEntityType> OPTIONAL_UDT = Optional.of(HelenusEntityType.UDT);
|
||||
|
||||
private final Map<Class<?>, HelenusEntity> entityMap = new HashMap<Class<?>, HelenusEntity>();
|
||||
|
||||
|
@ -98,8 +99,7 @@ public final class SessionRepositoryBuilder {
|
|||
entity = helenusEntity;
|
||||
|
||||
if (type.isPresent() && entity.getType() != type.get()) {
|
||||
throw new HelenusMappingException(
|
||||
"unexpected entity type " + entity.getType() + " for " + entity);
|
||||
throw new HelenusMappingException("unexpected entity type " + entity.getType() + " for " + entity);
|
||||
}
|
||||
|
||||
HelenusEntity concurrentEntity = entityMap.putIfAbsent(iface, entity);
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.datastax.driver.core.TableMetadata;
|
||||
import com.datastax.driver.core.schemabuilder.SchemaStatement;
|
||||
import java.util.List;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.support.HelenusException;
|
||||
|
||||
|
@ -27,8 +29,7 @@ public final class TableOperations {
|
|||
private final boolean dropUnusedColumns;
|
||||
private final boolean dropUnusedIndexes;
|
||||
|
||||
public TableOperations(
|
||||
AbstractSessionOperations sessionOps, boolean dropUnusedColumns, boolean dropUnusedIndexes) {
|
||||
public TableOperations(AbstractSessionOperations sessionOps, boolean dropUnusedColumns, boolean dropUnusedIndexes) {
|
||||
this.sessionOps = sessionOps;
|
||||
this.dropUnusedColumns = dropUnusedColumns;
|
||||
this.dropUnusedIndexes = dropUnusedIndexes;
|
||||
|
@ -47,10 +48,7 @@ public final class TableOperations {
|
|||
|
||||
if (tmd == null) {
|
||||
throw new HelenusException(
|
||||
"table does not exists "
|
||||
+ entity.getName()
|
||||
+ "for entity "
|
||||
+ entity.getMappingInterface());
|
||||
"table does not exists " + entity.getName() + "for entity " + entity.getMappingInterface());
|
||||
}
|
||||
|
||||
List<SchemaStatement> list = SchemaUtil.alterTable(tmd, entity, dropUnusedColumns);
|
||||
|
@ -59,10 +57,7 @@ public final class TableOperations {
|
|||
|
||||
if (!list.isEmpty()) {
|
||||
throw new HelenusException(
|
||||
"schema changed for entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ ", apply this command: "
|
||||
+ list);
|
||||
"schema changed for entity " + entity.getMappingInterface() + ", apply this command: " + list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -78,17 +73,14 @@ public final class TableOperations {
|
|||
|
||||
public void createView(HelenusEntity entity) {
|
||||
sessionOps.execute(
|
||||
SchemaUtil.createMaterializedView(
|
||||
sessionOps.usingKeyspace(), entity.getName().toCql(), entity),
|
||||
true);
|
||||
// executeBatch(SchemaUtil.createIndexes(entity)); NOTE: Unfortunately C* 3.10 does not yet support 2i on materialized views.
|
||||
SchemaUtil.createMaterializedView(sessionOps.usingKeyspace(), entity.getName().toCql(), entity), true);
|
||||
// executeBatch(SchemaUtil.createIndexes(entity)); NOTE: Unfortunately C* 3.10
|
||||
// does not yet support 2i on materialized views.
|
||||
}
|
||||
|
||||
public void dropView(HelenusEntity entity) {
|
||||
sessionOps.execute(
|
||||
SchemaUtil.dropMaterializedView(
|
||||
sessionOps.usingKeyspace(), entity.getName().toCql(), entity),
|
||||
true);
|
||||
SchemaUtil.dropMaterializedView(sessionOps.usingKeyspace(), entity.getName().toCql(), entity), true);
|
||||
}
|
||||
|
||||
public void updateView(TableMetadata tmd, HelenusEntity entity) {
|
||||
|
@ -103,8 +95,7 @@ public final class TableOperations {
|
|||
|
||||
private void executeBatch(List<SchemaStatement> list) {
|
||||
|
||||
list.forEach(
|
||||
s -> {
|
||||
list.forEach(s -> {
|
||||
sessionOps.execute(s, true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -18,14 +18,16 @@ package net.helenus.core;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.support.Either;
|
||||
|
||||
public interface UnitOfWork<X extends Exception> extends AutoCloseable {
|
||||
|
||||
/**
|
||||
* Marks the beginning of a transactional section of work. Will write a record to the shared
|
||||
* write-ahead log.
|
||||
* Marks the beginning of a transactional section of work. Will write a record
|
||||
* to the shared write-ahead log.
|
||||
*
|
||||
* @return the handle used to commit or abort the work.
|
||||
*/
|
||||
|
@ -34,16 +36,19 @@ public interface UnitOfWork<X extends Exception> extends AutoCloseable {
|
|||
void addNestedUnitOfWork(UnitOfWork<X> uow);
|
||||
|
||||
/**
|
||||
* Checks to see if the work performed between calling begin and now can be committed or not.
|
||||
* Checks to see if the work performed between calling begin and now can be
|
||||
* committed or not.
|
||||
*
|
||||
* @return a function from which to chain work that only happens when commit is successful
|
||||
* @throws X when the work overlaps with other concurrent writers.
|
||||
* @return a function from which to chain work that only happens when commit is
|
||||
* successful
|
||||
* @throws X
|
||||
* when the work overlaps with other concurrent writers.
|
||||
*/
|
||||
PostCommitFunction<Void, Void> commit() throws X;
|
||||
|
||||
/**
|
||||
* Explicitly abort the work within this unit of work. Any nested aborted unit of work will
|
||||
* trigger the entire unit of work to commit.
|
||||
* Explicitly abort the work within this unit of work. Any nested aborted unit
|
||||
* of work will trigger the entire unit of work to commit.
|
||||
*/
|
||||
void abort();
|
||||
|
||||
|
@ -53,10 +58,9 @@ public interface UnitOfWork<X extends Exception> extends AutoCloseable {
|
|||
|
||||
Optional<Either<Object, Set<Object>>> cacheLookup(String key);
|
||||
|
||||
Optional<Either<Object, Set<Object>>> cacheLookupByFacet(Set<BoundFacet> facets);
|
||||
Optional<Either<Object, Set<Object>>> cacheLookupByFacet(Set<Facet> facets);
|
||||
|
||||
Optional<Either<Object, Set<Object>>> cacheLookupByStatement(String[] statementKeys);
|
||||
|
||||
void cacheUpdate(
|
||||
Either<Object, Set<Object>> pojo, String[] statementKeys, Map<String, BoundFacet> facets);
|
||||
void cacheUpdate(Either<Object, Set<Object>> pojo, String[] statementKeys, Map<String, BoundFacet> facets);
|
||||
}
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package net.helenus.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.datastax.driver.core.UserType;
|
||||
import com.datastax.driver.core.schemabuilder.SchemaStatement;
|
||||
import java.util.List;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.support.HelenusException;
|
||||
|
||||
|
@ -52,10 +54,7 @@ public final class UserTypeOperations {
|
|||
|
||||
if (!list.isEmpty()) {
|
||||
throw new HelenusException(
|
||||
"schema changed for entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ ", apply this command: "
|
||||
+ list);
|
||||
"schema changed for entity " + entity.getMappingInterface() + ", apply this command: " + list);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,8 +70,7 @@ public final class UserTypeOperations {
|
|||
|
||||
private void executeBatch(List<SchemaStatement> list) {
|
||||
|
||||
list.forEach(
|
||||
s -> {
|
||||
list.forEach(s -> {
|
||||
sessionOps.execute(s, true);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -22,4 +22,5 @@ import java.lang.annotation.Target;
|
|||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface Cacheable {}
|
||||
public @interface Cacheable {
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.lang.annotation.ElementType;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.helenus.core.ConflictingUnitOfWorkException;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -2,7 +2,7 @@ package net.helenus.core.aspect;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import net.helenus.core.annotation.Retry;
|
||||
|
||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
|
@ -13,6 +13,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import net.helenus.core.annotation.Retry;
|
||||
|
||||
@Aspect
|
||||
public class RetryAspect {
|
||||
|
||||
|
@ -37,8 +39,8 @@ public class RetryAspect {
|
|||
return tryProceeding(pjp, times, retryOn);
|
||||
}
|
||||
|
||||
private Object tryProceeding(
|
||||
ProceedingJoinPoint pjp, int times, Class<? extends Throwable>[] retryOn) throws Throwable {
|
||||
private Object tryProceeding(ProceedingJoinPoint pjp, int times, Class<? extends Throwable>[] retryOn)
|
||||
throws Throwable {
|
||||
try {
|
||||
return proceed(pjp);
|
||||
} catch (Throwable throwable) {
|
||||
|
|
|
@ -17,9 +17,10 @@ package net.helenus.core.cache;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
public class BoundFacet {
|
||||
public class BoundFacet extends Facet {
|
||||
private final Map<HelenusProperty, Object> properties;
|
||||
|
||||
BoundFacet(Map<HelenusProperty, Object> properties) {
|
||||
|
@ -27,12 +28,7 @@ public class BoundFacet {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return String.join(
|
||||
";",
|
||||
properties
|
||||
.keySet()
|
||||
.stream()
|
||||
.map(key -> properties.get(key).toString())
|
||||
.collect(Collectors.toSet()));
|
||||
return String.join(";",
|
||||
properties.keySet().stream().map(key -> properties.get(key).toString()).collect(Collectors.toSet()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
public class EntityIdentifyingFacet extends Facet {
|
||||
|
|
35
src/main/java/net/helenus/core/cache/Facet.java
vendored
35
src/main/java/net/helenus/core/cache/Facet.java
vendored
|
@ -1,20 +1,23 @@
|
|||
package net.helenus.core.cache;
|
||||
|
||||
public class Facet {}
|
||||
public class Facet {
|
||||
}
|
||||
/*
|
||||
|
||||
An Entity is identifiable via one or more Facets
|
||||
|
||||
A Facet is is a set of Properties and bound Facets
|
||||
|
||||
An Entity will have it's Keyspace, Table and Schema Version Facets bound.
|
||||
|
||||
A property may also have a TTL or write time bound.
|
||||
|
||||
The cache contains key->value mappings of merkel-hash -> Entity or Set<Entity>
|
||||
The only way a Set<Entity> is put into the cache is with a key = hash([Entity's bound Facets, hash(filter clause from SELECT)])
|
||||
|
||||
REMEMBER to update the cache on build() for all impacted facets, delete existing keys and add new keys
|
||||
|
||||
|
||||
*
|
||||
* An Entity is identifiable via one or more Facets
|
||||
*
|
||||
* A Facet is is a set of Properties and bound Facets
|
||||
*
|
||||
* An Entity will have it's Keyspace, Table and Schema Version Facets bound.
|
||||
*
|
||||
* A property may also have a TTL or write time bound.
|
||||
*
|
||||
* The cache contains key->value mappings of merkel-hash -> Entity or
|
||||
* Set<Entity> The only way a Set<Entity> is put into the cache is with a key =
|
||||
* hash([Entity's bound Facets, hash(filter clause from SELECT)])
|
||||
*
|
||||
* REMEMBER to update the cache on build() for all impacted facets, delete
|
||||
* existing keys and add new keys
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -17,10 +17,12 @@ package net.helenus.core.operation;
|
|||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.helenus.core.*;
|
||||
|
||||
public abstract class AbstractFilterOperation<E, O extends AbstractFilterOperation<E, O>>
|
||||
extends AbstractOperation<E, O> {
|
||||
extends
|
||||
AbstractOperation<E, O> {
|
||||
|
||||
protected List<Filter<?>> filters = null;
|
||||
protected List<Filter<?>> ifFilters = null;
|
||||
|
|
|
@ -19,12 +19,13 @@ import java.util.LinkedHashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.*;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
public abstract class AbstractFilterOptionalOperation<
|
||||
E, O extends AbstractFilterOptionalOperation<E, O>>
|
||||
extends AbstractOptionalOperation<E, O> {
|
||||
public abstract class AbstractFilterOptionalOperation<E, O extends AbstractFilterOptionalOperation<E, O>>
|
||||
extends
|
||||
AbstractOptionalOperation<E, O> {
|
||||
|
||||
protected Map<HelenusProperty, Filter<?>> filters = null;
|
||||
protected List<Filter<?>> ifFilters = null;
|
||||
|
|
|
@ -19,12 +19,13 @@ import java.util.LinkedHashMap;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.*;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
public abstract class AbstractFilterStreamOperation<
|
||||
E, O extends AbstractFilterStreamOperation<E, O>>
|
||||
extends AbstractStreamOperation<E, O> {
|
||||
public abstract class AbstractFilterStreamOperation<E, O extends AbstractFilterStreamOperation<E, O>>
|
||||
extends
|
||||
AbstractStreamOperation<E, O> {
|
||||
|
||||
protected Map<HelenusProperty, Filter<?>> filters = null;
|
||||
protected List<Filter<?>> ifFilters = null;
|
||||
|
|
|
@ -15,16 +15,21 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
|
||||
public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
||||
extends AbstractStatementOperation<E, O> {
|
||||
public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>> extends AbstractStatementOperation<E, O> {
|
||||
|
||||
public AbstractOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
}
|
||||
|
||||
public abstract E transform(ResultSet resultSet);
|
||||
|
||||
|
@ -32,10 +37,6 @@ public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
|||
return false;
|
||||
}
|
||||
|
||||
public AbstractOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
}
|
||||
|
||||
public PreparedOperation<E> prepare() {
|
||||
return new PreparedOperation<E>(prepareStatement(), this);
|
||||
}
|
||||
|
@ -43,15 +44,8 @@ public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
|||
public E sync() throws TimeoutException {
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
ResultSet resultSet =
|
||||
this.execute(
|
||||
sessionOps,
|
||||
null,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
false);
|
||||
ResultSet resultSet = this.execute(sessionOps, null, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, false);
|
||||
return transform(resultSet);
|
||||
} finally {
|
||||
context.stop();
|
||||
|
@ -59,19 +53,13 @@ public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
|||
}
|
||||
|
||||
public E sync(UnitOfWork uow) throws TimeoutException {
|
||||
if (uow == null) return sync();
|
||||
if (uow == null)
|
||||
return sync();
|
||||
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
ResultSet resultSet =
|
||||
execute(
|
||||
sessionOps,
|
||||
uow,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
true);
|
||||
ResultSet resultSet = execute(sessionOps, uow, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, true);
|
||||
E result = transform(resultSet);
|
||||
return result;
|
||||
} finally {
|
||||
|
@ -80,8 +68,7 @@ public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
|||
}
|
||||
|
||||
public CompletableFuture<E> async() {
|
||||
return CompletableFuture.<E>supplyAsync(
|
||||
() -> {
|
||||
return CompletableFuture.<E>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
@ -91,9 +78,9 @@ public abstract class AbstractOperation<E, O extends AbstractOperation<E, O>>
|
|||
}
|
||||
|
||||
public CompletableFuture<E> async(UnitOfWork uow) {
|
||||
if (uow == null) return async();
|
||||
return CompletableFuture.<E>supplyAsync(
|
||||
() -> {
|
||||
if (uow == null)
|
||||
return async();
|
||||
return CompletableFuture.<E>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
|
|
@ -15,23 +15,26 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOperation<E, O>>
|
||||
extends AbstractStatementOperation<E, O> {
|
||||
extends
|
||||
AbstractStatementOperation<E, O> {
|
||||
|
||||
public AbstractOptionalOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
|
@ -45,8 +48,7 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
|
||||
public ListenableFuture<PreparedOptionalOperation<E>> prepareAsync() {
|
||||
final O _this = (O) this;
|
||||
return Futures.transform(
|
||||
prepareStatementAsync(),
|
||||
return Futures.transform(prepareStatementAsync(),
|
||||
new Function<PreparedStatement, PreparedOptionalOperation<E>>() {
|
||||
@Override
|
||||
public PreparedOptionalOperation<E> apply(PreparedStatement preparedStatement) {
|
||||
|
@ -58,15 +60,8 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
public Optional<E> sync() throws TimeoutException {
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
ResultSet resultSet =
|
||||
this.execute(
|
||||
sessionOps,
|
||||
null,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
false);
|
||||
ResultSet resultSet = this.execute(sessionOps, null, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, false);
|
||||
return transform(resultSet);
|
||||
} finally {
|
||||
context.stop();
|
||||
|
@ -74,7 +69,8 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
}
|
||||
|
||||
public Optional<E> sync(UnitOfWork<?> uow) throws TimeoutException {
|
||||
if (uow == null) return sync();
|
||||
if (uow == null)
|
||||
return sync();
|
||||
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
|
@ -84,7 +80,7 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
String[] statementKeys = null;
|
||||
|
||||
if (enableCache) {
|
||||
Set<BoundFacet> facets = bindFacetValues();
|
||||
Set<Facet> facets = bindFacetValues();
|
||||
statementKeys = getQueryKeys();
|
||||
cacheResult = checkCache(uow, facets, statementKeys);
|
||||
if (cacheResult != null) {
|
||||
|
@ -94,21 +90,15 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
|
||||
if (!result.isPresent()) {
|
||||
// Formulate the query and execute it against the Cassandra cluster.
|
||||
ResultSet resultSet =
|
||||
execute(
|
||||
sessionOps,
|
||||
uow,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
true);
|
||||
ResultSet resultSet = execute(sessionOps, uow, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, true);
|
||||
|
||||
// Transform the query result set into the desired shape.
|
||||
result = transform(resultSet);
|
||||
}
|
||||
|
||||
// If we have a result, it wasn't from cache, and we're caching things then we need to put this result
|
||||
// If we have a result, it wasn't from cache, and we're caching things then we
|
||||
// need to put this result
|
||||
// into the cache for future requests to find.
|
||||
if (enableCache && cacheResult == null && result.isPresent()) {
|
||||
updateCache(uow, result.get(), getIdentifyingFacets(), statementKeys);
|
||||
|
@ -121,8 +111,7 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
}
|
||||
|
||||
public CompletableFuture<Optional<E>> async() {
|
||||
return CompletableFuture.<Optional<E>>supplyAsync(
|
||||
() -> {
|
||||
return CompletableFuture.<Optional<E>>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
@ -132,9 +121,9 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
}
|
||||
|
||||
public CompletableFuture<Optional<E>> async(UnitOfWork<?> uow) {
|
||||
if (uow == null) return async();
|
||||
return CompletableFuture.<Optional<E>>supplyAsync(
|
||||
() -> {
|
||||
if (uow == null)
|
||||
return async();
|
||||
return CompletableFuture.<Optional<E>>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
|
|
@ -15,8 +15,15 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContext;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.datastax.driver.core.ConsistencyLevel;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.RegularStatement;
|
||||
|
@ -27,24 +34,20 @@ import com.datastax.driver.core.policies.FallthroughRetryPolicy;
|
|||
import com.datastax.driver.core.policies.RetryPolicy;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContext;
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
import net.helenus.mapping.value.BeanColumnValueProvider;
|
||||
import net.helenus.support.Either;
|
||||
import net.helenus.support.HelenusException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class AbstractStatementOperation<E, O extends AbstractStatementOperation<E, O>>
|
||||
extends Operation<E> {
|
||||
public abstract class AbstractStatementOperation<E, O extends AbstractStatementOperation<E, O>> extends Operation<E> {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
protected boolean enableCache = true;
|
||||
|
@ -279,7 +282,8 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
|
||||
public String cql() {
|
||||
Statement statement = buildStatement(false);
|
||||
if (statement == null) return "";
|
||||
if (statement == null)
|
||||
return "";
|
||||
if (statement instanceof BuiltStatement) {
|
||||
BuiltStatement buildStatement = (BuiltStatement) statement;
|
||||
return buildStatement.setForceNoValues(true).getQueryString();
|
||||
|
@ -316,12 +320,12 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
throw new HelenusException("only RegularStatements can be prepared");
|
||||
}
|
||||
|
||||
protected E checkCache(UnitOfWork<?> uow, Set<BoundFacet> facets, String[] statementKeys) {
|
||||
protected E checkCache(UnitOfWork<?> uow, Set<Facet> facets, String[] statementKeys) {
|
||||
E result = null;
|
||||
Optional<Either<Object, Set<Object>>> optionalCachedResult = Optional.empty();
|
||||
|
||||
if (!facets.isEmpty()) {
|
||||
//TODO(gburd): what about select ResultSet, Tuple... etc.?
|
||||
// TODO(gburd): what about select ResultSet, Tuple... etc.?
|
||||
optionalCachedResult = uow.cacheLookupByFacet(facets);
|
||||
if (optionalCachedResult.isPresent()) {
|
||||
Either<Object, Set<Object>> eitherCachedResult = optionalCachedResult.get();
|
||||
|
@ -334,7 +338,8 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
}
|
||||
|
||||
if (result == null && statementKeys != null) {
|
||||
// Then check to see if this query happens to uniquely identify a single object in thecache.
|
||||
// Then check to see if this query happens to uniquely identify a single object
|
||||
// in thecache.
|
||||
optionalCachedResult = uow.cacheLookupByStatement(statementKeys);
|
||||
if (optionalCachedResult.isPresent()) {
|
||||
Either<Object, Set<Object>> eitherCachedResult = optionalCachedResult.get();
|
||||
|
@ -362,35 +367,23 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
return result;
|
||||
}
|
||||
|
||||
protected void updateCache(
|
||||
UnitOfWork<?> uow,
|
||||
E pojo,
|
||||
Map<String, EntityIdentifyingFacet> facetMap,
|
||||
protected void updateCache(UnitOfWork<?> uow, E pojo, Map<String, EntityIdentifyingFacet> facetMap,
|
||||
String[] statementKeys) {
|
||||
|
||||
// Insert this entity into the cache for each facet for this entity that we can fully bind.
|
||||
// Insert this entity into the cache for each facet for this entity that we can
|
||||
// fully bind.
|
||||
Map<String, BoundFacet> boundFacets = new HashMap<String, BoundFacet>();
|
||||
Map<String, Object> valueMap =
|
||||
pojo instanceof MapExportable ? ((MapExportable) pojo).toMap() : null;
|
||||
facetMap.forEach(
|
||||
(facetName, facet) -> {
|
||||
Map<String, Object> valueMap = pojo instanceof MapExportable ? ((MapExportable) pojo).toMap() : null;
|
||||
facetMap.forEach((facetName, facet) -> {
|
||||
if (!facet.isFullyBound()) {
|
||||
EntityIdentifyingFacet.Binder binder = facet.binder();
|
||||
facet
|
||||
.getProperties()
|
||||
.forEach(
|
||||
prop -> {
|
||||
facet.getProperties().forEach(prop -> {
|
||||
if (valueMap == null) {
|
||||
Object value =
|
||||
BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop, false);
|
||||
binder.setValueForProperty(
|
||||
prop, prop.getColumnName().toCql() + "==" + value.toString());
|
||||
Object value = BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop, false);
|
||||
binder.setValueForProperty(prop, prop.getColumnName().toCql() + "==" + value.toString());
|
||||
} else {
|
||||
binder.setValueForProperty(
|
||||
prop,
|
||||
prop.getColumnName().toCql()
|
||||
+ "=="
|
||||
+ valueMap.get(prop.getPropertyName()).toString());
|
||||
binder.setValueForProperty(prop,
|
||||
prop.getColumnName().toCql() + "==" + valueMap.get(prop.getPropertyName()).toString());
|
||||
}
|
||||
});
|
||||
boundFacets.put(facetName, binder.bind());
|
||||
|
|
|
@ -15,23 +15,26 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.PreparedStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperation<E, O>>
|
||||
extends AbstractStatementOperation<E, O> {
|
||||
extends
|
||||
AbstractStatementOperation<E, O> {
|
||||
|
||||
public AbstractStreamOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
|
@ -45,8 +48,7 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
|
||||
public ListenableFuture<PreparedStreamOperation<E>> prepareAsync() {
|
||||
final O _this = (O) this;
|
||||
return Futures.transform(
|
||||
prepareStatementAsync(),
|
||||
return Futures.transform(prepareStatementAsync(),
|
||||
new Function<PreparedStatement, PreparedStreamOperation<E>>() {
|
||||
@Override
|
||||
public PreparedStreamOperation<E> apply(PreparedStatement preparedStatement) {
|
||||
|
@ -58,15 +60,8 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
public Stream<E> sync() throws TimeoutException {
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
ResultSet resultSet =
|
||||
this.execute(
|
||||
sessionOps,
|
||||
null,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
false);
|
||||
ResultSet resultSet = this.execute(sessionOps, null, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, false);
|
||||
return transform(resultSet);
|
||||
} finally {
|
||||
context.stop();
|
||||
|
@ -74,7 +69,8 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
}
|
||||
|
||||
public Stream<E> sync(UnitOfWork<?> uow) throws TimeoutException {
|
||||
if (uow == null) return sync();
|
||||
if (uow == null)
|
||||
return sync();
|
||||
|
||||
final Timer.Context context = requestLatency.time();
|
||||
try {
|
||||
|
@ -83,7 +79,7 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
String[] statementKeys = null;
|
||||
|
||||
if (enableCache) {
|
||||
Set<BoundFacet> facets = bindFacetValues();
|
||||
Set<Facet> facets = bindFacetValues();
|
||||
statementKeys = getQueryKeys();
|
||||
cachedResult = checkCache(uow, facets, statementKeys);
|
||||
if (cachedResult != null) {
|
||||
|
@ -92,19 +88,13 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
}
|
||||
|
||||
if (result == null) {
|
||||
ResultSet resultSet =
|
||||
execute(
|
||||
sessionOps,
|
||||
uow,
|
||||
traceContext,
|
||||
queryExecutionTimeout,
|
||||
queryTimeoutUnits,
|
||||
showValues,
|
||||
true);
|
||||
ResultSet resultSet = execute(sessionOps, uow, traceContext, queryExecutionTimeout, queryTimeoutUnits,
|
||||
showValues, true);
|
||||
result = transform(resultSet);
|
||||
}
|
||||
|
||||
// If we have a result and we're caching then we need to put it into the cache for future requests to find.
|
||||
// If we have a result and we're caching then we need to put it into the cache
|
||||
// for future requests to find.
|
||||
if (enableCache && cachedResult != null) {
|
||||
updateCache(uow, cachedResult, getIdentifyingFacets(), statementKeys);
|
||||
}
|
||||
|
@ -116,8 +106,7 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
}
|
||||
|
||||
public CompletableFuture<Stream<E>> async() {
|
||||
return CompletableFuture.<Stream<E>>supplyAsync(
|
||||
() -> {
|
||||
return CompletableFuture.<Stream<E>>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
@ -127,9 +116,9 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
}
|
||||
|
||||
public CompletableFuture<Stream<E>> async(UnitOfWork<?> uow) {
|
||||
if (uow == null) return async();
|
||||
return CompletableFuture.<Stream<E>>supplyAsync(
|
||||
() -> {
|
||||
if (uow == null)
|
||||
return async();
|
||||
return CompletableFuture.<Stream<E>>supplyAsync(() -> {
|
||||
try {
|
||||
return sync();
|
||||
} catch (TimeoutException ex) {
|
||||
|
|
|
@ -15,19 +15,18 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class BoundOptionalOperation<E>
|
||||
extends AbstractOptionalOperation<E, BoundOptionalOperation<E>> {
|
||||
public final class BoundOptionalOperation<E> extends AbstractOptionalOperation<E, BoundOptionalOperation<E>> {
|
||||
|
||||
private final BoundStatement boundStatement;
|
||||
private final AbstractOptionalOperation<E, ?> delegate;
|
||||
|
||||
public BoundOptionalOperation(
|
||||
BoundStatement boundStatement, AbstractOptionalOperation<E, ?> operation) {
|
||||
public BoundOptionalOperation(BoundStatement boundStatement, AbstractOptionalOperation<E, ?> operation) {
|
||||
super(operation.sessionOps);
|
||||
this.boundStatement = boundStatement;
|
||||
this.delegate = operation;
|
||||
|
|
|
@ -15,21 +15,21 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.datastax.driver.core.BoundStatement;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
|
||||
public final class BoundStreamOperation<E>
|
||||
extends AbstractStreamOperation<E, BoundStreamOperation<E>> {
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public final class BoundStreamOperation<E> extends AbstractStreamOperation<E, BoundStreamOperation<E>> {
|
||||
|
||||
private final BoundStatement boundStatement;
|
||||
private final AbstractStreamOperation<E, ?> delegate;
|
||||
|
||||
public BoundStreamOperation(
|
||||
BoundStatement boundStatement, AbstractStreamOperation<E, ?> operation) {
|
||||
public BoundStreamOperation(BoundStatement boundStatement, AbstractStreamOperation<E, ?> operation) {
|
||||
super(operation.sessionOps);
|
||||
this.boundStatement = boundStatement;
|
||||
this.delegate = operation;
|
||||
|
@ -41,7 +41,7 @@ public final class BoundStreamOperation<E>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
return delegate.bindFacetValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.datastax.driver.core.querybuilder.BuiltStatement;
|
|||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.querybuilder.Select.Where;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.Filter;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
|
@ -73,11 +74,8 @@ public final class CountOperation extends AbstractFilterOperation<Long, CountOpe
|
|||
if (entity == null) {
|
||||
entity = p.getEntity();
|
||||
} else if (entity != p.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can count columns only in single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ p.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can count columns only in single entity "
|
||||
+ entity.getMappingInterface() + " or " + p.getEntity().getMappingInterface());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import com.datastax.driver.core.querybuilder.BuiltStatement;
|
|||
import com.datastax.driver.core.querybuilder.Delete;
|
||||
import com.datastax.driver.core.querybuilder.Delete.Where;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.Filter;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
|
@ -117,11 +118,8 @@ public final class DeleteOperation extends AbstractFilterOperation<ResultSet, De
|
|||
if (entity == null) {
|
||||
entity = p.getEntity();
|
||||
} else if (entity != p.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can delete rows only in single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ p.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can delete rows only in single entity "
|
||||
+ entity.getMappingInterface() + " or " + p.getEntity().getMappingInterface());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,13 +15,15 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.Getter;
|
||||
import net.helenus.core.Helenus;
|
||||
|
@ -41,8 +43,7 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
|
||||
private HelenusEntity entity;
|
||||
|
||||
private final List<Fun.Tuple2<HelenusPropertyNode, Object>> values =
|
||||
new ArrayList<Fun.Tuple2<HelenusPropertyNode, Object>>();
|
||||
private final List<Fun.Tuple2<HelenusPropertyNode, Object>> values = new ArrayList<Fun.Tuple2<HelenusPropertyNode, Object>>();
|
||||
private final T pojo;
|
||||
private final Class<?> resultType;
|
||||
private boolean ifNotExists;
|
||||
|
@ -58,8 +59,7 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
this.resultType = ResultSet.class;
|
||||
}
|
||||
|
||||
public InsertOperation(
|
||||
AbstractSessionOperations sessionOperations, Class<?> resultType, boolean ifNotExists) {
|
||||
public InsertOperation(AbstractSessionOperations sessionOperations, Class<?> resultType, boolean ifNotExists) {
|
||||
super(sessionOperations);
|
||||
|
||||
this.ifNotExists = ifNotExists;
|
||||
|
@ -67,12 +67,8 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
this.resultType = resultType;
|
||||
}
|
||||
|
||||
public InsertOperation(
|
||||
AbstractSessionOperations sessionOperations,
|
||||
HelenusEntity entity,
|
||||
T pojo,
|
||||
Set<String> mutations,
|
||||
boolean ifNotExists) {
|
||||
public InsertOperation(AbstractSessionOperations sessionOperations, HelenusEntity entity, T pojo,
|
||||
Set<String> mutations, boolean ifNotExists) {
|
||||
super(sessionOperations);
|
||||
|
||||
this.entity = entity;
|
||||
|
@ -87,11 +83,11 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
boolean addProp = false;
|
||||
|
||||
switch (prop.getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
addProp = true;
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
addProp = (keys == null || keys.contains(prop.getPropertyName()));
|
||||
}
|
||||
|
||||
|
@ -138,7 +134,8 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
|
||||
values.forEach(t -> addPropertyNode(t._1));
|
||||
|
||||
if (values.isEmpty()) return null;
|
||||
if (values.isEmpty())
|
||||
return null;
|
||||
|
||||
if (entity == null) {
|
||||
throw new HelenusMappingException("unknown entity");
|
||||
|
@ -150,8 +147,7 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
insert.ifNotExists();
|
||||
}
|
||||
|
||||
values.forEach(
|
||||
t -> {
|
||||
values.forEach(t -> {
|
||||
insert.value(t._1.getColumnName(), t._2);
|
||||
});
|
||||
|
||||
|
@ -183,16 +179,17 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
if (backingMap.containsKey(key)) {
|
||||
// Some values man need to be converted (e.g. from String to Enum). This is done
|
||||
// within the BeanColumnValueProvider below.
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getReadConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop
|
||||
.getReadConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
backingMap.put(key, converter.get().apply(backingMap.get(key)));
|
||||
}
|
||||
} else {
|
||||
// If we started this operation with an instance of this type, use values from that.
|
||||
// If we started this operation with an instance of this type, use values from
|
||||
// that.
|
||||
if (pojo != null) {
|
||||
backingMap.put(
|
||||
key, BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop, immutable));
|
||||
backingMap.put(key,
|
||||
BeanColumnValueProvider.INSTANCE.getColumnValue(pojo, -1, prop, immutable));
|
||||
} else {
|
||||
// Otherwise we'll use default values for the property type if available.
|
||||
Class<?> propType = prop.getJavaType();
|
||||
|
@ -211,7 +208,8 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
return (T) Helenus.map(iface, backingMap);
|
||||
}
|
||||
// Oddly, this insert didn't change any value so simply return the pojo.
|
||||
// TODO(gburd): this pojo is the result of a Draft.build() call which will not preserve object identity (o1 == o2), ... fix me.
|
||||
// TODO(gburd): this pojo is the result of a Draft.build() call which will not
|
||||
// preserve object identity (o1 == o2), ... fix me.
|
||||
return (T) pojo;
|
||||
}
|
||||
return (T) resultSet;
|
||||
|
@ -233,27 +231,22 @@ public final class InsertOperation<T> extends AbstractOperation<T, InsertOperati
|
|||
if (entity == null) {
|
||||
entity = p.getEntity();
|
||||
} else if (entity != p.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can insert only single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ p.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can insert only single entity " + entity.getMappingInterface()
|
||||
+ " or " + p.getEntity().getMappingInterface());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getQueryKeys() {
|
||||
List<String> keys = new ArrayList<>(values.size());
|
||||
values.forEach(
|
||||
t -> {
|
||||
values.forEach(t -> {
|
||||
HelenusPropertyNode prop = t._1;
|
||||
switch (prop.getProperty().getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
keys.add(
|
||||
entity.getName().toCql() + '.' + prop.getColumnName() + "==" + t._2.toString());
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
keys.add(entity.getName().toCql() + '.' + prop.getColumnName() + "==" + t._2.toString());
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
|
@ -15,23 +15,25 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContext;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import com.codahale.metrics.Meter;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import com.codahale.metrics.Timer;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.ResultSetFuture;
|
||||
import com.datastax.driver.core.Statement;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import brave.Span;
|
||||
import brave.Tracer;
|
||||
import brave.propagation.TraceContext;
|
||||
import net.helenus.core.AbstractSessionOperations;
|
||||
import net.helenus.core.UnitOfWork;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public abstract class Operation<E> {
|
||||
|
||||
|
@ -48,17 +50,11 @@ public abstract class Operation<E> {
|
|||
this.requestLatency = metrics.timer("net.helenus.request-latency");
|
||||
}
|
||||
|
||||
public ResultSet execute(
|
||||
AbstractSessionOperations session,
|
||||
UnitOfWork uow,
|
||||
TraceContext traceContext,
|
||||
long timeout,
|
||||
TimeUnit units,
|
||||
boolean showValues,
|
||||
boolean cached)
|
||||
throws TimeoutException {
|
||||
public ResultSet execute(AbstractSessionOperations session, UnitOfWork uow, TraceContext traceContext, long timeout,
|
||||
TimeUnit units, boolean showValues, boolean cached) throws TimeoutException {
|
||||
|
||||
// Start recording in a Zipkin sub-span our execution time to perform this operation.
|
||||
// Start recording in a Zipkin sub-span our execution time to perform this
|
||||
// operation.
|
||||
Tracer tracer = session.getZipkinTracer();
|
||||
Span span = null;
|
||||
if (tracer != null && traceContext != null) {
|
||||
|
@ -99,7 +95,7 @@ public abstract class Operation<E> {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ public final class PreparedOptionalOperation<E> {
|
|||
private final PreparedStatement preparedStatement;
|
||||
private final AbstractOptionalOperation<E, ?> operation;
|
||||
|
||||
public PreparedOptionalOperation(
|
||||
PreparedStatement statement, AbstractOptionalOperation<E, ?> operation) {
|
||||
public PreparedOptionalOperation(PreparedStatement statement, AbstractOptionalOperation<E, ?> operation) {
|
||||
this.preparedStatement = statement;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ public final class PreparedStreamOperation<E> {
|
|||
private final PreparedStatement preparedStatement;
|
||||
private final AbstractStreamOperation<E, ?> operation;
|
||||
|
||||
public PreparedStreamOperation(
|
||||
PreparedStatement statement, AbstractStreamOperation<E, ?> operation) {
|
||||
public PreparedStreamOperation(PreparedStatement statement, AbstractStreamOperation<E, ?> operation) {
|
||||
this.preparedStatement = statement;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
|
|
@ -15,17 +15,18 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
|
||||
public final class SelectFirstOperation<E>
|
||||
extends AbstractFilterOptionalOperation<E, SelectFirstOperation<E>> {
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public final class SelectFirstOperation<E> extends AbstractFilterOptionalOperation<E, SelectFirstOperation<E>> {
|
||||
|
||||
private final SelectOperation<E> delegate;
|
||||
|
||||
|
@ -57,7 +58,7 @@ public final class SelectFirstOperation<E>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
return delegate.bindFacetValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,15 +15,18 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public final class SelectFirstTransformingOperation<R, E>
|
||||
extends AbstractFilterOptionalOperation<R, SelectFirstTransformingOperation<R, E>> {
|
||||
extends
|
||||
AbstractFilterOptionalOperation<R, SelectFirstTransformingOperation<R, E>> {
|
||||
|
||||
private final SelectOperation<E> delegate;
|
||||
private final Function<E, R> fn;
|
||||
|
@ -43,7 +46,7 @@ public final class SelectFirstTransformingOperation<R, E>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
return delegate.bindFacetValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
|
@ -24,13 +29,10 @@ import com.datastax.driver.core.querybuilder.Select;
|
|||
import com.datastax.driver.core.querybuilder.Select.Selection;
|
||||
import com.datastax.driver.core.querybuilder.Select.Where;
|
||||
import com.google.common.collect.Iterables;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import net.helenus.core.*;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.MappingUtil;
|
||||
|
@ -42,9 +44,8 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, SelectOperation<E>> {
|
||||
|
||||
protected Function<Row, E> rowMapper = null;
|
||||
protected final List<HelenusPropertyNode> props = new ArrayList<HelenusPropertyNode>();
|
||||
|
||||
protected Function<Row, E> rowMapper = null;
|
||||
protected List<Ordering> ordering = null;
|
||||
protected Integer limit = null;
|
||||
protected boolean allowFiltering = false;
|
||||
|
@ -54,8 +55,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
public SelectOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
|
||||
this.rowMapper =
|
||||
new Function<Row, E>() {
|
||||
this.rowMapper = new Function<Row, E>() {
|
||||
|
||||
@Override
|
||||
public E apply(Row source) {
|
||||
|
@ -78,31 +78,21 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
|
||||
super(sessionOperations);
|
||||
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
.forEach(p -> this.props.add(p));
|
||||
}
|
||||
|
||||
public SelectOperation(
|
||||
AbstractSessionOperations sessionOperations,
|
||||
HelenusEntity entity,
|
||||
public SelectOperation(AbstractSessionOperations sessionOperations, HelenusEntity entity,
|
||||
Function<Row, E> rowMapper) {
|
||||
|
||||
super(sessionOperations);
|
||||
this.rowMapper = rowMapper;
|
||||
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
.forEach(p -> this.props.add(p));
|
||||
}
|
||||
|
||||
public SelectOperation(
|
||||
AbstractSessionOperations sessionOperations,
|
||||
Function<Row, E> rowMapper,
|
||||
public SelectOperation(AbstractSessionOperations sessionOperations, Function<Row, E> rowMapper,
|
||||
HelenusPropertyNode... props) {
|
||||
|
||||
super(sessionOperations);
|
||||
|
@ -119,11 +109,8 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
if (entity == null) {
|
||||
entity = prop.getEntity();
|
||||
} else if (entity != prop.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can count records only from a single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ prop.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can count records only from a single entity "
|
||||
+ entity.getMappingInterface() + " or " + prop.getEntity().getMappingInterface());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,10 +122,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
HelenusEntity entity = Helenus.entity(materializedViewClass);
|
||||
this.alternateTableName = entity.getName().toCql();
|
||||
this.props.clear();
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
.map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
|
||||
.forEach(p -> this.props.add(p));
|
||||
return this;
|
||||
}
|
||||
|
@ -156,9 +140,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
|
||||
this.rowMapper = null;
|
||||
|
||||
return new SelectTransformingOperation<R, E>(
|
||||
this,
|
||||
(r) -> {
|
||||
return new SelectTransformingOperation<R, E>(this, (r) -> {
|
||||
Map<String, Object> map = new ValueProviderMap(r, sessionOps.getValueProvider(), entity);
|
||||
return (R) Helenus.map(entityClass, map);
|
||||
});
|
||||
|
@ -194,18 +176,6 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getQueryKeys() {
|
||||
int i = 0;
|
||||
String[] keys = new String[filters.size()];
|
||||
HelenusEntity entity = props.get(0).getEntity();
|
||||
String entityName = entity.getName().toCql();
|
||||
for (Filter<?> filter : filters.values()) {
|
||||
keys[i++] = entityName + '.' + filter.toString();
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, EntityIdentifyingFacet> getIdentifyingFacets() {
|
||||
HelenusEntity entity = props.get(0).getEntity();
|
||||
|
@ -213,23 +183,19 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
HelenusEntity entity = props.get(0).getEntity();
|
||||
Set<BoundFacet> boundFacets = new HashSet<BoundFacet>();
|
||||
Set<Facet> boundFacets = new HashSet<Facet>();
|
||||
// Check to see if this select statement has enough information to build one or
|
||||
// more identifying facets.
|
||||
entity
|
||||
.getIdentifyingFacets()
|
||||
.forEach(
|
||||
(facetName, facet) -> {
|
||||
entity.getIdentifyingFacets().forEach((facetName, facet) -> {
|
||||
EntityIdentifyingFacet.Binder binder = facet.binder();
|
||||
facet
|
||||
.getProperties()
|
||||
.forEach(
|
||||
prop -> {
|
||||
facet.getProperties().forEach(prop -> {
|
||||
Filter filter = filters.get(prop);
|
||||
if (filter != null) {
|
||||
binder.setValueForProperty(prop, filter.toString());
|
||||
} else if (facetName.equals("*")) {
|
||||
binder.setValueForProperty(prop, "");
|
||||
}
|
||||
});
|
||||
if (binder.isFullyBound()) {
|
||||
|
@ -256,19 +222,16 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
if (entity == null) {
|
||||
entity = prop.getEntity();
|
||||
} else if (entity != prop.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can select columns only from a single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ prop.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can select columns only from a single entity "
|
||||
+ entity.getMappingInterface() + " or " + prop.getEntity().getMappingInterface());
|
||||
}
|
||||
|
||||
if (cached) {
|
||||
switch (prop.getProperty().getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
if (entity.equals(prop.getEntity())) {
|
||||
if (prop.getNext().isPresent()) {
|
||||
columnName = Iterables.getLast(prop).getColumnName().toCql(true);
|
||||
|
@ -308,8 +271,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
}
|
||||
|
||||
if (ifFilters != null && !ifFilters.isEmpty()) {
|
||||
logger.error(
|
||||
"onlyIf conditions " + ifFilters + " would be ignored in the statement " + select);
|
||||
logger.error("onlyIf conditions " + ifFilters + " would be ignored in the statement " + select);
|
||||
}
|
||||
|
||||
if (allowFiltering) {
|
||||
|
@ -323,14 +285,12 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
@Override
|
||||
public Stream<E> transform(ResultSet resultSet) {
|
||||
if (rowMapper != null) {
|
||||
return StreamSupport.stream(
|
||||
Spliterators.spliteratorUnknownSize(resultSet.iterator(), Spliterator.ORDERED), false)
|
||||
return StreamSupport
|
||||
.stream(Spliterators.spliteratorUnknownSize(resultSet.iterator(), Spliterator.ORDERED), false)
|
||||
.map(rowMapper);
|
||||
} else {
|
||||
return (Stream<E>)
|
||||
StreamSupport.stream(
|
||||
Spliterators.spliteratorUnknownSize(resultSet.iterator(), Spliterator.ORDERED),
|
||||
false);
|
||||
return (Stream<E>) StreamSupport
|
||||
.stream(Spliterators.spliteratorUnknownSize(resultSet.iterator(), Spliterator.ORDERED), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -15,17 +15,20 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
import net.helenus.core.cache.BoundFacet;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.core.cache.Facet;
|
||||
|
||||
public final class SelectTransformingOperation<R, E>
|
||||
extends AbstractFilterStreamOperation<R, SelectTransformingOperation<R, E>> {
|
||||
extends
|
||||
AbstractFilterStreamOperation<R, SelectTransformingOperation<R, E>> {
|
||||
|
||||
private final SelectOperation<E> delegate;
|
||||
private final Function<E, R> fn;
|
||||
|
@ -45,7 +48,7 @@ public final class SelectTransformingOperation<R, E>
|
|||
}
|
||||
|
||||
@Override
|
||||
public Set<BoundFacet> bindFacetValues() {
|
||||
public Set<Facet> bindFacetValues() {
|
||||
return delegate.bindFacetValues();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,14 +15,16 @@
|
|||
*/
|
||||
package net.helenus.core.operation;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.querybuilder.Assignment;
|
||||
import com.datastax.driver.core.querybuilder.BuiltStatement;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Update;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.*;
|
||||
import net.helenus.core.reflect.HelenusPropertyNode;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
|
@ -48,15 +50,13 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
this.draftMap = null;
|
||||
}
|
||||
|
||||
public UpdateOperation(
|
||||
AbstractSessionOperations sessionOperations, AbstractEntityDraft<E> draft) {
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, AbstractEntityDraft<E> draft) {
|
||||
super(sessionOperations);
|
||||
this.draft = draft;
|
||||
this.draftMap = draft.toMap();
|
||||
}
|
||||
|
||||
public UpdateOperation(
|
||||
AbstractSessionOperations sessionOperations, HelenusPropertyNode p, Object v) {
|
||||
public UpdateOperation(AbstractSessionOperations sessionOperations, HelenusPropertyNode p, Object v) {
|
||||
super(sessionOperations);
|
||||
this.draft = null;
|
||||
this.draftMap = null;
|
||||
|
@ -298,8 +298,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
|
||||
Object valueObj = value;
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
List convertedList = (List) converter.get().apply(Immutables.listOf(value));
|
||||
valueObj = convertedList.get(0);
|
||||
|
@ -314,8 +313,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
|
||||
List valueObj = value;
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
valueObj = (List) converter.get().apply(value);
|
||||
}
|
||||
|
@ -420,8 +418,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusProperty prop = p.getProperty();
|
||||
Object valueObj = value;
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
Set convertedSet = (Set) converter.get().apply(Immutables.setOf(value));
|
||||
valueObj = convertedSet.iterator().next();
|
||||
|
@ -435,8 +432,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusProperty prop = p.getProperty();
|
||||
Set valueObj = value;
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
valueObj = (Set) converter.get().apply(value);
|
||||
}
|
||||
|
@ -460,11 +456,10 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(mapGetter);
|
||||
HelenusProperty prop = p.getProperty();
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
Map<Object, Object> convertedMap =
|
||||
(Map<Object, Object>) converter.get().apply(Immutables.mapOf(key, value));
|
||||
Map<Object, Object> convertedMap = (Map<Object, Object>) converter.get()
|
||||
.apply(Immutables.mapOf(key, value));
|
||||
for (Map.Entry<Object, Object> e : convertedMap.entrySet()) {
|
||||
assignments.add(QueryBuilder.put(p.getColumnName(), e.getKey(), e.getValue()));
|
||||
}
|
||||
|
@ -489,8 +484,7 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
HelenusPropertyNode p = MappingUtil.resolveMappingProperty(mapGetter);
|
||||
HelenusProperty prop = p.getProperty();
|
||||
|
||||
Optional<Function<Object, Object>> converter =
|
||||
prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
Optional<Function<Object, Object>> converter = prop.getWriteConverter(sessionOps.getSessionRepository());
|
||||
if (converter.isPresent()) {
|
||||
Map convertedMap = (Map) converter.get().apply(map);
|
||||
assignments.add(QueryBuilder.putAll(p.getColumnName(), convertedMap));
|
||||
|
@ -570,11 +564,8 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
if (entity == null) {
|
||||
entity = p.getEntity();
|
||||
} else if (entity != p.getEntity()) {
|
||||
throw new HelenusMappingException(
|
||||
"you can update columns only in single entity "
|
||||
+ entity.getMappingInterface()
|
||||
+ " or "
|
||||
+ p.getEntity().getMappingInterface());
|
||||
throw new HelenusMappingException("you can update columns only in single entity "
|
||||
+ entity.getMappingInterface() + " or " + p.getEntity().getMappingInterface());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -584,7 +575,8 @@ public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateO
|
|||
return sync();
|
||||
}
|
||||
E result = super.sync(uow);
|
||||
// TODO(gburd): Only drafted entity objects are updated in the cache at this time.
|
||||
// TODO(gburd): Only drafted entity objects are updated in the cache at this
|
||||
// time.
|
||||
if (draft != null) {
|
||||
updateCache(uow, result, getIdentifyingFacets(), getQueryKeys());
|
||||
}
|
||||
|
|
|
@ -19,20 +19,13 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
public enum DefaultPrimitiveTypes {
|
||||
BOOLEAN(boolean.class, false),
|
||||
BYTE(byte.class, (byte) 0x0),
|
||||
CHAR(char.class, (char) 0x0),
|
||||
SHORT(short.class, (short) 0),
|
||||
INT(int.class, 0),
|
||||
LONG(long.class, 0L),
|
||||
FLOAT(float.class, 0.0f),
|
||||
DOUBLE(double.class, 0.0);
|
||||
BOOLEAN(boolean.class, false), BYTE(byte.class, (byte) 0x0), CHAR(char.class, (char) 0x0), SHORT(short.class,
|
||||
(short) 0), INT(int.class, 0), LONG(long.class, 0L), FLOAT(float.class, 0.0f), DOUBLE(double.class, 0.0);
|
||||
|
||||
private final Class<?> primitiveClass;
|
||||
private final Object defaultValue;
|
||||
|
||||
private static final Map<Class<?>, DefaultPrimitiveTypes> map =
|
||||
new HashMap<Class<?>, DefaultPrimitiveTypes>();
|
||||
private static final Map<Class<?>, DefaultPrimitiveTypes> map = new HashMap<Class<?>, DefaultPrimitiveTypes>();
|
||||
|
||||
static {
|
||||
for (DefaultPrimitiveTypes type : DefaultPrimitiveTypes.values()) {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package net.helenus.core.reflect;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
|
||||
public interface DslExportable {
|
||||
|
|
|
@ -15,13 +15,15 @@
|
|||
*/
|
||||
package net.helenus.core.reflect;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusMappingEntity;
|
||||
|
@ -47,10 +49,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
private final Map<Method, Object> udtMap = new HashMap<Method, Object>();
|
||||
private final Map<Method, Object> tupleMap = new HashMap<Method, Object>();
|
||||
|
||||
public DslInvocationHandler(
|
||||
Class<E> iface,
|
||||
ClassLoader classLoader,
|
||||
Optional<HelenusPropertyNode> parent,
|
||||
public DslInvocationHandler(Class<E> iface, ClassLoader classLoader, Optional<HelenusPropertyNode> parent,
|
||||
Metadata metadata) {
|
||||
|
||||
this.metadata = metadata;
|
||||
|
@ -78,11 +77,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
|
||||
if (type instanceof UDTDataType && !UDTValue.class.isAssignableFrom(javaType)) {
|
||||
|
||||
Object childDsl =
|
||||
Helenus.dsl(
|
||||
javaType,
|
||||
classLoader,
|
||||
Optional.of(new HelenusPropertyNode(prop, parent)),
|
||||
Object childDsl = Helenus.dsl(javaType, classLoader, Optional.of(new HelenusPropertyNode(prop, parent)),
|
||||
metadata);
|
||||
|
||||
udtMap.put(prop.getGetterMethod(), childDsl);
|
||||
|
@ -91,15 +86,10 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
if (type instanceof DTDataType) {
|
||||
DTDataType dataType = (DTDataType) type;
|
||||
|
||||
if (dataType.getDataType() instanceof TupleType
|
||||
&& !TupleValue.class.isAssignableFrom(javaType)) {
|
||||
if (dataType.getDataType() instanceof TupleType && !TupleValue.class.isAssignableFrom(javaType)) {
|
||||
|
||||
Object childDsl =
|
||||
Helenus.dsl(
|
||||
javaType,
|
||||
classLoader,
|
||||
Optional.of(new HelenusPropertyNode(prop, parent)),
|
||||
metadata);
|
||||
Object childDsl = Helenus.dsl(javaType, classLoader,
|
||||
Optional.of(new HelenusPropertyNode(prop, parent)), metadata);
|
||||
|
||||
tupleMap.put(prop.getGetterMethod(), childDsl);
|
||||
}
|
||||
|
@ -126,9 +116,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (DslExportable.SET_METADATA_METHOD.equals(methodName)
|
||||
&& args.length == 1
|
||||
&& args[0] instanceof Metadata) {
|
||||
if (DslExportable.SET_METADATA_METHOD.equals(methodName) && args.length == 1 && args[0] instanceof Metadata) {
|
||||
if (metadata == null) {
|
||||
this.setCassandraMetadataForHelenusSession((Metadata) args[0]);
|
||||
}
|
||||
|
@ -182,7 +170,7 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
DataType dt = dataType.getDataType();
|
||||
|
||||
switch (dt.getName()) {
|
||||
case TUPLE:
|
||||
case TUPLE :
|
||||
Object childDsl = tupleMap.get(method);
|
||||
|
||||
if (childDsl != null) {
|
||||
|
@ -191,16 +179,16 @@ public class DslInvocationHandler<E> implements InvocationHandler {
|
|||
|
||||
break;
|
||||
|
||||
case SET:
|
||||
case SET :
|
||||
return new SetDsl(new HelenusPropertyNode(prop, parent));
|
||||
|
||||
case LIST:
|
||||
case LIST :
|
||||
return new ListDsl(new HelenusPropertyNode(prop, parent));
|
||||
|
||||
case MAP:
|
||||
case MAP :
|
||||
return new MapDsl(new HelenusPropertyNode(prop, parent));
|
||||
|
||||
default:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,9 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.*;
|
||||
import net.helenus.mapping.type.AbstractDataType;
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.core.reflect;
|
|||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package net.helenus.core.reflect;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.support.DslPropertyException;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Collection;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.support.DslPropertyException;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.Proxy;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.mapping.annotation.Transient;
|
||||
import net.helenus.support.HelenusException;
|
||||
|
@ -39,23 +40,22 @@ public class MapperInvocationHandler<E> implements InvocationHandler, Serializab
|
|||
}
|
||||
|
||||
private Object invokeDefault(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
// NOTE: This is reflection magic to invoke (non-recursively) a default method implemented on an interface
|
||||
// that we've proxied (in ReflectionDslInstantiator). I found the answer in this article.
|
||||
// NOTE: This is reflection magic to invoke (non-recursively) a default method
|
||||
// implemented on an interface
|
||||
// that we've proxied (in ReflectionDslInstantiator). I found the answer in this
|
||||
// article.
|
||||
// https://zeroturnaround.com/rebellabs/recognize-and-conquer-java-proxies-default-methods-and-method-handles/
|
||||
|
||||
// First, we need an instance of a private inner-class found in MethodHandles.
|
||||
Constructor<MethodHandles.Lookup> constructor =
|
||||
MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class);
|
||||
Constructor<MethodHandles.Lookup> constructor = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class,
|
||||
int.class);
|
||||
constructor.setAccessible(true);
|
||||
|
||||
// Now we need to lookup and invoke special the default method on the interface class.
|
||||
// Now we need to lookup and invoke special the default method on the interface
|
||||
// class.
|
||||
final Class<?> declaringClass = method.getDeclaringClass();
|
||||
Object result =
|
||||
constructor
|
||||
.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE)
|
||||
.unreflectSpecial(method, declaringClass)
|
||||
.bindTo(proxy)
|
||||
.invokeWithArguments(args);
|
||||
Object result = constructor.newInstance(declaringClass, MethodHandles.Lookup.PRIVATE)
|
||||
.unreflectSpecial(method, declaringClass).bindTo(proxy).invokeWithArguments(args);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -111,13 +111,15 @@ public class MapperInvocationHandler<E> implements InvocationHandler, Serializab
|
|||
|
||||
if (value == null) {
|
||||
|
||||
// Default implementations of non-Transient methods in entities are the default value when the
|
||||
// Default implementations of non-Transient methods in entities are the default
|
||||
// value when the
|
||||
// map contains 'null'.
|
||||
if (method.isDefault()) {
|
||||
return invokeDefault(proxy, method, args);
|
||||
}
|
||||
|
||||
// Otherwise, if the return type of the method is a primitive Java type then we'll return the standard
|
||||
// Otherwise, if the return type of the method is a primitive Java type then
|
||||
// we'll return the standard
|
||||
// default values to avoid a NPE in user code.
|
||||
if (returnType.isPrimitive()) {
|
||||
DefaultPrimitiveTypes type = DefaultPrimitiveTypes.lookup(returnType);
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
*/
|
||||
package net.helenus.core.reflect;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
|
||||
import net.helenus.core.DslInstantiator;
|
||||
|
||||
public enum ReflectionDslInstantiator implements DslInstantiator {
|
||||
|
@ -25,15 +27,10 @@ public enum ReflectionDslInstantiator implements DslInstantiator {
|
|||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <E> E instantiate(
|
||||
Class<E> iface,
|
||||
ClassLoader classLoader,
|
||||
Optional<HelenusPropertyNode> parent,
|
||||
public <E> E instantiate(Class<E> iface, ClassLoader classLoader, Optional<HelenusPropertyNode> parent,
|
||||
Metadata metadata) {
|
||||
DslInvocationHandler<E> handler =
|
||||
new DslInvocationHandler<E>(iface, classLoader, parent, metadata);
|
||||
E proxy =
|
||||
(E) Proxy.newProxyInstance(classLoader, new Class[] {iface, DslExportable.class}, handler);
|
||||
DslInvocationHandler<E> handler = new DslInvocationHandler<E>(iface, classLoader, parent, metadata);
|
||||
E proxy = (E) Proxy.newProxyInstance(classLoader, new Class[]{iface, DslExportable.class}, handler);
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,8 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class ReflectionInstantiator {
|
||||
|
||||
private ReflectionInstantiator() {}
|
||||
private ReflectionInstantiator() {
|
||||
}
|
||||
|
||||
public static <T> T instantiateClass(Class<T> clazz) {
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.core.reflect;
|
|||
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.MapperInstantiator;
|
||||
|
||||
public enum ReflectionMapperInstantiator implements MapperInstantiator {
|
||||
|
@ -27,8 +28,7 @@ public enum ReflectionMapperInstantiator implements MapperInstantiator {
|
|||
public <E> E instantiate(Class<E> iface, Map<String, Object> src, ClassLoader classLoader) {
|
||||
|
||||
MapperInvocationHandler<E> handler = new MapperInvocationHandler<E>(iface, src);
|
||||
E proxy =
|
||||
(E) Proxy.newProxyInstance(classLoader, new Class[] {iface, MapExportable.class}, handler);
|
||||
E proxy = (E) Proxy.newProxyInstance(classLoader, new Class[]{iface, MapExportable.class}, handler);
|
||||
return proxy;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ package net.helenus.core.reflect;
|
|||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
||||
public final class SetDsl<V> implements Set<V> {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package net.helenus.mapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.helenus.mapping.annotation.ClusteringColumn;
|
||||
import net.helenus.mapping.annotation.Column;
|
||||
import net.helenus.mapping.annotation.PartitionKey;
|
||||
|
@ -102,21 +103,13 @@ public final class ColumnInformation {
|
|||
private void ensureSingleColumnType(ColumnType columnTypeLocal, Method getter) {
|
||||
|
||||
if (columnTypeLocal != ColumnType.COLUMN) {
|
||||
throw new HelenusMappingException(
|
||||
"property can be annotated only by a single column type " + getter);
|
||||
throw new HelenusMappingException("property can be annotated only by a single column type " + getter);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ColumnInformation [columnName="
|
||||
+ columnName
|
||||
+ ", columnType="
|
||||
+ columnType
|
||||
+ ", ordinal="
|
||||
+ ordinal
|
||||
+ ", ordering="
|
||||
+ ordering
|
||||
+ "]";
|
||||
return "ColumnInformation [columnName=" + columnName + ", columnType=" + columnType + ", ordinal=" + ordinal
|
||||
+ ", ordering=" + ordering + "]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,5 @@
|
|||
package net.helenus.mapping;
|
||||
|
||||
public enum ColumnType {
|
||||
PARTITION_KEY,
|
||||
CLUSTERING_COLUMN,
|
||||
STATIC_COLUMN,
|
||||
COLUMN;
|
||||
PARTITION_KEY, CLUSTERING_COLUMN, STATIC_COLUMN, COLUMN;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.mapping;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
|
||||
public interface HelenusEntity {
|
||||
|
|
|
@ -16,8 +16,5 @@
|
|||
package net.helenus.mapping;
|
||||
|
||||
public enum HelenusEntityType {
|
||||
TABLE,
|
||||
VIEW,
|
||||
TUPLE,
|
||||
UDT;
|
||||
TABLE, VIEW, TUPLE, UDT;
|
||||
}
|
||||
|
|
|
@ -15,18 +15,22 @@
|
|||
*/
|
||||
package net.helenus.mapping;
|
||||
|
||||
import com.datastax.driver.core.*;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
|
||||
import com.datastax.driver.core.DefaultMetadata;
|
||||
import com.datastax.driver.core.Metadata;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import net.helenus.config.HelenusSettings;
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.core.annotation.Cacheable;
|
||||
import net.helenus.core.cache.EntityIdentifyingFacet;
|
||||
import net.helenus.mapping.annotation.*;
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
import org.apache.commons.lang3.ClassUtils;
|
||||
|
||||
public final class HelenusMappingEntity implements HelenusEntity {
|
||||
|
||||
|
@ -63,8 +67,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
}
|
||||
|
||||
for (Class<?> c : ClassUtils.getAllInterfaces(iface)) {
|
||||
if (c.getDeclaredAnnotation(Table.class) != null
|
||||
|| c.getDeclaredAnnotation(InheritedTable.class) != null) {
|
||||
if (c.getDeclaredAnnotation(Table.class) != null || c.getDeclaredAnnotation(InheritedTable.class) != null) {
|
||||
for (Method m : c.getDeclaredMethods()) {
|
||||
Method o = methods.get(m.getName());
|
||||
if (o != null) {
|
||||
|
@ -110,20 +113,18 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
cacheable = (null != iface.getDeclaredAnnotation(Cacheable.class));
|
||||
|
||||
ImmutableMap.Builder<String, EntityIdentifyingFacet> allFacetsBuilder = ImmutableMap.builder();
|
||||
ImmutableMap.Builder<String, EntityIdentifyingFacet> ancillaryFacetsBuilder =
|
||||
ImmutableMap.builder();
|
||||
ImmutableMap.Builder<String, EntityIdentifyingFacet> ancillaryFacetsBuilder = ImmutableMap.builder();
|
||||
EntityIdentifyingFacet primaryFacet = null;
|
||||
List<HelenusProperty> primaryProperties = new ArrayList<HelenusProperty>(4);
|
||||
for (HelenusProperty prop : propsLocal) {
|
||||
switch (prop.getColumnType()) {
|
||||
case PARTITION_KEY:
|
||||
case CLUSTERING_COLUMN:
|
||||
case PARTITION_KEY :
|
||||
case CLUSTERING_COLUMN :
|
||||
primaryProperties.add(prop);
|
||||
break;
|
||||
default:
|
||||
default :
|
||||
if (primaryProperties != null) {
|
||||
primaryFacet =
|
||||
new EntityIdentifyingFacet(new HashSet<HelenusProperty>(primaryProperties));
|
||||
primaryFacet = new EntityIdentifyingFacet(new HashSet<HelenusProperty>(primaryProperties));
|
||||
allFacetsBuilder.put("*", primaryFacet);
|
||||
primaryProperties = null;
|
||||
}
|
||||
|
@ -165,7 +166,7 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
HelenusProperty property = props.get(name);
|
||||
if (property == null && methods.containsKey(name)) {
|
||||
property = new HelenusMappingProperty(this, methods.get(name), new DefaultMetadata());
|
||||
return property; //TODO(gburd): review adding these into the props map...
|
||||
return property; // TODO(gburd): review adding these into the props map...
|
||||
}
|
||||
return props.get(name);
|
||||
}
|
||||
|
@ -183,16 +184,16 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
private static IdentityName resolveName(Class<?> iface, HelenusEntityType type) {
|
||||
|
||||
switch (type) {
|
||||
case TABLE:
|
||||
case TABLE :
|
||||
return MappingUtil.getTableName(iface, true);
|
||||
|
||||
case VIEW:
|
||||
case VIEW :
|
||||
return MappingUtil.getViewName(iface, true);
|
||||
|
||||
case TUPLE:
|
||||
case TUPLE :
|
||||
return IdentityName.of(MappingUtil.getDefaultEntityName(iface), false);
|
||||
|
||||
case UDT:
|
||||
case UDT :
|
||||
return MappingUtil.getUserDefinedTypeName(iface, true);
|
||||
}
|
||||
|
||||
|
@ -213,22 +214,21 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
return HelenusEntityType.UDT;
|
||||
}
|
||||
|
||||
throw new HelenusMappingException(
|
||||
"entity must be annotated by @Table or @Tuple or @UserDefinedType " + iface);
|
||||
throw new HelenusMappingException("entity must be annotated by @Table or @Tuple or @UserDefinedType " + iface);
|
||||
}
|
||||
|
||||
private void validateOrdinals() {
|
||||
|
||||
switch (getType()) {
|
||||
case TABLE:
|
||||
case TABLE :
|
||||
validateOrdinalsForTable();
|
||||
break;
|
||||
|
||||
case TUPLE:
|
||||
case TUPLE :
|
||||
validateOrdinalsInTuple();
|
||||
break;
|
||||
|
||||
default:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -245,29 +245,24 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
int ordinal = prop.getOrdinal();
|
||||
|
||||
switch (type) {
|
||||
case PARTITION_KEY:
|
||||
case PARTITION_KEY :
|
||||
if (partitionKeys.get(ordinal)) {
|
||||
throw new HelenusMappingException(
|
||||
"detected two or more partition key columns with the same ordinal "
|
||||
+ ordinal
|
||||
+ " in "
|
||||
"detected two or more partition key columns with the same ordinal " + ordinal + " in "
|
||||
+ prop.getEntity());
|
||||
}
|
||||
partitionKeys.set(ordinal);
|
||||
break;
|
||||
|
||||
case CLUSTERING_COLUMN:
|
||||
case CLUSTERING_COLUMN :
|
||||
if (clusteringColumns.get(ordinal)) {
|
||||
throw new HelenusMappingException(
|
||||
"detected two or clustering columns with the same ordinal "
|
||||
+ ordinal
|
||||
+ " in "
|
||||
+ prop.getEntity());
|
||||
throw new HelenusMappingException("detected two or clustering columns with the same ordinal "
|
||||
+ ordinal + " in " + prop.getEntity());
|
||||
}
|
||||
clusteringColumns.set(ordinal);
|
||||
break;
|
||||
|
||||
default:
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -276,27 +271,17 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
private void validateOrdinalsInTuple() {
|
||||
boolean[] ordinals = new boolean[props.size()];
|
||||
|
||||
getOrderedProperties()
|
||||
.forEach(
|
||||
p -> {
|
||||
getOrderedProperties().forEach(p -> {
|
||||
int ordinal = p.getOrdinal();
|
||||
|
||||
if (ordinal < 0 || ordinal >= ordinals.length) {
|
||||
throw new HelenusMappingException(
|
||||
"invalid ordinal "
|
||||
+ ordinal
|
||||
+ " found for property "
|
||||
+ p.getPropertyName()
|
||||
+ " in "
|
||||
+ p.getEntity());
|
||||
throw new HelenusMappingException("invalid ordinal " + ordinal + " found for property "
|
||||
+ p.getPropertyName() + " in " + p.getEntity());
|
||||
}
|
||||
|
||||
if (ordinals[ordinal]) {
|
||||
throw new HelenusMappingException(
|
||||
"detected two or more properties with the same ordinal "
|
||||
+ ordinal
|
||||
+ " in "
|
||||
+ p.getEntity());
|
||||
"detected two or more properties with the same ordinal " + ordinal + " in " + p.getEntity());
|
||||
}
|
||||
|
||||
ordinals[ordinal] = true;
|
||||
|
@ -313,12 +298,8 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
public String toString() {
|
||||
|
||||
StringBuilder str = new StringBuilder();
|
||||
str.append(iface.getSimpleName())
|
||||
.append("(")
|
||||
.append(name.getName())
|
||||
.append(") ")
|
||||
.append(type.name().toLowerCase())
|
||||
.append(":\n");
|
||||
str.append(iface.getSimpleName()).append("(").append(name.getName()).append(") ")
|
||||
.append(type.name().toLowerCase()).append(":\n");
|
||||
|
||||
for (HelenusProperty prop : getOrderedProperties()) {
|
||||
str.append(prop.toString());
|
||||
|
|
|
@ -15,13 +15,16 @@
|
|||
*/
|
||||
package net.helenus.mapping;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
|
||||
import com.datastax.driver.core.Metadata;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.javatype.AbstractJavaType;
|
||||
import net.helenus.mapping.javatype.MappingJavaTypes;
|
||||
|
@ -62,9 +65,8 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
this.javaType = getter.getReturnType();
|
||||
this.abstractJavaType = MappingJavaTypes.resolveJavaType(this.javaType);
|
||||
|
||||
this.dataType =
|
||||
abstractJavaType.resolveDataType(
|
||||
this.getter, this.genericJavaType, this.columnInfo.getColumnType(), metadata);
|
||||
this.dataType = abstractJavaType.resolveDataType(this.getter, this.genericJavaType,
|
||||
this.columnInfo.getColumnType(), metadata);
|
||||
|
||||
this.validators = MappingUtil.getValidators(getter);
|
||||
}
|
||||
|
@ -168,13 +170,13 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
ColumnType type = this.getColumnType();
|
||||
|
||||
switch (type) {
|
||||
case PARTITION_KEY:
|
||||
case PARTITION_KEY :
|
||||
str.append("partition_key[");
|
||||
str.append(this.getOrdinal());
|
||||
str.append("] ");
|
||||
break;
|
||||
|
||||
case CLUSTERING_COLUMN:
|
||||
case CLUSTERING_COLUMN :
|
||||
str.append("clustering_column[");
|
||||
str.append(this.getOrdinal());
|
||||
str.append("] ");
|
||||
|
@ -184,11 +186,11 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
}
|
||||
break;
|
||||
|
||||
case STATIC_COLUMN:
|
||||
case STATIC_COLUMN :
|
||||
str.append("static ");
|
||||
break;
|
||||
|
||||
case COLUMN:
|
||||
case COLUMN :
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,9 @@ import java.lang.annotation.Annotation;
|
|||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.type.AbstractDataType;
|
||||
|
||||
|
|
|
@ -20,8 +20,10 @@ import java.lang.reflect.Method;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
import javax.validation.ConstraintValidator;
|
||||
|
||||
import net.helenus.core.Getter;
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.core.reflect.*;
|
||||
|
@ -32,10 +34,10 @@ import net.helenus.support.HelenusMappingException;
|
|||
public final class MappingUtil {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static final ConstraintValidator<? extends Annotation, ?>[] EMPTY_VALIDATORS =
|
||||
new ConstraintValidator[0];
|
||||
public static final ConstraintValidator<? extends Annotation, ?>[] EMPTY_VALIDATORS = new ConstraintValidator[0];
|
||||
|
||||
private MappingUtil() {}
|
||||
private MappingUtil() {
|
||||
}
|
||||
|
||||
public static ConstraintValidator<? extends Annotation, ?>[] getValidators(Method getterMethod) {
|
||||
|
||||
|
@ -60,8 +62,8 @@ public final class MappingUtil {
|
|||
}
|
||||
}
|
||||
|
||||
private static List<ConstraintValidator<? extends Annotation, ?>> addValidators(
|
||||
Annotation constraintAnnotation, List<ConstraintValidator<? extends Annotation, ?>> list) {
|
||||
private static List<ConstraintValidator<? extends Annotation, ?>> addValidators(Annotation constraintAnnotation,
|
||||
List<ConstraintValidator<? extends Annotation, ?>> list) {
|
||||
|
||||
Class<? extends Annotation> annotationType = constraintAnnotation.annotationType();
|
||||
|
||||
|
@ -73,8 +75,8 @@ public final class MappingUtil {
|
|||
|
||||
for (Class<? extends ConstraintValidator<?, ?>> clazz : constraint.validatedBy()) {
|
||||
|
||||
ConstraintValidator<? extends Annotation, ?> validator =
|
||||
ReflectionInstantiator.instantiateClass(clazz);
|
||||
ConstraintValidator<? extends Annotation, ?> validator = ReflectionInstantiator
|
||||
.instantiateClass(clazz);
|
||||
|
||||
((ConstraintValidator) validator).initialize(constraintAnnotation);
|
||||
|
||||
|
@ -106,9 +108,7 @@ public final class MappingUtil {
|
|||
}
|
||||
}
|
||||
|
||||
return indexName != null
|
||||
? Optional.of(new IdentityName(indexName, forceQuote))
|
||||
: Optional.empty();
|
||||
return indexName != null ? Optional.of(new IdentityName(indexName, forceQuote)) : Optional.empty();
|
||||
}
|
||||
|
||||
public static boolean caseSensitiveIndex(Method getterMethod) {
|
||||
|
|
|
@ -22,8 +22,7 @@ public enum TypeAndOrdinalColumnComparator implements Comparator<HelenusProperty
|
|||
|
||||
public int compare(HelenusProperty thisVal, HelenusProperty anotherVal) {
|
||||
|
||||
int c =
|
||||
Integer.compare(thisVal.getColumnType().ordinal(), anotherVal.getColumnType().ordinal());
|
||||
int c = Integer.compare(thisVal.getColumnType().ordinal(), anotherVal.getColumnType().ordinal());
|
||||
|
||||
if (c == 0) {
|
||||
c = Integer.compare(thisVal.getOrdinal(), anotherVal.getOrdinal());
|
||||
|
|
|
@ -19,34 +19,44 @@ import java.lang.annotation.ElementType;
|
|||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import net.helenus.mapping.OrderingDirection;
|
||||
|
||||
/**
|
||||
* ClusteringColumn is the family column in legacy Cassandra API
|
||||
*
|
||||
* <p>The purpose of this column is have additional dimension in the table. Both @PartitionKey
|
||||
* and @ClusteringColumn together are parts of the primary key of the table. The primary difference
|
||||
* between them is that the first one is using for routing purposes in order to locate a data node
|
||||
* in the cluster, otherwise the second one is using inside the node to locate peace of data in
|
||||
* <p>
|
||||
* The purpose of this column is have additional dimension in the table.
|
||||
* Both @PartitionKey and @ClusteringColumn together are parts of the primary
|
||||
* key of the table. The primary difference between them is that the first one
|
||||
* is using for routing purposes in order to locate a data node in the cluster,
|
||||
* otherwise the second one is using inside the node to locate peace of data in
|
||||
* concrete machine.
|
||||
*
|
||||
* <p>ClusteringColumn can be represented as a Key in SortedMap that fully stored in a single node.
|
||||
* All developers must be careful for selecting fields for clustering columns, because all data
|
||||
* inside this SortedMap must fit in to one node.
|
||||
* <p>
|
||||
* ClusteringColumn can be represented as a Key in SortedMap that fully stored
|
||||
* in a single node. All developers must be careful for selecting fields for
|
||||
* clustering columns, because all data inside this SortedMap must fit in to one
|
||||
* node.
|
||||
*
|
||||
* <p>ClusteringColumn can have more than one part and the order of parts is important. This order
|
||||
* defines the way how Cassandra joins the parts and influence of data retrieval operations. Each
|
||||
* part can have ordering property that defines default ascending or descending order of data. In
|
||||
* case of two and more parts in select queries developer needs to have consisdent order of all
|
||||
* parts as they defined in table.
|
||||
* <p>
|
||||
* ClusteringColumn can have more than one part and the order of parts is
|
||||
* important. This order defines the way how Cassandra joins the parts and
|
||||
* influence of data retrieval operations. Each part can have ordering property
|
||||
* that defines default ascending or descending order of data. In case of two
|
||||
* and more parts in select queries developer needs to have consisdent order of
|
||||
* all parts as they defined in table.
|
||||
*
|
||||
* <p>For example, first part is ASC ordering, second is also ASC, so Cassandra will sort entries
|
||||
* like this: a-a a-b b-a b-b In this case we are able run queries: ORDER BY first ASC, second ASC
|
||||
* ORDER BY first DESC, second DESC WHERE first=? ORDER BY second ASC WHERE first=? ORDER BY second
|
||||
* DESC WHERE first=? AND second=?
|
||||
* <p>
|
||||
* For example, first part is ASC ordering, second is also ASC, so Cassandra
|
||||
* will sort entries like this: a-a a-b b-a b-b In this case we are able run
|
||||
* queries: ORDER BY first ASC, second ASC ORDER BY first DESC, second DESC
|
||||
* WHERE first=? ORDER BY second ASC WHERE first=? ORDER BY second DESC WHERE
|
||||
* first=? AND second=?
|
||||
*
|
||||
* <p>But, we can not run queries: ORDER BY first DESC, second ASC ORDER BY first ASC, second DESC
|
||||
* WHERE second=? ORDER BY first (ASC,DESC)
|
||||
* <p>
|
||||
* But, we can not run queries: ORDER BY first DESC, second ASC ORDER BY first
|
||||
* ASC, second DESC WHERE second=? ORDER BY first (ASC,DESC)
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
|
@ -60,35 +70,40 @@ public @interface ClusteringColumn {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* ClusteringColumn parts must be ordered in the @Table. It is the requirement of Cassandra.
|
||||
* Cassandra joins all parts to the final clustering key that is stored in column family name.
|
||||
* Additionally all parts can have some ordering (ASC, DESC) that with sequence of parts
|
||||
* determines key comparison function, so Cassandra storing column family names always in sorted
|
||||
* order.
|
||||
* ClusteringColumn parts must be ordered in the @Table. It is the requirement
|
||||
* of Cassandra. Cassandra joins all parts to the final clustering key that is
|
||||
* stored in column family name. Additionally all parts can have some ordering
|
||||
* (ASC, DESC) that with sequence of parts determines key comparison function,
|
||||
* so Cassandra storing column family names always in sorted order.
|
||||
*
|
||||
* <p>Be default ordinal has 0 value, that's because in most cases @Table have single column for
|
||||
* ClusteringColumn If you have 2 and more parts of the ClusteringColumn, then you need to use
|
||||
* ordinal() to define the sequence of the parts
|
||||
* <p>
|
||||
* Be default ordinal has 0 value, that's because in most cases @Table have
|
||||
* single column for ClusteringColumn If you have 2 and more parts of the
|
||||
* ClusteringColumn, then you need to use ordinal() to define the sequence of
|
||||
* the parts
|
||||
*
|
||||
* @return number that used to sort clustering columns
|
||||
*/
|
||||
int ordinal() default 0;
|
||||
|
||||
/**
|
||||
* Default order of values in the ClusteringColumn This ordering is using for comparison of the
|
||||
* clustering column values when Cassandra stores it in the sorted order.
|
||||
* Default order of values in the ClusteringColumn This ordering is using for
|
||||
* comparison of the clustering column values when Cassandra stores it in the
|
||||
* sorted order.
|
||||
*
|
||||
* <p>Default value is the ascending order
|
||||
* <p>
|
||||
* Default value is the ascending order
|
||||
*
|
||||
* @return ascending order or descending order of clustering column values
|
||||
*/
|
||||
OrderingDirection ordering() default OrderingDirection.ASC;
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -18,15 +18,18 @@ package net.helenus.mapping.annotation;
|
|||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Column annotation is used to define additional properties of the column in entity mapping
|
||||
* interfaces: @Table, @UDT, @Tuple
|
||||
* Column annotation is used to define additional properties of the column in
|
||||
* entity mapping interfaces: @Table, @UDT, @Tuple
|
||||
*
|
||||
* <p>Column annotation can be used to override default name of the column or to setup order of the
|
||||
* columns in the mapping
|
||||
* <p>
|
||||
* Column annotation can be used to override default name of the column or to
|
||||
* setup order of the columns in the mapping
|
||||
*
|
||||
* <p>Usually for @Table and @UDT types it is not important to define order of the columns, but
|
||||
* in @Tuple mapping it is required, because tuple itself represents the sequence of the types with
|
||||
* particular order in the table's column
|
||||
* <p>
|
||||
* Usually for @Table and @UDT types it is not important to define order of the
|
||||
* columns, but in @Tuple mapping it is required, because tuple itself
|
||||
* represents the sequence of the types with particular order in the table's
|
||||
* column
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -43,18 +46,21 @@ public @interface Column {
|
|||
/**
|
||||
* Ordinal will be used for ascending sorting of columns
|
||||
*
|
||||
* <p>Default value is 0, because not all mapping entities require all fields to have unique
|
||||
* ordinals, only @Tuple mapping entity requires all of them to be unique.
|
||||
* <p>
|
||||
* Default value is 0, because not all mapping entities require all fields to
|
||||
* have unique ordinals, only @Tuple mapping entity requires all of them to be
|
||||
* unique.
|
||||
*
|
||||
* @return number that used to sort columns, usually for @Tuple only
|
||||
*/
|
||||
int ordinal() default 0;
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -16,83 +16,106 @@
|
|||
package net.helenus.mapping.annotation;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import javax.validation.Constraint;
|
||||
|
||||
import net.helenus.mapping.validator.*;
|
||||
|
||||
/**
|
||||
* Constraint annotations are using for data integrity mostly for @java.lang.String types. The place
|
||||
* of the annotation is the particular method in model interface.
|
||||
* Constraint annotations are using for data integrity mostly
|
||||
* for @java.lang.String types. The place of the annotation is the particular
|
||||
* method in model interface.
|
||||
*
|
||||
* <p>All of them does not have effect on selects and data retrieval operations.
|
||||
* <p>
|
||||
* All of them does not have effect on selects and data retrieval operations.
|
||||
*
|
||||
* <p>Support types: - @NotNull supports any @java.lang.Object type - All annotations
|
||||
* support @java.lang.String type
|
||||
* <p>
|
||||
* Support types: - @NotNull supports any @java.lang.Object type - All
|
||||
* annotations support @java.lang.String type
|
||||
*/
|
||||
public final class Constraints {
|
||||
|
||||
private Constraints() {}
|
||||
private Constraints() {
|
||||
}
|
||||
|
||||
/**
|
||||
* NotNull annotation is using to check that value is not null before storing it
|
||||
*
|
||||
* <p>Applicable to use in any @java.lang.Object
|
||||
* <p>
|
||||
* Applicable to use in any @java.lang.Object
|
||||
*
|
||||
* <p>It does not check on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not check on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = NotNullValidator.class)
|
||||
public @interface NotNull {}
|
||||
public @interface NotNull {
|
||||
}
|
||||
|
||||
/**
|
||||
* NotEmpty annotation is using to check that value has text before storing it
|
||||
*
|
||||
* <p>Also checks for the null and it is more strict annotation then @NotNull
|
||||
* <p>
|
||||
* Also checks for the null and it is more strict annotation then @NotNull
|
||||
*
|
||||
* <p>Can be used for @java.lang.CharSequence, @ByteBuffer and any array
|
||||
* <p>
|
||||
* Can be used for @java.lang.CharSequence, @ByteBuffer and any array
|
||||
*
|
||||
* <p>It does not check on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not check on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = NotEmptyValidator.class)
|
||||
public @interface NotEmpty {}
|
||||
public @interface NotEmpty {
|
||||
}
|
||||
|
||||
/**
|
||||
* Email annotation is using to check that value has a valid email before storing it
|
||||
* Email annotation is using to check that value has a valid email before
|
||||
* storing it
|
||||
*
|
||||
* <p>Can be used only for @CharSequence
|
||||
* <p>
|
||||
* Can be used only for @CharSequence
|
||||
*
|
||||
* <p>It does not check on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not check on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = EmailValidator.class)
|
||||
public @interface Email {}
|
||||
public @interface Email {
|
||||
}
|
||||
|
||||
/**
|
||||
* Number annotation is using to check that all letters in value are digits before storing it
|
||||
* Number annotation is using to check that all letters in value are digits
|
||||
* before storing it
|
||||
*
|
||||
* <p>Can be used only for @java.lang.CharSequence
|
||||
* <p>
|
||||
* Can be used only for @java.lang.CharSequence
|
||||
*
|
||||
* <p>It does not check on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not check on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = NumberValidator.class)
|
||||
public @interface Number {}
|
||||
public @interface Number {
|
||||
}
|
||||
|
||||
/**
|
||||
* Alphabet annotation is using to check that all letters in value are in specific alphabet before
|
||||
* storing it
|
||||
* Alphabet annotation is using to check that all letters in value are in
|
||||
* specific alphabet before storing it
|
||||
*
|
||||
* <p>Can be used only for @java.lang.CharSequence
|
||||
* <p>
|
||||
* Can be used only for @java.lang.CharSequence
|
||||
*
|
||||
* <p>It does not check on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not check on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -109,11 +132,14 @@ public final class Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* Length annotation is using to ensure that value has exact length before storing it
|
||||
* Length annotation is using to ensure that value has exact length before
|
||||
* storing it
|
||||
*
|
||||
* <p>Can be used for @java.lang.CharSequence, @ByteBuffer and any array
|
||||
* <p>
|
||||
* Can be used for @java.lang.CharSequence, @ByteBuffer and any array
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -125,12 +151,14 @@ public final class Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* MaxLength annotation is using to ensure that value has length less or equal to some threshold
|
||||
* before storing it
|
||||
* MaxLength annotation is using to ensure that value has length less or equal
|
||||
* to some threshold before storing it
|
||||
*
|
||||
* <p>Can be used for @java.lang.CharSequence, @ByteBuffer and byte[]
|
||||
* <p>
|
||||
* Can be used for @java.lang.CharSequence, @ByteBuffer and byte[]
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -142,12 +170,14 @@ public final class Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* MinLength annotation is using to ensure that value has length greater or equal to some
|
||||
* threshold before storing it
|
||||
* MinLength annotation is using to ensure that value has length greater or
|
||||
* equal to some threshold before storing it
|
||||
*
|
||||
* <p>Can be used for @java.lang.CharSequence, @ByteBuffer and byte[]
|
||||
* <p>
|
||||
* Can be used for @java.lang.CharSequence, @ByteBuffer and byte[]
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -159,38 +189,48 @@ public final class Constraints {
|
|||
}
|
||||
|
||||
/**
|
||||
* LowerCase annotation is using to ensure that value is in lower case before storing it
|
||||
* LowerCase annotation is using to ensure that value is in lower case before
|
||||
* storing it
|
||||
*
|
||||
* <p>Can be used only for @java.lang.CharSequence
|
||||
* <p>
|
||||
* Can be used only for @java.lang.CharSequence
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = LowerCaseValidator.class)
|
||||
public @interface LowerCase {}
|
||||
public @interface LowerCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* UpperCase annotation is using to ensure that value is in upper case before storing it
|
||||
* UpperCase annotation is using to ensure that value is in upper case before
|
||||
* storing it
|
||||
*
|
||||
* <p>Can be used only for @java.lang.CharSequence
|
||||
* <p>
|
||||
* Can be used only for @java.lang.CharSequence
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
@Constraint(validatedBy = UpperCaseValidator.class)
|
||||
public @interface UpperCase {}
|
||||
public @interface UpperCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pattern annotation is LowerCase annotation is using to ensure that value is upper case before
|
||||
* storing it
|
||||
* Pattern annotation is LowerCase annotation is using to ensure that value is
|
||||
* upper case before storing it
|
||||
*
|
||||
* <p>Can be used only for @java.lang.CharSequence
|
||||
* <p>
|
||||
* Can be used only for @java.lang.CharSequence
|
||||
*
|
||||
* <p>It does not have effect on selects and data retrieval operations
|
||||
* <p>
|
||||
* It does not have effect on selects and data retrieval operations
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -3,17 +3,20 @@ package net.helenus.mapping.annotation;
|
|||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* CoveringIndex annotation is using under the specific column or method in entity interface
|
||||
* with @Table annotation.
|
||||
* CoveringIndex annotation is using under the specific column or method in
|
||||
* entity interface with @Table annotation.
|
||||
*
|
||||
* <p>A corresponding materialized view will be created based on the underline @Table for the
|
||||
* specific column.
|
||||
* <p>
|
||||
* A corresponding materialized view will be created based on the
|
||||
* underline @Table for the specific column.
|
||||
*
|
||||
* <p>This is useful when you need to perform IN or SORT/ORDER-BY queries and to do so you'll need
|
||||
* different materialized table on disk in Cassandra.
|
||||
* <p>
|
||||
* This is useful when you need to perform IN or SORT/ORDER-BY queries and to do
|
||||
* so you'll need different materialized table on disk in Cassandra.
|
||||
*
|
||||
* <p>For each @Table annotated interface Helenus will create/update/verify Cassandra Materialized
|
||||
* Views and some indexes if needed on startup.
|
||||
* <p>
|
||||
* For each @Table annotated interface Helenus will create/update/verify
|
||||
* Cassandra Materialized Views and some indexes if needed on startup.
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -21,7 +24,8 @@ import java.lang.annotation.*;
|
|||
public @interface CoveringIndex {
|
||||
|
||||
/**
|
||||
* Defined the name of the index. By default the entity name with column name as suffix.
|
||||
* Defined the name of the index. By default the entity name with column name as
|
||||
* suffix.
|
||||
*
|
||||
* @return name of the covering index
|
||||
*/
|
||||
|
|
|
@ -18,18 +18,22 @@ package net.helenus.mapping.annotation;
|
|||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Index annotation is using under the specific column or method in entity interface with @Table
|
||||
* annotation.
|
||||
* Index annotation is using under the specific column or method in entity
|
||||
* interface with @Table annotation.
|
||||
*
|
||||
* <p>The corresponding secondary index will be created in the underline @Table for the specific
|
||||
* column.
|
||||
* <p>
|
||||
* The corresponding secondary index will be created in the underline @Table for
|
||||
* the specific column.
|
||||
*
|
||||
* <p>Currently Cassandra supports only single column index, so this index works only for single
|
||||
* column.
|
||||
* <p>
|
||||
* Currently Cassandra supports only single column index, so this index works
|
||||
* only for single column.
|
||||
*
|
||||
* <p>Make sure that you are using low cardinality columns for this index, that is the requirement
|
||||
* of the Cassandra. Low cardinality fields examples: gender, country, age, status and etc High
|
||||
* cardinality fields examples: id, email, timestamp, UUID and etc
|
||||
* <p>
|
||||
* Make sure that you are using low cardinality columns for this index, that is
|
||||
* the requirement of the Cassandra. Low cardinality fields examples: gender,
|
||||
* country, age, status and etc High cardinality fields examples: id, email,
|
||||
* timestamp, UUID and etc
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -44,17 +48,19 @@ public @interface Index {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
boolean forceQuote() default false;
|
||||
|
||||
/**
|
||||
* Create a case-insensitive index using Cassandra 3.x+ support for SASI indexing.
|
||||
* Create a case-insensitive index using Cassandra 3.x+ support for SASI
|
||||
* indexing.
|
||||
*
|
||||
* @return true if the index should ignore case when comparing
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,9 @@ import java.lang.annotation.*;
|
|||
/**
|
||||
* Inherited Entity annotation
|
||||
*
|
||||
* <p>Inherited Table annotation is used to indicate that the methods should also be mapped
|
||||
* <p>
|
||||
* Inherited Table annotation is used to indicate that the methods should also
|
||||
* be mapped
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
|
@ -20,13 +20,17 @@ import java.lang.annotation.*;
|
|||
/**
|
||||
* Materialized alternate view of another Entity annotation
|
||||
*
|
||||
* <p>MaterializedView annotation is used to define different mapping to some other Table interface
|
||||
* <p>
|
||||
* MaterializedView annotation is used to define different mapping to some other
|
||||
* Table interface
|
||||
*
|
||||
* <p>This is useful when you need to perform IN or SORT/ORDER-BY queries and to do so you'll need
|
||||
* different materialized table on disk in Cassandra.
|
||||
* <p>
|
||||
* This is useful when you need to perform IN or SORT/ORDER-BY queries and to do
|
||||
* so you'll need different materialized table on disk in Cassandra.
|
||||
*
|
||||
* <p>For each @Table annotated interface Helenus will create/update/verify Cassandra Materialized
|
||||
* Views and some indexes if needed on startup.
|
||||
* <p>
|
||||
* For each @Table annotated interface Helenus will create/update/verify
|
||||
* Cassandra Materialized Views and some indexes if needed on startup.
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -41,10 +45,11 @@ public @interface MaterializedView {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -21,16 +21,20 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* PartitionKey annotation is using to define that particular column is the part of partition key in
|
||||
* the table.
|
||||
* PartitionKey annotation is using to define that particular column is the part
|
||||
* of partition key in the table.
|
||||
*
|
||||
* <p>Partition Key is the routing key. Cassandra is using it to find the primary data node in the
|
||||
* cluster that holds data. Cassandra combines all parts of the partition key to byte array and then
|
||||
* calculates hash function by using good distribution algorithm (by default MurMur3). After that it
|
||||
* uses hash number as a token in the ring to find a virtual and then a physical data server.
|
||||
* <p>
|
||||
* Partition Key is the routing key. Cassandra is using it to find the primary
|
||||
* data node in the cluster that holds data. Cassandra combines all parts of the
|
||||
* partition key to byte array and then calculates hash function by using good
|
||||
* distribution algorithm (by default MurMur3). After that it uses hash number
|
||||
* as a token in the ring to find a virtual and then a physical data server.
|
||||
*
|
||||
* <p>For @Table mapping entity it is required to have as minimum one PartitionKey column. For @UDT
|
||||
* and @Tuple mapping entities @PartitionKey annotation is not using.
|
||||
* <p>
|
||||
* For @Table mapping entity it is required to have as minimum one PartitionKey
|
||||
* column. For @UDT and @Tuple mapping entities @PartitionKey annotation is not
|
||||
* using.
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
|
@ -44,23 +48,26 @@ public @interface PartitionKey {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* PartitionKey parts must be ordered in the @Table. It is the requirement of Cassandra. That is
|
||||
* how the partition key calculation works, column parts will be joined based on some order and
|
||||
* final hash/token will be calculated.
|
||||
* PartitionKey parts must be ordered in the @Table. It is the requirement of
|
||||
* Cassandra. That is how the partition key calculation works, column parts will
|
||||
* be joined based on some order and final hash/token will be calculated.
|
||||
*
|
||||
* <p>Be default ordinal has 0 value, that's because in most cases @Table have single column
|
||||
* for @PartitionKey If you have 2 and more parts of the PartitionKey, then you need to use
|
||||
* ordinal() to define the sequence of the parts
|
||||
* <p>
|
||||
* Be default ordinal has 0 value, that's because in most cases @Table have
|
||||
* single column for @PartitionKey If you have 2 and more parts of the
|
||||
* PartitionKey, then you need to use ordinal() to define the sequence of the
|
||||
* parts
|
||||
*
|
||||
* @return number that used to sort columns in PartitionKey
|
||||
*/
|
||||
int ordinal() default 0;
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -23,12 +23,14 @@ import java.lang.annotation.Target;
|
|||
/**
|
||||
* StaticColumn annotation is using to define a static column in Cassandra Table
|
||||
*
|
||||
* <p>It does not have effect in @UDT and @Tuple types and in @Table-s that does not
|
||||
* have @ClusteringColumn-s
|
||||
* <p>
|
||||
* It does not have effect in @UDT and @Tuple types and in @Table-s that does
|
||||
* not have @ClusteringColumn-s
|
||||
*
|
||||
* <p>In case of using @ClusteringColumn we can repeat some information that is unique for a row.
|
||||
* For this purpose we can define @StaticColumn annotation, that will create static column in the
|
||||
* table
|
||||
* <p>
|
||||
* In case of using @ClusteringColumn we can repeat some information that is
|
||||
* unique for a row. For this purpose we can define @StaticColumn annotation,
|
||||
* that will create static column in the table
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
|
@ -49,10 +51,11 @@ public @interface StaticColumn {
|
|||
int ordinal() default 0;
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -20,12 +20,15 @@ import java.lang.annotation.*;
|
|||
/**
|
||||
* Entity annotation
|
||||
*
|
||||
* <p>Table annotation is used to define Table mapping to some interface
|
||||
* <p>
|
||||
* Table annotation is used to define Table mapping to some interface
|
||||
*
|
||||
* <p>There are three types of Entity mapping annotations: @Table, @UDT, @Tuple
|
||||
* <p>
|
||||
* There are three types of Entity mapping annotations: @Table, @UDT, @Tuple
|
||||
*
|
||||
* <p>For each @Table annotated interface Helenus will create/update/verify Cassandra Table and some
|
||||
* indexes if needed on startup.
|
||||
* <p>
|
||||
* For each @Table annotated interface Helenus will create/update/verify
|
||||
* Cassandra Table and some indexes if needed on startup.
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -40,10 +43,11 @@ public @interface Table {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -17,8 +17,12 @@ package net.helenus.mapping.annotation;
|
|||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/** Transient annotation is used to mark properties that are need not be mapped to the database. */
|
||||
/**
|
||||
* Transient annotation is used to mark properties that are need not be mapped
|
||||
* to the database.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Transient {}
|
||||
public @interface Transient {
|
||||
}
|
||||
|
|
|
@ -20,15 +20,19 @@ import java.lang.annotation.*;
|
|||
/**
|
||||
* Entity annotation
|
||||
*
|
||||
* <p>Tuple annotation is used to define Tuple type mapping to some interface
|
||||
* <p>
|
||||
* Tuple annotation is used to define Tuple type mapping to some interface
|
||||
*
|
||||
* <p>There are three types of Entity mapping annotations: @Table, @UDT, @Tuple
|
||||
* <p>
|
||||
* There are three types of Entity mapping annotations: @Table, @UDT, @Tuple
|
||||
*
|
||||
* <p>Tuple is fully embedded type, it is the sequence of the underline types and the order of the
|
||||
* sub-types is important, therefore all @Column-s must have ordinal() and only @Column annotation
|
||||
* supported for underline types
|
||||
* <p>
|
||||
* Tuple is fully embedded type, it is the sequence of the underline types and
|
||||
* the order of the sub-types is important, therefore all @Column-s must have
|
||||
* ordinal() and only @Column annotation supported for underline types
|
||||
*/
|
||||
@Inherited
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
public @interface Tuple {}
|
||||
public @interface Tuple {
|
||||
}
|
||||
|
|
|
@ -15,62 +15,79 @@
|
|||
*/
|
||||
package net.helenus.mapping.annotation;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* Types annotations are using for clarification of Cassandra data type for particular Java type.
|
||||
* Types annotations are using for clarification of Cassandra data type for
|
||||
* particular Java type.
|
||||
*
|
||||
* <p>Sometimes it is possible to have for single Java type multiple Cassandra data types: - @String
|
||||
* can be @DataType.Name.ASCII or @DataType.Name.TEXT or @DataType.Name.VARCHAR - @Long can
|
||||
* be @DataType.Name.BIGINT or @DataType.Name.COUNTER
|
||||
* <p>
|
||||
* Sometimes it is possible to have for single Java type multiple Cassandra data
|
||||
* types: - @String can be @DataType.Name.ASCII or @DataType.Name.TEXT
|
||||
* or @DataType.Name.VARCHAR - @Long can be @DataType.Name.BIGINT
|
||||
* or @DataType.Name.COUNTER
|
||||
*
|
||||
* <p>All those type annotations simplify mapping between Java types and Cassandra data types. They
|
||||
* are not required, for each Java type there is a default Cassandra data type in Helenus, but in
|
||||
* some cases you would like to control mapping to make sure that the right Cassandra data type is
|
||||
* using.
|
||||
* <p>
|
||||
* All those type annotations simplify mapping between Java types and Cassandra
|
||||
* data types. They are not required, for each Java type there is a default
|
||||
* Cassandra data type in Helenus, but in some cases you would like to control
|
||||
* mapping to make sure that the right Cassandra data type is using.
|
||||
*
|
||||
* <p>For complex types like collections, UDF and Tuple types all those annotations are using to
|
||||
* clarify the sub-type(s) or class/UDF names.
|
||||
* <p>
|
||||
* For complex types like collections, UDF and Tuple types all those annotations
|
||||
* are using to clarify the sub-type(s) or class/UDF names.
|
||||
*
|
||||
* <p>Has significant effect on schema operations.
|
||||
* <p>
|
||||
* Has significant effect on schema operations.
|
||||
*/
|
||||
public final class Types {
|
||||
|
||||
private Types() {}
|
||||
private Types() {
|
||||
}
|
||||
|
||||
/** Says to use @DataType.Name.ASCII data type in schema Java type is @String */
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Ascii {}
|
||||
public @interface Ascii {
|
||||
}
|
||||
|
||||
/** Says to use @DataType.Name.BIGINT data type in schema Java type is @Long */
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Bigint {}
|
||||
public @interface Bigint {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.BLOB data type in schema Java type is @ByteBuffer or @byte[] Using
|
||||
* by default
|
||||
* Says to use @DataType.Name.BLOB data type in schema Java type is @ByteBuffer
|
||||
* or @byte[] Using by default
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Blob {}
|
||||
public @interface Blob {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.LIST data type in schema with specific sub-type Java type is @List
|
||||
* Says to use @DataType.Name.LIST data type in schema with specific sub-type
|
||||
* Java type is @List
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: prepend, prependAll, setIdx, append, appendAll,
|
||||
* discard and discardAll in @UpdateOperation
|
||||
* <p>
|
||||
* For this type there are special operations: prepend, prependAll, setIdx,
|
||||
* append, appendAll, discard and discardAll in @UpdateOperation
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -78,10 +95,11 @@ public final class Types {
|
|||
public @interface List {
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT sub-type in the list, consider @UDTList annotation
|
||||
* <p>
|
||||
* In case if you need UDT sub-type in the list, consider @UDTList annotation
|
||||
*
|
||||
* @return data type name of the value
|
||||
*/
|
||||
|
@ -89,15 +107,22 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific sub-types Java type is @Map
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific sub-types
|
||||
* Java type is @Map
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: put and putAll in @UpdateOperation.
|
||||
* <p>
|
||||
* For this type there are special operations: put and putAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -105,22 +130,24 @@ public final class Types {
|
|||
public @interface Map {
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT key sub-type in the map, consider @UDTKeyMap or @UDTMap
|
||||
* annotations
|
||||
* <p>
|
||||
* In case if you need UDT key sub-type in the map, consider @UDTKeyMap
|
||||
* or @UDTMap annotations
|
||||
*
|
||||
* @return data type name of the key
|
||||
*/
|
||||
DataType.Name key();
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT value sub-type in the map, consider @UDTValueMap or @UDTMap
|
||||
* annotations
|
||||
* <p>
|
||||
* In case if you need UDT value sub-type in the map, consider @UDTValueMap
|
||||
* or @UDTMap annotations
|
||||
*
|
||||
* @return data type name of the value
|
||||
*/
|
||||
|
@ -130,24 +157,33 @@ public final class Types {
|
|||
/**
|
||||
* Says to use @DataType.Name.COUNTER type in schema Java type is @Long
|
||||
*
|
||||
* <p>For this type there are special operations: increment and decrement in @UpdateOperation. You
|
||||
* do not need to initialize counter value, it will be done automatically by Cassandra.
|
||||
* <p>
|
||||
* For this type there are special operations: increment and decrement
|
||||
* in @UpdateOperation. You do not need to initialize counter value, it will be
|
||||
* done automatically by Cassandra.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Counter {}
|
||||
public @interface Counter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.SET data type in schema with specific sub-type Java type is @Set
|
||||
* Says to use @DataType.Name.SET data type in schema with specific sub-type
|
||||
* Java type is @Set
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: add, addAll, remove and removeAll
|
||||
* <p>
|
||||
* For this type there are special operations: add, addAll, remove and removeAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
|
@ -156,10 +192,11 @@ public final class Types {
|
|||
public @interface Set {
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT sub-type in the set, consider @UDTSet annotation
|
||||
* <p>
|
||||
* In case if you need UDT sub-type in the set, consider @UDTSet annotation
|
||||
*
|
||||
* @return data type name of the value
|
||||
*/
|
||||
|
@ -167,10 +204,12 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.CUSTOM type in schema Java type is @ByteBuffer or @byte[]
|
||||
* Says to use @DataType.Name.CUSTOM type in schema Java type is @ByteBuffer
|
||||
* or @byte[]
|
||||
*
|
||||
* <p>Uses for custom user types that has special implementation. Helenus does not deal with this
|
||||
* class directly for now, uses only in serialized form.
|
||||
* <p>
|
||||
* Uses for custom user types that has special implementation. Helenus does not
|
||||
* deal with this class directly for now, uses only in serialized form.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -185,39 +224,53 @@ public final class Types {
|
|||
String className();
|
||||
}
|
||||
|
||||
/** Says to use @DataType.Name.TEXT type in schema Java type is @String Using by default */
|
||||
/**
|
||||
* Says to use @DataType.Name.TEXT type in schema Java type is @String Using by
|
||||
* default
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Text {}
|
||||
|
||||
/** Says to use @DataType.Name.TIMESTAMP type in schema Java type is @Date Using by default */
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Timestamp {}
|
||||
|
||||
/** Says to use @DataType.Name.TIMEUUID type in schema Java type is @UUID or @Date */
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Timeuuid {}
|
||||
public @interface Text {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.TUPLE type in schema Java type is @TupleValue or model interface
|
||||
* with @Tuple annotation
|
||||
* Says to use @DataType.Name.TIMESTAMP type in schema Java type is @Date Using
|
||||
* by default
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Timestamp {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.TIMEUUID type in schema Java type is @UUID
|
||||
* or @Date
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Timeuuid {
|
||||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.TUPLE type in schema Java type is @TupleValue or
|
||||
* model interface with @Tuple annotation
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Tuple {
|
||||
|
||||
/**
|
||||
* If Java type is the @TupleValue then this field is required. Any Cassandra Tuple is the
|
||||
* sequence of Cassandra types. For now Helenus supports only simple data types in tuples
|
||||
* for @TupleValue Java type
|
||||
* If Java type is the @TupleValue then this field is required. Any Cassandra
|
||||
* Tuple is the sequence of Cassandra types. For now Helenus supports only
|
||||
* simple data types in tuples for @TupleValue Java type
|
||||
*
|
||||
* <p>In case if Java type is the model interface with @Tuple annotation then all methods in
|
||||
* this interface can have Types annotations that can be complex types as well.
|
||||
* <p>
|
||||
* In case if Java type is the model interface with @Tuple annotation then all
|
||||
* methods in this interface can have Types annotations that can be complex
|
||||
* types as well.
|
||||
*
|
||||
* @return data type name sequence
|
||||
*/
|
||||
|
@ -225,8 +278,8 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.UDT type in schema Java type is @UDTValue or model interface
|
||||
* with @UDT annotation
|
||||
* Says to use @DataType.Name.UDT type in schema Java type is @UDTValue or model
|
||||
* interface with @UDT annotation
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -234,13 +287,17 @@ public final class Types {
|
|||
public @interface UDT {
|
||||
|
||||
/**
|
||||
* If Java type is the @UDTValue then this field is required. Any Cassandra UDT has name and
|
||||
* must be created before this use as a Cassandra Type.
|
||||
* If Java type is the @UDTValue then this field is required. Any Cassandra UDT
|
||||
* has name and must be created before this use as a Cassandra Type.
|
||||
*
|
||||
* <p>This value is the UDT name of the Cassandra Type that was already created in the schema
|
||||
* <p>
|
||||
* This value is the UDT name of the Cassandra Type that was already created in
|
||||
* the schema
|
||||
*
|
||||
* <p>In case of Java type is the model interface with @UDT annotation then this field is not
|
||||
* using since model interface defines UserDefinedType with specific name
|
||||
* <p>
|
||||
* In case of Java type is the model interface with @UDT annotation then this
|
||||
* field is not using since model interface defines UserDefinedType with
|
||||
* specific name
|
||||
*
|
||||
* @return UDT name
|
||||
*/
|
||||
|
@ -249,10 +306,13 @@ public final class Types {
|
|||
/**
|
||||
* Only used for JavaType @UDTValue
|
||||
*
|
||||
* <p>In case if value() method returns reserved word that can not be used as a name of UDT then
|
||||
* forceQuote will add additional quotes around this name in all CQL queries.
|
||||
* <p>
|
||||
* In case if value() method returns reserved word that can not be used as a
|
||||
* name of UDT then forceQuote will add additional quotes around this name in
|
||||
* all CQL queries.
|
||||
*
|
||||
* <p>Default value is false.
|
||||
* <p>
|
||||
* Default value is false.
|
||||
*
|
||||
* @return true if quotation is needed
|
||||
*/
|
||||
|
@ -260,16 +320,22 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific UDT sub-type as a key and
|
||||
* simple sub-type as a value Java type is @Map
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific UDT sub-type
|
||||
* as a key and simple sub-type as a value Java type is @Map
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: put and putAll in @UpdateOperation.
|
||||
* <p>
|
||||
* For this type there are special operations: put and putAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -284,10 +350,12 @@ public final class Types {
|
|||
UDT key();
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT value sub-type in the map, consider @UDTMap annotations
|
||||
* <p>
|
||||
* In case if you need UDT value sub-type in the map, consider @UDTMap
|
||||
* annotations
|
||||
*
|
||||
* @return data type name of the value
|
||||
*/
|
||||
|
@ -295,17 +363,22 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.LIST data type in schema with specific UDT sub-type Java type
|
||||
* is @List
|
||||
* Says to use @DataType.Name.LIST data type in schema with specific UDT
|
||||
* sub-type Java type is @List
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: prepend, prependAll, setIdx, append, appendAll,
|
||||
* discard and discardAll in @UpdateOperation
|
||||
* <p>
|
||||
* For this type there are special operations: prepend, prependAll, setIdx,
|
||||
* append, appendAll, discard and discardAll in @UpdateOperation
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -321,16 +394,22 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific UDT sub-types Java type
|
||||
* is @Map
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific UDT
|
||||
* sub-types Java type is @Map
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: put and putAll in @UpdateOperation.
|
||||
* <p>
|
||||
* For this type there are special operations: put and putAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -345,7 +424,8 @@ public final class Types {
|
|||
UDT key();
|
||||
|
||||
/**
|
||||
* Clarification of using the UDT data type as a value sub-type in the collection.
|
||||
* Clarification of using the UDT data type as a value sub-type in the
|
||||
* collection.
|
||||
*
|
||||
* @return annotation of the UDT value
|
||||
*/
|
||||
|
@ -353,15 +433,21 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.SET data type in schema with specific UDT sub-type Java type is @Set
|
||||
* Says to use @DataType.Name.SET data type in schema with specific UDT sub-type
|
||||
* Java type is @Set
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: add, addAll, remove and removeAll
|
||||
* <p>
|
||||
* For this type there are special operations: add, addAll, remove and removeAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
|
@ -378,16 +464,22 @@ public final class Types {
|
|||
}
|
||||
|
||||
/**
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific simple sub-type as a key and
|
||||
* UDT sub-type as a value Java type is @Map
|
||||
* Says to use @DataType.Name.MAP data type in schema with specific simple
|
||||
* sub-type as a key and UDT sub-type as a value Java type is @Map
|
||||
*
|
||||
* <p>Helenus does not allow to use a specific implementation of the collection thereof data
|
||||
* retrieval operation result can be a collection with another implementation.
|
||||
* <p>
|
||||
* Helenus does not allow to use a specific implementation of the collection
|
||||
* thereof data retrieval operation result can be a collection with another
|
||||
* implementation.
|
||||
*
|
||||
* <p>This annotation is usually used only for sub-types clarification and only in case if
|
||||
* sub-type is Java type that corresponds to multiple Cassandra data types.
|
||||
* <p>
|
||||
* This annotation is usually used only for sub-types clarification and only in
|
||||
* case if sub-type is Java type that corresponds to multiple Cassandra data
|
||||
* types.
|
||||
*
|
||||
* <p>For this type there are special operations: put and putAll in @UpdateOperation.
|
||||
* <p>
|
||||
* For this type there are special operations: put and putAll
|
||||
* in @UpdateOperation.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
@ -395,32 +487,39 @@ public final class Types {
|
|||
public @interface UDTValueMap {
|
||||
|
||||
/**
|
||||
* Clarification of using the sub-type data type in the collection. It supports only simple data
|
||||
* type (not Collection, UDT or Tuple)
|
||||
* Clarification of using the sub-type data type in the collection. It supports
|
||||
* only simple data type (not Collection, UDT or Tuple)
|
||||
*
|
||||
* <p>In case if you need UDT key sub-type in the map, consider @UDTMap annotations
|
||||
* <p>
|
||||
* In case if you need UDT key sub-type in the map, consider @UDTMap annotations
|
||||
*
|
||||
* @return data type name of the key
|
||||
*/
|
||||
DataType.Name key();
|
||||
|
||||
/**
|
||||
* Clarification of using the UDT data type as a value sub-type in the collection.
|
||||
* Clarification of using the UDT data type as a value sub-type in the
|
||||
* collection.
|
||||
*
|
||||
* @return annotation of the UDT value
|
||||
*/
|
||||
UDT value();
|
||||
}
|
||||
|
||||
/** Says to use @DataType.Name.UUID type in schema Java type is @UUID Using by default */
|
||||
/**
|
||||
* Says to use @DataType.Name.UUID type in schema Java type is @UUID Using by
|
||||
* default
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Uuid {}
|
||||
public @interface Uuid {
|
||||
}
|
||||
|
||||
/** Says to use @DataType.Name.VARCHAR type in schema Java type is @String */
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value = {ElementType.METHOD, ElementType.ANNOTATION_TYPE})
|
||||
public @interface Varchar {}
|
||||
public @interface Varchar {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,10 +39,11 @@ public @interface UDT {
|
|||
String value() default "";
|
||||
|
||||
/**
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This property marks that the
|
||||
* name of the UDT type needs to be quoted.
|
||||
* For reserved words in Cassandra we need quotation in CQL queries. This
|
||||
* property marks that the name of the UDT type needs to be quoted.
|
||||
*
|
||||
* <p>Default value is false, we are quoting only selected names.
|
||||
* <p>
|
||||
* Default value is false, we are quoting only selected names.
|
||||
*
|
||||
* @return true if name have to be quoted
|
||||
*/
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package net.helenus.mapping.convert;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.core.reflect.MapExportable;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
*/
|
||||
package net.helenus.mapping.convert;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.google.common.base.CaseFormat;
|
||||
|
||||
public enum CamelCaseToUnderscoreConverter implements Function<String, String> {
|
||||
INSTANCE;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ package net.helenus.mapping.convert;
|
|||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.support.Timeuuid;
|
||||
|
||||
/** Simple Date to TimeUUID Converter */
|
||||
|
|
|
@ -17,6 +17,7 @@ package net.helenus.mapping.convert;
|
|||
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.Helenus;
|
||||
import net.helenus.mapping.HelenusEntity;
|
||||
import net.helenus.mapping.value.ColumnValueProvider;
|
||||
|
|
|
@ -18,6 +18,7 @@ package net.helenus.mapping.convert;
|
|||
import java.util.Date;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.support.Timeuuid;
|
||||
|
||||
public enum TimeuuidToDateConverter implements Function<UUID, Date> {
|
||||
|
|
|
@ -15,16 +15,17 @@
|
|||
*/
|
||||
package net.helenus.mapping.convert;
|
||||
|
||||
import com.datastax.driver.core.TupleType;
|
||||
import com.datastax.driver.core.TupleValue;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.TupleType;
|
||||
import com.datastax.driver.core.TupleValue;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.mapping.value.TupleColumnValuePreparer;
|
||||
|
||||
public class TupleValueWriter extends AbstractEntityValueWriter<TupleValue>
|
||||
implements Function<Object, TupleValue> {
|
||||
public class TupleValueWriter extends AbstractEntityValueWriter<TupleValue> implements Function<Object, TupleValue> {
|
||||
|
||||
private final TupleType tupleType;
|
||||
private final TupleColumnValuePreparer valuePreparer;
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package net.helenus.mapping.convert;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.support.HelenusMappingException;
|
||||
|
||||
public class TypedConverter<I, O> implements Function<Object, Object> {
|
||||
|
@ -30,8 +31,7 @@ public class TypedConverter<I, O> implements Function<Object, Object> {
|
|||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
public static <I, O> TypedConverter<I, O> create(
|
||||
Class<I> inputType, Class<O> outputType, Function<I, O> delegate) {
|
||||
public static <I, O> TypedConverter<I, O> create(Class<I> inputType, Class<O> outputType, Function<I, O> delegate) {
|
||||
return new TypedConverter<I, O>(inputType, outputType, delegate);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,16 +15,17 @@
|
|||
*/
|
||||
package net.helenus.mapping.convert;
|
||||
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
import com.datastax.driver.core.UserType;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
import com.datastax.driver.core.UserType;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.HelenusProperty;
|
||||
import net.helenus.mapping.value.UDTColumnValuePreparer;
|
||||
|
||||
public class UDTValueWriter extends AbstractEntityValueWriter<UDTValue>
|
||||
implements Function<Object, UDTValue> {
|
||||
public class UDTValueWriter extends AbstractEntityValueWriter<UDTValue> implements Function<Object, UDTValue> {
|
||||
|
||||
final UserType userType;
|
||||
final UDTColumnValuePreparer valuePreparer;
|
||||
|
|
|
@ -15,17 +15,17 @@
|
|||
*/
|
||||
package net.helenus.mapping.convert.tuple;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.datastax.driver.core.TupleType;
|
||||
import com.datastax.driver.core.TupleValue;
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.helenus.core.SessionRepository;
|
||||
import net.helenus.mapping.convert.TupleValueWriter;
|
||||
|
||||
public final class EntityToTupleValueConverter extends TupleValueWriter
|
||||
implements Function<Object, TupleValue> {
|
||||
public final class EntityToTupleValueConverter extends TupleValueWriter implements Function<Object, TupleValue> {
|
||||
|
||||
public EntityToTupleValueConverter(
|
||||
Class<?> iface, TupleType tupleType, SessionRepository repository) {
|
||||
public EntityToTupleValueConverter(Class<?> iface, TupleType tupleType, SessionRepository repository) {
|
||||
super(iface, tupleType, repository);
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue