Пример #1
0
        public int DeleteAttribute(EntityAttribute entityAttribute)
        {
            int rowsAffected = 0;
            lock (_syncRoot)
            {
                _connection.Open();

                try
                {
                    using (SqlCommand command = new SqlCommand(DeleteStatement, _connection))
                    {
                        command.Parameters.Add(new SqlParameter("EntityType", SqlDbType.VarChar)).Value = entityAttribute.EntityType;
                        command.Parameters.Add(new SqlParameter("EntityName", SqlDbType.VarChar)).Value = entityAttribute.EntityName;
                        command.Parameters.Add(new SqlParameter("AttributeName", SqlDbType.VarChar)).Value = entityAttribute.AttributeName;
                        command.Parameters.Add(new SqlParameter("RefDate", SqlDbType.DateTime)).Value = entityAttribute.RefDate;

                        rowsAffected = command.ExecuteNonQuery();
                    }
                }
                finally
                {
                    _connection.Close();
                }
            }

            return rowsAffected;
        }
Пример #2
0
        public EntityAttribute WriteAttribute(EntityAttribute entityAttribute)
        {
            lock (_syncRoot)
            {
                _connection.Open();

                try
                {
                    using (SqlCommand command = new SqlCommand())
                    {
                        SqlTransaction txn = _connection.BeginTransaction();

                        command.Connection = _connection;
                        command.Transaction = txn;
                        command.CommandText = "declare xx clob; begin dbms_lob.createtemporary(xx, true, 0); :tempclob := xx; end;";
                        command.Parameters.Add(new SqlParameter("tempclob", SqlDbType.Text)).Direction = ParameterDirection.Output;

                        command.ExecuteNonQuery();
                        object tempLob = command.Parameters[0].Value;

                        //tempLob.BeginBatch(OracleLobOpenMode.ReadWrite);  //TODO:  Fix (bg)
                        
                        byte[] value = System.Text.Encoding.Unicode.GetBytes(entityAttribute.ValueAsString);
                        //tempLob.Write(value, 0, value.Length);
                        //tempLob.EndBatch();
                    
                        command.Parameters.Clear();
                        command.CommandText = MergeStatement;
                    
                        command.Parameters.Add(new SqlParameter("EntityType", SqlDbType.VarChar)).Value = entityAttribute.EntityType;
                        command.Parameters.Add(new SqlParameter("EntityName", SqlDbType.VarChar)).Value = entityAttribute.EntityName;
                        command.Parameters.Add(new SqlParameter("AttributeName", SqlDbType.VarChar)).Value = entityAttribute.AttributeName;
                        command.Parameters.Add(new SqlParameter("RefDate", SqlDbType.DateTime)).Value = entityAttribute.RefDate;
                        command.Parameters.Add(new SqlParameter("Value", SqlDbType.Text)).Value = tempLob;
                        command.Parameters.Add(new SqlParameter("DataType", SqlDbType.VarChar)).Value = entityAttribute.DataType;
                        command.Parameters.Add(new SqlParameter("CreatedBy", SqlDbType.VarChar)).Value = entityAttribute.CreatedBy;
                        command.Parameters.Add(new SqlParameter("CreatedOn", SqlDbType.DateTime)).Value = entityAttribute.CreatedOn;                           

                        command.ExecuteNonQuery();
                        txn.Commit();
                    }

                }
                catch (Exception ex)
                { 
                    throw;
                }
                finally
                {                        
                    _connection.Close();
                }             
            }

            return entityAttribute;
        }
Пример #3
0
        /// <summary>
        /// Writes an attribute to the store
        /// </summary>
        /// <param name="entityType">The type of entity (e.g. Book)</param>
        /// <param name="entityName">The name of the entity (e.g. MyBook)</param>
        /// <param name="attributeName">The name of the attribute (e.g. BookAlias)</param>
        /// <param name="refDate">The reference date to get the attribute for</param>
        /// <param name="value">The value to store</param>
        /// <param name="createdBy">The name of the user creating the attribute</param>
        /// <returns>The EntityAttribute object representing the created entry</returns>
        public EntityAttribute Write(string entityType, string entityName, string attributeName, DateTime? refDate, object value, string createdBy)
        {
            if (createdBy == null)
            {
                createdBy = Environment.UserName;
            }

            EntityAttribute attribute = new EntityAttribute(entityType, entityName, attributeName, refDate.HasValue ? refDate.Value : DateTime.MinValue, value, createdBy, DateTime.UtcNow);
            return Write(attribute);
        }
Пример #4
0
 /// <summary>
 /// Deletes the passed entity attribute
 /// </summary>
 /// <param name="entityAttribute">The entity attribute to delete</param>
 /// <returns>the number of items deleted (note, this should really only ever return 1)</returns>
 public int Delete(EntityAttribute entityAttribute)
 {
     return _readerWriter.DeleteAttribute(entityAttribute);
 }
Пример #5
0
        /// <summary>
        /// Writes the passed entity attribute to the store
        /// </summary>
        /// <param name="entityAttribute">The entityAttribute to save</param>
        /// <returns>The updated attribute</returns>
        public EntityAttribute Write(EntityAttribute entityAttribute)
        {
            if (entityAttribute == null)
            {
                throw new ArgumentNullException("entityAttribute");
            }

            return _readerWriter.WriteAttribute(entityAttribute);
        }