Datei: IntegrationTests/IntegrationTests/PersistenceManagerFactory.cs

Last Commit (7c5c9f1)
1 //
2 // Copyright (c) 2002-2025 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.IO;
25 using NDO;
26 using NDO.Mapping;
27
28 namespace NdoUnitTests
29 {
30 ····/// <summary>
31 ····/// Zusammenfassung för PersistenceManagerFactory.
32 ····/// </summary>
33 ····public class PmFactory
34 ····{
35 ········static object lockObject = new object();
36 ········static NDOMapping _mapping;
37
38 public static PersistenceManager NewPersistenceManager( TransactionMode transactionMode = TransactionMode. Optimistic)
39 ········{
40 ············var appPath = AppDomain.CurrentDomain.BaseDirectory;
41 ············string path = Path.Combine(appPath, "NDOMapping.xml");
42 ············
43 ············PersistenceManager pm;
44 ············
45 ············lock (lockObject)
46 ············{
47 ················if (_mapping != null)
48 ················{
 
49 ····················pm = new PersistenceManager( _mapping );
 
 
50 ················}
51 ················else
52 ················{
 
53 ····················pm = new PersistenceManager( path );
 
 
54 ····················_mapping = pm.NDOMapping;
55 ················}
56 ············}
57
58 ············pm.TransactionMode = transactionMode;
59 ············
60 ············//Connection conn = (Connection)pm.NDOMapping.Connections.First();
61 #if ORACLE || POSTGRE
62 ············pm.IdGenerationEvent += new NDO.IdGenerationHandler(IdGenerator.OnIdGenerationEvent);
63 ············IdGenerator.ConnectionString = ((Connection)pm.NDOMapping.Connections.First()).Name;
64 #endif
65 ············return pm;
66 ········}
67 ····}
68 }
69
New Commit (1e1255d)
1 //
2 // Copyright (c) 2002-2025 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.IO;
25 using NDO;
26 using NDO.Mapping;
27
28 namespace NdoUnitTests
29 {
30 ····/// <summary>
31 ····/// Zusammenfassung för PersistenceManagerFactory.
32 ····/// </summary>
33 ····public class PmFactory
34 ····{
35 ········static object lockObject = new object();
36 ········static NDOMapping _mapping;
37
38 public static PersistenceManager NewPersistenceManager( TransactionMode transactionMode = TransactionMode. Optimistic, IServiceProvider scopedSp = null)
39 ········{
40 ············var appPath = AppDomain.CurrentDomain.BaseDirectory;
41 ············string path = Path.Combine(appPath, "NDOMapping.xml");
42 ············
43 ············PersistenceManager pm;
44 ············
45 ············lock (lockObject)
46 ············{
47 ················if (_mapping != null)
48 ················{
49 ····················if (scopedSp == null)
50 ························pm = new PersistenceManager( _mapping );
51 ····················else
52 ························pm = new PersistenceManager( _mapping, scopedSp );
53 ················}
54 ················else
55 ················{
56 ····················if (scopedSp == null)
57 ························pm = new PersistenceManager( path );
58 ····················else
59 ························pm = new PersistenceManager( path, scopedSp );
60 ····················_mapping = pm.NDOMapping;
61 ················}
62 ············}
63
64 ············pm.TransactionMode = transactionMode;
65 ············
66 ············//Connection conn = (Connection)pm.NDOMapping.Connections.First();
67 #if ORACLE || POSTGRE
68 ············pm.IdGenerationEvent += new NDO.IdGenerationHandler(IdGenerator.OnIdGenerationEvent);
69 ············IdGenerator.ConnectionString = ((Connection)pm.NDOMapping.Connections.First()).Name;
70 #endif
71 ············return pm;
72 ········}
73 ····}
74 }
75