private IExtObjectContainer OpenNewSession() { return((IExtObjectContainer)Db4oClientServer.OpenClient("localhost", _server.Ext().Port(), UserName, Password)); }
// #end example private static IObjectContainer OpenClient(IClientConfiguration configuration) { return(Db4oClientServer.OpenClient(configuration, "localhost", PortNumber, UserAndPassword, UserAndPassword)); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //LinqIndex.Run(); //return; //TreeProgram.Run(); //return; IObjectContainer db; IObjectServer server = null; bool multiple_client = false; string dbpath = "temp.n.db"; File.Delete(dbpath); if (!multiple_client) { db = Db4oEmbedded.OpenFile(dbpath); } else { var config = Db4oClientServer.NewServerConfiguration(); config.Common.Diagnostic.AddListener(new DiagnosticToConsole()); //Wait before close() config.TimeoutServerSocket = 1000 * 10; server = Db4oClientServer.OpenServer(config, dbpath, 0); IObjectContainer client = server.OpenClient(); db = client; } try { // Store a few Person objects db.Store(new Person("Petra")); db.Store(new Person("Gallad")); // Retrieve the Person Person p; { Console.WriteLine("001"); var results = db.Query <Person>(x => x.Name == "Petra"); p = results.First(); Console.WriteLine(p.Name); } { Console.WriteLine("002"); var result2 = from Person tp in db where tp.Name == "Petra" select tp; p = result2.First(); Console.WriteLine(p.Name); } { Console.WriteLine("003"); var result2 = from Person tp in db where tp.Name.StartsWith("Petr") select tp; p = result2.First(); Console.WriteLine(p.Name); } { Console.WriteLine("004"); var result2 = from Person tp in db where tp.Age == 9 && tp.Name == "Petra" select tp; p = result2.First(); Console.WriteLine(p.Name); } { Console.WriteLine("005"); var uid = db.Ext().GetObjectInfo(p).GetInternalID(); p = (Person)db.Ext().GetByID(uid); Console.WriteLine(p.Name); } { Console.WriteLine("006"); var result2 = from Person tp in db where tp.PName() == "Petra-ABC" select tp; p = result2.First(); Console.WriteLine(p.Name); } p.Name = "Peter"; db.Store(p); // Delete the person db.Delete(p); // Don't forget to commit! db.Commit(); Console.WriteLine("Commited " + db.Query <Person>().Count(x => x.Age >= 0)); } catch (Exception ex) { db.Rollback(); Console.WriteLine(ex.ToString()); throw ex; } finally { // Close the db cleanly db.Close(); //Environment.Exit(0);, just Exit() will faster server?.Close(); } Console.WriteLine("End."); }
protected virtual IObjectContainer OpenClient(IConfiguration config, string host, int port, string user, string password) { return(Db4oClientServer.OpenClient(Db4oClientServerLegacyConfigurationBridge.AsClientConfiguration (config), host, port, user, password)); }
public static void Run() { String file = "tree.n.db"; File.Delete(file); var cfg = Db4oClientServer.NewServerConfiguration(); cfg.Common.ObjectClass(typeof(Node)).CallConstructor(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnActivate(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnUpdate(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnDelete(true); using (var server = Db4oClientServer.OpenServer(cfg, file, 0)) { using (var client = server.OpenClient()) { Node root = new Node(); root.Name = "Root"; root.Left = new Node(); root.Left.Name = "Left"; root.Right = new Node(); root.Right.Name = "Right"; root.Right.Right = new Node(); root.Right.Right.Name = "Right.Right"; client.Store(root); client.Commit(); } using (var client = server.OpenClient()) { var root = (from Node n in client where n.Name == "Root" select n).First(); Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var root = client.Query((Node n) => { return(n.Name == "Root"); }).First(); Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var root = client.QueryByExample(new Node { Name = "Root" })[0] as Node; Console.WriteLine(root.Right.Right.Name); } //Not Recommended using (var client = server.OpenClient()) { var q = client.Query(); q.Constrain(typeof(Node)); q.Descend("Name").Constrain("Root").Equal(); var root = q.Execute()[0] as Node; Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var rr = (from Node n in client where n.Name == "Right.Right" select n).First(); Console.WriteLine(rr.Name); rr.Name += ".Update"; client.Store(rr); client.Commit(); } using (var client = server.OpenClient()) { var root = (from Node n in client where n.Name == "Root" select n).First(); Console.WriteLine(root.Right.Right.Name); } } }
protected virtual IObjectContainer OpenClient(string host, int port, string user, string password) { return(Db4oClientServer.OpenClient(host, port, user, password)); }
private IObjectContainer OpenClient() { return(Db4oClientServer.OpenClient("localhost", Port, "db4o", "db4o")); }
/// <exception cref="System.Exception"></exception> public virtual void SetUp() { _applied = new ArrayList(); _config = (ServerConfigurationImpl)Db4oClientServer.NewServerConfiguration(); }
public override IFixtureProvider[] FixtureProviders() { return(new IFixtureProvider[] { Subjects(new object[] { Db4oEmbedded.NewConfiguration (), Db4oClientServer.NewClientConfiguration(), Db4oClientServer.NewServerConfiguration () }) }); }
public Connection(string host, int port, string user, string password) { Database = Db4oClientServer.OpenClient(host, port, user, password); }
private static void ConcurrencyLimitations() { DeleteDatabases(); // #example: Lost replication IObjectServer serverDatabase = OpenDatabaseServer(DesktopDatabaseName); IObjectContainer mobileDatabase = OpenDatabase(MobileDatabaseName); { IObjectContainer serverDbConnection = Db4oClientServer.OpenClient(Host, Port, UserName, UserName); serverDbConnection.Store(new Pilot("Pilot 1")); serverDbConnection.Commit(); // The replication starts here IObjectContainer connectionForReplication = Db4oClientServer.OpenClient(Host, Port, UserName, UserName); IReplicationProvider clientReplication = new Db4oEmbeddedReplicationProvider(connectionForReplication); IReplicationProvider mobileRelicationPartner = new Db4oEmbeddedReplicationProvider(mobileDatabase); IReplicationSession replicationSession = Replication.Begin(clientReplication, mobileRelicationPartner); IObjectSet changesOnDesktop = replicationSession.ProviderA().ObjectsChangedSinceLastReplication(); // during the replication other clients store data on the server serverDbConnection.Store(new Pilot("Pilot 2")); serverDbConnection.Commit(); foreach (object changedObjectOnDesktop in changesOnDesktop) { replicationSession.Replicate(changedObjectOnDesktop); } replicationSession.Commit(); serverDbConnection.Store(new Pilot("Pilot 3")); serverDbConnection.Commit(); } // Pilot 2 is not replicated PrintPilots(mobileDatabase); { IObjectContainer connectionForReplication = Db4oClientServer.OpenClient(Host, Port, UserName, UserName); IReplicationProvider clientRelicationPartner = new Db4oEmbeddedReplicationProvider(connectionForReplication); IReplicationProvider mobileRelicationPartner = new Db4oEmbeddedReplicationProvider(mobileDatabase); IReplicationSession replicationSession = Replication.Begin(clientRelicationPartner, mobileRelicationPartner); IObjectSet changesOnDesktop = replicationSession.ProviderA().ObjectsChangedSinceLastReplication(); foreach (object changedOnDesktop in changesOnDesktop) { replicationSession.Replicate(changedOnDesktop); } replicationSession.Commit(); } // Pilot 2 is still not replicated PrintPilots(mobileDatabase); // #end example serverDatabase.Close(); mobileDatabase.Close(); }
/// <exception cref="System.Exception"></exception> public void Run() { Db4oClientServer.OpenServer(DatabaseFile, port); }
/// <exception cref="System.Exception"></exception> public void Run() { Db4oClientServer.OpenServer(ServerPortUsedTestCase.DatabaseFile, port); }
/// <exception cref="System.Exception"></exception> public override void SetUp() { fileName = TempFile(); server = Db4oClientServer.OpenServer(fileName, -1).Ext(); server.GrantAccess(Credentials(), Credentials()); }
private IObjectContainer OpenClient(string user, string password) { return(Db4oClientServer.OpenClient(Db4oClientServerLegacyConfigurationBridge.AsClientConfiguration (Config()), ServerHostname, ClientServerFixture().ServerPort(), user, password)); }
private IObjectContainer OpenClient() { return(Db4oClientServer.OpenClient("localhost", Port(), Credentials(), Credentials ())); }
private static IObjectContainer OpenClient() { return(Db4oClientServer.OpenClient("localhost", PortNumber, UsertNameAndPassword, UsertNameAndPassword)); }
public virtual IObjectContainer OpenClient() { return(Db4oClientServer.OpenClient(Host, _server.Ext().Port(), User, Pass)); }
private static IObjectServer OpenServer() { IServerConfiguration configuration = Db4oClientServer.NewServerConfiguration(); return(Db4oClientServer.OpenServer(configuration, DatabaseFileName, PortNumber)); }
protected virtual IObjectServer OpenServer(IConfiguration config) { return(Db4oClientServer.OpenServer(Db4oClientServerLegacyConfigurationBridge.AsServerConfiguration (config), "nofile", unchecked ((int)(0xdb40)))); }
protected virtual IObjectServer OpenServer(IConfiguration config, string databaseFileName , int port) { return(Db4oClientServer.OpenServer(Db4oClientServerLegacyConfigurationBridge.AsServerConfiguration (config), databaseFileName, port)); }
public IObjectContainer Connect() { wasCalled++; return(Db4oClientServer.OpenClient("localhost", Port, UserAndPassword, UserAndPassword)); }
public static void Run() { String file = "tree.n.db"; File.Delete(file); long internalId; String objectId; var cfg = Db4oClientServer.NewServerConfiguration(); cfg.Common.ObjectClass(typeof(Node)).CallConstructor(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnActivate(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnUpdate(true); cfg.Common.ObjectClass(typeof(Node)).CascadeOnDelete(true); cfg.Common.Add(new TransparentActivationSupport()); cfg.Common.Add(new TransparentPersistenceSupport()); cfg.File.GenerateUUIDs = ConfigScope.Globally; using (var server = Db4oClientServer.OpenServer(cfg, file, 0)) { using (var client = server.OpenClient()) { var root = new Node(); root.Name = "Root"; root.Left = new Node(); root.Left.Name = "Left"; root.Right = new Node(); root.Right.Name = "Right"; root.Right.Right = new Node(); root.Right.Right.Name = "Right.Right"; client.Store(root); client.Commit(); } using (var oc = server.OpenClient()) { var metaInfo = oc.Ext().StoredClass(typeof(Node)); // list a fields and check if they have a index foreach (var field in metaInfo.GetStoredFields()) { if (field.HasIndex()) { Console.WriteLine("The field '" + field.GetName() + "' is indexed"); } else { Console.WriteLine("The field '" + field.GetName() + "' isn't indexed"); } } } using (var client = server.OpenClient()) { var root = client.QueryByExample(new Node { Name = "Root" })[0]; Console.WriteLine(root.Right.Right.Name); internalId = client.Ext().GetID(root); objectId = client.Ext().GetObjectInfo(root).GetUUID().ToString(); } using (var client = server.OpenClient()) { Console.WriteLine(objectId); var root = client.Ext().GetByUUID <Node>(objectId); Console.WriteLine(root.Right.Right.Name); } using (var oc = server.OpenClient()) { Console.WriteLine(internalId); var root = oc.Ext().GetByID <Node>(internalId); Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var root = (from Node n in client where n.Name == "Root" select n).First(); Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var root = client.Query((Node n) => { return(n.Name == "Root"); }).First(); Console.WriteLine(root.Right.Right.Name); } //Not Recommended using (var client = server.OpenClient()) { var q = client.Query(); q.Constrain(typeof(Node)); q.Descend("Name").Constrain("Root").Equal(); var root = q.Execute()[0] as Node; Console.WriteLine(root.Right.Right.Name); } using (var client = server.OpenClient()) { var rr = (from Node n in client where n.Name == "Right.Right" select n).First(); Console.WriteLine(rr.Name); rr.Name += ".Update"; client.Store(rr); client.Commit(); } using (var client = server.OpenClient()) { var root = (from Node n in client where n.Name == "Root" select n).First(); Console.WriteLine(root.Right.Right.Name); } } var ecfg = Db4oEmbedded.NewConfiguration(); ecfg.Common.ObjectClass(typeof(Node)).CallConstructor(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnActivate(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnUpdate(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnDelete(true); ecfg.Common.Add(new TransparentActivationSupport()); ecfg.Common.Add(new TransparentPersistenceSupport()); ecfg.File.GenerateUUIDs = ConfigScope.Globally; using (var oc = Db4oEmbedded.OpenFile(ecfg, file)) { Console.WriteLine(objectId); var root = oc.Ext().GetByUUID <Node>(objectId); Console.WriteLine(root.Right.Right.Name); Console.WriteLine(internalId); root = oc.Ext().GetByID <Node>(internalId); Console.WriteLine(root.Right.Right.Name); } ecfg = Db4oEmbedded.NewConfiguration(); ecfg.Common.ObjectClass(typeof(Node)).CallConstructor(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnActivate(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnUpdate(true); ecfg.Common.ObjectClass(typeof(Node)).CascadeOnDelete(true); ecfg.Common.Add(new TransparentActivationSupport()); ecfg.Common.Add(new TransparentPersistenceSupport()); ecfg.File.GenerateUUIDs = ConfigScope.Globally; using (var oc = Db4oEmbedded.OpenFile(ecfg, file)) { using (var see = oc.Ext().OpenSession()) { Console.WriteLine(objectId); var root = see.Ext().GetByUUID <Node>(objectId); Console.WriteLine(root.Right.Right.Name); } using (var see = oc.Ext().OpenSession()) { Console.WriteLine(internalId); var root = see.Ext().GetByID <Node>(internalId); Console.WriteLine(root.Right.Right.Name); } } }