Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for UUID in automated mapping #95

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/netflix/astyanax/mapping/Coercions.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -36,6 +37,8 @@ static <T> void setFieldFromColumn(T instance, Field field,
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();
}
Expand Down Expand Up @@ -80,6 +83,8 @@ static <T> void setColumnMutationFromField(T instance, Field field,
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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -40,7 +42,7 @@ public FakeKeyspaceBean() {
*
* @return value
*/
public String getId() {
public UUID getId() {
return id;
}

Expand All @@ -50,7 +52,7 @@ public String getId() {
* @param id
* value
*/
public void setId(String id) {
public void setId(UUID id) {
this.id = id;
}

Expand Down
8 changes: 5 additions & 3 deletions src/test/java/com/netflix/astyanax/mapping/TestMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down