void ConfigureDatabase() { #if DB4O_8_0 DatabaseConfiguration = Db4oEmbedded.NewConfiguration(); DatabaseConfiguration.Common.AllowVersionUpdates = true; DatabaseConfiguration.Common.ActivationDepth = 0; //DatabaseConfiguration.Common.Queries.EvaluationMode(QueryEvaluationMode.Lazy); DatabaseConfiguration.Common.WeakReferenceCollectionInterval = 60 * 1000; //DatabaseConfiguration.Common.Diagnostic.AddListener(new DiagnosticToConsole()); var msgConf = DatabaseConfiguration.Common.ObjectClass(typeof(MessageModel)); msgConf.CascadeOnActivate(true); msgConf.CascadeOnDelete(true); msgConf.Indexed(true); msgConf.ObjectField("f_TimeStamp").Indexed(true); #else DatabaseConfiguration = Db4oFactory.Configure(); DatabaseConfiguration.AllowVersionUpdates(true); DatabaseConfiguration.ObjectClass(typeof(MessageModel)). ObjectField("f_TimeStamp").Indexed(true); #endif }
protected override void OpenDatabase() { if (string.IsNullOrEmpty(fileName)) { throw new Exception("File name required"); } IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration(); config.Common.UpdateDepth = 2; foreach (IPropertyRepository repo in Collections) { foreach (PropertyInfo pi in repo.ContentsType.GetProperties().Where(p => p.PropertyType == typeof(DbImage))) { config.Common.ObjectClass(repo.ContentsType).ObjectField(pi.Name).CascadeOnUpdate(true); config.Common.ObjectClass(repo.ContentsType).ObjectField(pi.Name).CascadeOnDelete(true); } } OnConfigCreate(config); container = Db4oEmbedded.OpenFile(config, fileName); }
private static void MigrationOnTheFly() { DeleteDatabases(); IObjectContainer desktopDatabaseWithoutUUID = Db4oEmbedded.OpenFile(DesktopDatabaseName); desktopDatabaseWithoutUUID.Store(new Car(new Pilot("Max"), "Max's Car")); desktopDatabaseWithoutUUID.Store(new Car(new Pilot("Joe"), "Joe's Car")); desktopDatabaseWithoutUUID.Commit(); desktopDatabaseWithoutUUID.Close(); IObjectContainer desktopDatabase = OpenDatabase(DesktopDatabaseName); IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName); IReplicationProvider desktopRelicationPartner = new Db4oEmbeddedReplicationProvider(desktopDatabase); IReplicationProvider mobileRelicationPartner = new Db4oEmbeddedReplicationProvider(mobileDatabase); // #example: Migrate on the fly IReplicationSession replicationSession = Replication.Begin(desktopRelicationPartner, mobileRelicationPartner); IList <Car> initialReplication = desktopDatabase.Query <Car>(); foreach (Car changedObjectOnDesktop in initialReplication) { IObjectInfo infoAboutObject = desktopDatabase.Ext().GetObjectInfo(changedObjectOnDesktop); if (null == infoAboutObject.GetUUID()) { desktopDatabase.Ext().Store(changedObjectOnDesktop, 2); } replicationSession.Replicate(changedObjectOnDesktop); } replicationSession.Commit(); // #end example PrintCars(mobileDatabase); CloseDBs(desktopDatabase, mobileDatabase); }
public static void Main(string[] args) { // #example: Configure rollback strategy IEmbeddedConfiguration configuration = Db4oEmbedded.NewConfiguration(); configuration.Common .Add(new TransparentPersistenceSupport(new DeactivatingRollbackStrategy())); // #end example using (IObjectContainer container = Db4oEmbedded.OpenFile(configuration, "database.db4o")) { StorePilot(container); // #example: Rollback with rollback strategy Pilot pilot = container.Query <Pilot>()[0]; pilot.Name = "NewName"; // Rollback container.Rollback(); // Now the pilot has the old name again Console.Out.WriteLine(pilot.Name); // #end example } }
public static void DeleteAddress() { using (IObjectContainer db = Db4oEmbedded.OpenFile(@"C:\DBO\ODB.yap")) { string userName; string DeleteStreet; string DeleteCity; Console.WriteLine("Insert person surname who address You want delete: "); userName = Console.ReadLine(); Console.WriteLine("Insert address witch You want delete, by city and street: "); Console.WriteLine("Street: "); DeleteStreet = Console.ReadLine(); Console.WriteLine("City: "); DeleteCity = Console.ReadLine(); IObjectSet result = db.QueryByExample(new Person(null, userName, new Address(null, null, null), new ObjectDataBase.Phone(null, null, null))); Person found; if (result.HasNext()) { found = (Person)result.Next(); db.Delete(found.PersonAddresses.Find(x => (x.City == DeleteCity) && (x.Street == DeleteStreet))); //RetrieveAllPerson(db); Console.WriteLine("\nPerson address has been deleted from database"); } else { Console.WriteLine("This person don't exist in database"); } } }
private void button1_Click(object sender, EventArgs e) { IObjectContainer db = Db4oEmbedded.OpenFile("EmployeeManager3.yap"); if (double.Parse(textBox4.Text) < 300) { MessageBox.Show("Lỗi nhập liệu", "Lỗi"); } else { var employee = new Employee(textBox1.Text, textBox2.Text, (Company)this.comboBox1.SelectedItem, double.Parse(textBox4.Text)); db.Store(employee); var pilot1 = new Company { CompanyName = comboBox1.Text, }; IObjectSet result = db.QueryByExample(pilot1); int a = result.Count; Company p2 = (Company)result[0]; Company p = (Company)result[1]; var pilot2 = new Employee { FullName = textBox1.Text, }; IObjectSet result1 = db.QueryByExample(pilot2); Employee p1 = (Employee)result1[0]; p1.HomeBase = p2; db.Store(p1); db.Delete(p); db.Close(); getdata(); } }
private void InitEvents() { openFile.Click += (s, e) => { OpenFileDialog openFile = new OpenFileDialog(); if (openFile.ShowDialog() == true) { try { db = Db4oEmbedded.OpenFile(openFile.FileName); IObjectSet objectsList = db.QueryByExample(null); foreach (var item in objectsList) { treeView.Items.Add(item); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }; }
public void SetIndex(ArrayList fieldnames, string className, ArrayList Indexed, string path, bool customConfig) { IObjectContainer con = null; try { IEmbeddedConfiguration embeddedConfig = !customConfig?Db4oEmbedded.NewConfiguration() : Config(); for (int i = 0; i < fieldnames.Count; i++) { embeddedConfig.Common.ObjectClass(className).ObjectField(fieldnames[i].ToString()).Indexed( Convert.ToBoolean(Indexed[i])); } con = Db4oEmbedded.OpenFile(embeddedConfig, path); IReflectClass clazz = con.Ext().Reflector().ForName(className); con.QueryByExample(clazz); } finally { con.Close(); } }
private static void SessionsIsolation() { CleanUp(); using (IObjectContainer rootContainer = Db4oEmbedded.OpenFile(DatabaseFileName)) { using (IObjectContainer session1 = rootContainer.Ext().OpenSession(), session2 = rootContainer.Ext().OpenSession()) { // #example: Session are isolated from each other session1.Store(new Person("Joe")); session1.Store(new Person("Joanna")); // the second session won't see the changes until the changes are committed PrintAll(session2.Query <Person>()); session1.Commit(); // new the changes are visiable for the second session PrintAll(session2.Query <Person>()); // #end example } } }
private static void AlreadyOpenDatabaseThrows() { IObjectContainer allReadyOpen = Db4oEmbedded.OpenFile("database.db4o"); try { // #example: If the database is already open try { IObjectContainer container = Db4oEmbedded.OpenFile("database.db4o"); } catch (DatabaseFileLockedException e) { // Database is already open! // Use another database-file or handle this case gracefully } // #end example } finally { allReadyOpen.Close(); } }
private static void DeleteAddressForPerson() { Console.WriteLine("Podaj imie:"); var imie = Console.ReadLine(); Console.WriteLine("Podaj nazwisko:"); var nazwisko = Console.ReadLine(); using (IObjectContainer db = Db4oEmbedded.OpenFile("baza.txt")) { var querry = db.Query <Person>(typeof(Person)); var result = querry.FirstOrDefault(x => x.Name == imie && x.Lastname == nazwisko); if (result != null) { if (result.Adress != null) { db.Delete(result.Adress); } db.Store(result); } } }