diff options
author | Jeff Ames | 2008-01-14 16:47:36 +0000 |
---|---|---|
committer | Jeff Ames | 2008-01-14 16:47:36 +0000 |
commit | 6716668187675d5950d2b3a7a925da7327440ca1 (patch) | |
tree | a1448cee1cf162b0d5c0e755fae5b956f465ec51 /ThirdParty/TribalMedia/TribalMedia.Framework.Data | |
parent | Remove unused SOG constructor (diff) | |
download | opensim-SC_OLD-6716668187675d5950d2b3a7a925da7327440ca1.zip opensim-SC_OLD-6716668187675d5950d2b3a7a925da7327440ca1.tar.gz opensim-SC_OLD-6716668187675d5950d2b3a7a925da7327440ca1.tar.bz2 opensim-SC_OLD-6716668187675d5950d2b3a7a925da7327440ca1.tar.xz |
Set svn:eol-style.
Diffstat (limited to 'ThirdParty/TribalMedia/TribalMedia.Framework.Data')
8 files changed, 1010 insertions, 1010 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs index f0b3e88..6f84d43 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DataReader.cs | |||
@@ -1,150 +1,150 @@ | |||
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 | ||
27 | using System; | 27 | using System; |
28 | using System.Data; | 28 | using System.Data; |
29 | using System.IO; | 29 | using System.IO; |
30 | 30 | ||
31 | namespace TribalMedia.Framework.Data | 31 | namespace TribalMedia.Framework.Data |
32 | { | 32 | { |
33 | public class DataReader | 33 | public class DataReader |
34 | { | 34 | { |
35 | private readonly IDataReader m_source; | 35 | private readonly IDataReader m_source; |
36 | 36 | ||
37 | public DataReader(IDataReader source) | 37 | public DataReader(IDataReader source) |
38 | { | 38 | { |
39 | m_source = source; | 39 | m_source = source; |
40 | } | 40 | } |
41 | 41 | ||
42 | public object Get(string name) | 42 | public object Get(string name) |
43 | { | 43 | { |
44 | return m_source[name]; | 44 | return m_source[name]; |
45 | } | 45 | } |
46 | 46 | ||
47 | public ushort GetUShort(string name) | 47 | public ushort GetUShort(string name) |
48 | { | 48 | { |
49 | return (ushort) m_source.GetInt32(m_source.GetOrdinal(name)); | 49 | return (ushort) m_source.GetInt32(m_source.GetOrdinal(name)); |
50 | } | 50 | } |
51 | 51 | ||
52 | public byte GetByte(string name) | 52 | public byte GetByte(string name) |
53 | { | 53 | { |
54 | int ordinal = m_source.GetOrdinal(name); | 54 | int ordinal = m_source.GetOrdinal(name); |
55 | byte value = (byte) m_source.GetInt16(ordinal); | 55 | byte value = (byte) m_source.GetInt16(ordinal); |
56 | return value; | 56 | return value; |
57 | } | 57 | } |
58 | 58 | ||
59 | public sbyte GetSByte(string name) | 59 | public sbyte GetSByte(string name) |
60 | { | 60 | { |
61 | return (sbyte) m_source.GetInt16(m_source.GetOrdinal(name)); | 61 | return (sbyte) m_source.GetInt16(m_source.GetOrdinal(name)); |
62 | } | 62 | } |
63 | 63 | ||
64 | //public Vector3 GetVector(string s) | 64 | //public Vector3 GetVector(string s) |
65 | //{ | 65 | //{ |
66 | // float x = GetFloat(s + "X"); | 66 | // float x = GetFloat(s + "X"); |
67 | // float y = GetFloat(s + "Y"); | 67 | // float y = GetFloat(s + "Y"); |
68 | // float z = GetFloat(s + "Z"); | 68 | // float z = GetFloat(s + "Z"); |
69 | 69 | ||
70 | // Vector3 vector = new Vector3(x, y, z); | 70 | // Vector3 vector = new Vector3(x, y, z); |
71 | 71 | ||
72 | // return vector; | 72 | // return vector; |
73 | //} | 73 | //} |
74 | 74 | ||
75 | //public Quaternion GetQuaternion(string s) | 75 | //public Quaternion GetQuaternion(string s) |
76 | //{ | 76 | //{ |
77 | // float x = GetFloat(s + "X"); | 77 | // float x = GetFloat(s + "X"); |
78 | // float y = GetFloat(s + "Y"); | 78 | // float y = GetFloat(s + "Y"); |
79 | // float z = GetFloat(s + "Z"); | 79 | // float z = GetFloat(s + "Z"); |
80 | // float w = GetFloat(s + "W"); | 80 | // float w = GetFloat(s + "W"); |
81 | 81 | ||
82 | // Quaternion quaternion = new Quaternion(x, y, z, w); | 82 | // Quaternion quaternion = new Quaternion(x, y, z, w); |
83 | 83 | ||
84 | // return quaternion; | 84 | // return quaternion; |
85 | //} | 85 | //} |
86 | 86 | ||
87 | public float GetFloat(string name) | 87 | public float GetFloat(string name) |
88 | { | 88 | { |
89 | return m_source.GetFloat(m_source.GetOrdinal(name)); | 89 | return m_source.GetFloat(m_source.GetOrdinal(name)); |
90 | } | 90 | } |
91 | 91 | ||
92 | public byte[] GetBytes(string name) | 92 | public byte[] GetBytes(string name) |
93 | { | 93 | { |
94 | int ordinal = m_source.GetOrdinal(name); | 94 | int ordinal = m_source.GetOrdinal(name); |
95 | 95 | ||
96 | if (m_source.GetValue(ordinal) == DBNull.Value) | 96 | if (m_source.GetValue(ordinal) == DBNull.Value) |
97 | { | 97 | { |
98 | return null; | 98 | return null; |
99 | } | 99 | } |
100 | 100 | ||
101 | byte[] buffer = new byte[16384]; | 101 | byte[] buffer = new byte[16384]; |
102 | 102 | ||
103 | MemoryStream memStream = new MemoryStream(); | 103 | MemoryStream memStream = new MemoryStream(); |
104 | 104 | ||
105 | long totalRead = 0; | 105 | long totalRead = 0; |
106 | 106 | ||
107 | int bytesRead; | 107 | int bytesRead; |
108 | do | 108 | do |
109 | { | 109 | { |
110 | bytesRead = (int) m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); | 110 | bytesRead = (int) m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length); |
111 | totalRead += bytesRead; | 111 | totalRead += bytesRead; |
112 | 112 | ||
113 | memStream.Write(buffer, 0, bytesRead); | 113 | memStream.Write(buffer, 0, bytesRead); |
114 | } while (bytesRead == buffer.Length); | 114 | } while (bytesRead == buffer.Length); |
115 | 115 | ||
116 | return memStream.ToArray(); | 116 | return memStream.ToArray(); |
117 | } | 117 | } |
118 | 118 | ||
119 | public string GetString(string name) | 119 | public string GetString(string name) |
120 | { | 120 | { |
121 | int ordinal = m_source.GetOrdinal(name); | 121 | int ordinal = m_source.GetOrdinal(name); |
122 | object value = m_source.GetValue(ordinal); | 122 | object value = m_source.GetValue(ordinal); |
123 | 123 | ||
124 | if (value is DBNull) | 124 | if (value is DBNull) |
125 | { | 125 | { |
126 | return null; | 126 | return null; |
127 | } | 127 | } |
128 | 128 | ||
129 | return (string) value; | 129 | return (string) value; |
130 | } | 130 | } |
131 | 131 | ||
132 | public bool Read() | 132 | public bool Read() |
133 | { | 133 | { |
134 | return m_source.Read(); | 134 | return m_source.Read(); |
135 | } | 135 | } |
136 | 136 | ||
137 | internal Guid GetGuid(string name) | 137 | internal Guid GetGuid(string name) |
138 | { | 138 | { |
139 | string guidString = GetString(name); | 139 | string guidString = GetString(name); |
140 | if (String.IsNullOrEmpty(guidString)) | 140 | if (String.IsNullOrEmpty(guidString)) |
141 | { | 141 | { |
142 | return Guid.Empty; | 142 | return Guid.Empty; |
143 | } | 143 | } |
144 | else | 144 | else |
145 | { | 145 | { |
146 | return new Guid(guidString); | 146 | return new Guid(guidString); |
147 | } | 147 | } |
148 | } | 148 | } |
149 | } | 149 | } |
150 | } \ No newline at end of file | 150 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs index fe31177..0b9d16d 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/DatabaseMapper.cs | |||
@@ -1,135 +1,135 @@ | |||
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 | ||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Data; | 29 | using System.Data; |
30 | using System.Data.Common; | 30 | using System.Data.Common; |
31 | 31 | ||
32 | namespace TribalMedia.Framework.Data | 32 | namespace TribalMedia.Framework.Data |
33 | { | 33 | { |
34 | public abstract class DatabaseMapper | 34 | public abstract class DatabaseMapper |
35 | { | 35 | { |
36 | protected string m_connectionString; | 36 | protected string m_connectionString; |
37 | 37 | ||
38 | public DatabaseMapper(string connectionString) | 38 | public DatabaseMapper(string connectionString) |
39 | { | 39 | { |
40 | m_connectionString = connectionString; | 40 | m_connectionString = connectionString; |
41 | } | 41 | } |
42 | 42 | ||
43 | public abstract DbConnection GetNewConnection(); | 43 | public abstract DbConnection GetNewConnection(); |
44 | 44 | ||
45 | public abstract string CreateParamName(string fieldName); | 45 | public abstract string CreateParamName(string fieldName); |
46 | 46 | ||
47 | public DbCommand CreateSelectCommand(TableMapper mapper, DbConnection connection, string fieldName, object key) | 47 | public DbCommand CreateSelectCommand(TableMapper mapper, DbConnection connection, string fieldName, object key) |
48 | { | 48 | { |
49 | string table = mapper.TableName; | 49 | string table = mapper.TableName; |
50 | 50 | ||
51 | DbCommand command = connection.CreateCommand(); | 51 | DbCommand command = connection.CreateCommand(); |
52 | 52 | ||
53 | string conditionString = CreateCondition(mapper, command, fieldName, key); | 53 | string conditionString = CreateCondition(mapper, command, fieldName, key); |
54 | 54 | ||
55 | string query = | 55 | string query = |
56 | String.Format("select * from {0} where {1}", table, conditionString); | 56 | String.Format("select * from {0} where {1}", table, conditionString); |
57 | 57 | ||
58 | command.CommandText = query; | 58 | command.CommandText = query; |
59 | command.CommandType = CommandType.Text; | 59 | command.CommandType = CommandType.Text; |
60 | 60 | ||
61 | return command; | 61 | return command; |
62 | } | 62 | } |
63 | 63 | ||
64 | public string CreateCondition(TableMapper mapper, DbCommand command, string fieldName, object key) | 64 | public string CreateCondition(TableMapper mapper, DbCommand command, string fieldName, object key) |
65 | { | 65 | { |
66 | string keyFieldParamName = mapper.CreateParamName(fieldName); | 66 | string keyFieldParamName = mapper.CreateParamName(fieldName); |
67 | 67 | ||
68 | DbParameter param = command.CreateParameter(); | 68 | DbParameter param = command.CreateParameter(); |
69 | param.ParameterName = keyFieldParamName; | 69 | param.ParameterName = keyFieldParamName; |
70 | param.Value = FieldMapper.ConvertToDbType(key); | 70 | param.Value = FieldMapper.ConvertToDbType(key); |
71 | command.Parameters.Add(param); | 71 | command.Parameters.Add(param); |
72 | 72 | ||
73 | return String.Format("{0}={1}", fieldName, keyFieldParamName); | 73 | return String.Format("{0}={1}", fieldName, keyFieldParamName); |
74 | } | 74 | } |
75 | 75 | ||
76 | public DbCommand CreateUpdateCommand(TableMapper mapper, DbConnection connection, object rowMapper, object primaryKey) | 76 | public DbCommand CreateUpdateCommand(TableMapper mapper, DbConnection connection, object rowMapper, object primaryKey) |
77 | { | 77 | { |
78 | string table = mapper.TableName; | 78 | string table = mapper.TableName; |
79 | 79 | ||
80 | List<string> fieldNames = new List<string>(); | 80 | List<string> fieldNames = new List<string>(); |
81 | 81 | ||
82 | DbCommand command = connection.CreateCommand(); | 82 | DbCommand command = connection.CreateCommand(); |
83 | 83 | ||
84 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) | 84 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) |
85 | { | 85 | { |
86 | if (fieldMapper != mapper.KeyFieldMapper) | 86 | if (fieldMapper != mapper.KeyFieldMapper) |
87 | { | 87 | { |
88 | fieldMapper.ExpandField(rowMapper, command, fieldNames); | 88 | fieldMapper.ExpandField(rowMapper, command, fieldNames); |
89 | } | 89 | } |
90 | } | 90 | } |
91 | 91 | ||
92 | List<string> assignments = new List<string>(); | 92 | List<string> assignments = new List<string>(); |
93 | 93 | ||
94 | foreach (string field in fieldNames) | 94 | foreach (string field in fieldNames) |
95 | { | 95 | { |
96 | assignments.Add(String.Format("{0}={1}", field, mapper.CreateParamName(field))); | 96 | assignments.Add(String.Format("{0}={1}", field, mapper.CreateParamName(field))); |
97 | } | 97 | } |
98 | 98 | ||
99 | string conditionString = mapper.CreateCondition(command, mapper.KeyFieldMapper.FieldName, primaryKey); | 99 | string conditionString = mapper.CreateCondition(command, mapper.KeyFieldMapper.FieldName, primaryKey); |
100 | 100 | ||
101 | command.CommandText = | 101 | command.CommandText = |
102 | String.Format("update {0} set {1} where {2}", table, String.Join(", ", assignments.ToArray()), | 102 | String.Format("update {0} set {1} where {2}", table, String.Join(", ", assignments.ToArray()), |
103 | conditionString); | 103 | conditionString); |
104 | 104 | ||
105 | return command; | 105 | return command; |
106 | } | 106 | } |
107 | 107 | ||
108 | public DbCommand CreateInsertCommand(TableMapper mapper, DbConnection connection, object obj) | 108 | public DbCommand CreateInsertCommand(TableMapper mapper, DbConnection connection, object obj) |
109 | { | 109 | { |
110 | string table = mapper.TableName; | 110 | string table = mapper.TableName; |
111 | 111 | ||
112 | List<string> fieldNames = new List<string>(); | 112 | List<string> fieldNames = new List<string>(); |
113 | 113 | ||
114 | DbCommand command = connection.CreateCommand(); | 114 | DbCommand command = connection.CreateCommand(); |
115 | 115 | ||
116 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) | 116 | foreach (FieldMapper fieldMapper in mapper.Schema.Fields.Values) |
117 | { | 117 | { |
118 | fieldMapper.ExpandField(obj, command, fieldNames); | 118 | fieldMapper.ExpandField(obj, command, fieldNames); |
119 | } | 119 | } |
120 | 120 | ||
121 | List<string> paramNames = new List<string>(); | 121 | List<string> paramNames = new List<string>(); |
122 | 122 | ||
123 | foreach (string field in fieldNames) | 123 | foreach (string field in fieldNames) |
124 | { | 124 | { |
125 | paramNames.Add(mapper.CreateParamName(field)); | 125 | paramNames.Add(mapper.CreateParamName(field)); |
126 | } | 126 | } |
127 | 127 | ||
128 | command.CommandText = | 128 | command.CommandText = |
129 | String.Format("insert into {0} ({1}) values ({2})", table, String.Join(", ", fieldNames.ToArray()), | 129 | String.Format("insert into {0} ({1}) values ({2})", table, String.Join(", ", fieldNames.ToArray()), |
130 | String.Join(", ", paramNames.ToArray())); | 130 | String.Join(", ", paramNames.ToArray())); |
131 | 131 | ||
132 | return command; | 132 | return command; |
133 | } | 133 | } |
134 | } | 134 | } |
135 | } \ No newline at end of file | 135 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs index 28a603a..a1fafbe 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/FieldMapper.cs | |||
@@ -1,249 +1,249 @@ | |||
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 | ||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Data.Common; | 29 | using System.Data.Common; |
30 | 30 | ||
31 | namespace TribalMedia.Framework.Data | 31 | namespace TribalMedia.Framework.Data |
32 | { | 32 | { |
33 | public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); | 33 | public delegate TField RowMapperGetAccessor<TRowMapper, TField>(TRowMapper rowMapper); |
34 | 34 | ||
35 | public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); | 35 | public delegate void RowMapperSetAccessor<TRowMapper, TField>(TRowMapper rowMapper, TField value); |
36 | 36 | ||
37 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); | 37 | public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj); |
38 | 38 | ||
39 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); | 39 | public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value); |
40 | 40 | ||
41 | public abstract class FieldMapper | 41 | public abstract class FieldMapper |
42 | { | 42 | { |
43 | private readonly TableMapper m_tableMapper; | 43 | private readonly TableMapper m_tableMapper; |
44 | private readonly string m_fieldName; | 44 | private readonly string m_fieldName; |
45 | 45 | ||
46 | public string FieldName | 46 | public string FieldName |
47 | { | 47 | { |
48 | get { return m_fieldName; } | 48 | get { return m_fieldName; } |
49 | } | 49 | } |
50 | 50 | ||
51 | protected Type m_valueType; | 51 | protected Type m_valueType; |
52 | 52 | ||
53 | public Type ValueType | 53 | public Type ValueType |
54 | { | 54 | { |
55 | get { return m_valueType; } | 55 | get { return m_valueType; } |
56 | } | 56 | } |
57 | 57 | ||
58 | public abstract object GetParamValue(object obj); | 58 | public abstract object GetParamValue(object obj); |
59 | 59 | ||
60 | public FieldMapper( TableMapper tableMapper, string fieldName, Type valueType) | 60 | public FieldMapper( TableMapper tableMapper, string fieldName, Type valueType) |
61 | { | 61 | { |
62 | m_fieldName = fieldName; | 62 | m_fieldName = fieldName; |
63 | m_valueType = valueType; | 63 | m_valueType = valueType; |
64 | m_tableMapper = tableMapper; | 64 | m_tableMapper = tableMapper; |
65 | } | 65 | } |
66 | 66 | ||
67 | public abstract void SetPropertyFromReader(object mapper, DataReader reader); | 67 | public abstract void SetPropertyFromReader(object mapper, DataReader reader); |
68 | 68 | ||
69 | public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value) | 69 | public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value) |
70 | { | 70 | { |
71 | string paramName = m_tableMapper.CreateParamName(fieldName); | 71 | string paramName = m_tableMapper.CreateParamName(fieldName); |
72 | fieldNames.Add(fieldName); | 72 | fieldNames.Add(fieldName); |
73 | 73 | ||
74 | DbParameter param = command.CreateParameter(); | 74 | DbParameter param = command.CreateParameter(); |
75 | param.ParameterName = paramName; | 75 | param.ParameterName = paramName; |
76 | param.Value = value; | 76 | param.Value = value; |
77 | 77 | ||
78 | command.Parameters.Add(param); | 78 | command.Parameters.Add(param); |
79 | } | 79 | } |
80 | 80 | ||
81 | public void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames) | 81 | public void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames) |
82 | { | 82 | { |
83 | string fieldName = FieldName; | 83 | string fieldName = FieldName; |
84 | object value = GetParamValue(obj); | 84 | object value = GetParamValue(obj); |
85 | 85 | ||
86 | //if (ValueType == typeof (Vector3)) | 86 | //if (ValueType == typeof (Vector3)) |
87 | //{ | 87 | //{ |
88 | // Vector3 vector = (Vector3) value; | 88 | // Vector3 vector = (Vector3) value; |
89 | 89 | ||
90 | // RawAddParam(command, fieldNames, fieldName + "X", vector.X); | 90 | // RawAddParam(command, fieldNames, fieldName + "X", vector.X); |
91 | // RawAddParam(command, fieldNames, fieldName + "Y", vector.Y); | 91 | // RawAddParam(command, fieldNames, fieldName + "Y", vector.Y); |
92 | // RawAddParam(command, fieldNames, fieldName + "Z", vector.Z); | 92 | // RawAddParam(command, fieldNames, fieldName + "Z", vector.Z); |
93 | //} | 93 | //} |
94 | //else if (ValueType == typeof (Quaternion)) | 94 | //else if (ValueType == typeof (Quaternion)) |
95 | //{ | 95 | //{ |
96 | // Quaternion quaternion = (Quaternion) value; | 96 | // Quaternion quaternion = (Quaternion) value; |
97 | 97 | ||
98 | // RawAddParam(command, fieldNames, fieldName + "X", quaternion.X); | 98 | // RawAddParam(command, fieldNames, fieldName + "X", quaternion.X); |
99 | // RawAddParam(command, fieldNames, fieldName + "Y", quaternion.Y); | 99 | // RawAddParam(command, fieldNames, fieldName + "Y", quaternion.Y); |
100 | // RawAddParam(command, fieldNames, fieldName + "Z", quaternion.Z); | 100 | // RawAddParam(command, fieldNames, fieldName + "Z", quaternion.Z); |
101 | // RawAddParam(command, fieldNames, fieldName + "W", quaternion.W); | 101 | // RawAddParam(command, fieldNames, fieldName + "W", quaternion.W); |
102 | //} | 102 | //} |
103 | //else | 103 | //else |
104 | //{ | 104 | //{ |
105 | RawAddParam(command, fieldNames, fieldName, ConvertToDbType(value)); | 105 | RawAddParam(command, fieldNames, fieldName, ConvertToDbType(value)); |
106 | //} | 106 | //} |
107 | } | 107 | } |
108 | 108 | ||
109 | protected object GetValue(DataReader reader) | 109 | protected object GetValue(DataReader reader) |
110 | { | 110 | { |
111 | object value; | 111 | object value; |
112 | //if (ValueType == typeof (Vector3)) | 112 | //if (ValueType == typeof (Vector3)) |
113 | //{ | 113 | //{ |
114 | // value = reader.GetVector(m_fieldName); | 114 | // value = reader.GetVector(m_fieldName); |
115 | //} | 115 | //} |
116 | //else if (ValueType == typeof (Quaternion)) | 116 | //else if (ValueType == typeof (Quaternion)) |
117 | //{ | 117 | //{ |
118 | // value = reader.GetQuaternion(m_fieldName); | 118 | // value = reader.GetQuaternion(m_fieldName); |
119 | //} | 119 | //} |
120 | //else | 120 | //else |
121 | //if (ValueType == typeof(UID)) | 121 | //if (ValueType == typeof(UID)) |
122 | //{ | 122 | //{ |
123 | // Guid guid = reader.GetGuid(m_fieldName); | 123 | // Guid guid = reader.GetGuid(m_fieldName); |
124 | // value = new UID(guid); | 124 | // value = new UID(guid); |
125 | //} | 125 | //} |
126 | //else | 126 | //else |
127 | if (ValueType == typeof(Guid)) | 127 | if (ValueType == typeof(Guid)) |
128 | { | 128 | { |
129 | value = reader.GetGuid(m_fieldName); | 129 | value = reader.GetGuid(m_fieldName); |
130 | } | 130 | } |
131 | else if (ValueType == typeof (bool)) | 131 | else if (ValueType == typeof (bool)) |
132 | { | 132 | { |
133 | uint boolVal = reader.GetUShort(m_fieldName); | 133 | uint boolVal = reader.GetUShort(m_fieldName); |
134 | value = (boolVal == 1); | 134 | value = (boolVal == 1); |
135 | } | 135 | } |
136 | else | 136 | else |
137 | if (ValueType == typeof (byte)) | 137 | if (ValueType == typeof (byte)) |
138 | { | 138 | { |
139 | value = reader.GetByte(m_fieldName); | 139 | value = reader.GetByte(m_fieldName); |
140 | } | 140 | } |
141 | else if (ValueType == typeof (sbyte)) | 141 | else if (ValueType == typeof (sbyte)) |
142 | { | 142 | { |
143 | value = reader.GetSByte(m_fieldName); | 143 | value = reader.GetSByte(m_fieldName); |
144 | } | 144 | } |
145 | else if (ValueType == typeof (ushort)) | 145 | else if (ValueType == typeof (ushort)) |
146 | { | 146 | { |
147 | value = reader.GetUShort(m_fieldName); | 147 | value = reader.GetUShort(m_fieldName); |
148 | } | 148 | } |
149 | else if (ValueType == typeof (byte[])) | 149 | else if (ValueType == typeof (byte[])) |
150 | { | 150 | { |
151 | value = reader.GetBytes(m_fieldName); | 151 | value = reader.GetBytes(m_fieldName); |
152 | } | 152 | } |
153 | else | 153 | else |
154 | { | 154 | { |
155 | value = reader.Get(m_fieldName); | 155 | value = reader.Get(m_fieldName); |
156 | } | 156 | } |
157 | 157 | ||
158 | if (value is DBNull) | 158 | if (value is DBNull) |
159 | { | 159 | { |
160 | value = default(ValueType); | 160 | value = default(ValueType); |
161 | } | 161 | } |
162 | 162 | ||
163 | return value; | 163 | return value; |
164 | } | 164 | } |
165 | 165 | ||
166 | public static object ConvertToDbType(object value) | 166 | public static object ConvertToDbType(object value) |
167 | { | 167 | { |
168 | //if (value is UID) | 168 | //if (value is UID) |
169 | //{ | 169 | //{ |
170 | // return (value as UID).UUID.ToString(); | 170 | // return (value as UID).UUID.ToString(); |
171 | //} | 171 | //} |
172 | 172 | ||
173 | return value; | 173 | return value; |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | public class RowMapperField<TRowMapper, TField> : FieldMapper | 177 | public class RowMapperField<TRowMapper, TField> : FieldMapper |
178 | where TRowMapper : RowMapper | 178 | where TRowMapper : RowMapper |
179 | { | 179 | { |
180 | private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; | 180 | private readonly RowMapperGetAccessor<TRowMapper, TField> m_fieldGetAccessor; |
181 | private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; | 181 | private readonly RowMapperSetAccessor<TRowMapper, TField> m_fieldSetAccessor; |
182 | 182 | ||
183 | public override object GetParamValue(object obj) | 183 | public override object GetParamValue(object obj) |
184 | { | 184 | { |
185 | return m_fieldGetAccessor((TRowMapper) obj); | 185 | return m_fieldGetAccessor((TRowMapper) obj); |
186 | } | 186 | } |
187 | 187 | ||
188 | public override void SetPropertyFromReader(object mapper, DataReader reader) | 188 | public override void SetPropertyFromReader(object mapper, DataReader reader) |
189 | { | 189 | { |
190 | object value; | 190 | object value; |
191 | 191 | ||
192 | value = GetValue(reader); | 192 | value = GetValue(reader); |
193 | 193 | ||
194 | if (value == null) | 194 | if (value == null) |
195 | { | 195 | { |
196 | m_fieldSetAccessor((TRowMapper) mapper, default(TField)); | 196 | m_fieldSetAccessor((TRowMapper) mapper, default(TField)); |
197 | } | 197 | } |
198 | else | 198 | else |
199 | { | 199 | { |
200 | m_fieldSetAccessor((TRowMapper) mapper, (TField) value); | 200 | m_fieldSetAccessor((TRowMapper) mapper, (TField) value); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, | 205 | public RowMapperField(TableMapper tableMapper, string fieldName, RowMapperGetAccessor<TRowMapper, TField> rowMapperGetAccessor, |
206 | RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) | 206 | RowMapperSetAccessor<TRowMapper, TField> rowMapperSetAccessor) |
207 | : base(tableMapper, fieldName, typeof(TField)) | 207 | : base(tableMapper, fieldName, typeof(TField)) |
208 | { | 208 | { |
209 | m_fieldGetAccessor = rowMapperGetAccessor; | 209 | m_fieldGetAccessor = rowMapperGetAccessor; |
210 | m_fieldSetAccessor = rowMapperSetAccessor; | 210 | m_fieldSetAccessor = rowMapperSetAccessor; |
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | public class ObjectField<TObject, TField> : FieldMapper | 214 | public class ObjectField<TObject, TField> : FieldMapper |
215 | { | 215 | { |
216 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; | 216 | private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor; |
217 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; | 217 | private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor; |
218 | 218 | ||
219 | public override object GetParamValue(object obj) | 219 | public override object GetParamValue(object obj) |
220 | { | 220 | { |
221 | return m_fieldGetAccessor((TObject) obj); | 221 | return m_fieldGetAccessor((TObject) obj); |
222 | } | 222 | } |
223 | 223 | ||
224 | public override void SetPropertyFromReader(object obj, DataReader reader) | 224 | public override void SetPropertyFromReader(object obj, DataReader reader) |
225 | { | 225 | { |
226 | object value; | 226 | object value; |
227 | 227 | ||
228 | value = GetValue(reader); | 228 | value = GetValue(reader); |
229 | 229 | ||
230 | if (value == null) | 230 | if (value == null) |
231 | { | 231 | { |
232 | m_fieldSetAccessor((TObject) obj, default(TField)); | 232 | m_fieldSetAccessor((TObject) obj, default(TField)); |
233 | } | 233 | } |
234 | else | 234 | else |
235 | { | 235 | { |
236 | m_fieldSetAccessor((TObject) obj, (TField) value); | 236 | m_fieldSetAccessor((TObject) obj, (TField) value); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | 239 | ||
240 | 240 | ||
241 | public ObjectField(TableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, | 241 | public ObjectField(TableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor, |
242 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) | 242 | ObjectSetAccessor<TObject, TField> rowMapperSetAccessor) |
243 | : base(tableMapper, fieldName, typeof (TField)) | 243 | : base(tableMapper, fieldName, typeof (TField)) |
244 | { | 244 | { |
245 | m_fieldGetAccessor = rowMapperGetAccessor; | 245 | m_fieldGetAccessor = rowMapperGetAccessor; |
246 | m_fieldSetAccessor = rowMapperSetAccessor; | 246 | m_fieldSetAccessor = rowMapperSetAccessor; |
247 | } | 247 | } |
248 | } | 248 | } |
249 | } \ No newline at end of file | 249 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs index 631a2ca..44a6542 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/ObjectTableMapper.cs | |||
@@ -1,162 +1,162 @@ | |||
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 | ||
27 | using System; | 27 | using System; |
28 | using System.Collections.Generic; | 28 | using System.Collections.Generic; |
29 | using System.Data; | 29 | using System.Data; |
30 | using System.Data.Common; | 30 | using System.Data.Common; |
31 | using TribalMedia.Framework.Data; | 31 | using TribalMedia.Framework.Data; |
32 | 32 | ||
33 | namespace TribalMedia.Framework.Data | 33 | namespace TribalMedia.Framework.Data |
34 | { | 34 | { |
35 | public abstract class ObjectTableMapper<TRowMapper, TPrimaryKey> : TableMapper | 35 | public abstract class ObjectTableMapper<TRowMapper, TPrimaryKey> : TableMapper |
36 | { | 36 | { |
37 | public ObjectTableMapper(DatabaseMapper connectionPool, string tableName) | 37 | public ObjectTableMapper(DatabaseMapper connectionPool, string tableName) |
38 | : base(connectionPool, tableName) | 38 | : base(connectionPool, tableName) |
39 | { | 39 | { |
40 | } | 40 | } |
41 | 41 | ||
42 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) | 42 | public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value) |
43 | { | 43 | { |
44 | TRowMapper result = default(TRowMapper); | 44 | TRowMapper result = default(TRowMapper); |
45 | bool success = false; | 45 | bool success = false; |
46 | 46 | ||
47 | WithConnection(delegate(DbConnection connection) | 47 | WithConnection(delegate(DbConnection connection) |
48 | { | 48 | { |
49 | using ( | 49 | using ( |
50 | DbCommand command = | 50 | DbCommand command = |
51 | CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey)) | 51 | CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey)) |
52 | { | 52 | { |
53 | using (IDataReader reader = command.ExecuteReader()) | 53 | using (IDataReader reader = command.ExecuteReader()) |
54 | { | 54 | { |
55 | if (reader.Read()) | 55 | if (reader.Read()) |
56 | { | 56 | { |
57 | result = FromReader(new DataReader(reader)); | 57 | result = FromReader(new DataReader(reader)); |
58 | success = true; | 58 | success = true; |
59 | } | 59 | } |
60 | else | 60 | else |
61 | { | 61 | { |
62 | success = false; | 62 | success = false; |
63 | } | 63 | } |
64 | } | 64 | } |
65 | } | 65 | } |
66 | }); | 66 | }); |
67 | 67 | ||
68 | value = result; | 68 | value = result; |
69 | 69 | ||
70 | return success; | 70 | return success; |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | public virtual bool Remove(TPrimaryKey id) | 74 | public virtual bool Remove(TPrimaryKey id) |
75 | { | 75 | { |
76 | int deleted = 0; | 76 | int deleted = 0; |
77 | 77 | ||
78 | WithConnection(delegate(DbConnection connection) | 78 | WithConnection(delegate(DbConnection connection) |
79 | { | 79 | { |
80 | using ( | 80 | using ( |
81 | DbCommand command = | 81 | DbCommand command = |
82 | CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id)) | 82 | CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id)) |
83 | { | 83 | { |
84 | deleted = command.ExecuteNonQuery(); | 84 | deleted = command.ExecuteNonQuery(); |
85 | } | 85 | } |
86 | }); | 86 | }); |
87 | 87 | ||
88 | if (deleted == 1) | 88 | if (deleted == 1) |
89 | { | 89 | { |
90 | return true; | 90 | return true; |
91 | } | 91 | } |
92 | else | 92 | else |
93 | { | 93 | { |
94 | return false; | 94 | return false; |
95 | } | 95 | } |
96 | } | 96 | } |
97 | 97 | ||
98 | 98 | ||
99 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) | 99 | public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey) |
100 | { | 100 | { |
101 | string table = TableName; | 101 | string table = TableName; |
102 | 102 | ||
103 | DbCommand command = connection.CreateCommand(); | 103 | DbCommand command = connection.CreateCommand(); |
104 | 104 | ||
105 | string conditionString = CreateCondition(command, fieldName, primaryKey); | 105 | string conditionString = CreateCondition(command, fieldName, primaryKey); |
106 | 106 | ||
107 | string query = | 107 | string query = |
108 | String.Format("delete from {0} where {1}", table, conditionString); | 108 | String.Format("delete from {0} where {1}", table, conditionString); |
109 | 109 | ||
110 | command.CommandText = query; | 110 | command.CommandText = query; |
111 | command.CommandType = CommandType.Text; | 111 | command.CommandType = CommandType.Text; |
112 | 112 | ||
113 | return command; | 113 | return command; |
114 | } | 114 | } |
115 | 115 | ||
116 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) | 116 | public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value) |
117 | { | 117 | { |
118 | int updated = 0; | 118 | int updated = 0; |
119 | 119 | ||
120 | WithConnection(delegate(DbConnection connection) | 120 | WithConnection(delegate(DbConnection connection) |
121 | { | 121 | { |
122 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) | 122 | using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey)) |
123 | { | 123 | { |
124 | updated = command.ExecuteNonQuery(); | 124 | updated = command.ExecuteNonQuery(); |
125 | } | 125 | } |
126 | }); | 126 | }); |
127 | 127 | ||
128 | if (updated == 1) | 128 | if (updated == 1) |
129 | { | 129 | { |
130 | return true; | 130 | return true; |
131 | } | 131 | } |
132 | else | 132 | else |
133 | { | 133 | { |
134 | return false; | 134 | return false; |
135 | } | 135 | } |
136 | } | 136 | } |
137 | 137 | ||
138 | public virtual bool Add(TRowMapper value) | 138 | public virtual bool Add(TRowMapper value) |
139 | { | 139 | { |
140 | int added = 0; | 140 | int added = 0; |
141 | 141 | ||
142 | WithConnection(delegate(DbConnection connection) | 142 | WithConnection(delegate(DbConnection connection) |
143 | { | 143 | { |
144 | using (DbCommand command = CreateInsertCommand(connection, value)) | 144 | using (DbCommand command = CreateInsertCommand(connection, value)) |
145 | { | 145 | { |
146 | added = command.ExecuteNonQuery(); | 146 | added = command.ExecuteNonQuery(); |
147 | } | 147 | } |
148 | }); | 148 | }); |
149 | 149 | ||
150 | if (added == 1) | 150 | if (added == 1) |
151 | { | 151 | { |
152 | return true; | 152 | return true; |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
156 | return false; | 156 | return false; |
157 | } | 157 | } |
158 | } | 158 | } |
159 | 159 | ||
160 | public abstract TRowMapper FromReader(DataReader reader); | 160 | public abstract TRowMapper FromReader(DataReader reader); |
161 | } | 161 | } |
162 | } \ No newline at end of file | 162 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs index 4a073e9..583c310 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs | |||
@@ -1,40 +1,40 @@ | |||
1 | using System.Reflection; | 1 | using System.Reflection; |
2 | using System.Runtime.InteropServices; | 2 | using System.Runtime.InteropServices; |
3 | using System.Security; | 3 | using System.Security; |
4 | 4 | ||
5 | // General Information about an assembly is controlled through the following | 5 | // General Information about an assembly is controlled through the following |
6 | // set of attributes. Change these attribute values to modify the information | 6 | // set of attributes. Change these attribute values to modify the information |
7 | // associated with an assembly. | 7 | // associated with an assembly. |
8 | 8 | ||
9 | [assembly : AssemblyTitle("TribalMedia.Framework.Data")] | 9 | [assembly : AssemblyTitle("TribalMedia.Framework.Data")] |
10 | [assembly : AssemblyDescription("Generic Database Abstraction Layer")] | 10 | [assembly : AssemblyDescription("Generic Database Abstraction Layer")] |
11 | [assembly : AssemblyConfiguration("")] | 11 | [assembly : AssemblyConfiguration("")] |
12 | [assembly : AssemblyCompany("TribalMedia")] | 12 | [assembly : AssemblyCompany("TribalMedia")] |
13 | [assembly : AssemblyProduct("TribalMedia.Framework.Data")] | 13 | [assembly : AssemblyProduct("TribalMedia.Framework.Data")] |
14 | [assembly: AssemblyCopyright("Copyright © 2007 Tribal Media")] | 14 | [assembly: AssemblyCopyright("Copyright © 2007 Tribal Media")] |
15 | [assembly : AssemblyTrademark("")] | 15 | [assembly : AssemblyTrademark("")] |
16 | [assembly : AssemblyCulture("")] | 16 | [assembly : AssemblyCulture("")] |
17 | 17 | ||
18 | // Setting ComVisible to false makes the types in this assembly not visible | 18 | // Setting ComVisible to false makes the types in this assembly not visible |
19 | // to COM components. If you need to access a type in this assembly from | 19 | // to COM components. If you need to access a type in this assembly from |
20 | // COM, set the ComVisible attribute to true on that type. | 20 | // COM, set the ComVisible attribute to true on that type. |
21 | 21 | ||
22 | [assembly : ComVisible(false)] | 22 | [assembly : ComVisible(false)] |
23 | 23 | ||
24 | // The following GUID is for the ID of the typelib if this project is exposed to COM | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM |
25 | 25 | ||
26 | [assembly : Guid("9269f421-19d9-4eea-bfe3-c0ffe426fada")] | 26 | [assembly : Guid("9269f421-19d9-4eea-bfe3-c0ffe426fada")] |
27 | 27 | ||
28 | // Version information for an assembly consists of the following four values: | 28 | // Version information for an assembly consists of the following four values: |
29 | // | 29 | // |
30 | // Major Version | 30 | // Major Version |
31 | // Minor Version | 31 | // Minor Version |
32 | // Build Number | 32 | // Build Number |
33 | // Revision | 33 | // Revision |
34 | // | 34 | // |
35 | // You can specify all the values or you can default the Revision and Build Numbers | 35 | // You can specify all the values or you can default the Revision and Build Numbers |
36 | // by using the '*' as shown below: | 36 | // by using the '*' as shown below: |
37 | 37 | ||
38 | [assembly : AssemblyVersion("1.0.0.0")] | 38 | [assembly : AssemblyVersion("1.0.0.0")] |
39 | [assembly : AssemblyFileVersion("1.0.0.0")] | 39 | [assembly : AssemblyFileVersion("1.0.0.0")] |
40 | [assembly : AllowPartiallyTrustedCallers] \ No newline at end of file | 40 | [assembly : AllowPartiallyTrustedCallers] \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs index aa22c8b..2771ec9 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/RowMapper.cs | |||
@@ -1,85 +1,85 @@ | |||
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 | ||
27 | using TribalMedia.Framework.Data; | 27 | using TribalMedia.Framework.Data; |
28 | 28 | ||
29 | namespace TribalMedia.Framework.Data | 29 | namespace TribalMedia.Framework.Data |
30 | { | 30 | { |
31 | public abstract class RowMapper | 31 | public abstract class RowMapper |
32 | { | 32 | { |
33 | public abstract void FillObject(DataReader reader); | 33 | public abstract void FillObject(DataReader reader); |
34 | } | 34 | } |
35 | 35 | ||
36 | public class ObjectMapper<TObj> : RowMapper | 36 | public class ObjectMapper<TObj> : RowMapper |
37 | { | 37 | { |
38 | private readonly Schema m_schema; | 38 | private readonly Schema m_schema; |
39 | private readonly TObj m_obj; | 39 | private readonly TObj m_obj; |
40 | 40 | ||
41 | public TObj Object | 41 | public TObj Object |
42 | { | 42 | { |
43 | get { return m_obj; } | 43 | get { return m_obj; } |
44 | } | 44 | } |
45 | 45 | ||
46 | public ObjectMapper(Schema schema, TObj obj) | 46 | public ObjectMapper(Schema schema, TObj obj) |
47 | { | 47 | { |
48 | m_schema = schema; | 48 | m_schema = schema; |
49 | m_obj = obj; | 49 | m_obj = obj; |
50 | } | 50 | } |
51 | 51 | ||
52 | public override void FillObject(DataReader reader) | 52 | public override void FillObject(DataReader reader) |
53 | { | 53 | { |
54 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) | 54 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) |
55 | { | 55 | { |
56 | fieldMapper.SetPropertyFromReader(m_obj, reader); | 56 | fieldMapper.SetPropertyFromReader(m_obj, reader); |
57 | } | 57 | } |
58 | } | 58 | } |
59 | } | 59 | } |
60 | 60 | ||
61 | public class RowMapper<TObj> : RowMapper | 61 | public class RowMapper<TObj> : RowMapper |
62 | { | 62 | { |
63 | private readonly Schema m_schema; | 63 | private readonly Schema m_schema; |
64 | private readonly TObj m_obj; | 64 | private readonly TObj m_obj; |
65 | 65 | ||
66 | public TObj Object | 66 | public TObj Object |
67 | { | 67 | { |
68 | get { return m_obj; } | 68 | get { return m_obj; } |
69 | } | 69 | } |
70 | 70 | ||
71 | public RowMapper(Schema schema, TObj obj) | 71 | public RowMapper(Schema schema, TObj obj) |
72 | { | 72 | { |
73 | m_schema = schema; | 73 | m_schema = schema; |
74 | m_obj = obj; | 74 | m_obj = obj; |
75 | } | 75 | } |
76 | 76 | ||
77 | public override void FillObject(DataReader reader) | 77 | public override void FillObject(DataReader reader) |
78 | { | 78 | { |
79 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) | 79 | foreach (FieldMapper fieldMapper in m_schema.Fields.Values) |
80 | { | 80 | { |
81 | fieldMapper.SetPropertyFromReader(this, reader); | 81 | fieldMapper.SetPropertyFromReader(this, reader); |
82 | } | 82 | } |
83 | } | 83 | } |
84 | } | 84 | } |
85 | } \ No newline at end of file | 85 | } \ No newline at end of file |
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs index b7b8939..c6bf5d0 100644 --- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs +++ b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Schema.cs | |||
@@ -1,89 +1,89 @@ | |||
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 | ||
27 | using System.Collections.Generic; | 27 | using System.Collections.Generic; |
28 | using TribalMedia.Framework.Data; | 28 | using TribalMedia.Framework.Data; |
29 | 29 | ||
30 | namespace TribalMedia.Framework.Data | 30 | namespace TribalMedia.Framework.Data |
31 | { | 31 | { |
32 | public class Schema | 32 | public class Schema |
33 | { | 33 | { |
34 | protected TableMapper m_tableMapper; | 34 | protected TableMapper m_tableMapper; |
35 | protected Dictionary<string, FieldMapper> m_mappings; | 35 | protected Dictionary<string, FieldMapper> m_mappings; |
36 | 36 | ||
37 | public Dictionary<string, FieldMapper> Fields | 37 | public Dictionary<string, FieldMapper> Fields |
38 | { | 38 | { |
39 | get { return m_mappings; } | 39 | get { return m_mappings; } |
40 | } | 40 | } |
41 | 41 | ||
42 | public Schema(TableMapper tableMapper) | 42 | public Schema(TableMapper tableMapper) |
43 | { | 43 | { |
44 | m_mappings = new Dictionary<string, FieldMapper>(); | 44 | m_mappings = new Dictionary<string, FieldMapper>(); |
45 | m_tableMapper = tableMapper; | 45 | m_tableMapper = tableMapper; |
46 | } | 46 | } |
47 | } | 47 | } |
48 | 48 | ||
49 | public class ObjectSchema<TObj> : Schema | 49 | public class ObjectSchema<TObj> : Schema |
50 | { | 50 | { |
51 | public ObjectSchema(TableMapper tableMapper) : base(tableMapper) | 51 | public ObjectSchema(TableMapper tableMapper) : base(tableMapper) |
52 | { | 52 | { |
53 | } | 53 | } |
54 | 54 | ||
55 | public ObjectField<TObj, TField> AddMapping<TField>(string fieldName, | 55 | public ObjectField<TObj, TField> AddMapping<TField>(string fieldName, |
56 | ObjectGetAccessor<TObj, TField> rowMapperGetAccessor, | 56 | ObjectGetAccessor<TObj, TField> rowMapperGetAccessor, |
57 | ObjectSetAccessor<TObj, TField> rowMapperSetAccessor) | 57 | ObjectSetAccessor<TObj, TField> rowMapperSetAccessor) |
58 | { | 58 | { |
59 | ObjectField<TObj, TField> rowMapperField = | 59 | ObjectField<TObj, TField> rowMapperField = |
60 | new ObjectField<TObj, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); | 60 | new ObjectField<TObj, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); |
61 | 61 | ||
62 | m_mappings.Add(fieldName, rowMapperField); | 62 | m_mappings.Add(fieldName, rowMapperField); |
63 | 63 | ||
64 | return rowMapperField; | 64 | return rowMapperField; |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | public class RowMapperSchema<TRowMapper> : Schema | 68 | public class RowMapperSchema<TRowMapper> : Schema |
69 | where TRowMapper : RowMapper | 69 | where TRowMapper : RowMapper |
70 | { | 70 | { |
71 | public RowMapperSchema(TableMapper tableMapper) : base(tableMapper) | 71 | public RowMapperSchema(TableMapper tableMapper) : base(tableMapper) |
72 | { | 72 | { |
73 | } | 73 | } |
74 | 74 | ||
75 | public RowMapperField<TRowMapper, TField> AddMapping<TField>(string fieldName, | 75 | public RowMapperField<TRowMapper, TField> AddMapping<TField>(string fieldName, |
76 | RowMapperGetAccessor<TRowMapper, TField> | 76 | RowMapperGetAccessor<TRowMapper, TField> |
77 | rowMapperGetAccessor, | 77 | rowMapperGetAccessor, |
78 | RowMapperSetAccessor<TRowMapper, TField> | 78 | RowMapperSetAccessor<TRowMapper, TField> |
79 | rowMapperSetAccessor) | 79 | rowMapperSetAccessor) |
80 | { | 80 | { |
81 | RowMapperField<TRowMapper, TField> rowMapperField = | 81 | RowMapperField<TRowMapper, TField> rowMapperField = |
82 | new RowMapperField<TRowMapper, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); | 82 | new RowMapperField<TRowMapper, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor); |
83 | 83 | ||
84 | m_mappings.Add(fieldName, rowMapperField); | 84 | m_mappings.Add(fieldName, rowMapperField); |
85 | 85 | ||
86 | return rowMapperField; | 86 | return rowMapperField; |
87 | } | 87 | } |
88 | } | 88 | } |
89 | } \ No newline at end of file | 89 | } \ No newline at end of file |
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 | ||
27 | using System; | 27 | using System; |
28 | using System.Data; | 28 | using System.Data; |
29 | using System.Data.Common; | 29 | using System.Data.Common; |
30 | using TribalMedia.Framework.Data; | 30 | using TribalMedia.Framework.Data; |
31 | 31 | ||
32 | namespace TribalMedia.Framework.Data | 32 | namespace 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 |