@@ -45,6 +45,7 @@ this software and associated documentation files (the "Software"), to deal in
4545import java .util .concurrent .ConcurrentHashMap ;
4646import java .util .concurrent .ExecutorService ;
4747import java .util .concurrent .Executors ;
48+ import java .util .concurrent .Future ;
4849import javax .persistence .*;
4950
5051/**
@@ -111,7 +112,11 @@ public static int getCLASS_ID() {
111112 private static ThreadLocal <Session > contextSession = new ThreadLocal <Session >();
112113
113114 @ Transient
114- private final ExecutorService streampool = Executors .newCachedThreadPool ();
115+ private static final ExecutorService rqpool = Executors .newCachedThreadPool ();
116+ @ Transient
117+ private volatile RetrieveQueue retrieveQueue ;
118+ @ Transient
119+ private static final ExecutorService streampool = Executors .newCachedThreadPool ();
115120 @ Transient
116121 private final Map <Long , Integer > streammap = new ConcurrentHashMap <>();
117122 @ Transient
@@ -168,7 +173,7 @@ private void startStatement(LLT llt) throws Exception {
168173 //this.getTransaction().startStatement(this, llt);
169174 }
170175
171- public void setTransaction (Transaction transaction ) {
176+ protected void setTransaction (Transaction transaction ) {
172177 this .transaction = transaction ;
173178 }
174179
@@ -269,27 +274,36 @@ public EntityFactory getEntityFactory(Class c) {
269274 return new EntityFactory (c , this );
270275 }
271276
272- public List < Object > getAll (Class c ) throws Exception {
277+ public Object find (Class c , long id ) throws Exception {
273278 final Table t = Instance .getInstance ().getTableByName (c .getName ());
274279 if (t != null ) {
275280 this .startStatement ();
276- // t.lockTable(this);
277- final List <Object > r = t .getAll (this , 0 );
278- // t.unlockTable(this);
279- return r ;
281+ return t .getChunkById (id , this ).getEntity ();
280282 }
281283 return null ;
282284 }
283285
284- public Object find (Class c , long id ) throws Exception {
285- final Table t = Instance .getInstance ().getTableByName (c .getName ());
286+ protected synchronized RetrieveQueue getContentQueue (Table t ) {
286287 if (t != null ) {
287- this .startStatement ();
288- return t .getChunkById (id , this ).getEntity ();
288+ retrieveQueue = t .getContentQueue (this );
289+ Future f = rqpool .submit (retrieveQueue .getR ());
290+ return retrieveQueue ;
289291 }
290292 return null ;
291293 }
292294
295+ public void closeQueue () {
296+ if (this .retrieveQueue != null ) {
297+ retrieveQueue .stop ();
298+ }
299+ retrieveQueue = null ;
300+ }
301+
302+ public void close () {
303+ rqpool .shutdownNow ();
304+ streampool .isShutdown ();
305+ }
306+
293307 //todo uncommitted data not retrieved
294308 public void stream (Class c , StreamCallable task ) {
295309 final Map <Long , Long > retrieved = new HashMap <>();
@@ -318,17 +332,7 @@ public void run() {
318332 });
319333 }
320334
321- public List <Object > ngetAll (Class c ) throws Exception {
322- final Table t = Instance .getInstance ().getTableByName (c .getName ());
323- if (t != null ) {
324- // t.lockTable(this);
325- final List <Object > r = t .getAll (this , 0 );
326- // t.unlockTable(this);
327- return r ;
328- }
329- return null ;
330- }
331-
335+ @ Deprecated
332336 public Object nfind (Class c , long id ) throws InternalException , NoSuchMethodException , InvocationTargetException , IOException , InvalidFrameHeader , InvalidFrame , EmptyFrameHeaderFound , IncorrectUndoChunkFound , ClassNotFoundException , InstantiationException , IllegalAccessException {
333337 final Table t = Instance .getInstance ().getTableByName (c .getName ());
334338 if (t != null ) {
@@ -544,6 +548,10 @@ public static void setDntmSession(Session dntmSession) {
544548 Session .dntmSession = dntmSession ;
545549 }
546550
551+ public RetrieveQueue getRetrieveQueue () {
552+ return retrieveQueue ;
553+ }
554+
547555 public void streamFramePtr (Frame f , int ptr ) {
548556 streammap .put (f .getAllocFile ()+f .getAllocPointer (), ptr );
549557 }
0 commit comments