fullRuntime/src/sc/db/DBTypeDescriptor.java
public IDBObject lookupInstById(Object id, int typeId, boolean createProto, boolean selectDefault) {
      if (baseType != null) {
         return baseType.lookupInstById(id, typeId == DBUnsetTypeId ? this.typeId : typeId, createProto, selectDefault);
      }

      if (typeInstances == null) {
         initTypeInstances();
      }
      DBTypeDescriptor resTypeDesc = getSubTypeByTypeId(typeId);
      if (resTypeDesc == null) {
         throw new IllegalArgumentException("Attempt to lookup instance of abstract type: " + this);
      }

      // TODO: add a cacheMode option to enable a call to dbRefresh() or dbFetchDefault() on the returned instance, then return null if the item no longer exists
      IDBObject inst = typeInstances.get(id);
      if (inst != null) {
         return inst;
      }
      if (!createProto && dbDisabled)
         return null;

      DBObject dbObj;
      synchronized (this) {
         // check again after synchronizing
         inst = typeInstances.get(id);
         if (inst != null)
            return inst;
         // When typeId is unset, this returns null for abstract types or those with sub-types because we don't really know the
         // concrete type. In this case, we will create a stub DBObject to store the id properties and manage access to the query
         // to populate properties on this instance - at which point we learn the type and create the wrapper.
         inst = resTypeDesc.createPrototype(typeId == DBUnsetTypeId);
         if (inst != null) {
            dbObj = (DBObject) inst.getDBObject();
            dbObj.setDBId(id);
            typeInstances.put(id, inst);

            initSyncForInst(inst, true, false);
         }
         // Don't know the concrete type so create a DBObject without the instance and register that instead
         else if (selectDefault) {
            dbObj = new DBObject(this);
            dbObj.setDBId(id);
            dbObj.setPrototype(true);
            typeInstances.put(id, dbObj);
         }
         else // We do not know the concrete class yet for this object so just return
            return null;

         checkCacheSize();
      }

      // If requested, select the default (primary table) property group - if the row does not exist, the object does not exist
      if (selectDefault) {
         if (!dbObj.dbFetchDefault()) {
            // TODO: should we optionally cache a null-sentinel here for some time to avoid re-executing the same null result queries?
            typeInstances.remove(id);
            return null;
         }
      }
      if (dbObj.wrapper != inst)
         return dbObj.wrapper;
      return inst;
   }
/**
    * Lower level method used to lookup an instance of this type with a given id - based on the "highlander principle" - we try to ensure
    * there's only one instance of an object with the same id to prevent aliasing, simplify code and caching and provide a 'transactional view'
    * of objects with persistent state.
    *
    * If createProto is true, and the instance is not in the cache, a prototype is created with that and returned. If selectDefault
    * is true, that prototype is populated with the default property group if the row exists and returned. If the row does not exist
    * null is returned in that case.
    */
Lower level method used to lookup an instance of this type with a given id - based on the "highlander principle" - we try to ensure
there's only one instance of an object with the same id to prevent aliasing, simplify code and caching and provide a 'transactional view'
of objects with persistent state.

