public IDictionary <string, IStorageContext> GenerateStorageContexts <T>(string rountingName, int top, IFilterCondition[] where, IOrderByCondition[] orderby) where T : class, IAlbianObject, new() { IDictionary <string, IStorageContext> storageContexts = new Dictionary <string, IStorageContext>(); IFakeCommandBuilder fakeBuilder = new FakeCommandBuilder(); IFakeCommandAttribute fakeCommandAttrribute = fakeBuilder.GenerateQuery <T>(rountingName, top, where, orderby); if (null == fakeCommandAttrribute) //the PermissionMode is not enough { if (null != Logger) { Logger.WarnFormat("The permission is not enough in the {0} routing.", rountingName); } throw new PersistenceException(string.Format("The permission is not enough in the {0} routing.", rountingName)); } IStorageContext storageContext = new StorageContext { FakeCommand = new List <IFakeCommandAttribute>(), StorageName = fakeCommandAttrribute.StorageName, }; storageContext.FakeCommand.Add(fakeCommandAttrribute); storageContexts.Add(fakeCommandAttrribute.StorageName, storageContext); return(storageContexts); }
public IDictionary <string, IStorageContext> GenerateFakeCommandByRoutings <T>(T target, PropertyInfo[] properties, IObjectAttribute objectAttribute, BuildFakeCommandByRoutingHandler <T> buildFakeCommandByRoutingHandler) where T : IAlbianObject { if (null == properties || 0 == properties.Length) { throw new ArgumentNullException("properties"); } if (null == objectAttribute) { throw new ArgumentNullException("objectAttribute"); } if (null == objectAttribute.RoutingAttributes || null == objectAttribute.RoutingAttributes.Values || 0 == objectAttribute.RoutingAttributes.Values.Count) { if (null != Logger) { Logger.Error("The routing attributes or routings is null"); } throw new Exception("The routing attributes or routing is null"); } IDictionary <string, IStorageContext> storageContexts = new Dictionary <string, IStorageContext>(); foreach (var routing in objectAttribute.RoutingAttributes.Values) { IFakeCommandAttribute fakeCommandAttrribute = buildFakeCommandByRoutingHandler(PermissionMode.W, target, routing, objectAttribute, properties); if (null == fakeCommandAttrribute) //the PermissionMode is not enough { if (null != Logger) { Logger.WarnFormat("The permission is not enough in the {0} routing.", routing.Name); } continue; } if (storageContexts.ContainsKey(fakeCommandAttrribute.StorageName)) { storageContexts[fakeCommandAttrribute.StorageName].FakeCommand.Add(fakeCommandAttrribute); } else { IStorageContext storageContext = new StorageContext { FakeCommand = new List <IFakeCommandAttribute>(), StorageName = fakeCommandAttrribute.StorageName, }; storageContext.FakeCommand.Add(fakeCommandAttrribute); storageContexts.Add(fakeCommandAttrribute.StorageName, storageContext); } } return(storageContexts); }
protected virtual IDataReader Execute(ITask task) { if (null == task) { throw new ArgumentNullException("task"); } if (1 != task.Context.Count) //only one { throw new PersistenceException("The query task is error."); } IStorageContext storageContext = PreExecute(task); try { if (ConnectionState.Open != storageContext.Connection.State) { storageContext.Connection.Open(); } IFakeCommandAttribute fc = storageContext.FakeCommand[0]; //only one IDbCommand cmd = storageContext.Connection.CreateCommand(); cmd.CommandText = fc.CommandText; cmd.CommandType = CommandType.Text; foreach (DbParameter para in fc.Paras) { cmd.Parameters.Add(para); } IDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); cmd.Parameters.Clear(); return(dr); } catch (Exception exc) { if (storageContext.Connection.State != ConnectionState.Closed) { storageContext.Connection.Close(); } throw exc; } }