Ejemplo n.º 1
0
        public static void RemoveRow(TableHandle tableHandle, RowHandle rowHandle)
        {
            NativeException nativeException;

            remove_row(tableHandle, rowHandle, out nativeException);
            nativeException.ThrowIfNecessary();
        }
Ejemplo n.º 2
0
        internal RealmObject MakeObjectForRow(Type objectType, RowHandle rowHandle)
        {
            RealmObject ret = Metadata[objectType].Helper.CreateInstance();

            ret._Manage(this, rowHandle);
            return(ret);
        }
Ejemplo n.º 3
0
        internal RealmObject MakeObjectForRow(RealmObject.Metadata metadata, RowHandle row)
        {
            RealmObject ret = metadata.Helper.CreateInstance();

            ret._Manage(this, row, metadata);
            return(ret);
        }
Ejemplo n.º 4
0
        internal static RowHandle CreateRowHandle(IntPtr rowPtr, SharedRealmHandle sharedRealmHandle)
        {
            var rowHandle = new RowHandle(sharedRealmHandle);

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* Retain handle in a constrained execution region */ }
            finally
            {
                rowHandle.SetHandle(rowPtr);
            }
            return(rowHandle);
        }
Ejemplo n.º 5
0
        internal LinkListHandle TableLinkList(IntPtr columnIndex, RowHandle rowHandle)
        {
            var listHandle = RootedLinkListHandle();

            //At this point sh is invalid due to its handle being uninitialized, but the root is set correctly
            //a finalize at this point will not leak anything and the handle will not do anything

            //now, set the TableView handle...
            RuntimeHelpers.PrepareConstrainedRegions();//the following finally will run with no out-of-band exceptions
            try
            { }
            finally
            {
                var rowIndex = rowHandle.RowIndex;
                listHandle.SetHandle(NativeTable.get_linklist(this, columnIndex, (IntPtr)rowIndex));
            }//at this point we have atomically acquired a handle and also set the root correctly so it can be unbound correctly
            return(listHandle);
        }
Ejemplo n.º 6
0
        internal override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.Method.DeclaringType == typeof(Queryable))
            {
                if (m.Method.Name == "Where")
                {
                    this.Visit(m.Arguments[0]);
                    LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                    this.Visit(lambda.Body);
                    return(m);
                }
                if (m.Method.Name == "OrderBy")
                {
                    this.Visit(m.Arguments[0]);
                    AddSort((LambdaExpression)StripQuotes(m.Arguments[1]), true, true);
                    return(m);
                }
                if (m.Method.Name == "OrderByDescending")
                {
                    this.Visit(m.Arguments[0]);
                    AddSort((LambdaExpression)StripQuotes(m.Arguments[1]), true, false);
                    return(m);
                }
                if (m.Method.Name == "ThenBy")
                {
                    this.Visit(m.Arguments[0]);
                    AddSort((LambdaExpression)StripQuotes(m.Arguments[1]), false, true);
                    return(m);
                }
                if (m.Method.Name == "ThenByDescending")
                {
                    this.Visit(m.Arguments[0]);
                    AddSort((LambdaExpression)StripQuotes(m.Arguments[1]), false, false);
                    return(m);
                }
                if (m.Method.Name == "Count")
                {
                    RecurseToWhereOrRunLambda(m);
                    int foundCount = (int)NativeQuery.count(_coreQueryHandle);
                    return(Expression.Constant(foundCount));
                }
                if (m.Method.Name == "Any")
                {
                    RecurseToWhereOrRunLambda(m);
                    var  rowPtr   = NativeQuery.findDirect(_coreQueryHandle, IntPtr.Zero);
                    var  firstRow = Realm.CreateRowHandle(rowPtr, _realm.SharedRealmHandle);
                    bool foundAny = !firstRow.IsInvalid;
                    return(Expression.Constant(foundAny));
                }
                if (m.Method.Name == "First")
                {
                    RecurseToWhereOrRunLambda(m);
                    RowHandle firstRow = null;
                    if (_optionalSortOrderHandle == null)
                    {
                        var rowPtr = NativeQuery.findDirect(_coreQueryHandle, IntPtr.Zero);
                        firstRow = Realm.CreateRowHandle(rowPtr, _realm.SharedRealmHandle);
                    }
                    else
                    {
                        using (ResultsHandle rh = _realm.MakeResultsForQuery(_retType, _coreQueryHandle, _optionalSortOrderHandle))
                        {
                            var rowPtr = NativeResults.get_row(rh, IntPtr.Zero);
                            firstRow = Realm.CreateRowHandle(rowPtr, _realm.SharedRealmHandle);
                        }
                    }
                    if (firstRow == null || firstRow.IsInvalid)
                    {
                        throw new InvalidOperationException("Sequence contains no matching element");
                    }
                    return(Expression.Constant(_realm.MakeObjectForRow(_retType, firstRow)));
                }
                if (m.Method.Name == "Single")  // same as unsorted First with extra checks
                {
                    RecurseToWhereOrRunLambda(m);
                    var rowPtr   = NativeQuery.findDirect(_coreQueryHandle, IntPtr.Zero);
                    var firstRow = Realm.CreateRowHandle(rowPtr, _realm.SharedRealmHandle);
                    if (firstRow.IsInvalid)
                    {
                        throw new InvalidOperationException("Sequence contains no matching element");
                    }
                    IntPtr nextIndex  = (IntPtr)(firstRow.RowIndex + 1);
                    var    nextRowPtr = NativeQuery.findDirect(_coreQueryHandle, nextIndex);
                    var    nextRow    = Realm.CreateRowHandle(nextRowPtr, _realm.SharedRealmHandle);
                    if (!nextRow.IsInvalid)
                    {
                        throw new InvalidOperationException("Sequence contains more than one matching element");
                    }
                    return(Expression.Constant(_realm.MakeObjectForRow(_retType, firstRow)));
                }
            }

            if (m.Method.DeclaringType == typeof(string))
            {
                NativeQuery.Operation <string> queryMethod = null;

                if (m.Method == Methods.String.Contains.Value)
                {
                    queryMethod = (q, c, v) => NativeQuery.string_contains(q, c, v, (IntPtr)v.Length);
                }
                else if (m.Method == Methods.String.StartsWith.Value)
                {
                    queryMethod = (q, c, v) => NativeQuery.string_starts_with(q, c, v, (IntPtr)v.Length);
                }
                else if (m.Method == Methods.String.EndsWith.Value)
                {
                    queryMethod = (q, c, v) => NativeQuery.string_ends_with(q, c, v, (IntPtr)v.Length);
                }

                if (queryMethod != null)
                {
                    var member = m.Object as MemberExpression;
                    if (member == null)
                    {
                        throw new NotSupportedException($"The method '{m.Method}' has to be invoked on a RealmObject member");
                    }
                    var columnIndex = NativeQuery.get_column_index(_coreQueryHandle, member.Member.Name, (IntPtr)member.Member.Name.Length);

                    var argument = ExtractConstantValue(m.Arguments.SingleOrDefault());
                    if (argument == null || argument.GetType() != typeof(string))
                    {
                        throw new NotSupportedException($"The method '{m.Method}' has to be invoked with a single string constant argument or closure variable");
                    }
                    queryMethod(_coreQueryHandle, columnIndex, (string)argument);
                    return(m);
                }
            }

            throw new NotSupportedException($"The method '{m.Method.Name}' is not supported");
        }
Ejemplo n.º 7
0
 public static extern void remove_row(TableHandle tableHandle, RowHandle rowHandle);
Ejemplo n.º 8
0
 internal RealmObject MakeObjectForRow(string className, RowHandle row)
 {
     return(MakeObjectForRow(Metadata[className], row));
 }
Ejemplo n.º 9
0
 public static extern IntPtr get_is_attached(RowHandle rowHandle, out NativeException ex);
Ejemplo n.º 10
0
 public static extern IntPtr get_row_index(RowHandle rowHandle, out NativeException ex);
Ejemplo n.º 11
0
 public static extern IntPtr row_get_is_attached(RowHandle rowHandle);
Ejemplo n.º 12
0
 public static extern IntPtr row_get_row_index(RowHandle rowHandle);
Ejemplo n.º 13
0
 internal void _Manage(Realm realm, RowHandle rowHandle, Metadata metadata)
 {
     _realm     = realm;
     _rowHandle = rowHandle;
     _metadata  = metadata;
 }
Ejemplo n.º 14
0
 internal void _Manage(Realm realm, RowHandle rowHandle)
 {
     _realm     = realm;
     _rowHandle = rowHandle;
     _metadata  = realm.Metadata[GetType()];
 }
Ejemplo n.º 15
0
 private static extern void remove_row(TableHandle tableHandle, RowHandle rowHandle, out NativeException ex);