//ok crr 2009.10.31 /// <summary> /// Store multiple properties using a custom command and particular mappings. /// </summary> /// <param name="cmdType"></param> /// <param name="mapType"></param> /// <param name="appObjects"></param> /// <returns></returns> public ObjectIdentifier Store(string cmdIdentifier, Type mapType, IDictionary<string, object> appObjects) { try { GetMap(mapType); //make the specific command to execute an Insert with custom command _cmd = MakeStoreCommand(_map, cmdIdentifier, appObjects);//4 makeStoreCommand 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 (ObjectIdentifier)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_STORE_NEW, ex); } }
/// <summary> /// Retrieve object(s) with custom criterias. Collection return support. /// </summary> /// <param name="mapType"></param> /// <param name="cmdType"></param> /// <param name="returnCollection"></param> /// <param name="criterias"></param> /// <returns></returns> public object Retrieve(Type mapType, string cmdIdentifier, bool returnCollection, IList<object> criterias) { try { GetMap(mapType); _cmd = MakeRetrieveCommand(_map, mapType, cmdIdentifier, returnCollection, criterias); if (_cmd == null) throw new Exception(NO_CMD_MAP); if (returnCollection) return (DataView)_cmd.Run(); return (IPersistable)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_RETRIEVE, ex); } }
//ok crr 2009.10.31 /// <summary> /// Insert any object into a persistent storage. Can use another map type than its. /// </summary> /// <param name="appObject"></param> /// <param name="mapType"></param> /// <returns></returns> public ObjectIdentifier Store(object appObject,Type mapType) { try { //Get a dematerializer object and the Map with the property-parameter conversion data if (appObject == null) return null; //set the _map variable GetMap(mapType); //make the specific command to execute an Insert //Factory Methods: let the subclasses define the creation of concrete objects _cmd = MakeStoreCommand(_map, appObject);//1 MakeStoreCommand 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 (ObjectIdentifier)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_STORE_NEW, ex); } }
//ok crr 2015.10.19 REVIEW:Replace return value? From concrete class to an abstract or interface //ok crr 2009.10.31 /// <summary> /// Retrieve all. Return a IList type. Receive the class type as parameter /// </summary> /// <param name="mapType"></param> /// <returns></returns> public DataView Retrieve(Type mapType) { try { GetMap(mapType); _cmd = MakeRetrieveCommand(_map, mapType); if (_cmd == null) throw new Exception(NO_CMD_MAP); return _cmd.Run() as DataView; } catch (Exception ex) { throw new Exception(CANNOT_RETRIEVE, 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); } }
/// <summary> /// Execute a SQL explicit transaction procedure with multiple objects. /// </summary> /// <param name="mapType"></param> /// <param name="cmdIdentifier"></param> /// <param name="appObjects"></param> /// <returns></returns> public bool ExecuteTransaction(Type mapType, string cmdIdentifier, IDictionary<string, object> appObjects) { try { GetMap(mapType); _cmd = MakeTransactionCommand(_map, cmdIdentifier, false, appObjects); if (_cmd == null) throw new Exception(NO_CMD_MAP); //Command Pattern: A request is encapsulated in a class. return (bool)_cmd.Run(); } catch (Exception ex) { throw new Exception(CANNOT_TRANSACTION, ex); } }
/// <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); } }
/// <summary> /// Updates a record using multiple object properties. /// </summary> /// <param name="mapType"></param> /// <param name="appObjects"></param> /// <returns></returns> public bool Change(Type mapType, IDictionary<string, object> appObjects) { try { GetMap(mapType); //make the specific command to execute an Insert _cmd = MakeChangeCommand(_map, appObjects); 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_STORE_NEW, ex); } }
/// <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); } }
public void Add(int index, PersistenceCommand cmd) { _cmds.Add(index, cmd); }