Exemplo n.º 1
0
        private TableHandle GetTable(Schema.ObjectSchema schema)
        {
            var result    = new TableHandle();
            var tableName = schema.Name;

            RuntimeHelpers.PrepareConstrainedRegions();
            try { /* Retain handle in a constrained execution region */ }
            finally
            {
                var tablePtr = SharedRealmHandle.GetTable(tableName);
                result.SetHandle(tablePtr);
            }
            return(result);
        }
Exemplo n.º 2
0
        private QueryHandle CreateQuery(Schema.ObjectSchema elementType)
        {
            var tableHandle = _realm.Metadata[elementType.Name].Table;
            var queryHandle = tableHandle.TableWhere();

            //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
            {
                queryHandle.SetHandle(NativeTable.Where(tableHandle));
            }//at this point we have atomically acquired a handle and also set the root correctly so it can be unbound correctly
            return(queryHandle);
        }
Exemplo n.º 3
0
        private RealmObject.Metadata CreateRealmObjectMetadata(Schema.ObjectSchema schema)
        {
            var table = this.GetTable(schema);

            Weaving.IRealmObjectHelper helper;

            if (schema.Type != null && !Config.Dynamic)
            {
                var wovenAtt = schema.Type.GetCustomAttribute <WovenAttribute>();
                if (wovenAtt == null)
                {
                    throw new RealmException($"Fody not properly installed. {schema.Type.FullName} is a RealmObject but has not been woven.");
                }
                helper = (Weaving.IRealmObjectHelper)Activator.CreateInstance(wovenAtt.HelperType);
            }
            else
            {
                helper = Dynamic.DynamicRealmObjectHelper.Instance;
            }
            // build up column index in a loop so can spot and cache primary key index on the way
            var initColumnMap       = new Dictionary <string, IntPtr>();
            int initPrimaryKeyIndex = -1;

            foreach (var prop in schema)
            {
                var colIndex = NativeTable.GetColumnIndex(table, prop.Name);
                initColumnMap.Add(prop.Name, colIndex);
                if (prop.IsPrimaryKey)
                {
                    initPrimaryKeyIndex = (int)colIndex;
                }
            }
            return(new RealmObject.Metadata
            {
                Table = table,
                Helper = helper,
                ColumnIndices = initColumnMap,
                PrimaryKeyColumnIndex = initPrimaryKeyIndex,
                Schema = schema
            });
        }
Exemplo n.º 4
0
 internal RealmResultsEnumerator(Realm realm, ResultsHandle rh, Schema.ObjectSchema schema)
 {
     _realm = realm;
     _enumeratingResults = rh;
     _schema             = schema;
 }