示例#1
0
        /// <summary>
        /// Gets the object by GUID.
        /// </summary>
        /// <returns>The object by GUID.</returns>
        /// <param name="guid">GUID of the requested object.</param>
        public IMappedObject GetObjectByGuid(Guid guid)
        {
            Stopwatch watch = Stopwatch.StartNew();

            using (var tran = this.engine.GetTransaction())
            {
                var row = tran.Select <byte[], string>(MappedObjectsGuidsTable, guid.ToByteArray());
                if (row.Exists)
                {
                    DbCustomSerializer <MappedObject> value = tran.Select <string, DbCustomSerializer <MappedObject> >(MappedObjectsTable, row.Value).Value;
                    if (value != null)
                    {
                        MappedObject data = value.Get;

                        if (data == null)
                        {
                            watch.Stop();
                            Logger.Debug(string.Format("Method GetObjectByGuid returned after {0} ms", watch.ElapsedMilliseconds));
                            return(null);
                        }

                        watch.Stop();
                        Logger.Debug(string.Format("Method GetObjectByGuid returned after {0} ms", watch.ElapsedMilliseconds));
                        return(new MappedObject(data));
                    }
                }
            }

            watch.Stop();
            Logger.Debug(string.Format("Method GetObjectByGuid returned after {0} ms", watch.ElapsedMilliseconds));
            return(null);
        }
示例#2
0
        /// <summary>
        /// Inserts a record in table
        /// </summary>
        /// <param name="collectionName">Collection name</param>
        /// <param name="primaryKeyColumnName">primary column name</param>
        /// <param name="secondryIndexColumnNameCollection">secondry index column collection name</param>
        /// <param name="data">JSON object</param>
        public void InsertRecord <T>(string collectionName, T data)
        {
            string        primaryKeyColumnName = null;
            List <string> secondaryIndexColumnNameCollection = null;

            PopulateKeyInfomationFromSchema(collectionName, ref primaryKeyColumnName, ref secondaryIndexColumnNameCollection);
            //solution can be build using nested tables as well...but might increase the complexity during search
            List <string> lockTables = GetLockTables(collectionName, secondaryIndexColumnNameCollection);


            // start the transaction
            using (var tran = engine.GetTransaction())
            {
                // acquire a lock, on main table and secondry index table as well
                tran.SynchronizeTables(lockTables.ToArray());

                Type   primaryPropertyType = data.GetType().GetProperty(primaryKeyColumnName).PropertyType;
                object primaryKey          = data.GetType().GetProperty(primaryKeyColumnName).GetValue(data);

                bool   wasUpdated = false;
                byte[] refPtr;

                var genericData = new DbCustomSerializer <T>(data);

                var        parameters          = new object[] { collectionName, primaryKey, genericData, null, null };
                MethodInfo insertMethodGeneric = Helper.CreateGenericInsertMethod <T>(tran, primaryPropertyType);
                insertMethodGeneric.Invoke(tran, parameters);
                refPtr     = (byte[])parameters[3];
                wasUpdated = (bool)parameters[4];

                if (wasUpdated)
                {
                    // delete the value from secondary tables
                    secondaryIndexColumnNameCollection.ForEach(indexCol =>
                    {
                        string secondaryIndexTableName   = string.Format("{0}{1}", collectionName, indexCol);
                        Type secondaryPropertyType       = data.GetType().GetProperty(indexCol).PropertyType;
                        object secondaryIndexColumnValue = data.GetType().GetProperty(indexCol).GetValue(data);
                        string secondaryIndexTableKey    = string.Format("{0}{1}{2}", secondaryIndexColumnValue, separator, primaryKey);
                        // always keep key in all lower case
                        secondaryIndexTableKey = secondaryIndexTableKey.ToLower();

                        tran.RemoveKey(secondaryIndexTableName, secondaryIndexTableKey);
                    });
                }

                secondaryIndexColumnNameCollection.ForEach(indexCol =>
                {
                    string secondaryIndexTableName = string.Format("{0}{1}", collectionName, indexCol);

                    Type secondaryPropertyType       = data.GetType().GetProperty(indexCol).PropertyType;
                    object secondaryIndexColumnValue = data.GetType().GetProperty(indexCol).GetValue(data);
                    string secondaryIndexTableKey    = string.Format("{0}{1}{2}", secondaryIndexColumnValue, separator, primaryKey);
                    // always keep key in all lower case
                    secondaryIndexTableKey = secondaryIndexTableKey.ToLower();
                    tran.Insert(secondaryIndexTableName, secondaryIndexTableKey, refPtr);
                });
                tran.Commit();
            }
        }
