diff --git a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparator.java b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparator.java
index 2c8f9e553..e9cc2ad9d 100644
--- a/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparator.java
+++ b/spring-data-cassandra/src/main/java/org/springframework/data/cassandra/mapping/CassandraPersistentPropertyComparator.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2013-2016 the original author or authors
+ * Copyright 2013-2017 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,10 +17,19 @@ package org.springframework.data.cassandra.mapping;
import java.util.Comparator;
+import org.springframework.cassandra.core.cql.CqlIdentifier;
+
/**
* {@link Comparator} implementation that orders {@link CassandraPersistentProperty} instances.
- *
- * Composite primary key properties and primary key properties sort before non-primary key properties.
+ *
+ * Composite primary key properties and primary key properties sort before non-primary key properties. Ordering rules:
+ *
+ * - Composite primary keys first (equal if both {@link CassandraPersistentProperty} are a composite primary key)
+ * - Primary key columns (see {@link CassandraPrimaryKeyColumnAnnotationComparator}, compare by ordinal/name/ordering)
+ *
+ * - Regular columns, compared by column name (see
+ * {@link org.springframework.cassandra.core.cql.CqlIdentifier#compareTo(CqlIdentifier)})
+ *
*
* @author Alex Shvid
* @author Matthew T. Adams
@@ -30,6 +39,16 @@ import java.util.Comparator;
* @see org.springframework.data.cassandra.mapping.CassandraPersistentProperty
*/
public enum CassandraPersistentPropertyComparator implements Comparator {
+
+ /**
+ * Comparator instance.
+ */
+ INSTANCE,
+
+ /**
+ * @deprecated as of 1.5, use {@link #INSTANCE}
+ */
+ @Deprecated
IT;
@Override
@@ -37,14 +56,11 @@ public enum CassandraPersistentPropertyComparator implements Comparator persistentEntity = context.getPersistentEntity(TwoColumns.class);
+
+ CassandraPersistentProperty annotated = persistentEntity.getPersistentProperty("annotated");
+ CassandraPersistentProperty another = persistentEntity.getPersistentProperty("anotherAnnotated");
+ CassandraPersistentProperty plain = persistentEntity.getPersistentProperty("plain");
+
+ assertThat(CassandraPersistentPropertyComparator.IT.compare(annotated, plain), is(lessThanOrEqualTo(-1)));
+ assertThat(CassandraPersistentPropertyComparator.IT.compare(plain, annotated), is(greaterThanOrEqualTo(1)));
+ assertThat(CassandraPersistentPropertyComparator.IT.compare(another, another), is(0));
+ }
+
+ static class TwoColumns {
+
+ @Column("annotated") String annotated;
+
+ @Column("another") String anotherAnnotated;
+
+ String plain;
}
}