If createProto is true, and the instance is not in the cache, a prototype is created with that and returned. If selectDefault
is true, that prototype is populated with the default property group if the row exists and returned. If the row does not exist
null is returned in that case.
Lower level method used to lookup an instance of this type with a given id - based on the " highlander principle " - we try to ensure there ' s only one instance of an object with the same id to prevent aliasing simplify code and caching and provide a ' transactional view ' of objects with persistent state . If createProto is true and the instance is not in the cache a prototype is created with that and returned . If selectDefault is true that prototype is populated with the default property group if the row exists and returned . If the row does not exist null is returned in that case .
public IDBObject lookupInstById(Object id, int typeId, boolean createProto, boolean selectDefault) {
      if (baseType != null) {
         return baseType.lookupInstById(id, typeId == DBUnsetTypeId ? this.typeId : typeId, createProto, selectDefault);
      }
      if (typeInstances == null) {
         initTypeInstances();
      }
      DBTypeDescriptor resTypeDesc = getSubTypeByTypeId(typeId);
      if (resTypeDesc == null) {
         throw new IllegalArgumentException("Attempt to lookup instance of abstract type: " + this);
      }
      IDBObject inst = typeInstances.get(id);
      if (inst != null) {
         return inst;
      }
      if (!createProto && dbDisabled)
         return null;
      DBObject dbObj;
      synchronized (this) {
         inst = typeInstances.get(id);
         if (inst != null)
            return inst;
         inst = resTypeDesc.createPrototype(typeId == DBUnsetTypeId);
         if (inst != null) {
            dbObj = (DBObject) inst.getDBObject();
            dbObj.setDBId(id);
            typeInstances.put(id, inst);
            initSyncForInst(inst, true, false);
         }
         else if (selectDefault) {
            dbObj = new DBObject(this);
            dbObj.setDBId(id);
            dbObj.setPrototype(true);
            typeInstances.put(id, dbObj);
         }
         else 
            return null;
         checkCacheSize();
      }
      if (selectDefault) {
         if (!dbObj.dbFetchDefault()) {
            typeInstances.remove(id);
            return null;
         }
      }
      if (dbObj.wrapper != inst)
         return dbObj.wrapper;
      return inst;
   }
public IDBObject lookupInstById ( Object id , int typeId , boolean createProto , boolean selectDefault ) { if ( baseType != null ) { return baseType . lookupInstById ( id , typeId == DBUnsetTypeId ? this . typeId : typeId , createProto , selectDefault ) ; } if ( typeInstances == null ) { initTypeInstances ( ) ; } DBTypeDescriptor resTypeDesc = getSubTypeByTypeId ( typeId ) ; if ( resTypeDesc == null ) { throw new IllegalArgumentException ( "Attempt to lookup instance of abstract type: " + this ) ; } IDBObject inst = typeInstances . get ( id ) ; if ( inst != null ) { return inst ; } if ( ! createProto && dbDisabled ) return null ; DBObject dbObj ; synchronized ( this ) { inst = typeInstances . get ( id ) ; if ( inst != null ) return inst ; inst = resTypeDesc . createPrototype ( typeId == DBUnsetTypeId ) ; if ( inst != null ) { dbObj = ( DBObject ) inst . getDBObject ( ) ; dbObj . setDBId ( id ) ; typeInstances . put ( id , inst ) ; initSyncForInst ( inst , true , false ) ; } else if ( selectDefault ) { dbObj = new DBObject ( this ) ; dbObj . setDBId ( id ) ; dbObj . setPrototype ( true ) ; typeInstances . put ( id , dbObj ) ; } else return null ; checkCacheSize ( ) ; } if ( selectDefault ) { if ( ! dbObj . dbFetchDefault ( ) ) { typeInstances . remove ( id ) ; return null ; } } if ( dbObj . wrapper != inst ) return dbObj . wrapper ; return inst ; }
Lower level method used to lookup an instance of this type with a given id - based on the "highlander principle" - we try to ensure
 there's only one instance of an object with the same id to prevent aliasing, simplify code and caching and provide a 'transactional view'
 of objects with persistent state.
Lower level method used to lookup an instance of this type with a given id - based on the " highlander principle " - we try to ensure there ' s only one instance of an object with the same id to prevent aliasing simplify code and caching and provide a ' transactional view ' of objects with persistent state .
// TODO: add a cacheMode option to enable a call to dbRefresh() or dbFetchDefault() on the returned instance, then return null if the item no longer exists // check again after synchronizing // When typeId is unset, this returns null for abstract types or those with sub-types because we don't really know the // concrete type. In this case, we will create a stub DBObject to store the id properties and manage access to the query // to populate properties on this instance - at which point we learn the type and create the wrapper. // Don't know the concrete type so create a DBObject without the instance and register that instead // We do not know the concrete class yet for this object so just return // If requested, select the default (primary table) property group - if the row does not exist, the object does not exist // TODO: should we optionally cache a null-sentinel here for some time to avoid re-executing the same null result queries?