diff --git a/db/5_sem/AngestellterDb4o/AngestellterDb4o.sln b/db/5_sem/AngestellterDb4o/AngestellterDb4o.sln new file mode 100644 index 0000000..c757c4e --- /dev/null +++ b/db/5_sem/AngestellterDb4o/AngestellterDb4o.sln @@ -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 diff --git a/db/5_sem/AngestellterDb4o/AngestellterDb4o/AngestellterDb4o.csproj b/db/5_sem/AngestellterDb4o/AngestellterDb4o/AngestellterDb4o.csproj new file mode 100644 index 0000000..0ca1901 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/AngestellterDb4o/AngestellterDb4o.csproj @@ -0,0 +1,52 @@ + + + + + Debug + AnyCPU + {9C32CFB8-8EB4-46A5-A15E-28ECD684754E} + Exe + AngestellterDb4o + AngestellterDb4o + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/AngestellterDb4o/App.config b/db/5_sem/AngestellterDb4o/AngestellterDb4o/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/db/5_sem/AngestellterDb4o/AngestellterDb4o/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/AngestellterDb4o/Program.cs b/db/5_sem/AngestellterDb4o/AngestellterDb4o/Program.cs new file mode 100644 index 0000000..8349812 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/AngestellterDb4o/Program.cs @@ -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) + { + } + } +} diff --git a/db/5_sem/AngestellterDb4o/AngestellterDb4o/Properties/AssemblyInfo.cs b/db/5_sem/AngestellterDb4o/AngestellterDb4o/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..9e67bc7 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/AngestellterDb4o/Properties/AssemblyInfo.cs @@ -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")] diff --git a/db/5_sem/AngestellterDb4o/Db4oBasics/Angestellter.cs b/db/5_sem/AngestellterDb4o/Db4oBasics/Angestellter.cs new file mode 100644 index 0000000..6c927b3 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oBasics/Angestellter.cs @@ -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; + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oBasics/App.config b/db/5_sem/AngestellterDb4o/Db4oBasics/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oBasics/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oBasics/Db4oBasics.csproj b/db/5_sem/AngestellterDb4o/Db4oBasics/Db4oBasics.csproj new file mode 100644 index 0000000..105c0c2 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oBasics/Db4oBasics.csproj @@ -0,0 +1,56 @@ + + + + + Debug + AnyCPU + {E6A5FE58-72BC-4726-966A-EE4137285D23} + Exe + Db4oBasics + Db4oBasics + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oBasics/Program.cs b/db/5_sem/AngestellterDb4o/Db4oBasics/Program.cs new file mode 100644 index 0000000..1ca119a --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oBasics/Program.cs @@ -0,0 +1,70 @@ +using Db4objects.Db4o; +using Db4objects.Db4o.Config; +using System; +using System.IO; + +namespace Db4oBasics +{ + class Program + { + /// + /// Datenbankdatei + /// + 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(); + } + + /// + /// Alle Angestellte auf die Konsole ausgeben + /// + /// Datenbank + private static void ListAngestellte(IObjectContainer db) + { + IObjectSet result = db.Query(typeof(Angestellter)); + Console.WriteLine($"----- {result.Count} -----"); + foreach (object item in result) + { + Console.WriteLine(item); + } + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oBasics/Properties/AssemblyInfo.cs b/db/5_sem/AngestellterDb4o/Db4oBasics/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b81a464 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oBasics/Properties/AssemblyInfo.cs @@ -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")] diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/Adresse.cs b/db/5_sem/AngestellterDb4o/Db4oQueries/Adresse.cs new file mode 100644 index 0000000..c405dea --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/Adresse.cs @@ -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; + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/Angestellter.cs b/db/5_sem/AngestellterDb4o/Db4oQueries/Angestellter.cs new file mode 100644 index 0000000..f83067a --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/Angestellter.cs @@ -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; + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/App.config b/db/5_sem/AngestellterDb4o/Db4oQueries/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/Db4oQueries.csproj b/db/5_sem/AngestellterDb4o/Db4oQueries/Db4oQueries.csproj new file mode 100644 index 0000000..2e414e3 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/Db4oQueries.csproj @@ -0,0 +1,60 @@ + + + + + Debug + AnyCPU + {BB183256-DC01-4E78-923D-7AC734A918B8} + Exe + Db4oQueries + Db4oQueries + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/Program.cs b/db/5_sem/AngestellterDb4o/Db4oQueries/Program.cs new file mode 100644 index 0000000..d30c020 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/Program.cs @@ -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 + { + /// + /// Datenbankdatei + /// + 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(); + } + } + + /// + /// Query by example + /// + /// + 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))); + } + + /// + /// Native queries + /// + /// + private static void nativeQueries(IObjectContainer db) + { + IList angestellte = db.Query(delegate (Angestellter angestellter) + { + { + return angestellter.Salaer > 4000; + } + }); + listAngestellte(angestellte); + + angestellte = db.Query(delegate (Angestellter angestellter) + { + { + return angestellter.Name.StartsWith("Ruedi"); + } + }); + listAngestellte(angestellte); + + angestellte = db.Query(delegate (Angestellter angestellter) + { + { + return angestellter.Salaer > 4000 + && angestellter.Adresse.Strasse.Contains("1"); + } + }); + listAngestellte(angestellte); + } + + /// + /// SODA Simple Object Database Access queries + /// + /// + 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()); + } + + /// + /// Alle Angestellte auf die Konsole ausgeben + /// + /// Datenbank + private static void listAngestellte(IObjectSet result) + { + Console.WriteLine($"----- {result.Count} -----"); + foreach (object item in result) + { + Console.WriteLine(item); + } + } + + /// + /// Alle Angestellte auf die Konsole ausgeben + /// + /// Datenbank + private static void listAngestellte(IList result) + { + Console.WriteLine($"----- {result.Count} -----"); + foreach (object item in result) + { + Console.WriteLine(item); + } + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oQueries/Properties/AssemblyInfo.cs b/db/5_sem/AngestellterDb4o/Db4oQueries/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f39d223 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oQueries/Properties/AssemblyInfo.cs @@ -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")] diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/Adresse.cs b/db/5_sem/AngestellterDb4o/Db4oRelations/Adresse.cs new file mode 100644 index 0000000..ff78091 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/Adresse.cs @@ -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; + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/Angestellter.cs b/db/5_sem/AngestellterDb4o/Db4oRelations/Angestellter.cs new file mode 100644 index 0000000..1d217a5 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/Angestellter.cs @@ -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; + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/App.config b/db/5_sem/AngestellterDb4o/Db4oRelations/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/Db4oRelations.csproj b/db/5_sem/AngestellterDb4o/Db4oRelations/Db4oRelations.csproj new file mode 100644 index 0000000..c439e08 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/Db4oRelations.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {5DD9B2AD-B41D-4F58-AFC8-6DFF402B1E66} + Exe + Db4oRelations + Db4oRelations + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/Program.cs b/db/5_sem/AngestellterDb4o/Db4oRelations/Program.cs new file mode 100644 index 0000000..aff718e --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/Program.cs @@ -0,0 +1,84 @@ +using Db4objects.Db4o; +using Db4objects.Db4o.Config; +using System; +using System.IO; + +namespace Db4oRelations +{ + class Program + { + /// + /// Datenbankdatei + /// + 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); + } + } + } +} diff --git a/db/5_sem/AngestellterDb4o/Db4oRelations/Properties/AssemblyInfo.cs b/db/5_sem/AngestellterDb4o/Db4oRelations/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..f415fa6 --- /dev/null +++ b/db/5_sem/AngestellterDb4o/Db4oRelations/Properties/AssemblyInfo.cs @@ -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")] diff --git a/db/5_sem/F1/F1-Diagram.cd b/db/5_sem/F1/F1-Diagram.cd new file mode 100644 index 0000000..11b93f0 --- /dev/null +++ b/db/5_sem/F1/F1-Diagram.cd @@ -0,0 +1,18 @@ + + + + + + AAAAIAAAAAAQgAAEgAAAAAQAAAAAAAAAAAAAAAAAAAA= + Pilot.cs + + + + + + IAAIAABBAAAAAAAAAAAAAAAAAQAAAAAAAQICJEAAECA= + Program.cs + + + + \ No newline at end of file diff --git a/db/5_sem/F1/F1.csproj b/db/5_sem/F1/F1.csproj new file mode 100644 index 0000000..4e9c00a --- /dev/null +++ b/db/5_sem/F1/F1.csproj @@ -0,0 +1,99 @@ + + + + Debug + AnyCPU + 9.0.21022 + 2.0 + {8A3803A4-49AD-4C69-AB7E-F52141FA5CF5} + Exe + Properties + F1 + F1 + v4.6.1 + 512 + + + + + 3.5 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + false + + + + ..\..\..\..\..\Program Files (x86)\db4o\db4o-8.0\bin\net-4.0\Db4objects.Db4o.dll + + + + 3.5 + + + 3.5 + + + 3.5 + + + + + + + + + + + + + Designer + + + + + False + .NET Framework 3.5 SP1 + true + + + + + \ No newline at end of file diff --git a/db/5_sem/F1/F1.sln b/db/5_sem/F1/F1.sln new file mode 100644 index 0000000..f9f1e59 --- /dev/null +++ b/db/5_sem/F1/F1.sln @@ -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 diff --git a/db/5_sem/F1/Pilot.cs b/db/5_sem/F1/Pilot.cs new file mode 100644 index 0000000..681be11 --- /dev/null +++ b/db/5_sem/F1/Pilot.cs @@ -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); + } + } +} diff --git a/db/5_sem/F1/Program.cs b/db/5_sem/F1/Program.cs new file mode 100644 index 0000000..3e2a6de --- /dev/null +++ b/db/5_sem/F1/Program.cs @@ -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); + } + } + } +} diff --git a/db/5_sem/F1/Properties/AssemblyInfo.cs b/db/5_sem/F1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2885105 --- /dev/null +++ b/db/5_sem/F1/Properties/AssemblyInfo.cs @@ -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")] diff --git a/db/5_sem/F1/app.config b/db/5_sem/F1/app.config new file mode 100644 index 0000000..3dbff35 --- /dev/null +++ b/db/5_sem/F1/app.config @@ -0,0 +1,3 @@ + + +