@@ -52,12 +52,18 @@ public class PojoRepositoryImpl<T, ID extends Serializable>
5252 private Field idField ;
5353 private String idFieldName ;
5454
55- public PojoRepositoryImpl (DatabaseClient client , Class <T > entityClass , Class < ID > idClass ) {
55+ PojoRepositoryImpl (DatabaseClient client , Class <T > entityClass ) {
5656 this .client = client ;
5757 this .entityClass = entityClass ;
58- this .idClass = idClass ;
58+ this .idClass = null ;
5959 this .docMgr = client .newJSONDocumentManager ();
60+ this .docMgr .setResponseFormat (Format .JSON );
6061 this .qb = new PojoQueryBuilderImpl <T >(entityClass );
62+ }
63+
64+ PojoRepositoryImpl (DatabaseClient client , Class <T > entityClass , Class <ID > idClass ) {
65+ this (client , entityClass );
66+ this .idClass = idClass ;
6167 findId ();
6268 if ( idMethod == null && idField == null ) {
6369 throw new IllegalArgumentException ("Your class " + entityClass .getName () +
@@ -77,7 +83,8 @@ public void write(T entity, Transaction transaction) {
7783 public void write (T entity , Transaction transaction , String ... collections ) {
7884 if ( entity == null ) return ;
7985 JacksonPojoHandle contentHandle = new JacksonPojoHandle (entity );
80- contentHandle .getMapper ().enableDefaultTyping (ObjectMapper .DefaultTyping .NON_FINAL , JsonTypeInfo .As .WRAPPER_OBJECT );
86+ contentHandle .getMapper ().enableDefaultTyping (
87+ ObjectMapper .DefaultTyping .NON_FINAL , JsonTypeInfo .As .WRAPPER_OBJECT );
8188 DocumentMetadataHandle metadataHandle = new DocumentMetadataHandle ();
8289 metadataHandle = metadataHandle .withCollections (entityClass .getName ());
8390 if ( collections != null && collections .length > 0 ) {
@@ -125,56 +132,33 @@ public void delete(String... collections) {
125132 }
126133
127134 public T read (ID id ) {
128- return read (id , null , null );
129- }
130- public T read (ID id , String ... collections ) {
131- return read (id , null , collections );
135+ return read (id , null );
132136 }
133137 public T read (ID id , Transaction transaction ) {
134- return read (id , transaction , null );
135- }
136- public T read (ID id , Transaction transaction , String ... collections ) {
137- PojoPage <T > page = read (transaction , collections , id );
138+ ArrayList <ID > ids = new ArrayList <ID >();
139+ ids .add (id );
140+ PojoPage <T > page = read (ids .toArray ((ID [])new Serializable [0 ]), transaction );
138141 if ( page == null ) return null ;
139142 Iterator <T > iterator = page .iterator ();
140143 if ( iterator .hasNext () ) return iterator .next ();
141144 return null ;
142145 }
143- public PojoPage <T > read (ID ... ids ) {
144- return read (null , null , ids );
146+ public PojoPage <T > read (ID [] ids ) {
147+ return read (ids , null );
145148 }
146- public PojoPage <T > read (Transaction transaction , ID ... ids ) {
147- return read (transaction , null , ids );
148- }
149- public PojoPage <T > read (Transaction transaction , String [] collections , ID ... ids ) {
150- long pageLength = getPageLength ();
151- QueryDefinition query = null ;
152- if ( ids != null ) {
153- long tempPageLength = pageLength ;
154- tempPageLength = ids .length ;
155- setPageLength (tempPageLength );
156- if ( ids .length == 1 ) {
157- query = qb .value (idFieldName , String .valueOf (ids [0 ]));
158- } else {
159- ArrayList <StructuredQueryDefinition > idQueries =
160- new ArrayList <StructuredQueryDefinition >(ids .length );
161- for ( ID id : ids ) {
162- idQueries .add ( qb .value (idFieldName , String .valueOf (id )) );
163- }
164- query = qb .and ( idQueries .toArray (new StructuredQueryDefinition [0 ]));
165- }
166- if ( collections != null ) query .setCollections (collections );
167- } else {
168- if ( collections != null ) query = qb .collection (collections );
149+ public PojoPage <T > read (ID [] ids , Transaction transaction ) {
150+ ArrayList <String > uris = new ArrayList <String >();
151+ for ( ID id : ids ) {
152+ uris .add (createUri (id ));
169153 }
170- PojoPage page = search ( wrapQuery ( query ), 1 , null , transaction );
171- setPageLength ( pageLength );
172- return page ;
154+ DocumentPage docPage = ( DocumentPage ) docMgr . read ( transaction , uris . toArray ( new String [ 0 ]) );
155+ PojoPage < T > pojoPage = new PojoPageImpl ( docPage , entityClass );
156+ return pojoPage ;
173157 }
174- public PojoPage <T > read (long start ) {
158+ public PojoPage <T > readAll (long start ) {
175159 return search (null , start , null , null );
176160 }
177- public PojoPage <T > read (long start , Transaction transaction ) {
161+ public PojoPage <T > readAll (long start , Transaction transaction ) {
178162 return search (null , start , null , transaction );
179163 }
180164
@@ -213,8 +197,6 @@ public PojoPage<T> search(QueryDefinition query, long start, SearchReadHandle se
213197 }
214198
215199 String tid = transaction == null ? null : transaction .getTransactionId ();
216- // we don't need any metadata
217- Set metadata = null ;
218200 DocumentPage docPage = docMgr .search (wrapQuery (query ), start , searchHandle , transaction );
219201 docMgr .setResponseFormat (docMgrFormat );
220202 PojoPage <T > pojoPage = new PojoPageImpl (docPage , entityClass );
0 commit comments