1 package com.genimen.djeneric.web.actors; 2 3 import java.util.HashMap ; 4 import java.util.Iterator ; 5 6 import com.genimen.djeneric.language.Messages; 7 import com.genimen.djeneric.repository.DjCursor; 8 import com.genimen.djeneric.repository.DjExtent; 9 import com.genimen.djeneric.repository.DjList; 10 import com.genimen.djeneric.repository.DjObject; 11 import com.genimen.djeneric.repository.DjOql; 12 import com.genimen.djeneric.repository.exceptions.DjenericException; 13 import com.genimen.djeneric.web.util.DjenericSessionManager; 14 import com.genimen.djeneric.web.util.OqlUtil; 15 import com.genimen.djeneric.web.util.PairList; 16 17 public class Querier 18 { 19 private static final String PAIRLIST = "pairlist"; 20 private static final String MESSAGE = "_message"; 21 private static final String TRUNCATED = "_truncated"; 22 private static final int MAX_OBJECTS_IN_LIST = 300; 23 protected static final String _RESULT = "_result"; 24 protected DjenericSessionManager _mgr; 25 26 public Querier(DjenericSessionManager mgr) 27 { 28 _mgr = mgr; 29 } 30 31 public HashMap execute(String extentName, HashMap values) 32 { 33 HashMap result = new HashMap (); 34 PairList pairlist = new PairList(); 35 36 result.put(_RESULT, "error"); 37 result.put(TRUNCATED, "false"); 38 result.put(MESSAGE, "Ok"); 39 result.put(PAIRLIST, pairlist); 40 try 41 { 42 DjExtent extent = _mgr.getExtent(extentName); 43 DjOql oql = OqlUtil.createOql(_mgr, extent, values); 44 45 DjList lst = new DjList(); 46 lst.setStoredTypeName(extent); 47 DjCursor cursor = _mgr.getPrimarySession().getObjectsCursor(oql); 48 int maxObjects = MAX_OBJECTS_IN_LIST; 49 DjObject obj; 50 while (((obj = cursor.getNext()) != null) && maxObjects-- > 0) 51 { 52 lst.add(obj); 53 } 54 if (maxObjects < 0) 55 { 56 result.put(TRUNCATED, "true"); 57 result.put(MESSAGE, Messages.getString("DjenericFolder.FoundTruncated", String.valueOf(MAX_OBJECTS_IN_LIST), 58 extent.getNamePlural())); 59 } 60 cursor.close(); 61 62 lst.sort(); 63 64 Iterator it = lst.iterator(); 65 while (it.hasNext()) 66 { 67 DjObject o = (DjObject) it.next(); 68 pairlist.add(new Long (o.getObjectId()), o.toString()); 69 } 70 71 result.put(_RESULT, "ok"); 72 } 73 catch (DjenericException dje) 74 { 75 result.put(_RESULT, dje.getMessage()); 76 System.out.println(dje.getMessage()); 77 } 78 return result; 79 } 80 81 } 82 | Popular Tags |