Exemplo n.º 1
0
 public override int Count(string objectFullName, ObjectFindOptions options, ObjectIndex[] indexes)
 {
     using (var db = OpenData())
     {
         var parameters = new List<IDataParameter>();
         var sql = _CreateSQLFromFindOptions(db, objectFullName, options, indexes, SQLStatements.RowsCount, parameters);
         return db.ExecuteScalar<int>(sql, 0, parameters.ToArray());
     }
 }
Exemplo n.º 2
0
 public void Add(byte[] secondaryKey, byte[] value, ObjectIndex[] indexes)
 {
     _bulkStoreObjects.Add(
         new PersistentObject()
         {
             Name = _client.ObjectName,
             SecondaryKey = secondaryKey,
             Value = value,
             Indexes = indexes
         });
 }
Exemplo n.º 3
0
        private static string _CreateSQLFromFindOptions(IDatabaseService db, 
            string objectFullName, 
            ObjectFindOptions options, 
            ObjectIndex[] indexes, 
            string templateSql, 
            IList<IDataParameter> parameters)
        {
            var logic = options.Logic;
            var oper = options.Operator;
            var limit = options.Limit;

            bool useOr = ObjectFindLogic.Or == logic;
            bool useLike = ObjectFindOperator.Like == oper;
            bool isNull = ObjectFindOperator.IsNull == oper;

            var limitSql = (0 == limit) ? SQLStatements.NoLimit : string.Format(SQLStatements.Limit, limit);

            var tableName = _CreateTableName(db, objectFullName);

            var sqlConstraint = new StringBuilder();
            if (null != indexes && 0 < indexes.Length)
            {
                // initialize the where clause
                sqlConstraint.Append("WHERE ");
                for (int i = 0; indexes.Length > i; i++)
                {
                    var idx = indexes[i];

                    // skip over null objects
                    if (null == idx)
                    {
                        continue;
                    }

                    if (0 < i)
                    {
                        if (useOr)
                        {
                            sqlConstraint.Append(" OR ");
                        }
                        else
                        {
                            sqlConstraint.Append(" AND ");
                        }
                    }

                    var paramName = "p" + i + idx.Name;
                    var value = idx.GetObjectValue();
                    sqlConstraint.Append(db.MakeQuotedName(idx.Name));

                    if (useLike)
                    {
                        sqlConstraint.Append(' ');
                        sqlConstraint.Append(db.MakeLikeParamReference(paramName));
                        parameters.Add(ObjectIndexProvider.MakeLikeParameter(db, paramName, value));
                    }
                    else if (isNull)
                    {
                        sqlConstraint.Append(" IS NULL");
                    }
                    else
                    {
                        sqlConstraint.Append(" = ");
                        sqlConstraint.Append(db.MakeParamReference(paramName));
                        parameters.Add(db.MakeParam(paramName, value));
                    }
                }
            }
            var orderBySql = _CreateOrderBySQL(db, options.Order);
            return string.Format(templateSql, tableName, sqlConstraint.ToString(), orderBySql, limitSql);
        }
Exemplo n.º 4
0
 public void Add(byte[] value, ObjectIndex[] indexes)
 {
     Add(null, value, indexes);
 }
Exemplo n.º 5
0
        public static ObjectIndex Create(string name, object value)
        {
            ObjectIndex returnValue = null;

            if (null == name)
            {
                throw new ArgumentNullException("name");
            }

            if (!ObjectNameValidator.IsValidIndexName(name))
            {
                throw new ArgumentException("Invalid index name found " + name + ". It should be 1-30 characters long and contain only alphanumeric characters or underscores.");
            }

            if (null != value)
            {
                var dataType = DefaultDataType.GetDataType(value);
                if (ObjectIndexType.Unknown == dataType)
                {
                    throw new ArgumentException("Unsupported Type: " + value.GetType().Name);
                }

                returnValue = new ObjectIndex(name, dataType.ConvertToBinary(value), value, dataType);
            }
            else
            {
                returnValue = new ObjectIndex(name, null, null, ObjectIndexType.Unknown);
            }

            return returnValue;
        }
Exemplo n.º 6
0
 public override int Count(string objectFullName, ObjectFindOptions options, ObjectIndex[] indexes)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 public ObjectID Store(int objectId, byte[] secondaryKey, byte[] value, ObjectIndex[] indexes)
 {
     return _service.Store(_nameSpace,
         new PersistentObject()
         {
             Name = _objectName,
             ID = objectId,
             SecondaryKey = secondaryKey,
             Value = value,
             Indexes = indexes
         });
 }
Exemplo n.º 8
0
 public int Count(ObjectFindOptions options, ObjectIndex[] indexes)
 {
     return _service.Count(_nameSpace, _objectName, options, indexes);
 }
Exemplo n.º 9
0
 public ObjectID Store(byte[] value, ObjectIndex[] indexes)
 {
     return Store(null, value, indexes);
 }
Exemplo n.º 10
0
 public byte[][] Find(ObjectFindOptions options, ObjectIndex[] indexes)
 {
     return _service.Find(_nameSpace, _objectName, options, indexes).ToArray();
 }
Exemplo n.º 11
0
        /// <summary>
        /// Updates the index values for a single Object.
        /// </summary>
        /// <param name="nameSpace"></param>
        /// <param name="objectName"></param>
        /// <param name="objectId"></param>
        /// <param name="indexes"></param>
        public void UpdateIndexes(string nameSpace, string objectName, int objectId, ObjectIndex[] indexes)
        {
            _ValidateArguments(nameSpace, objectName);
            var objectFullName = ObjectNaming.CreateFullObjectName(nameSpace, objectName);

            using (var trans = new TransactionScope(TransactionScopeOption.Required, _DefaultTransactionOptions))
            {
                if (null != indexes && 0 < indexes.Length)
                {
                    _objectIndexer.IndexObject(objectFullName, objectId,
                        indexes);
                    _objectVersions.Update(objectFullName);
                }

                trans.Complete();
            }
        }
Exemplo n.º 12
0
        public IEnumerable<byte[]> Find(string nameSpace, string objectName, ObjectFindOptions options, ObjectIndex[] indexes)
        {
            _ValidateArguments(nameSpace, objectName);

            var objectFullName = ObjectNaming.CreateFullObjectName(nameSpace, objectName);
            var objectIds = _objectIndexer.Find(objectFullName, options, indexes);
            foreach (var objectId in objectIds)
            {
                yield return _objectStore.Get(objectFullName, objectId);
            }
        }
Exemplo n.º 13
0
        public int Count(string nameSpace, string objectName, ObjectFindOptions options, ObjectIndex[] indexes)
        {
            _ValidateArguments(nameSpace, objectName);

            var objectFullName = ObjectNaming.CreateFullObjectName(nameSpace, objectName);
            return _objectIndexer.Count(objectFullName, options, indexes);
        }