Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

EntityMapper: Consider fields in parent class #248

Open
wants to merge 7 commits into from

4 participants

@snoopdave
  • Modifies EntityMapper so that it considers annotated fields in parent classes recursively.
  • Avoids a possible Null Pointer Exception in the LeafColumnMapper
snoopdave added some commits
@snoopdave snoopdave prevent NPE 64766d7
@snoopdave snoopdave Consider mapped fields in super classes, recursively 9fa24c5
@snoopdave snoopdave Merge branch 'master' of https://github.com/Netflix/astyanax
Conflicts:
	astyanax-entity-mapper/src/main/java/com/netflix/astyanax/entitystore/EntityMapper.java
	src/main/java/com/netflix/astyanax/entitystore/LeafColumnMapper.java
79e0f43
@snoopdave snoopdave fix merge mistake 4632ba1
@snoopdave snoopdave Merge branch 'master' of https://github.com/Netflix/astyanax
Conflicts:
	pom.xml
8afed09
@elandau
Owner

Looks good. Can you please provide some unit tests as well.

@oGLOWo

Awesome. I was just looking to implement this, but I figured I would look at the pull requests to see if anyone had done it. @elandau please accept @snoopdave 's pull request =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 21, 2013
  1. @snoopdave

    prevent NPE

    snoopdave authored
  2. @snoopdave
  3. @snoopdave

    Merge branch 'master' of https://github.com/Netflix/astyanax

    snoopdave authored
    Conflicts:
    	astyanax-entity-mapper/src/main/java/com/netflix/astyanax/entitystore/EntityMapper.java
    	src/main/java/com/netflix/astyanax/entitystore/LeafColumnMapper.java
  4. @snoopdave

    fix merge mistake

    snoopdave authored
Commits on Mar 25, 2013
  1. @snoopdave
Commits on Apr 30, 2013
  1. @snoopdave
Commits on May 1, 2013
  1. @snoopdave

    Call this build 1.2.2-WAYIN

    snoopdave authored
This page is out of date. Refresh to see the latest.
View
16 astyanax-entity-mapper/src/main/java/com/netflix/astyanax/entitystore/EntityMapper.java
@@ -25,6 +25,7 @@
import com.netflix.astyanax.MutationBatch;
import com.netflix.astyanax.model.ColumnFamily;
import com.netflix.astyanax.model.ColumnList;
+import java.util.ArrayList;
/**
* utility class to map btw root Entity and cassandra data model
@@ -83,7 +84,7 @@
}
this.ttlMethod = tmpTtlMethod;
- Field[] declaredFields = clazz.getDeclaredFields();
+ Field[] declaredFields = getFields(clazz, true).toArray(new Field[0]);
columnList = Maps.newHashMapWithExpectedSize(declaredFields.length);
Set<String> usedColumnNames = Sets.newHashSet();
Field tmpIdField = null;
@@ -119,6 +120,19 @@
idField = tmpIdField;
}
+ private List<Field> getFields(Class clazz, boolean recursuvely) {
+ List<Field> allFields = new ArrayList<Field>();
+ if (clazz.getDeclaredFields() != null && clazz.getDeclaredFields().length > 0) {
+ for (Field field : clazz.getDeclaredFields()) {
+ allFields.add(field);
+ }
+ if (recursuvely && clazz.getSuperclass() != null) {
+ allFields.addAll(getFields(clazz.getSuperclass(), true));
+ }
+ }
+ return allFields;
+ }
+
void fillMutationBatch(MutationBatch mb, ColumnFamily<K, String> columnFamily, T entity) {
try {
@SuppressWarnings("unchecked")
View
4 astyanax-entity-mapper/src/main/java/com/netflix/astyanax/entitystore/LeafColumnMapper.java
@@ -38,7 +38,9 @@ public boolean fillMutationBatch(Object entity, ColumnListMutation<String> clm,
final Serializer valueSerializer = serializer;
// TODO: suppress the unchecked raw type now.
// we have to use the raw type to avoid compiling error
- clm.putColumn(prefix + columnName, value, valueSerializer, null);
+ if (value != null) {
+ clm.putColumn(prefix + columnName, value, valueSerializer, null);
+ }
return true;
}
View
2  gradle.properties
@@ -1 +1 @@
-version=1.56.39-SNAPSHOT
+version=1.2.2-WAYIN
Something went wrong with that request. Please try again.