Esempio n. 1
0
 protected ObjectIdentifier GetObjectIdenfierFromReturnValue(object returnValue)
 {
     OID oid = new OID();
     oid.ID = returnValue;
     return oid;
 }
Esempio n. 2
0
        /// <summary>
        ///Return a persistentObject with a storedObject of the persisted object
        ///and concurrency support data.
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        protected IPersistable MapRecordToObject(DataView record)
        {
            try
            {
                if (record == null || record.Count == 0)
                    return null;

                object obj = null;
                object version = null;
                object inUse = null;

                if (!_type.IsAbstract && !_type.IsInterface)
                    obj = Activator.CreateInstance(_type);
                else
                {
                    return null;
                }
                int counter = CommandMap.GetRetrievedColumnsCount();

                for (byte i = 0; i < counter; i++)
                {
                    //if no property or is null then continue the loop
                    if ((_propertyArray2[i] == "") || (record[0][_columnArray[i]].GetType() == Type.GetType("System.DBNull")))
                        continue;

                    //set reference objectidentifier properties for foreign keys
                    if (_propertyArray2[i] == "ID") //then you need a collection of oids. TODO: Please use a variable in a configuratin file!!!
                    {
                        OID oid = new OID(record[0][_columnArray[i]], _columnArray[i], IDDataType.NotSet, IDType.NotSet);

                        if (CommandMap.IsRetrievedColumObjectIdentifier(i))
                        {
                            ObjectToPersist.OID = oid;
                            continue;
                        }
                        ObjectToPersist.AddReference(oid);
                        continue;
                    }

                    //Setting values depending on the object map for the returned table.
                    obj.GetType().GetProperty(_propertyArray2[i]).SetValue(obj, record[0][_columnArray[i]], null);

                }

                //return a persistentObject
                //Add concurrency support info in the persistenObject (version, inUse)
                if ((OptimisticField != null) && (OptimisticField != string.Empty))
                    version = record[0][OptimisticField];//get field value for optimistic support
                if ((PessimisticField != null) && (PessimisticField != string.Empty))
                    inUse = record[0][PessimisticField];//get field value for pessimistic support

                ObjectToPersist.StoredObject = obj;
                //ObjectToPersist = (IPersistable)obj;
                ObjectToPersist.Version = version;
                ObjectToPersist.InUse = inUse;

                return ObjectToPersist;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }