ExtClient is an extended interface, which can be used to access database from the client side. ExtClient object can be simply cast from the ObjectContainer, returned by openClient method:
c#: IExtClient clientExt = (IExtClient) server.OpenClient()
VB: Dim clientExt IExtClient = CType(server.OpenClient(),IExtClient)
Please, note that this cast is only possible in embedded server mode.
ExtClient is extending ExtObjectContainer interface. In addition ExtClient provides 3 client-specific methods:
In some special cases you may want to store different objects to different files.
This approach has the following advantages:
To make database switch handling easier you should consider using the ExtClient#switchToFile(fileName) and ExtClient#switchToMainFile() methods. This allows you to use single connection to the server for all database files, thus avoiding overhead of opening and managing new connections (a server starts a new thread for each connection). All you have to do is just point out which database file to use.
01public static void SwitchExtClients() 02
{ 03
File.Delete(Db4oFileName); 04
File.Delete(ExtFileName); 05
IObjectServer server=Db4oFactory.OpenServer(Db4oFileName,0); 06
try 07
{ 08
IObjectContainer client=server.OpenClient(); 09
Car car = new Car("BMW"); 10
client.Set(car); 11
System.Console.WriteLine("Objects in the Main database file:"); 12
RetrieveAll(client); 13
14
System.Console.WriteLine("Switching to additional database:"); 15
IExtClient clientExt = (IExtClient)client; 16
clientExt.SwitchToFile(ExtFileName); 17
car = new Car("Ferrari"); 18
clientExt.Set(car); 19
RetrieveAll(clientExt); 20
System.Console.WriteLine("Main database file again: "); 21
clientExt.SwitchToMainFile(); 22
RetrieveAll(clientExt); 23
clientExt.Close(); 24
} 25
finally 26
{ 27
server.Close(); 28
} 29
}
01Private Shared Sub SwitchExtClients() 02
File.Delete(Db4oFileName) 03
File.Delete(ExtFileName) 04
Dim server As IObjectServer = Db4oFactory.OpenServer(Db4oFileName, 0) 05
Try 06
Dim client As IObjectContainer = server.OpenClient() 07
Dim car As Car = New Car("BMW") 08
client.Set(car) 09
System.Console.WriteLine("Objects in the Main database file:") 10
RetrieveAll(client) 11
12
System.Console.WriteLine("Switching to additional database:") 13
Dim clientExt As IExtClient = CType(client, IExtClient) 14
clientExt.SwitchToFile(ExtFileName) 15
car = New Car("Ferrari") 16
clientExt.Set(car) 17
RetrieveAll(clientExt) 18
System.Console.WriteLine("Main database file again: ") 19
clientExt.SwitchToMainFile() 20
RetrieveAll(clientExt) 21
clientExt.Close() 22
Finally 23
server.Close() 24
End Try 25
End Sub
The following can be an example usecase of multiple database usage.
The main database file is used for login, user and rights management only. Multiple satellite database files are used for different applications or multiple user circles. User authorization to the satellite databases is not checked.
Only one single db4o server session needs to be run.