public DbContext Resolve(DBSelector dbSelector = DBSelector.Master) { DbContext dbContext = null; if (dbSelector.Equals(DBSelector.Master)) { _cacheDbContext.TryGetValue(dbSelector, out dbContext); } //ISSUE:A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe //We do it in temprary, we must optimzie the Framewrok to resolve the multiple thread to call DbContext. else { _slaveCacheDbContext.TryGetValue(Thread.CurrentThread.ManagedThreadId, out dbContext); } if (dbContext != null) { return(dbContext); } var configurer = new AbpDbContextConfiguration <TDbContext>(_dbOptions.DbConnections[dbSelector]); _dbContextConfigurer.Configure(configurer); var actualContext = typeof(TDbContext); dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options); if (dbSelector.Equals(DBSelector.Master)) { _cacheDbContext.Add(dbSelector, dbContext); } else { _slaveCacheDbContext.Add(Thread.CurrentThread.ManagedThreadId, dbContext); } return(dbContext); }
public static ISession DBSession(DBSelector db = DBSelector.DEFAULT) { switch (db) { case DBSelector.CUSTOM: { var cfgFile = string.Empty; cfgFile = $"{AppDomain.CurrentDomain.BaseDirectory}\\mypath\\custom.cfg.xml"; //replace the [mypath] with your path Configuration configuration = new Configuration() .AddAssembly("NHibernateCustomCfgFile") .Configure(cfgFile); ISessionFactory sessionFactory = configuration.BuildSessionFactory(); session = sessionFactory.OpenSession(); } break; default: case DBSelector.DEFAULT: { Configuration configuration = new Configuration() .AddAssembly("NHibernateCustomCfgFile") .Configure();//by default it reads hibernate.cfg.xml ISessionFactory sessionFactory = configuration.BuildSessionFactory(); session = sessionFactory.OpenSession(); break; } } return(session); }
public override IQueryable <EFEntity> GetAll() { //Have to set the slave database, it should be work for this. //NOTE:need to be optimzied _dbSelector = DBSelector.Slave; return(Table); }
public int saveOrder(Order theOrder) { DBSelector selector = new DBSelector(); return(selector.getRow <int>("INSERT INTO \"Order\" (\"ConfirmationNumber\", \"OrderDateTime\", \"TotalPrice\", \"UserID\") VALUES ('" + theOrder.ConfirmationNumber + "','" + theOrder.OrderDateTime + "','" + theOrder.TotalPrice + "','" + theOrder.UserID + "')" + "RETURNING \"OrderID\"")); }
/// <summary> /// Load network's memory from database /// </summary> /// <param name="dbConfig"></param> /// <param name="networkID"></param> /// <param name="destinationMemoryFilePath"></param> public void DBMemoryLoad(DatabaseConfig dbConfig, Guid networkID, string destinationMemoryFilePath) { try { DBSelector dbSelector = new DBSelector(dbConfig); // Creating the general string list of memory: List <string> memoryInTextList = new List <string>(); // Getting all layers ids' ordered by own number in network: List <Guid> layersIDList = dbSelector.GetLayerIDList(networkID); // As parallel fill the metadata of network: NetworkStructure networkStructure = new NetworkStructure(); networkStructure.NeuronsByLayers = new int[layersIDList.Count]; for (int i = 0; i < layersIDList.Count; i++) { List <Guid> neuronsIDList = dbSelector.GetNeuronsIDList(layersIDList[i]); // Fillin the metadata of count of neurons on current layer: networkStructure.NeuronsByLayers[i] = neuronsIDList.Count; for (int k = 0; k < neuronsIDList.Count; k++) { List <double> weightList = dbSelector.GetWeightsList(neuronsIDList[k]); // Adding memory neuron data to text list: string neuronDataText = $"layer_{i} neuron_{k} "; for (int j = 0; j < weightList.Count; j++) { neuronDataText += weightList[j]; } memoryInTextList.Add(neuronDataText); // Fillin metadata of inputVectorLength of network: if (i == 0 && k == 0) { networkStructure.InputVectorLength = weightList.Count; } } } // Saving memory from textList: FileManager.SaveMemoryFromModel(networkStructure, memoryInTextList, destinationMemoryFilePath); } catch (Exception ex) { Logger.LogError(ErrorType.DBMemoryLoadError, "DB Memory loading error!\n" + ex); Console.WriteLine($" {DateTime.Now } DB Memory loading error!\n {ex}"); } }
public int saveLoginInfo(string username, string password) { DBModifier modder = new DBModifier(); modder.modifyRows("INSERT INTO \"Login\" (\"UserName\", \"Password\") VALUES ('" + username + "','" + password + "')"); DBSelector selector = new DBSelector(); Login newLogin = selector.getRow <Login>("SELECT * FROM \"Login\" WHERE " + "\"UserName\" = '" + username + "' AND \"Password\" = '" + password + "'"); return(newLogin.ID); }
public DbContext Resolve(DBSelector dbSelector = DBSelector.Master) { DbContext dbContext; CacheDbContext.TryGetValue(dbSelector, out dbContext); if (dbContext != null) { return(dbContext); } var configurer = new AbpDbContextConfiguration <TDbContext>(dbOptions.DbConnections[dbSelector]); dbContextConfigurer.Configure(configurer); var actualContext = typeof(TDbContext); dbContext = (DbContext)Activator.CreateInstance(actualContext, configurer.DbContextOptions.Options); CacheDbContext.Add(dbSelector, dbContext); return(dbContext); }
public void addItem(Item theItem, Vendor theVendor) { DBModifier modder = new DBModifier(); DBSelector selector = new DBSelector(); //put the item in the DB modder.modifyRows("INSERT INTO \"Item\"(\"RetailPrice\",\"StockQuantity\",\"ItemName\",\"CostPrice\",\"Category\") VALUES(" + theItem.RetailPrice + "," + theItem.StockQuantity + ",'" + theItem.ItemName + "'," + theItem.CostPrice + ",'" + theItem.Category + "')"); Item newitem = selector.getRow <Item>("SELECT * FROM \"Item\" WHERE \"RetailPrice\" = " + theItem.RetailPrice + " AND \"StockQuantity\" = " + theItem.StockQuantity + " AND \"ItemName\" = '" + theItem.ItemName + "' AND \"CostPrice\" = " + theItem.CostPrice + " AND \"Category\" = '" + theItem.Category + "'"); //add it to the vedor modder.modifyRows("INSERT INTO \"Vendor_Items\"(\"VendorID\",\"ItemID\") VALUES( " + theVendor.VendorID + "," + newitem.ItemID + ")"); }
public List <Item> getOrderItems(int orderID) { DBSelector selector = new DBSelector(); List <ItemList> itemList = selector.getRows <ItemList>("SELECT * FROM \"ItemList\" WHERE \"OrderID\"= '" + orderID + "'"); StringBuilder sb = new StringBuilder(); for (int i = 0; i < itemList.Count; ++i) { sb.Append("'"); sb.Append(itemList[i].ItemID); sb.Append("'"); //add a comma if it's not the last id if (i < (itemList.Count - 1)) { sb.Append(","); } } return(selector.getRows <Item>("SELECT * FROM \"Item\" WHERE \"ItemID\" IN (" + sb.ToString() + ")")); }
public List <Login> getAllLogins() { DBSelector selector = new DBSelector(); return(selector.getRows <Login>("SELECT * FROM \"Login\"")); }
public override void Delete(EFEntity entity) { _dbSelector = DBSelector.Master; Table.Remove(entity); }
public override EFEntity Update(EFEntity entity) { _dbSelector = DBSelector.Master; return(Table.Update(entity).Entity); }
public override EFEntity Insert(EFEntity entity) { _dbSelector = DBSelector.Master; return(Table.Add(entity).Entity); }
public List <Vendor> getAllVendors() { DBSelector selector = new DBSelector(); return(selector.getRows <Vendor>("SELECT * FROM \"Vendor\"")); }
public override IQueryable <TEntity> GetAll() { dbSelector = DBSelector.Slave; throw new NotImplementedException(); }
public List <User> getAllUsers() { DBSelector selector = new DBSelector(); return(selector.getRows <User>("SELECT * FROM \"User\"")); }
public User getUserByID(int ID) { DBSelector selector = new DBSelector(); return(selector.getRow <User>("SELECT * FROM \"User\" WHERE \"ID\"= '" + ID + "'")); }
public override IQueryable <EFEntity> GetAll() { //Must Have the slave database, it should be work for this. dbSelector = DBSelector.Slave; return(Table); }
public Vendor getVendorByID(int id) { DBSelector selector = new DBSelector(); return(selector.getRow <Vendor>("SELECT * FROM \"Vendor\" WHERE \"VendorName\"='" + id + "'")); }
public List <Order> getOrdersByUser(int userID) { DBSelector selector = new DBSelector(); return(selector.getRows <Order>("SELECT * FROM \"Order\" WHERE \"UserID\"= '" + userID + "'")); }
public Item getItemByID(int ID) { DBSelector selector = new DBSelector(); return(selector.getRow <Item>("SELECT * FROM \"Item\" WHERE \"ItemID\"= '" + ID + "'")); }
public List <Item> geItemsByCategory(string category) { DBSelector selector = new DBSelector(); return(selector.getRows <Item>("SELECT * FROM \"Item\" WHERE \"Category\" = '" + category + "'")); }
public List <ItemList> getOrderLineItems(int orderID) { DBSelector selector = new DBSelector(); return(selector.getRows <ItemList>("SELECT * FROM \"ItemList\" WHERE \"OrderID\" = '" + orderID + "'")); }
public Order getOrderByID(int ID) { DBSelector selector = new DBSelector(); return(selector.getRow <Order>("SELECT * FROM \"Order\" WHERE \"OrderID\"= '" + ID + "'")); }
public Login getLoginByUserID(int userID) { DBSelector selector = new DBSelector(); return(selector.getRow <Login>("SELECT * FROM \"Public.Login\" WHERE \"ID\" = '" + userID + "'")); }
public List <String> getItemCategories() { DBSelector selector = new DBSelector(); return(selector.getRows <String>("SELECT DISTINCT \"Category\" FROM \"Item\"")); }
private void DBandTableControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e) { if ((bool)e.NewValue == true) { Dispatcher.BeginInvoke(DispatcherPriority.ContextIdle, new Action(delegate() { DBSelector.Focus(); })); } }
public Vendor getVendorByName(string name) { DBSelector selector = new DBSelector(); return(selector.getRow <Vendor>("SELECT * FROM \"Vendor\" WHERE \"VendorName\"='" + name + "'")); }