Beispiel #1
0
        /// <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;
        }
Beispiel #2
0
 /// <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;
 }
Beispiel #3
0
 //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)
 {
 }
Beispiel #5
0
 //update and object with default command type (update)
 protected abstract PersistenceCommand MakeChangeCommand(Map map, ObjectIdentifier oid, object appObject);
Beispiel #6
0
 protected abstract PersistenceCommand MakeDeleteCommand(Map map, ObjectIdentifier oid, string cmdType);
Beispiel #7
0
        /// <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);
            }
        }
Beispiel #8
0
        //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);
            }
        }
Beispiel #9
0
 public abstract IPersistable MakePersistable(object persistableObj, ObjectIdentifier oid);
Beispiel #10
0
        /// <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);
            }
        }
Beispiel #11
0
 /// <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)
 {
 }
Beispiel #13
0
 //create
 protected abstract bool PutObjectInStorage(ObjectIdentifier oid, Object appObject);
Beispiel #14
0
 protected abstract IPersistable MakePersistable(object appObject, ObjectIdentifier oid);
Beispiel #15
0
 //retrieve
 protected abstract IPersistable GetObjectFromStorage(ObjectIdentifier oid);
Beispiel #16
0
 //delete
 protected abstract bool DestroyObjectInStorage(ObjectIdentifier oid);
Beispiel #17
0
 //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);
 }
Beispiel #19
0
        /// <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);
        }