Exemplo n.º 1
0
		/**** User related operations *****/
		public void Put(object persistentObject)
		{
			System.Type t = persistentObject.GetType();
			string primaryKeyName = _get_primary_key_name(t);

			ClassInfo schemeInfo = SearchClassInfo(t.FullName);
			uint cid = 0;
			uint topNodeSid = 0;
			if (schemeInfo == null)
			{
				//insert it first
				InsertClassIno(t.FullName, _get_other_fields_name(t, primaryKeyName), ref cid, ref topNodeSid);
				schemeInfo = new ClassInfo(cid, t.FullName, _get_other_fields_name(t, primaryKeyName), topNodeSid);
			}
			else
			{
				cid = schemeInfo.CId;
				topNodeSid = schemeInfo.TopNodeSId;
			}
			
			Debug.Assert(topNodeSid > 0);

			OOD.Imp.Storage.ObjectTree ot = _get_object_tree(topNodeSid);

			//get the primary key value
			object keyValue = new object();
			//get the serialzed all othe fieldValues
			string[] otherFields;

			_get_data_for_storage(persistentObject, primaryKeyName, schemeInfo.FieldNames, out keyValue, out otherFields);

			Debug.Assert(otherFields != null);

			if (ot.InsertObject(keyValue, otherFields) == false)
				throw new OOD.Exception.DuplicatedPrimaryKey(
					this,
					"primary key is dupicated, insertion failed.");
			if (topNodeSid != ot.TopNodeSId)
			{
				//update the top node segment id needed
				m_catalogTree.UpdateTopNodeSId(t.FullName, ot.TopNodeSId);
			}
		}
Exemplo n.º 2
0
		public object _get_object_from_storage(ObjectInfo back, string primaryKeyName, Type tp, ClassInfo cinfo)
		{
			object result = tp.InvokeMember(null,
				BindingFlags.Public | BindingFlags.NonPublic |
				BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);
			//put the primary key back
			tp.InvokeMember(
				primaryKeyName,
				BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField | BindingFlags.Instance,
				null,
				result,
				new object[] { back.PrimaryKeyValue });
			//put other fields back
			for (int i=0; i< cinfo.FieldNames.Length; i++)
			{
				FieldInfo field = tp.GetField(cinfo.FieldNames[i], BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
				
				tp.InvokeMember(
					cinfo.FieldNames[i],
					BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField | BindingFlags.Instance,
					null,
					result,
					new object[] { Types.GetValue(back.SerializedOtherFieldValues[i], Types.GetInternalType(field.FieldType)) });
			}

            return result;
		}
Exemplo n.º 3
0
        public object _get_object_from_storage(ObjectInfo back, string primaryKeyName, Type tp, ClassInfo cinfo)
        {
            object result = tp.InvokeMember(null,
                                            BindingFlags.Public | BindingFlags.NonPublic |
                                            BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null);

            //put the primary key back
            tp.InvokeMember(
                primaryKeyName,
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField | BindingFlags.Instance,
                null,
                result,
                new object[] { back.PrimaryKeyValue });
            //put other fields back
            for (int i = 0; i < cinfo.FieldNames.Length; i++)
            {
                FieldInfo field = tp.GetField(cinfo.FieldNames[i], BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

                tp.InvokeMember(
                    cinfo.FieldNames[i],
                    BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.SetField | BindingFlags.Instance,
                    null,
                    result,
                    new object[] { Types.GetValue(back.SerializedOtherFieldValues[i], Types.GetInternalType(field.FieldType)) });
            }

            return(result);
        }