Formatting
This commit is contained in:
parent
7c683acb56
commit
a3b9ff9af3
26 changed files with 202 additions and 218 deletions
|
@ -69,39 +69,6 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
return new CreateCustomIndex.CreateIndexOn();
|
||||
}
|
||||
|
||||
public class CreateIndexOn extends CreateIndex.CreateIndexOn {
|
||||
/**
|
||||
* Specify the column to create the index on.
|
||||
*
|
||||
* @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));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index on the keys of the given map column.
|
||||
*
|
||||
* @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));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
CreateCustomIndex.this.keys = true;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
}
|
||||
}
|
||||
|
||||
String getCustomClassName() {
|
||||
return "";
|
||||
}
|
||||
|
@ -145,4 +112,37 @@ public class CreateCustomIndex extends CreateIndex {
|
|||
|
||||
return createStatement.toString();
|
||||
}
|
||||
|
||||
public class CreateIndexOn extends CreateIndex.CreateIndexOn {
|
||||
/**
|
||||
* Specify the column to create the index on.
|
||||
*
|
||||
* @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));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an index on the keys of the given map column.
|
||||
*
|
||||
* @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));
|
||||
CreateCustomIndex.this.columnName = columnName;
|
||||
CreateCustomIndex.this.keys = true;
|
||||
return SchemaStatement.fromQueryString(buildInternal());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,15 +4,10 @@ import com.google.common.base.Optional;
|
|||
|
||||
public class DropMaterializedView extends Drop {
|
||||
|
||||
enum DroppedItem {
|
||||
TABLE, TYPE, INDEX, MATERIALIZED_VIEW
|
||||
}
|
||||
|
||||
private final String itemType = "MATERIALIZED VIEW";
|
||||
private Optional<String> keyspaceName = Optional.absent();
|
||||
private String itemName;
|
||||
private boolean ifExists = true;
|
||||
private final String itemType = "MATERIALIZED VIEW";
|
||||
|
||||
public DropMaterializedView(String keyspaceName, String viewName) {
|
||||
this(keyspaceName, viewName, DroppedItem.MATERIALIZED_VIEW);
|
||||
}
|
||||
|
@ -47,4 +42,8 @@ public class DropMaterializedView extends Drop {
|
|||
dropStatement.append(itemName);
|
||||
return dropStatement.toString();
|
||||
}
|
||||
|
||||
enum DroppedItem {
|
||||
TABLE, TYPE, INDEX, MATERIALIZED_VIEW
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,6 @@ public final class Filter<V> {
|
|||
this.postulate = postulate;
|
||||
}
|
||||
|
||||
public HelenusPropertyNode getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public Clause getClause(ColumnValuePreparer valuePreparer) {
|
||||
return postulate.getClause(node, valuePreparer);
|
||||
}
|
||||
|
||||
public static <V> Filter<V> equal(Getter<V> getter, V val) {
|
||||
return create(getter, Operator.EQ, val);
|
||||
}
|
||||
|
@ -105,6 +97,14 @@ public final class Filter<V> {
|
|||
return new Filter<V>(node, postulate);
|
||||
}
|
||||
|
||||
public HelenusPropertyNode getNode() {
|
||||
return node;
|
||||
}
|
||||
|
||||
public Clause getClause(ColumnValuePreparer valuePreparer) {
|
||||
return postulate.getClause(node, valuePreparer);
|
||||
}
|
||||
|
||||
public V[] postulateValues() {
|
||||
return postulate.values();
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@ 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 Set<HelenusSession> sessions = new HashSet<HelenusSession>();
|
||||
private static volatile HelenusSettings settings = new DefaultHelenusSettings();
|
||||
private static volatile HelenusSession singleton;
|
||||
|
||||
private Helenus() {
|
||||
|
|
|
@ -59,8 +59,6 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
|
||||
private final Session session;
|
||||
private final CodecRegistry registry;
|
||||
private volatile String usingKeyspace;
|
||||
private volatile boolean showCql;
|
||||
private final ConsistencyLevel defaultConsistencyLevel;
|
||||
private final boolean defaultQueryIdempotency;
|
||||
private final MetricRegistry metricRegistry;
|
||||
|
@ -71,10 +69,11 @@ public final class HelenusSession extends AbstractSessionOperations implements C
|
|||
private final Executor executor;
|
||||
private final boolean dropSchemaOnClose;
|
||||
private final Cache sessionCache;
|
||||
|
||||
private final RowColumnValueProvider valueProvider;
|
||||
private final StatementColumnValuePreparer valuePreparer;
|
||||
private final Metadata metadata;
|
||||
private volatile String usingKeyspace;
|
||||
private volatile boolean showCql;
|
||||
|
||||
HelenusSession(Session session, String usingKeyspace, CodecRegistry registry, boolean showCql,
|
||||
PrintStream printStream, SessionRepositoryBuilder sessionRepositoryBuilder, Executor executor,
|
||||
|
|
|
@ -31,8 +31,6 @@ public enum Operator {
|
|||
|
||||
LTE("<=");
|
||||
|
||||
private final String name;
|
||||
|
||||
private static final Map<String, Operator> indexByName = new HashMap<String, Operator>();
|
||||
|
||||
static {
|
||||
|
@ -41,15 +39,17 @@ public enum Operator {
|
|||
}
|
||||
}
|
||||
|
||||
private final String name;
|
||||
|
||||
private Operator(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public static Operator findByOperator(String name) {
|
||||
return indexByName.get(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import net.helenus.support.PackageUtil;
|
|||
public final class SessionInitializer extends AbstractSessionOperations {
|
||||
|
||||
private final Session session;
|
||||
private final List<Either<Object, Class<?>>> initList = new ArrayList<Either<Object, Class<?>>>();
|
||||
private CodecRegistry registry;
|
||||
private String usingKeyspace;
|
||||
private boolean showCql = false;
|
||||
|
@ -50,15 +51,10 @@ public final class SessionInitializer extends AbstractSessionOperations {
|
|||
private PrintStream printStream = System.out;
|
||||
private Executor executor = MoreExecutors.directExecutor();
|
||||
private Class<? extends UnitOfWork> unitOfWorkClass = UnitOfWorkImpl.class;
|
||||
|
||||
private SessionRepositoryBuilder sessionRepository;
|
||||
|
||||
private boolean dropUnusedColumns = false;
|
||||
private boolean dropUnusedIndexes = false;
|
||||
|
||||
private KeyspaceMetadata keyspaceMetadata;
|
||||
|
||||
private final List<Either<Object, Class<?>>> initList = new ArrayList<Either<Object, Class<?>>>();
|
||||
private AutoDdl autoDdl = AutoDdl.UPDATE;
|
||||
|
||||
SessionInitializer(Session session) {
|
||||
|
|
|
@ -40,11 +40,10 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class InsertOperation<T> extends AbstractOperation<T, InsertOperation<T>> {
|
||||
|
||||
private HelenusEntity entity;
|
||||
|
||||
private final List<Fun.Tuple2<HelenusPropertyNode, Object>> values = new ArrayList<Fun.Tuple2<HelenusPropertyNode, Object>>();
|
||||
private final T pojo;
|
||||
private final Class<?> resultType;
|
||||
private HelenusEntity entity;
|
||||
private boolean ifNotExists;
|
||||
|
||||
private int[] ttl;
|
||||
|
|
|
@ -34,12 +34,10 @@ import net.helenus.support.Immutables;
|
|||
|
||||
public final class UpdateOperation<E> extends AbstractFilterOperation<E, UpdateOperation<E>> {
|
||||
|
||||
private HelenusEntity entity = null;
|
||||
|
||||
private final List<Assignment> assignments = new ArrayList<Assignment>();
|
||||
private final AbstractEntityDraft<E> draft;
|
||||
private final Map<String, Object> draftMap;
|
||||
|
||||
private HelenusEntity entity = null;
|
||||
private int[] ttl;
|
||||
private long[] timestamp;
|
||||
|
||||
|
|
|
@ -22,9 +22,6 @@ 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);
|
||||
|
||||
private final Class<?> primitiveClass;
|
||||
private final Object defaultValue;
|
||||
|
||||
private static final Map<Class<?>, DefaultPrimitiveTypes> map = new HashMap<Class<?>, DefaultPrimitiveTypes>();
|
||||
|
||||
static {
|
||||
|
@ -33,6 +30,9 @@ public enum DefaultPrimitiveTypes {
|
|||
}
|
||||
}
|
||||
|
||||
private final Class<?> primitiveClass;
|
||||
private final Object defaultValue;
|
||||
|
||||
private DefaultPrimitiveTypes(Class<?> primitiveClass, Object defaultValue) {
|
||||
this.primitiveClass = primitiveClass;
|
||||
this.defaultValue = defaultValue;
|
||||
|
|
|
@ -36,18 +36,14 @@ import net.helenus.support.HelenusException;
|
|||
|
||||
public class DslInvocationHandler<E> implements InvocationHandler {
|
||||
|
||||
private HelenusEntity entity = null;
|
||||
private Metadata metadata = null;
|
||||
|
||||
private final Class<E> iface;
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
private final Optional<HelenusPropertyNode> parent;
|
||||
|
||||
private final Map<Method, HelenusProperty> map = new HashMap<Method, HelenusProperty>();
|
||||
|
||||
private final Map<Method, Object> udtMap = new HashMap<Method, Object>();
|
||||
private final Map<Method, Object> tupleMap = new HashMap<Method, Object>();
|
||||
private HelenusEntity entity = null;
|
||||
private Metadata metadata = null;
|
||||
|
||||
public DslInvocationHandler(Class<E> iface, ClassLoader classLoader, Optional<HelenusPropertyNode> parent,
|
||||
Metadata metadata) {
|
||||
|
|
|
@ -138,6 +138,42 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
this.facets = facetsBuilder.build();
|
||||
}
|
||||
|
||||
private static IdentityName resolveName(Class<?> iface, HelenusEntityType type) {
|
||||
|
||||
switch (type) {
|
||||
case TABLE :
|
||||
return MappingUtil.getTableName(iface, true);
|
||||
|
||||
case VIEW :
|
||||
return MappingUtil.getViewName(iface, true);
|
||||
|
||||
case TUPLE :
|
||||
return IdentityName.of(MappingUtil.getDefaultEntityName(iface), false);
|
||||
|
||||
case UDT :
|
||||
return MappingUtil.getUserDefinedTypeName(iface, true);
|
||||
}
|
||||
|
||||
throw new HelenusMappingException("invalid entity type " + type + " in " + type);
|
||||
}
|
||||
|
||||
private static HelenusEntityType autoDetectType(Class<?> iface) {
|
||||
|
||||
Objects.requireNonNull(iface, "empty iface");
|
||||
|
||||
if (null != iface.getDeclaredAnnotation(Table.class)) {
|
||||
return HelenusEntityType.TABLE;
|
||||
} else if (null != iface.getDeclaredAnnotation(MaterializedView.class)) {
|
||||
return HelenusEntityType.VIEW;
|
||||
} else if (null != iface.getDeclaredAnnotation(Tuple.class)) {
|
||||
return HelenusEntityType.TUPLE;
|
||||
} else if (null != iface.getDeclaredAnnotation(UDT.class)) {
|
||||
return HelenusEntityType.UDT;
|
||||
}
|
||||
|
||||
throw new HelenusMappingException("entity must be annotated by @Table or @Tuple or @UserDefinedType " + iface);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HelenusEntityType getType() {
|
||||
return type;
|
||||
|
@ -178,42 +214,6 @@ public final class HelenusMappingEntity implements HelenusEntity {
|
|||
return name;
|
||||
}
|
||||
|
||||
private static IdentityName resolveName(Class<?> iface, HelenusEntityType type) {
|
||||
|
||||
switch (type) {
|
||||
case TABLE :
|
||||
return MappingUtil.getTableName(iface, true);
|
||||
|
||||
case VIEW :
|
||||
return MappingUtil.getViewName(iface, true);
|
||||
|
||||
case TUPLE :
|
||||
return IdentityName.of(MappingUtil.getDefaultEntityName(iface), false);
|
||||
|
||||
case UDT :
|
||||
return MappingUtil.getUserDefinedTypeName(iface, true);
|
||||
}
|
||||
|
||||
throw new HelenusMappingException("invalid entity type " + type + " in " + type);
|
||||
}
|
||||
|
||||
private static HelenusEntityType autoDetectType(Class<?> iface) {
|
||||
|
||||
Objects.requireNonNull(iface, "empty iface");
|
||||
|
||||
if (null != iface.getDeclaredAnnotation(Table.class)) {
|
||||
return HelenusEntityType.TABLE;
|
||||
} else if (null != iface.getDeclaredAnnotation(MaterializedView.class)) {
|
||||
return HelenusEntityType.VIEW;
|
||||
} else if (null != iface.getDeclaredAnnotation(Tuple.class)) {
|
||||
return HelenusEntityType.TUPLE;
|
||||
} else if (null != iface.getDeclaredAnnotation(UDT.class)) {
|
||||
return HelenusEntityType.UDT;
|
||||
}
|
||||
|
||||
throw new HelenusMappingException("entity must be annotated by @Table or @Tuple or @UserDefinedType " + iface);
|
||||
}
|
||||
|
||||
private void validateOrdinals() {
|
||||
|
||||
switch (getType()) {
|
||||
|
|
|
@ -45,12 +45,10 @@ public final class HelenusMappingProperty implements HelenusProperty {
|
|||
private final Class<?> javaType;
|
||||
private final AbstractJavaType abstractJavaType;
|
||||
private final AbstractDataType dataType;
|
||||
|
||||
private final ConstraintValidator<? extends Annotation, ?>[] validators;
|
||||
private volatile Optional<Function<Object, Object>> readConverter = null;
|
||||
private volatile Optional<Function<Object, Object>> writeConverter = null;
|
||||
|
||||
private final ConstraintValidator<? extends Annotation, ?>[] validators;
|
||||
|
||||
public HelenusMappingProperty(HelenusMappingEntity entity, Method getter, Metadata metadata) {
|
||||
this.entity = entity;
|
||||
this.getter = getter;
|
||||
|
|
|
@ -28,10 +28,6 @@ public enum OrderingDirection {
|
|||
this.cql = cql;
|
||||
}
|
||||
|
||||
public String cql() {
|
||||
return cql;
|
||||
}
|
||||
|
||||
public static OrderingDirection parseString(String name) {
|
||||
|
||||
if (ASC.cql.equalsIgnoreCase(name)) {
|
||||
|
@ -42,4 +38,8 @@ public enum OrderingDirection {
|
|||
|
||||
throw new HelenusMappingException("invalid ordering direction name " + name);
|
||||
}
|
||||
|
||||
public String cql() {
|
||||
return cql;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,14 +25,14 @@ import net.helenus.mapping.value.BeanColumnValueProvider;
|
|||
|
||||
public abstract class AbstractEntityValueWriter<V> {
|
||||
|
||||
abstract void writeColumn(V outValue, Object value, HelenusProperty prop);
|
||||
|
||||
final HelenusEntity entity;
|
||||
|
||||
public AbstractEntityValueWriter(Class<?> iface) {
|
||||
this.entity = Helenus.entity(iface);
|
||||
}
|
||||
|
||||
abstract void writeColumn(V outValue, Object value, HelenusProperty prop);
|
||||
|
||||
public void write(V outValue, Object source) {
|
||||
|
||||
if (source instanceof MapExportable) {
|
||||
|
|
|
@ -39,29 +39,6 @@ public abstract class AbstractJavaType {
|
|||
return false;
|
||||
}
|
||||
|
||||
public abstract Class<?> getJavaClass();
|
||||
|
||||
public boolean isApplicable(Class<?> javaClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract AbstractDataType resolveDataType(Method getter, Type genericJavaType, ColumnType columnType,
|
||||
Metadata metadata);
|
||||
|
||||
public Optional<Class<?>> getPrimitiveJavaClass() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Function<Object, Object>> resolveReadConverter(AbstractDataType dataType,
|
||||
SessionRepository repository) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Function<Object, Object>> resolveWriteConverter(AbstractDataType dataType,
|
||||
SessionRepository repository) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
static IdentityName resolveUDT(Types.UDT annotation) {
|
||||
return IdentityName.of(annotation.value(), annotation.forceQuote());
|
||||
}
|
||||
|
@ -82,21 +59,6 @@ public abstract class AbstractJavaType {
|
|||
}
|
||||
}
|
||||
|
||||
static class DataTypeInfo {
|
||||
final DataType dataType;
|
||||
final Class<?> typeArgument;
|
||||
|
||||
DataTypeInfo(DataType dataType) {
|
||||
this.dataType = dataType;
|
||||
this.typeArgument = null;
|
||||
}
|
||||
|
||||
DataTypeInfo(DataType dataType, Class<?> typeArgument) {
|
||||
this.dataType = dataType;
|
||||
this.typeArgument = typeArgument;
|
||||
}
|
||||
}
|
||||
|
||||
static Either<DataType, IdentityName> autodetectParameterType(Method getter, Type type, Metadata metadata) {
|
||||
|
||||
DataType dataType = null;
|
||||
|
@ -137,4 +99,42 @@ public abstract class AbstractJavaType {
|
|||
|
||||
return new Type[]{};
|
||||
}
|
||||
|
||||
public abstract Class<?> getJavaClass();
|
||||
|
||||
public boolean isApplicable(Class<?> javaClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public abstract AbstractDataType resolveDataType(Method getter, Type genericJavaType, ColumnType columnType,
|
||||
Metadata metadata);
|
||||
|
||||
public Optional<Class<?>> getPrimitiveJavaClass() {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Function<Object, Object>> resolveReadConverter(AbstractDataType dataType,
|
||||
SessionRepository repository) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Function<Object, Object>> resolveWriteConverter(AbstractDataType dataType,
|
||||
SessionRepository repository) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
static class DataTypeInfo {
|
||||
final DataType dataType;
|
||||
final Class<?> typeArgument;
|
||||
|
||||
DataTypeInfo(DataType dataType) {
|
||||
this.dataType = dataType;
|
||||
this.typeArgument = null;
|
||||
}
|
||||
|
||||
DataTypeInfo(DataType dataType, Class<?> typeArgument) {
|
||||
this.dataType = dataType;
|
||||
this.typeArgument = typeArgument;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,9 @@ public final class MappingJavaTypes {
|
|||
knownTypes = builder.build();
|
||||
}
|
||||
|
||||
private MappingJavaTypes() {
|
||||
}
|
||||
|
||||
private static void add(ImmutableMap.Builder<Class<?>, AbstractJavaType> builder, AbstractJavaType jt) {
|
||||
|
||||
builder.put(jt.getJavaClass(), jt);
|
||||
|
@ -76,9 +79,6 @@ public final class MappingJavaTypes {
|
|||
}
|
||||
}
|
||||
|
||||
private MappingJavaTypes() {
|
||||
}
|
||||
|
||||
public static AbstractJavaType resolveJavaType(Class<?> javaClass) {
|
||||
|
||||
AbstractJavaType ajt = knownTypes.get(javaClass);
|
||||
|
|
|
@ -43,6 +43,26 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public final class TupleValueJavaType extends AbstractJavaType {
|
||||
|
||||
public static TupleType toTupleType(Class<?> javaType, Metadata metadata) {
|
||||
HelenusEntity tupleEntity = Helenus.entity(javaType, metadata);
|
||||
|
||||
List<DataType> tupleTypes = tupleEntity.getOrderedProperties().stream().map(p -> p.getDataType())
|
||||
.filter(d -> d instanceof DTDataType).map(d -> (DTDataType) d).map(d -> d.getDataType())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (tupleTypes.size() < tupleEntity.getOrderedProperties().size()) {
|
||||
|
||||
List<IdentityName> wrongColumns = tupleEntity.getOrderedProperties().stream()
|
||||
.filter(p -> !(p.getDataType() instanceof DTDataType)).map(p -> p.getColumnName())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
throw new HelenusMappingException(
|
||||
"non simple types in tuple " + tupleEntity.getMappingInterface() + " in columns: " + wrongColumns);
|
||||
}
|
||||
|
||||
return metadata.newTupleType(tupleTypes.toArray(new DataType[tupleTypes.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> getJavaClass() {
|
||||
return TupleValue.class;
|
||||
|
@ -82,26 +102,6 @@ public final class TupleValueJavaType extends AbstractJavaType {
|
|||
}
|
||||
}
|
||||
|
||||
public static TupleType toTupleType(Class<?> javaType, Metadata metadata) {
|
||||
HelenusEntity tupleEntity = Helenus.entity(javaType, metadata);
|
||||
|
||||
List<DataType> tupleTypes = tupleEntity.getOrderedProperties().stream().map(p -> p.getDataType())
|
||||
.filter(d -> d instanceof DTDataType).map(d -> (DTDataType) d).map(d -> d.getDataType())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (tupleTypes.size() < tupleEntity.getOrderedProperties().size()) {
|
||||
|
||||
List<IdentityName> wrongColumns = tupleEntity.getOrderedProperties().stream()
|
||||
.filter(p -> !(p.getDataType() instanceof DTDataType)).map(p -> p.getColumnName())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
throw new HelenusMappingException(
|
||||
"non simple types in tuple " + tupleEntity.getMappingInterface() + " in columns: " + wrongColumns);
|
||||
}
|
||||
|
||||
return metadata.newTupleType(tupleTypes.toArray(new DataType[tupleTypes.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<Function<Object, Object>> resolveReadConverter(AbstractDataType dataType,
|
||||
SessionRepository repository) {
|
||||
|
|
|
@ -26,6 +26,12 @@ import net.helenus.support.HelenusMappingException;
|
|||
|
||||
public abstract class AbstractDataType {
|
||||
|
||||
final ColumnType columnType;
|
||||
|
||||
public AbstractDataType(ColumnType columnType) {
|
||||
this.columnType = columnType;
|
||||
}
|
||||
|
||||
public abstract void addColumn(Create create, IdentityName columnName);
|
||||
|
||||
public abstract void addColumn(CreateType create, IdentityName columnName);
|
||||
|
@ -35,12 +41,6 @@ public abstract class AbstractDataType {
|
|||
|
||||
public abstract Class<?>[] getTypeArguments();
|
||||
|
||||
final ColumnType columnType;
|
||||
|
||||
public AbstractDataType(ColumnType columnType) {
|
||||
this.columnType = columnType;
|
||||
}
|
||||
|
||||
public ColumnType getColumnType() {
|
||||
return columnType;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ import net.helenus.mapping.annotation.Constraints;
|
|||
|
||||
public final class LowerCaseValidator implements ConstraintValidator<Constraints.LowerCase, CharSequence> {
|
||||
|
||||
private static boolean isUpperCaseLetter(char ch) {
|
||||
return ch >= 'A' && ch <= 'Z';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Constraints.LowerCase constraintAnnotation) {
|
||||
}
|
||||
|
@ -48,8 +52,4 @@ public final class LowerCaseValidator implements ConstraintValidator<Constraints
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isUpperCaseLetter(char ch) {
|
||||
return ch >= 'A' && ch <= 'Z';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ import net.helenus.mapping.annotation.Constraints;
|
|||
|
||||
public class NumberValidator implements ConstraintValidator<Constraints.Number, CharSequence> {
|
||||
|
||||
private static boolean isNumber(char ch) {
|
||||
return ch >= '0' && ch <= '9';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Constraints.Number constraintAnnotation) {
|
||||
}
|
||||
|
@ -45,8 +49,4 @@ public class NumberValidator implements ConstraintValidator<Constraints.Number,
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isNumber(char ch) {
|
||||
return ch >= '0' && ch <= '9';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,10 @@ import net.helenus.mapping.annotation.Constraints;
|
|||
|
||||
public final class UpperCaseValidator implements ConstraintValidator<Constraints.UpperCase, CharSequence> {
|
||||
|
||||
private static boolean isLowerCaseLetter(char ch) {
|
||||
return ch >= 'a' && ch <= 'z';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(Constraints.UpperCase constraintAnnotation) {
|
||||
}
|
||||
|
@ -48,8 +52,4 @@ public final class UpperCaseValidator implements ConstraintValidator<Constraints
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isLowerCaseLetter(char ch) {
|
||||
return ch >= 'a' && ch <= 'z';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,14 @@ public final class Either<L, R> {
|
|||
this.right = right;
|
||||
}
|
||||
|
||||
public static <L, R> Either<L, R> left(L left) {
|
||||
return new Either<L, R>(left, null);
|
||||
}
|
||||
|
||||
public static <L, R> Either<L, R> right(R right) {
|
||||
return new Either<L, R>(null, right);
|
||||
}
|
||||
|
||||
public boolean isLeft() {
|
||||
return left != null;
|
||||
}
|
||||
|
@ -43,14 +51,6 @@ public final class Either<L, R> {
|
|||
return right;
|
||||
}
|
||||
|
||||
public static <L, R> Either<L, R> left(L left) {
|
||||
return new Either<L, R>(left, null);
|
||||
}
|
||||
|
||||
public static <L, R> Either<L, R> right(R right) {
|
||||
return new Either<L, R>(null, right);
|
||||
}
|
||||
|
||||
public EitherCase getCase() {
|
||||
if (left != null) {
|
||||
return EitherCase.LEFT;
|
||||
|
|
|
@ -31,9 +31,8 @@ import org.slf4j.LoggerFactory;
|
|||
|
||||
public class PackageUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PackageUtil.class);
|
||||
|
||||
public static final String JAR_URL_SEPARATOR = "!/";
|
||||
private static final Logger log = LoggerFactory.getLogger(PackageUtil.class);
|
||||
|
||||
private static void doFetchInPath(Set<Class<?>> classes, File directory, String packageName,
|
||||
ClassLoader classLoader) throws ClassNotFoundException {
|
||||
|
|
|
@ -21,10 +21,6 @@ import java.util.UUID;
|
|||
|
||||
public final class Timeuuid {
|
||||
|
||||
private static class Holder {
|
||||
static final SecureRandom numberGenerator = new SecureRandom();
|
||||
}
|
||||
|
||||
private Timeuuid() {
|
||||
}
|
||||
|
||||
|
@ -72,4 +68,8 @@ public final class Timeuuid {
|
|||
public static long getTimestampMillis(UUID uuid) {
|
||||
return UuidBuilder.getTimestampMillis(uuid);
|
||||
}
|
||||
|
||||
private static class Holder {
|
||||
static final SecureRandom numberGenerator = new SecureRandom();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,10 @@ public final class UuidBuilder {
|
|||
|
||||
private long mostSigBits = 0L;
|
||||
|
||||
public static long getTimestampMillis(UUID uuid) {
|
||||
return (uuid.timestamp() - NUM_100NS_SINCE_UUID_EPOCH) / NUM_100NS_IN_MILLISECOND;
|
||||
}
|
||||
|
||||
public long getLeastSignificantBits() {
|
||||
return leastSigBits;
|
||||
}
|
||||
|
@ -87,8 +91,4 @@ public final class UuidBuilder {
|
|||
this.leastSigBits = MAX_CLOCK_SEQ_AND_NODE;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static long getTimestampMillis(UUID uuid) {
|
||||
return (uuid.timestamp() - NUM_100NS_SINCE_UUID_EPOCH) / NUM_100NS_IN_MILLISECOND;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue