예제 #1
0
        void CreateMethodContains(IILGen ilGenerator, Type relationDBManipulatorType,
                                  ParameterInfo[] methodParameters, IDictionary <string, MethodInfo> apartFields, Action <IILGen> pushWriter,
                                  IILLocal writerLoc)
        {
            //ByteBufferWriter.WriteVUInt32(RelationInfo.Id);
            WriteIdIl(ilGenerator, pushWriter, (int)_relationInfo.Id);
            var primaryKeyFields = _relationInfo.ClientRelationVersionInfo.GetPrimaryKeyFields();

            var count = SaveMethodParameters(ilGenerator, "Contains", methodParameters, methodParameters.Length,
                                             apartFields, primaryKeyFields, writerLoc);

            if (count != primaryKeyFields.Count)
            {
                throw new BTDBException($"Number of parameters in Contains does not match primary key count {primaryKeyFields.Count}.");
            }

            //call manipulator.Contains
            ilGenerator
            .Ldarg(0);     //manipulator
            //call byteBuffer.data
            var dataGetter = typeof(ByteBufferWriter).GetProperty("Data").GetGetMethod(true);

            ilGenerator.Ldloc(writerLoc).Callvirt(dataGetter);
            ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("Contains"));
        }
예제 #2
0
 static void StoreNthArgumentOfTypeIntoLoc(IILGen il, ushort argIdx, Type type, ushort locIdx)
 {
     il
     .Ldarg(argIdx)
     .Castclass(type)
     .Stloc(locIdx);
 }
예제 #3
0
        void CreateMethodFindById(IILGen ilGenerator, Type relationDBManipulatorType, string methodName,
                                  ParameterInfo[] methodParameters, Type methodReturnType, IDictionary <string, MethodInfo> apartFields, Action <IILGen> pushWriter,
                                  IILLocal writerLoc)
        {
            var isPrefixBased = ReturnsEnumerableOfClientType(methodReturnType, _relationInfo.ClientType);

            if (isPrefixBased)
            {
                WriteShortPrefixIl(ilGenerator, pushWriter, _relationInfo.Prefix);
            }
            else
            {
                WriteShortPrefixIl(ilGenerator, pushWriter, ObjectDB.AllRelationsPKPrefix);
                //ByteBufferWriter.WriteVUInt32(RelationInfo.Id);
                WriteIdIl(ilGenerator, pushWriter, (int)_relationInfo.Id);
            }

            var primaryKeyFields = _relationInfo.ClientRelationVersionInfo.GetPrimaryKeyFields();

            var count = SaveMethodParameters(ilGenerator, methodName, methodParameters, methodParameters.Length,
                                             apartFields, primaryKeyFields, writerLoc);

            if (!isPrefixBased && count != primaryKeyFields.Count)
            {
                throw new BTDBException(
                          $"Number of parameters in {methodName} does not match primary key count {primaryKeyFields.Count}.");
            }

            //call manipulator.FindBy_
            ilGenerator
            .Ldarg(0);     //manipulator
            //call byteBuffer.data
            var dataGetter = typeof(ByteBufferWriter).GetProperty("Data").GetGetMethod(true);

            ilGenerator.Ldloc(writerLoc).Call(dataGetter);
            if (isPrefixBased)
            {
                ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindByPrimaryKeyPrefix"));
            }
            else
            {
                ilGenerator.LdcI4(ShouldThrowWhenKeyNotFound(methodName, methodReturnType) ? 1 : 0);
                ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindByIdOrDefault"));
                if (methodReturnType == typeof(void))
                {
                    ilGenerator.Pop();
                }
            }
        }
예제 #4
0
        static void MergerInitializeBufferReader(IILGen ilGenerator, ref BufferInfo bi, ushort arg)
        {
            if (bi.ReaderCreated)
            {
                return;
            }
            bi.ReaderCreated = true;
            var readerLoc = ilGenerator.DeclareLocal(typeof(ByteArrayReader));

            bi.PushReader = il => il.Ldloc(readerLoc);
            ilGenerator
            .Ldarg(arg)
            .Newobj(() => new ByteArrayReader(null))
            .Stloc(readerLoc);
        }
예제 #5
0
        void CreateMethodFindBy(IILGen ilGenerator, Type relationDBManipulatorType, string methodName,
                                ParameterInfo[] methodParameters, Type methodReturnType, IDictionary <string, MethodInfo> apartFields, Action <IILGen> pushWriter,
                                IILLocal writerLoc)
        {
            bool allowDefault = false;
            var  skName       = methodName.Substring(6);

            if (skName.EndsWith("OrDefault"))
            {
                skName       = skName.Substring(0, skName.Length - 9);
                allowDefault = true;
            }

            WriteShortPrefixIl(ilGenerator, pushWriter, ObjectDB.AllRelationsSKPrefix);
            var skIndex = _relationInfo.ClientRelationVersionInfo.GetSecondaryKeyIndex(skName);

            //ByteBuffered.WriteVUInt32(RelationInfo.Id);
            WriteIdIl(ilGenerator, pushWriter, (int)_relationInfo.Id);
            //ByteBuffered.WriteVUInt32(skIndex);
            WriteIdIl(ilGenerator, pushWriter, (int)skIndex);

            var secondaryKeyFields = _relationInfo.ClientRelationVersionInfo.GetSecondaryKeyFields(skIndex);

            SaveMethodParameters(ilGenerator, methodName, methodParameters, methodParameters.Length,
                                 apartFields, secondaryKeyFields, writerLoc);

            //call public T FindBySecondaryKeyOrDefault(uint secondaryKeyIndex, uint prefixParametersCount, ByteBuffer secKeyBytes, bool throwWhenNotFound)
            ilGenerator.Ldarg(0); //manipulator
            ilGenerator.LdcI4((int)skIndex);
            ilGenerator.LdcI4(methodParameters.Length + apartFields.Count);
            //call byteBuffer.data
            var dataGetter = typeof(ByteBufferWriter).GetProperty("Data").GetGetMethod(true);

            ilGenerator.Ldloc(writerLoc).Callvirt(dataGetter);
            if (ReturnsEnumerableOfClientType(methodReturnType, _relationInfo.ClientType))
            {
                ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindBySecondaryKey"));
            }
            else
            {
                ilGenerator.LdcI4(allowDefault ? 0 : 1); //? should throw
                ilGenerator.Callvirt(relationDBManipulatorType.GetMethod("FindBySecondaryKeyOrDefault"));
            }
        }
예제 #6
0
        void CreateMethodListById(IILGen ilGenerator, Type relationDBManipulatorType, string methodName,
                                  ParameterInfo[] methodParameters, IDictionary <string, MethodInfo> apartFields, Action <IILGen> pushWriter, IILLocal writerLoc)
        {
            WriteShortPrefixIl(ilGenerator, pushWriter, _relationInfo.Prefix);

            var primaryKeyFields = _relationInfo.ClientRelationVersionInfo.GetPrimaryKeyFields();

            var paramsCount = SaveMethodParameters(ilGenerator, methodName, methodParameters, methodParameters.Length,
                                                   apartFields, primaryKeyFields, writerLoc);

            //call manipulator.GetEnumerator(tr, byteBuffer)
            ilGenerator
            .Ldarg(0);     //manipulator
            //call byteBuffer.data
            var dataGetter = typeof(ByteBufferWriter).GetProperty("Data").GetGetMethod(true);

            ilGenerator.Ldloc(writerLoc).Callvirt(dataGetter);
            ilGenerator.LdcI4(paramsCount + apartFields.Count);
            ilGenerator.Callvirt(relationDBManipulatorType.GetMethod(methodName));
        }