diff --git a/src/main/java/net/helenus/core/SchemaUtil.java b/src/main/java/net/helenus/core/SchemaUtil.java index 0a12d35..4cf745b 100644 --- a/src/main/java/net/helenus/core/SchemaUtil.java +++ b/src/main/java/net/helenus/core/SchemaUtil.java @@ -337,7 +337,7 @@ public final class SchemaUtil { public static SchemaStatement createIndex(HelenusProperty prop) { if (prop.caseSensitiveIndex()) { - return SchemaBuilder.createIndex(prop.getIndexName().get().toCql()) + return SchemaBuilder.createIndex(indexName(prop)) .ifNotExists() .onTable(prop.getEntity().getName().toCql()) .andColumn(prop.getColumnName().toCql()); @@ -406,7 +406,7 @@ public final class SchemaUtil { } public static SchemaStatement dropIndex(HelenusProperty prop) { - return SchemaBuilder.dropIndex(prop.getIndexName().get().toCql()).ifExists(); + return SchemaBuilder.dropIndex(indexName(prop)).ifExists(); } private static SchemaBuilder.Direction mapDirection(OrderingDirection o) { @@ -465,4 +465,9 @@ public final class SchemaUtil { } return null; } + + private static String indexName(HelenusProperty prop) { + return prop.getEntity().getName().toCql() + "_" + prop.getIndexName().get().toCql(); + } + } diff --git a/src/main/java/net/helenus/core/reflect/Entity.java b/src/main/java/net/helenus/core/reflect/Entity.java index ff93edd..50af637 100644 --- a/src/main/java/net/helenus/core/reflect/Entity.java +++ b/src/main/java/net/helenus/core/reflect/Entity.java @@ -20,20 +20,53 @@ import net.helenus.core.Getter; public interface Entity { String WRITTEN_AT_METHOD = "writtenAt"; String TTL_OF_METHOD = "ttlOf"; + String TOKEN_OF_METHOD = "tokenOf"; + /** + * The write time for the property in question referenced by the getter. + * + * @param getter the property getter + * @return the timestamp associated with the property identified by the getter + */ default Long writtenAt(Getter getter) { return 0L; } + /** + * The write time for the property in question referenced by the property name. + * + * @param prop the name of a property in this entity + * @return the timestamp associated with the property identified by the property name if it exists + */ default Long writtenAt(String prop) { return 0L; }; + /** + * The time-to-live for the property in question referenced by the getter. + * + * @param getter the property getter + * @return the time-to-live in seconds associated with the property identified by the getter + */ default Integer ttlOf(Getter getter) { return 0; }; + /** + * The time-to-live for the property in question referenced by the property name. + * + * @param prop the name of a property in this entity + * @return the time-to-live in seconds associated with the property identified by the property name if it exists + */ default Integer ttlOf(String prop) { return 0; }; + + /** + * The token (partition identifier) for this entity which can change over time if + * the cluster grows or shrinks but should be stable otherwise. + * + * @return the token for the entity + */ + default Long tokenOf() { return 0L; } } diff --git a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java index 115ad84..53d9f2b 100644 --- a/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java +++ b/src/main/java/net/helenus/core/reflect/MapperInvocationHandler.java @@ -147,6 +147,14 @@ public class MapperInvocationHandler implements InvocationHandler, Serializab return 0L; } + if (Entity.TOKEN_OF_METHOD.equals(methodName) && method.getParameterCount() == 0) { + Long v = (Long) src.get(""); + if (v != null) { + return v; + } + return 0L; + } + if (Entity.TTL_OF_METHOD.equals(methodName) && method.getParameterCount() == 1) { final String key; if (args[0] instanceof String) {