/// <summary> /// Store a new object in a persistent storage. /// </summary> /// <param name="oid"></param> /// <param name="appObject"></param> /// <returns></returns> public bool Put(ObjectIdentifier oid, Object appObject) { bool success = PutObjectInStorage(oid, appObject); IPersistable pObject = MakePersistable(appObject, oid); _cachedObjects.Add(oid, pObject); return success; }
/// <summary> /// Retrieve a persistent object from a storage. /// </summary> /// <param name="oid"></param> /// <returns></returns> public IPersistable Get(ObjectIdentifier oid) { IPersistable obj = _cachedObjects[oid]; if (obj == null) { obj = GetObjectFromStorage(oid); _cachedObjects.Add(oid, obj); } return obj; }
//retrieve with oid and custom command protected abstract PersistenceCommand MakeRetrieveCommand(Map map, ObjectIdentifier oid, Type type, string cmdType);
//used for Retrieve and delete with an OID and a well-known command type public SqlServerPersistenceCommand(Map map, ObjectIdentifier oid, SqlCommand command, CRUD cmdType) : base(map, oid, command, cmdType) { }
//update and object with default command type (update) protected abstract PersistenceCommand MakeChangeCommand(Map map, ObjectIdentifier oid, object appObject);
protected abstract PersistenceCommand MakeDeleteCommand(Map map, ObjectIdentifier oid, string cmdType);
/// <summary> /// Custom command for destroying a persisent object using its identifier. /// </summary> /// <param name="objectId"></param> /// <param name="type"></param> /// <param name="cmdType"></param> /// <returns></returns> public bool Destroy(ObjectIdentifier oid, Type type, string cmdType) { try { GetMap(type); _cmd = MakeDeleteCommand(_map, oid, cmdType); if (_cmd == null) throw new Exception(NO_CMD_MAP); return (bool)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_DESTROY, ex); } }
//ok crr 2009.10.31 /// <summary> ///Retrieve method for custom retrieve operations giving an OID. /// </summary> /// <param name="objectId"></param> /// <param name="type"></param> /// <param name="cmdType"></param> /// <returns></returns> public IPersistable Retrieve(ObjectIdentifier objectId, Type type, string cmdType) { try { GetMap(type); _cmd = MakeRetrieveCommand(_map, objectId, type, cmdType); if (_cmd == null) throw new Exception(NO_CMD_MAP); return (IPersistable)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_RETRIEVE, ex); } }
public abstract IPersistable MakePersistable(object persistableObj, ObjectIdentifier oid);
/// <summary> /// Update a persistentObject using a particular Type for mapping. /// </summary> /// <param name="oid"></param> /// <param name="appObject"></param> /// <param name="mapType"></param> /// <returns></returns> public bool Change(ObjectIdentifier oid, object appObject, Type mapType) { try { GetMap(mapType); //make the specific command to execute an Update _cmd = MakeChangeCommand(_map, oid, appObject); if (_cmd == null) throw new Exception(NO_CMD_MAP); //Command Pattern: A request is encapsulated in a class. //Subtypes will take into account the concurrency support return (bool)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_UPDATE, ex); } }
/// <summary> /// Destroy a persistent object in a storage. /// </summary> /// <param name="oid"></param> /// <returns></returns> public bool Destroy(ObjectIdentifier oid) { bool success = DestroyObjectInStorage(oid); _cachedObjects.Remove(oid); return success; }
//used for Retrieve and Delete with an OID, a custom command type and concurrency support public SqlServerPersistenceCommand(Map map, ObjectIdentifier oid, SqlCommand command, string cmdType, ConcurrencySupportType concurrency) : base(map, oid, command, cmdType, concurrency) { }
//create protected abstract bool PutObjectInStorage(ObjectIdentifier oid, Object appObject);
protected abstract IPersistable MakePersistable(object appObject, ObjectIdentifier oid);
//retrieve protected abstract IPersistable GetObjectFromStorage(ObjectIdentifier oid);
//delete protected abstract bool DestroyObjectInStorage(ObjectIdentifier oid);
//TEST /// <summary> /// PersistentCommand for new records with identifier. /// </summary> /// <param name="map"></param> /// <param name="oid"></param> /// <param name="objectForProcess"></param> /// <param name="providerCommand"></param> public PersistenceCommand(Map map, ObjectIdentifier oid,object objectForProcess, object providerCommand) { _providerCommand = providerCommand; _objectForProcess = objectForProcess; _pObj = MakePersistable(objectForProcess, oid); _cmdMap = map.GetCommandMap(CRUD.Create.ToString()); }
public override IPersistable MakePersistable(object persistableObj, ObjectIdentifier oid) { return new PersistentObject(persistableObj, oid); }
/// <summary> /// PersistentObject for retrieve operations, custom command and concurrency support. /// </summary> /// <param name="map"></param> /// <param name="oid"></param> /// <param name="providerCommand"></param> /// <param name="cmdType"></param> /// <param name="concurrency"></param> public PersistenceCommand(Map map, ObjectIdentifier oid, object providerCommand, string cmdType, ConcurrencySupportType concurrency) { _providerCommand = providerCommand; _pObj = MakePersistable(null, oid);// Retrieve operations need only the OID _cmdMap = map.GetCommandMap(cmdType); //must get the proper command instruction from the map SetConcurrencySupport(concurrency); }