-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from TeamWanari/1.0.4-improvements
1.0.4 improvements
- Loading branch information
Showing
10 changed files
with
244 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
src/main/java/com/wanari/utils/couchbase/CouchbasePage.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package com.wanari.utils.couchbase; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SpringContext { | ||
|
||
@Bean | ||
public CouchbaseQueryExecutor couchbaseQueryExecutor() { | ||
return new CouchbaseQueryExecutor(); | ||
public CouchbaseQueryExecutor couchbaseQueryExecutor(CouchbaseQueryExecutorConfiguration couchbaseConfiguration, ObjectMapper objectMapper) { | ||
return new CouchbaseQueryExecutor(couchbaseConfiguration, objectMapper); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/wanari/utils/couchbase/converters/CouchbaseDataConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.wanari.utils.couchbase.converters; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
|
||
public class CouchbaseDataConverter<T> implements DataConverter<T> { | ||
private final ObjectMapper objectMapper; | ||
|
||
public CouchbaseDataConverter(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Override | ||
public T apply(HashMap hashMap, Class<T> clazz) { | ||
LinkedHashMap data = (LinkedHashMap) hashMap.get("data"); | ||
data.put("id", hashMap.get("id")); | ||
return objectMapper.convertValue(data, clazz); | ||
} | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
...main/java/com/wanari/utils/couchbase/converters/CouchbaseDataConverterWithReflection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.wanari.utils.couchbase.converters; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
|
||
public class CouchbaseDataConverterWithReflection<T> implements DataConverterWithReflection<T> { | ||
|
||
private final ObjectMapper objectMapper; | ||
|
||
public CouchbaseDataConverterWithReflection(ObjectMapper objectMapper) { | ||
this.objectMapper = objectMapper; | ||
} | ||
|
||
@Override | ||
public T apply(HashMap hashMap, Class<T> clazz) { | ||
LinkedHashMap data = (LinkedHashMap) hashMap.get("data"); | ||
|
||
T obj = objectMapper.convertValue(data, clazz); | ||
setId(obj, hashMap, clazz); | ||
|
||
return obj; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/wanari/utils/couchbase/converters/DataConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.wanari.utils.couchbase.converters; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.BiFunction; | ||
|
||
@FunctionalInterface | ||
public interface DataConverter<R> extends BiFunction<HashMap, Class<R>, R> { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/wanari/utils/couchbase/converters/DataConverterWithReflection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.wanari.utils.couchbase.converters; | ||
|
||
import com.couchbase.client.java.repository.annotation.Id; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
|
||
public interface DataConverterWithReflection<T> extends DataConverter<T> { | ||
default void setId(T obj, HashMap hashMap, Class<T> clazz) { | ||
Arrays.stream(clazz.getDeclaredFields()).forEach(field -> { | ||
if(field.getAnnotation(Id.class) != null) { | ||
try { | ||
field.setAccessible(true); | ||
field.set(obj, hashMap.get("id")); | ||
} catch(IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.