One of the most valuable aliases usecases is working with persistent Java classes from a .NET application and vice versa. You can use both TypeAlias and WildcardAlias depending on how many classes you need to access.
For example, Pilot objects are saved to a database from a Java application:
01public static void saveObjects(){ 02
new File(YAPFILENAME ).delete(); 03
ObjectContainer db = Db4o.openFile(YAPFILENAME); 04
try { 05
Pilot pilot = new Pilot("David Barrichello",99); 06
db.set(pilot); 07
pilot = new Pilot("Michael Schumacher",100); 08
db.set(pilot); 09
} finally { 10
db.close(); 11
} 12
}
In order to read the saved objects successfully from a .NET application we will need to define an alias, containing namespace and assembly information:
1public static void ConfigureAlias() 2
{ 3
Db4oFactory.Configure().AddAlias(new WildcardAlias("com.db4odoc.aliases.*", "Db4objects.Db4odoc.Aliases.*, Db4objects.Db4odoc")); 4
}
1Public Shared Sub ConfigureAlias() 2
Db4oFactory.Configure.AddAlias(New WildcardAlias("com.db4odoc.aliases.*", "Db4objects.Db4odoc.Aliases.*, Db4objects.Db4odoc")) 3
End Sub
01public static void GetObjects() 02
{ 03
IObjectContainer db = Db4oFactory.OpenFile(YapFileName); 04
try 05
{ 06
IObjectSet result = db.Query(typeof(Pilot)); 07
ListResult(result); 08
} 09
finally 10
{ 11
db.Close(); 12
} 13
}
1Public Shared Sub GetObjects() 2
Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 3
Try 4
Dim result As IObjectSet = db.Query(GetType(Pilot)) 5
ListResult(result) 6
Finally 7
db.Close() 8
End Try 9
End Sub
One thing to remember: field names in class definitions in Java and .NET should be exactly the same.