Esempio n. 1
0
        private DataTable GetDataTable(IPersistenceObjectCollection persistenceObjectCollection, IObjectKey parentObjectKey, HybridDictionary parameterCollection)
        {
            var pf = PersistenceFacade.GetInstance();
            var fieldMapperCollection = MapperFactory.GetInstance().GetFieldMappers(persistenceObjectCollection.GetType().FullName);

            var dt         = new DataTable();
            var connection = pf.GetDbConnection(_rdbObjectMapperInfo.RdbConnectionKey);

            using (connection)
            {
                var command = connection.CreateCommand();
                command.CommandText = _rdbObjectMapperInfo.MethodNameSelect ?? string.Format("{0}_sel", _rdbObjectMapperInfo.RdbEntityName);
                command.CommandType = CommandType.StoredProcedure;

                pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", parentObjectKey);
                foreach (DictionaryEntry param in parameterCollection)
                {
                    if (fieldMapperCollection.Contains(param.Key.ToString()))
                    {
                        pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldMapperCollection[param.Key.ToString()].ToString(), param.Value);
                    }
                    else // implied name from param.Key.ToString()
                    {
                        pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, param.Key.ToString(), param.Value);
                    }
                }

                var adapter = pf.GetDbDataAdapter(_rdbObjectMapperInfo.RdbConnectionKey);
                adapter.SelectCommand = command;
                adapter.Fill(dt);

                return(dt);
            }
        }
Esempio n. 2
0
        private void AddCommandParameter(DbCommand command, IPersistenceObject persistenceObject)
        {
            var gu = GeneralUtility.GetInstance();
            var pf = PersistenceFacade.GetInstance();
            var fieldMapperCollection       = MapperFactory.GetInstance().GetFieldMappers(persistenceObject.GetType().FullName);
            var fieldPropertyNameCollection = GetFieldPropertyNameCollection(persistenceObject);

            foreach (var fieldPropertyName in fieldPropertyNameCollection)
            {
                DbParameter parameter;
                if (fieldMapperCollection.Contains(fieldPropertyName.Name))
                {
                    parameter = pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldMapperCollection[fieldPropertyName.Name].ToString(), gu.GetMemberValue(persistenceObject, fieldPropertyName.Name));
                }
                else // implied name from fieldPropertyName
                {
                    parameter = pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, fieldPropertyName.Name, gu.GetMemberValue(persistenceObject, fieldPropertyName.Name));
                }
                if (!fieldPropertyName.IsRowVersion)
                {
                    continue;
                }
                parameter.Direction = ParameterDirection.InputOutput;
                if (parameter.Value == DBNull.Value)
                {
                    parameter.Value = new SqlBytes(new byte[8]);
                }
            }
        }
Esempio n. 3
0
        private DbDataReader GetDataReader(IObjectKey objectKey)
        {
            var pf         = PersistenceFacade.GetInstance();
            var connection = pf.GetDbConnection(_rdbObjectMapperInfo.RdbConnectionKey);
            var command    = connection.CreateCommand();

            command.CommandText = _rdbObjectMapperInfo.MethodNameSelect ?? string.Format("{0}_sel", _rdbObjectMapperInfo.RdbEntityName);
            command.CommandType = CommandType.StoredProcedure;
            pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", objectKey);
            return(command.ExecuteReader(CommandBehavior.CloseConnection));
        }
Esempio n. 4
0
 public static PersistenceFacade GetInstance()
 {
     if (_instance == null)
     {
         lock (SyncRoot)
         {
             if (_instance == null)
             {
                 _instance = new PersistenceFacade();
             }
         }
     }
     return(_instance);
 }
Esempio n. 5
0
        internal static void SetMemberValue(Type persistenceObjectType, IPersistenceObject persistenceObject, string targetMemberName, object value)
        {
            var gu         = GeneralUtility.GetInstance();
            var memberType = gu.GetMemberType(persistenceObjectType, persistenceObject, targetMemberName);

            if (memberType != null && memberType.GetInterface("IPersistenceObject") != null &&
                PersistenceFacade.GetInstance().HasObjectToObjectMapper(memberType.FullName))
            {
                var memberObject = Activator.CreateInstance(memberType, true);
                ((IPersistenceObject)memberObject).LoadFromObject(value);
                gu.SetMemberValue(persistenceObject, targetMemberName, memberObject);
            }
            else
            {
                gu.SetMemberValue(persistenceObject, targetMemberName, value);
            }
        }
Esempio n. 6
0
        private DataTable GetDataTable(IObjectKey parentObjectKey)
        {
            var dt         = new DataTable();
            var pf         = PersistenceFacade.GetInstance();
            var connection = pf.GetDbConnection(_rdbObjectMapperInfo.RdbConnectionKey);

            using (connection)
            {
                var command = connection.CreateCommand();
                command.CommandText = _rdbObjectMapperInfo.MethodNameSelect ?? string.Format("{0}_sel", _rdbObjectMapperInfo.RdbEntityName);
                command.CommandType = CommandType.StoredProcedure;
                pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", parentObjectKey);

                var adapter = pf.GetDbDataAdapter(_rdbObjectMapperInfo.RdbConnectionKey);
                adapter.SelectCommand = command;
                adapter.Fill(dt);

                return(dt);
            }
        }
Esempio n. 7
0
        public void Delete(IPersistenceObject persistenceObject)
        {
            DbCommand command = null;

            try
            {
                var pf = PersistenceFacade.GetInstance();
                command             = pf.GetDbCommand(_rdbObjectMapperInfo.RdbConnectionKey);
                command.CommandText = _rdbObjectMapperInfo.MethodNameDelete ?? string.Format("{0}_del", _rdbObjectMapperInfo.RdbEntityName);
                command.CommandType = CommandType.StoredProcedure;
                pf.AddCommandParameter(_rdbObjectMapperInfo.RdbConnectionKey, command, "objectKey", persistenceObject.ObjectKey);
                command.ExecuteNonQuery();
            }
            finally
            {
                if (command != null && command.Transaction == null)
                {
                    command.Connection.Close();
                }
            }
        }
Esempio n. 8
0
        public void Insert(IPersistenceObject persistenceObject)
        {
            DbCommand command = null;
            var       pf      = PersistenceFacade.GetInstance();

            try
            {
                command             = pf.GetDbCommand(_rdbObjectMapperInfo.RdbConnectionKey);
                command.CommandText = _rdbObjectMapperInfo.MethodNameInsert ?? string.Format("{0}_ins", _rdbObjectMapperInfo.RdbEntityName);
                command.CommandType = CommandType.StoredProcedure;
                AddCommandParameter(command, persistenceObject);
                command.ExecuteNonQuery();
                RetrieveRowVersion(persistenceObject, command);
            }
            finally
            {
                if (command != null && command.Transaction == null)
                {
                    command.Connection.Close();
                }
            }
        }