aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs214
1 files changed, 107 insertions, 107 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs
index f041e79..15005f8 100644
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs
+++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TableMapper.cs
@@ -1,108 +1,108 @@
1/* 1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/ 2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3* 3*
4* Redistribution and use in source and binary forms, with or without 4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met: 5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright 6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer. 7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright 8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the 9* notice, this list of conditions and the following disclaimer in the
10* documentation and/or other materials provided with the distribution. 10* documentation and/or other materials provided with the distribution.
11* * The name of Tribal Media AB may not be used to endorse or promote products 11* * The name of Tribal Media AB may not be used to endorse or promote products
12* derived from this software without specific prior written permission. 12* derived from this software without specific prior written permission.
13* 13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY 14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24* 24*
25*/ 25*/
26 26
27using System; 27using System;
28using System.Data; 28using System.Data;
29using System.Data.Common; 29using System.Data.Common;
30using TribalMedia.Framework.Data; 30using TribalMedia.Framework.Data;
31 31
32namespace TribalMedia.Framework.Data 32namespace TribalMedia.Framework.Data
33{ 33{
34 public abstract class TableMapper 34 public abstract class TableMapper
35 { 35 {
36 private readonly DatabaseMapper m_connectionPool; 36 private readonly DatabaseMapper m_connectionPool;
37 private readonly object m_syncRoot = new object(); 37 private readonly object m_syncRoot = new object();
38 38
39 protected void WithConnection(Action<DbConnection> action) 39 protected void WithConnection(Action<DbConnection> action)
40 { 40 {
41 lock (m_syncRoot) 41 lock (m_syncRoot)
42 { 42 {
43 DbConnection m_connection = m_connectionPool.GetNewConnection(); 43 DbConnection m_connection = m_connectionPool.GetNewConnection();
44 44
45 if (m_connection.State != ConnectionState.Open) 45 if (m_connection.State != ConnectionState.Open)
46 { 46 {
47 m_connection.Open(); 47 m_connection.Open();
48 } 48 }
49 49
50 action(m_connection); 50 action(m_connection);
51 51
52 if (m_connection.State == ConnectionState.Open) 52 if (m_connection.State == ConnectionState.Open)
53 { 53 {
54 m_connection.Close(); 54 m_connection.Close();
55 } 55 }
56 } 56 }
57 } 57 }
58 58
59 private readonly string m_tableName; 59 private readonly string m_tableName;
60 public string TableName 60 public string TableName
61 { 61 {
62 get { return m_tableName; } 62 get { return m_tableName; }
63 } 63 }
64 64
65 private Schema m_schema; 65 private Schema m_schema;
66 public Schema Schema 66 public Schema Schema
67 { 67 {
68 get { return m_schema; } 68 get { return m_schema; }
69 } 69 }
70 70
71 private FieldMapper m_keyFieldMapper; 71 private FieldMapper m_keyFieldMapper;
72 public FieldMapper KeyFieldMapper 72 public FieldMapper KeyFieldMapper
73 { 73 {
74 get { return m_keyFieldMapper; } 74 get { return m_keyFieldMapper; }
75 } 75 }
76 76
77 public TableMapper(DatabaseMapper connectionPool, string tableName) 77 public TableMapper(DatabaseMapper connectionPool, string tableName)
78 { 78 {
79 m_connectionPool = connectionPool; 79 m_connectionPool = connectionPool;
80 m_tableName = tableName.ToLower(); // Stupid MySQL hack. 80 m_tableName = tableName.ToLower(); // Stupid MySQL hack.
81 } 81 }
82 82
83 public string CreateParamName(string fieldName) 83 public string CreateParamName(string fieldName)
84 { 84 {
85 return m_connectionPool.CreateParamName(fieldName); 85 return m_connectionPool.CreateParamName(fieldName);
86 } 86 }
87 87
88 protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey) 88 protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
89 { 89 {
90 return m_connectionPool.CreateSelectCommand(this, connection, fieldName, primaryKey); 90 return m_connectionPool.CreateSelectCommand(this, connection, fieldName, primaryKey);
91 } 91 }
92 92
93 public string CreateCondition(DbCommand command, string fieldName, object key) 93 public string CreateCondition(DbCommand command, string fieldName, object key)
94 { 94 {
95 return m_connectionPool.CreateCondition(this, command, fieldName, key); 95 return m_connectionPool.CreateCondition(this, command, fieldName, key);
96 } 96 }
97 97
98 public DbCommand CreateInsertCommand(DbConnection connection, object obj) 98 public DbCommand CreateInsertCommand(DbConnection connection, object obj)
99 { 99 {
100 return m_connectionPool.CreateInsertCommand(this, connection, obj); 100 return m_connectionPool.CreateInsertCommand(this, connection, obj);
101 } 101 }
102 102
103 public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey) 103 public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
104 { 104 {
105 return m_connectionPool.CreateUpdateCommand(this, connection, rowMapper, primaryKey); 105 return m_connectionPool.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
106 } 106 }
107 } 107 }
108} \ No newline at end of file 108} \ No newline at end of file