Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

support for UUID in automated mapping #95

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+15 −6
Split
@@ -5,6 +5,7 @@
import java.lang.reflect.Field;
import java.util.Date;
+import java.util.UUID;
class Coercions {
static <T> void setFieldFromColumn(T instance, Field field,
@@ -36,6 +37,8 @@
objValue = column.getStringValue();
} else if (field.getType() == byte[].class) {
objValue = column.getByteArrayValue();
+ } else if (field.getType() == UUID.class) {
+ objValue = column.getUUIDValue();
} else {
throw new UnsupportedOperationException();
}
@@ -80,6 +83,8 @@
mutation.putColumn(columnName, (String) objValue, null);
} else if(objValue.getClass() == byte[].class) {
mutation.putColumn(columnName, (byte[]) objValue, null);
+ } else if (objValue.getClass() == UUID.class) {
+ mutation.putColumn(columnName, (UUID) objValue, null);
} else {
throw new UnsupportedOperationException();
}
@@ -1,9 +1,11 @@
package com.netflix.astyanax.mapping;
+import java.util.UUID;
+
@SuppressWarnings({ "UnusedDeclaration", "SimplifiableIfStatement" })
public class FakeKeyspaceBean implements Comparable<FakeKeyspaceBean> {
@Id("PK")
- private String id;
+ private UUID id;
@Column("OVERRIDE_BY_TYPE")
private String type;
@@ -40,7 +42,7 @@ public FakeKeyspaceBean() {
*
* @return value
*/
- public String getId() {
+ public UUID getId() {
return id;
}
@@ -50,7 +52,7 @@ public String getId() {
* @param id
* value
*/
- public void setId(String id) {
+ public void setId(UUID id) {
this.id = id;
}
@@ -3,11 +3,13 @@
import junit.framework.Assert;
import org.junit.Test;
+import java.util.UUID;
+
public class TestMapping {
@Test
public void testKeyspaceAnnotations() {
FakeKeyspaceBean override = new FakeKeyspaceBean();
- override.setId("1");
+ override.setId(UUID.fromString("553a6af3-14f0-419c-b257-b6c55babafe7"));
override.setCountry("USA");
override.setCountryStatus(2);
override.setCreateTS(12345678L);
@@ -20,10 +22,10 @@ public void testKeyspaceAnnotations() {
Mapping<FakeKeyspaceBean> mapping = Mapping
.make(FakeKeyspaceBean.class);
- Assert.assertEquals(mapping.getIdValue(override, String.class),
+ Assert.assertEquals(mapping.getIdValue(override, UUID.class),
override.getId());
Assert.assertEquals(
- mapping.getColumnValue(override, "PK", String.class),
+ mapping.getColumnValue(override, "PK", UUID.class),
override.getId());
Assert.assertEquals(mapping.getColumnValue(override,
"COUNTRY_OVERRIDE", String.class), override.getCountry());