View Javadoc
1 /* 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/ebxml/ObjectCache.java,v 1.9 2003/05/22 12:29:13 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 7 package com.sun.xml.registry.ebxml; 8 9 import java.util.*; 10 import java.lang.ref.*; 11 12 import javax.xml.registry.*; 13 import javax.xml.registry.infomodel.*; 14 15 /*** 16 * An ObjectCache 17 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 18 */ 19 public class ObjectCache { 20 21 private RegistryServiceImpl service = null; 22 private HashMap idToReferenceMap = null; 23 24 private ObjectCache() { 25 } 26 27 public ObjectCache(RegistryServiceImpl service) { 28 this.service = service; 29 30 idToReferenceMap = new HashMap(1024); 31 } 32 33 public Reference getReference(String id, String objectType) throws JAXRException { 34 Reference ref = (Reference)idToReferenceMap.get(id); 35 36 //Need to also check if ref.get() == null as referrant could have been GCed 37 if ((ref == null) || (ref.get() == null)) { 38 //Cache miss. Get from registry 39 //System.err.println("ObjectCache: cache miss for id: " + id); 40 DeclarativeQueryManager dqm = service.getDeclarativeQueryManager(); 41 String ebxmlObjType = service.mapJAXRNameToEbXMLName(objectType); 42 Query query = dqm.createQuery( 43 Query.QUERY_TYPE_SQL, "SELECT id FROM " + ebxmlObjType 44 + " WHERE id='" + id + "'"); 45 dqm.executeQuery(query); 46 47 //executeQuery should have fetched object and put it in cache 48 ref = (Reference)idToReferenceMap.get(id); 49 50 if (ref == null) { 51 throw new JAXRException("Unresolved reference for object with id: " + id); 52 //System.err.println("Unresolved reference for object with id: " + id); 53 } 54 } 55 else { 56 //System.err.println("ObjectCache: cache hit for id: " + id); 57 } 58 59 return ref; 60 } 61 62 private void putReference(String id, Reference ref) { 63 idToReferenceMap.put(id, ref); 64 } 65 66 public void putRegistryObject(RegistryObject ro) throws JAXRException { 67 putReference(ro.getKey().getId(), new SoftReference(ro)); 68 } 69 }

This page was automatically generated by Maven