make ordinal optional only for Column, add validations

This commit is contained in:
Albert Shift 2015-04-14 11:58:46 -07:00
parent 49736b594e
commit 9f1b2bfe7c
3 changed files with 58 additions and 4 deletions

View file

@ -17,6 +17,7 @@ package com.noorq.casser.mapping;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -143,8 +144,61 @@ public final class CasserMappingEntity implements CasserEntity {
throw new CasserMappingException("entity must be annotated by @Table or @Tuple or @UserDefinedType " + iface);
}
private void validateOrdinals() {
switch(getType()) {
case TABLE:
validateOrdinalsForTable();
break;
case TUPLE:
validateOrdinalsForTuple();
break;
default:
break;
}
}
private void validateOrdinalsForTable() {
BitSet partitionKeys = new BitSet();
BitSet clusteringColumns = new BitSet();
for (CasserProperty prop : getOrderedProperties()) {
ColumnType type = prop.getColumnType();
int ordinal = prop.getOrdinal();
switch(type) {
case PARTITION_KEY:
if (partitionKeys.get(ordinal)) {
throw new CasserMappingException("detected two or more partition key columns with the same ordinal " + ordinal + " in " + prop.getEntity());
}
partitionKeys.set(ordinal);
break;
case CLUSTERING_COLUMN:
if (clusteringColumns.get(ordinal)) {
throw new CasserMappingException("detected two or clustering columns with the same ordinal " + ordinal + " in " + prop.getEntity());
}
clusteringColumns.set(ordinal);
break;
default:
break;
}
}
}
private void validateOrdinalsForTuple() {
boolean[] ordinals = new boolean[props.size()];
getOrderedProperties().forEach(p -> {

View file

@ -27,7 +27,7 @@ import java.lang.annotation.Target;
@Target(value = { ElementType.METHOD, ElementType.ANNOTATION_TYPE })
public @interface Column {
int value();
int value() default 0;
String name() default "";

View file

@ -27,11 +27,11 @@ public interface Account {
@PartitionKey(0)
long id();
@Column(1)
@Column
Address address();
@UserTypeName("address0")
@Column(2)
@Column
UDTValue addressNoMapping();
}