示例#3
0
        /// <summary>
        /// Saves the mapped object.
        /// </summary>
        /// <param name='obj'>
        /// The MappedObject instance.
        /// </param>
        /// <exception cref="DublicateGuidException">Is thrown when guid already in database</exception>
        public void SaveMappedObject(IMappedObject obj)
        {
            string id = this.GetId(obj);

            using (var tran = this.engine.GetTransaction()) {
                var byteGuid = obj.Guid.ToByteArray();
                var row      = tran.Select <byte[], string>(MappedObjectsGuidsTable, byteGuid);
                if (row.Exists && row.Value != id)
                {
                    tran.Rollback();
                    throw new DublicateGuidException(string.Format("An entry with Guid {0} already exists", obj.Guid));
                }

                if (this.fullValidationOnEachManipulation && obj.ParentId != null)
                {
                    DbCustomSerializer <MappedObject> value = tran.Select <string, DbCustomSerializer <MappedObject> >(MappedObjectsTable, obj.ParentId).Value;
                    if (value == null)
                    {
                        tran.Rollback();
                        throw new InvalidDataException();
                    }
                }

                obj.LastTimeStoredInStorage = DateTime.UtcNow;
                tran.Insert <string, DbCustomSerializer <MappedObject> >(MappedObjectsTable, id, obj as MappedObject);
                if (!obj.Guid.Equals(Guid.Empty))
                {
                    tran.Insert <byte[], string>(MappedObjectsGuidsTable, obj.Guid.ToByteArray(), id);
                }

                tran.Commit();
            }

            this.ValidateObjectStructureIfFullValidationIsEnabled();
        }
示例#4
0
        public IFileTransmissionObject GetObjectByRemoteObjectId(string remoteObjectId)
        {
            using (var tran = this.engine.GetTransaction()) {
                DbCustomSerializer <FileTransmissionObject> value = tran.Select <string, DbCustomSerializer <FileTransmissionObject> >(FileTransmissionObjectsTable, remoteObjectId).Value;
                if (value == null)
                {
                    return(null);
                }

                return(value.Get);
            }
        }
示例#5
0
        /// <summary>
        /// Gets the object by remote identifier.
        /// </summary>
        /// <returns>
        /// The saved object with the given remote identifier.
        /// </returns>
        /// <param name='id'>
        /// CMIS Object Id.
        /// </param>
        public IMappedObject GetObjectByRemoteId(string id)
        {
            using (var tran = this.engine.GetTransaction()) {
                DbCustomSerializer <MappedObject> value = tran.Select <string, DbCustomSerializer <MappedObject> >(MappedObjectsTable, id).Value;
                if (value != null)
                {
                    MappedObject data = value.Get;

                    if (data == null)
                    {
                        return(null);
                    }

                    return(new MappedObject(data));
                }

                return(null);
            }
        }
示例#6
0
        /// <summary>
        /// Gets the object by GUID.
        /// </summary>
        /// <returns>The object by GUID.</returns>
        /// <param name="guid">GUID of the requested object.</param>
        public IMappedObject GetObjectByGuid(Guid guid)
        {
            using (var tran = this.engine.GetTransaction()) {
                var row = tran.Select <byte[], string>(MappedObjectsGuidsTable, guid.ToByteArray());
                if (row.Exists)
                {
                    DbCustomSerializer <MappedObject> value = tran.Select <string, DbCustomSerializer <MappedObject> >(MappedObjectsTable, row.Value).Value;
                    if (value != null)
                    {
                        MappedObject data = value.Get;

                        if (data == null)
                        {
                            return(null);
                        }

                        return(new MappedObject(data));
                    }
                }
            }

            return(null);
        }