add db4o examples

This commit is contained in:
Andreas Zweili 2018-03-02 18:59:49 +01:00
parent 57f92f8dcf
commit aa54233be3
29 changed files with 1254 additions and 0 deletions

View File

@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Db4oBasics", "Db4oBasics\Db4oBasics.csproj", "{E6A5FE58-72BC-4726-966A-EE4137285D23}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Db4oQueries", "Db4oQueries\Db4oQueries.csproj", "{BB183256-DC01-4E78-923D-7AC734A918B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Db4oRelations", "Db4oRelations\Db4oRelations.csproj", "{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E6A5FE58-72BC-4726-966A-EE4137285D23}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6A5FE58-72BC-4726-966A-EE4137285D23}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6A5FE58-72BC-4726-966A-EE4137285D23}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6A5FE58-72BC-4726-966A-EE4137285D23}.Release|Any CPU.Build.0 = Release|Any CPU
{BB183256-DC01-4E78-923D-7AC734A918B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB183256-DC01-4E78-923D-7AC734A918B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB183256-DC01-4E78-923D-7AC734A918B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB183256-DC01-4E78-923D-7AC734A918B8}.Release|Any CPU.Build.0 = Release|Any CPU
{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {43FDC210-790B-45CB-95F1-8A84402B560A}
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{9C32CFB8-8EB4-46A5-A15E-28ECD684754E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>AngestellterDb4o</RootNamespace>
<AssemblyName>AngestellterDb4o</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AngestellterDb4o
{
class Program
{
static void Main(string[] args)
{
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("AngestellterDb4o")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AngestellterDb4o")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9c32cfb8-8eb4-46a5-a15e-28ecd684754e")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Db4oBasics
{
public class Angestellter
{
private int _persNr;
private string _name;
private int _salaer;
public Angestellter(int persNr, string name, int salaer)
{
PersNr = persNr;
Name = name;
Salaer = salaer;
}
public int PersNr { get => _persNr; set => _persNr = value; }
public string Name { get => _name; set => _name = value; }
public int Salaer { get => _salaer; set => _salaer = value; }
public override string ToString()
{
return _persNr + "/" + _name + "/" + _salaer;
}
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E6A5FE58-72BC-4726-966A-EE4137285D23}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Db4oBasics</RootNamespace>
<AssemblyName>Db4oBasics</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Db4objects.Db4o">
<HintPath>..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Angestellter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,70 @@
using Db4objects.Db4o;
using Db4objects.Db4o.Config;
using System;
using System.IO;
namespace Db4oBasics
{
class Program
{
/// <summary>
/// Datenbankdatei
/// </summary>
private static string DB4OFILENAME = "database.db4o";
static void Main(string[] args)
{
// Datenbankdatei löschen
if (File.Exists(DB4OFILENAME))
File.Delete(DB4OFILENAME);
IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
IObjectContainer db = Db4oEmbedded.OpenFile(config, DB4OFILENAME);
try
{
Angestellter ang1 = new Angestellter(1, "Ruedi Loosli", 4200);
db.Store(ang1);
Angestellter ang2 = new Angestellter(2, "Fritz Münger", 4500);
db.Store(ang2);
// Anzeige, Ruedi u. Fritz
ListAngestellte(db);
// Suche Fritz
IObjectSet result = db.QueryByExample(new Angestellter(2, null, 0));
Angestellter found = (Angestellter) result.Next();
found.Salaer = 5100;
db.Store(found);
// Anzeige, Fritz mit neuem Gehalt
ListAngestellte(db);
// Suche Ruedi
result = db.QueryByExample(new Angestellter(1, null, 0));
found = (Angestellter) result.Next();
db.Delete(found);
// Anzeige, Fritz, Ruedi wurde gelöscht
ListAngestellte(db);
}
finally
{
db.Close();
}
/// <summary>
/// Alle Angestellte auf die Konsole ausgeben
/// </summary>
/// <param name="db">Datenbank</param>
private static void ListAngestellte(IObjectContainer db)
{
IObjectSet result = db.Query(typeof(Angestellter));
Console.WriteLine($"----- {result.Count} -----");
foreach (object item in result)
{
Console.WriteLine(item);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Db4oBasics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Db4oBasics")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e6a5fe58-72bc-4726-966a-ee4137285d23")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Db4oQueries
{
public class Adresse
{
private string _strasse;
private string _wohnort;
private int _plz;
public Adresse(string strasse, string wohnort, int plz)
{
Strasse = strasse;
Wohnort = wohnort;
Plz = plz;
}
public string Strasse { get => _strasse; set => _strasse = value; }
public string Wohnort { get => _wohnort; set => _wohnort = value; }
public int Plz { get => _plz; set => _plz = value; }
public override string ToString()
{
return Strasse + "/" + Plz + " " + Wohnort;
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Db4oQueries
{
public class Angestellter
{
private int _persNr;
private string _name;
private int _salaer;
private Adresse _adresse;
public Angestellter(int persNr, string name, int salaer)
{
PersNr = persNr;
Name = name;
Salaer = salaer;
}
public int PersNr { get => _persNr; set => _persNr = value; }
public string Name { get => _name; set => _name = value; }
public int Salaer { get => _salaer; set => _salaer = value; }
public Adresse Adresse { get => _adresse; set => _adresse = value; }
public override string ToString()
{
return _persNr + "/" + _name + "/" + _salaer;
}
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BB183256-DC01-4E78-923D-7AC734A918B8}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Db4oQueries</RootNamespace>
<AssemblyName>Db4oQueries</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Db4objects.Db4o">
<HintPath>..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Adresse.cs" />
<Compile Include="Angestellter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,150 @@
using Db4objects.Db4o;
using Db4objects.Db4o.Config;
using Db4objects.Db4o.Query;
using System;
using System.Collections.Generic;
using System.IO;
namespace Db4oQueries
{
class Program
{
/// <summary>
/// Datenbankdatei
/// </summary>
private static string DB4OFILENAME = "database.db4o";
static void Main(string[] args)
{
// Datenbankdatei löschen
if (File.Exists(DB4OFILENAME))
File.Delete(DB4OFILENAME);
IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
IObjectContainer db = Db4oEmbedded.OpenFile(config, DB4OFILENAME);
try
{
Angestellter ang1 = new Angestellter(1, "Ruedi Loosli", 4200);
db.Store(ang1);
Angestellter ang2 = new Angestellter(2, "Fritz Münger", 4500);
db.Store(ang2);
Angestellter ang3 = new Angestellter(3, "Meinrad Hardegger", 3900);
db.Store(ang3);
ang1.Adresse = new Adresse("Brüederstrasse 12", "Roggwil", 1234);
db.Store(ang1);
ang2.Adresse = new Adresse("Hartmatt 3", "Lochbüehl", 1516);
db.Store(ang2);
ang3.Adresse = new Adresse("Postweg 31", "Rupolding", 1235);
db.Store(ang3);
queryByExample(db);
nativeQueries(db);
sodaQueries(db);
}
finally
{
db.Close();
}
}
/// <summary>
/// Query by example
/// </summary>
/// <param name="db"></param>
private static void queryByExample(IObjectContainer db)
{
listAngestellte(db.QueryByExample(new Angestellter(1, null, 0)));
listAngestellte(db.QueryByExample(new Angestellter(0, "Ruedi Loosli", 0)));
listAngestellte(db.QueryByExample(new Angestellter(0, null, 4200)));
}
/// <summary>
/// Native queries
/// </summary>
/// <param name="db"></param>
private static void nativeQueries(IObjectContainer db)
{
IList<Angestellter> angestellte = db.Query<Angestellter>(delegate (Angestellter angestellter)
{
{
return angestellter.Salaer > 4000;
}
});
listAngestellte(angestellte);
angestellte = db.Query<Angestellter>(delegate (Angestellter angestellter)
{
{
return angestellter.Name.StartsWith("Ruedi");
}
});
listAngestellte(angestellte);
angestellte = db.Query<Angestellter>(delegate (Angestellter angestellter)
{
{
return angestellter.Salaer > 4000
&& angestellter.Adresse.Strasse.Contains("1");
}
});
listAngestellte(angestellte);
}
/// <summary>
/// SODA Simple Object Database Access queries
/// </summary>
/// <param name="db"></param>
private static void sodaQueries(IObjectContainer db)
{
IQuery query = db.Query();
query.Constrain(typeof(Angestellter));
listAngestellte(query.Execute());
query = db.Query();
query.Constrain(typeof(Angestellter));
query.Descend("Name").Constrain("Ruedi Loosli");
listAngestellte(query.Execute());
query = db.Query();
query.Constrain(typeof(Angestellter));
query.Descend("Salaer").Constrain(4000).Greater();
listAngestellte(query.Execute());
query = db.Query();
query.Constrain(typeof(Angestellter));
query.Descend("Salaer").Constrain(4000).Greater();
query.Descend("Adresse").Descend("Strasse").Constrain("1").Contains();
listAngestellte(query.Execute());
}
/// <summary>
/// Alle Angestellte auf die Konsole ausgeben
/// </summary>
/// <param name="db">Datenbank</param>
private static void listAngestellte(IObjectSet result)
{
Console.WriteLine($"----- {result.Count} -----");
foreach (object item in result)
{
Console.WriteLine(item);
}
}
/// <summary>
/// Alle Angestellte auf die Konsole ausgeben
/// </summary>
/// <param name="db">Datenbank</param>
private static void listAngestellte(IList<Angestellter> result)
{
Console.WriteLine($"----- {result.Count} -----");
foreach (object item in result)
{
Console.WriteLine(item);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Db4oQueries")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Db4oQueries")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bb183256-dc01-4e78-923d-7ac734a918b8")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Db4oRelations
{
public class Adresse
{
private string _strasse;
private string _wohnort;
private int _plz;
public Adresse(string strasse, string wohnort, int plz)
{
Strasse = strasse;
Wohnort = wohnort;
Plz = plz;
}
public string Strasse { get => _strasse; set => _strasse = value; }
public string Wohnort { get => _wohnort; set => _wohnort = value; }
public int Plz { get => _plz; set => _plz = value; }
public override string ToString()
{
return Strasse + "/" + Plz + " " + Wohnort;
}
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Db4oRelations
{
public class Angestellter
{
private int _persNr;
private string _name;
private int _salaer;
private Adresse _adresse;
public Angestellter(int persNr, string name, int salaer)
{
PersNr = persNr;
Name = name;
Salaer = salaer;
}
public int PersNr { get => _persNr; set => _persNr = value; }
public string Name { get => _name; set => _name = value; }
public int Salaer { get => _salaer; set => _salaer = value; }
public Adresse Adresse { get => _adresse; set => _adresse = value; }
public override string ToString()
{
return _persNr + "/" + _name + "/" + _salaer;
}
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View File

@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Db4oRelations</RootNamespace>
<AssemblyName>Db4oRelations</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Db4objects.Db4o">
<HintPath>..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Adresse.cs" />
<Compile Include="Angestellter.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -0,0 +1,84 @@
using Db4objects.Db4o;
using Db4objects.Db4o.Config;
using System;
using System.IO;
namespace Db4oRelations
{
class Program
{
/// <summary>
/// Datenbankdatei
/// </summary>
private static string DB4OFILENAME = "database.db4o";
static void Main(string[] args)
{
// Datenbankdatei löschen
if (File.Exists(DB4OFILENAME))
File.Delete(DB4OFILENAME);
IEmbeddedConfiguration config = Db4oEmbedded.NewConfiguration();
IObjectContainer db = Db4oEmbedded.OpenFile(config, DB4OFILENAME);
try
{
Angestellter ang1 = new Angestellter(1, "Ruedi Loosli", 4200);
db.Store(ang1);
Angestellter ang2 = new Angestellter(2, "Fritz Münger", 4500);
db.Store(ang2);
Angestellter ang3 = new Angestellter(3, "Meinrad Hardegger", 3900);
db.Store(ang3);
ang1.Adresse = new Adresse("Brüederstrasse 12", "Roggwil", 1234);
db.Store(ang1);
ang2.Adresse = new Adresse("Hartmatt 3", "Lochbüehl", 1516);
db.Store(ang2);
ang3.Adresse = new Adresse("Postweg 31", "Rupolding", 1235);
db.Store(ang3);
// funktioniert
Adresse adr2 = ang2.Adresse;
adr2.Strasse = "Horstgasse 45";
db.Store(adr2);
// funktioniert nur mit cascade
ang1.Adresse.Strasse = "Horstgasse 44";
db.Store(ang1);
// Ausgabe mit neuem Container
db.Close();
//
// Delete
//
config = Db4oEmbedded.NewConfiguration();
config.Common.ObjectClass(typeof(Angestellter)).CascadeOnDelete(true);
db = Db4oEmbedded.OpenFile(config, DB4OFILENAME);
listResult(db.Query(typeof(Angestellter)));
listResult(db.Query(typeof(Adresse)));
IObjectSet result = db.QueryByExample(new Angestellter(1, null, 0));
ang1 = (Angestellter) result.Next();
db.Delete(ang1);
listResult(db.Query(typeof(Angestellter)));
}
finally
{
db.Close();
}
}
private static void listResult(IObjectSet result)
{
Console.WriteLine($"----- {result.Count} -----");
foreach (object item in result)
{
Console.WriteLine(item);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Db4oRelations")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Db4oRelations")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5dd9b2ad-b41d-4f58-afc8-6dff402b1e66")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

18
db/5_sem/F1/F1-Diagram.cd Normal file
View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" MembersFormat="FullSignature">
<Class Name="F1.Pilot">
<Position X="5" Y="0.5" Width="3" />
<TypeIdentifier>
<HashCode>AAAAIAAAAAAQgAAEgAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Pilot.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="F1.Program">
<Position X="0.5" Y="0.5" Width="4" />
<TypeIdentifier>
<HashCode>IAAIAABBAAAAAAAAAAAAAAAAAQAAAAAAAQICJEAAECA=</HashCode>
<FileName>Program.cs</FileName>
</TypeIdentifier>
</Class>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>

99
db/5_sem/F1/F1.csproj Normal file
View File

@ -0,0 +1,99 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>F1</RootNamespace>
<AssemblyName>F1</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<OldToolsVersion>3.5</OldToolsVersion>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Db4objects.Db4o">
<HintPath>..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Pilot.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="F1-Diagram.cd">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

25
db/5_sem/F1/F1.sln Normal file
View File

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "F1", "F1.csproj", "{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8A3803A4-49AD-4C69-AB7E-F52141FA5CF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {421144DD-3BAB-4CE0-B6D9-FDBFEE24ED99}
EndGlobalSection
EndGlobal

45
db/5_sem/F1/Pilot.cs Normal file
View File

@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace F1
{
public class Pilot
{
string _name;
int _points;
public Pilot(string name, int points)
{
_name = name;
_points = points;
}
public string Name
{
get
{
return _name;
}
}
public int Points
{
get
{
return _points;
}
}
public void AddPoints(int points)
{
_points += points;
}
override public string ToString()
{
return string.Format("{0}/{1}", _name, _points);
}
}
}

120
db/5_sem/F1/Program.cs Normal file
View File

@ -0,0 +1,120 @@
using Db4objects.Db4o;
using System;
using System.IO;
namespace F1
{
class Program
{
readonly static string YapFileName = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"formula1.yap");
static void Main(string[] args)
{
File.Delete(YapFileName);
AccessDb4o();
File.Delete(YapFileName);
IObjectContainer db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), YapFileName);
try
{
StoreFirstPilot(db);
StoreSecondPilot(db);
RetrieveAllPilots(db);
RetrievePilotByName(db);
RetrievePilotByExactPoints(db);
UpdatePilot(db);
DeleteFirstPilotByName(db);
DeleteSecondPilotByName(db);
}
finally
{
db.Close();
}
Console.ReadLine();
}
public static void AccessDb4o()
{
IObjectContainer db = Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), YapFileName);
try
{
// do something with db4o
}
finally
{
db.Close();
}
}
public static void StoreFirstPilot(IObjectContainer db)
{
Pilot pilot1 = new Pilot("Michael Schumacher", 100);
db.Store(pilot1);
Console.WriteLine("Stored {0}", pilot1);
}
public static void StoreSecondPilot(IObjectContainer db)
{
Pilot pilot2 = new Pilot("Rubens Barrichello", 99);
db.Store(pilot2);
Console.WriteLine("Stored {0}", pilot2);
}
public static void RetrieveAllPilotQBE(IObjectContainer db)
{
Pilot proto = new Pilot(null, 0);
IObjectSet result = db.QueryByExample(proto);
ListResult(result);
}
public static void RetrieveAllPilots(IObjectContainer db)
{
IObjectSet result = db.QueryByExample(typeof(Pilot));
ListResult(result);
}
public static void RetrievePilotByName(IObjectContainer db)
{
Pilot proto = new Pilot("Michael Schumacher", 0);
IObjectSet result = db.QueryByExample(proto);
ListResult(result);
}
public static void RetrievePilotByExactPoints(IObjectContainer db)
{
Pilot proto = new Pilot(null, 100);
IObjectSet result = db.QueryByExample(proto);
ListResult(result);
}
public static void UpdatePilot(IObjectContainer db)
{
IObjectSet result = db.QueryByExample(new Pilot("Michael Schumacher", 0));
Pilot found = (Pilot)result.Next();
found.AddPoints(11);
db.Store(found);
Console.WriteLine("Added 11 points for {0}", found);
RetrieveAllPilots(db);
}
public static void DeleteFirstPilotByName(IObjectContainer db)
{
IObjectSet result = db.QueryByExample(new Pilot("Michael Schumacher", 0));
Pilot found = (Pilot)result.Next();
db.Delete(found);
Console.WriteLine("Deleted {0}", found);
RetrieveAllPilots(db);
}
public static void DeleteSecondPilotByName(IObjectContainer db)
{
IObjectSet result = db.QueryByExample(new Pilot("Rubens Barrichello", 0));
Pilot found = (Pilot)result.Next();
db.Delete(found);
Console.WriteLine("Deleted {0}", found);
RetrieveAllPilots(db);
}
public static void ListResult(IObjectSet result)
{
Console.WriteLine(result.Count);
foreach (object item in result)
{
Console.WriteLine(item);
}
}
}
}

View File

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("F1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("KETA Engineering GmbH")]
[assembly: AssemblyProduct("F1")]
[assembly: AssemblyCopyright("Copyright © KETA Engineering GmbH 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5974ac38-15e4-4fd5-8271-be2434d6d238")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

3
db/5_sem/F1/app.config Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration>