aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/ThirdParty
diff options
context:
space:
mode:
authorlbsa712008-03-03 07:48:35 +0000
committerlbsa712008-03-03 07:48:35 +0000
commitb3b1f74485882c14478a6e74de0f7c9da13ff7d2 (patch)
tree146e00bb25325eef313336fc084d0bb102b7ab60 /ThirdParty
parentThank you very much, Ahzzmandius for: (diff)
downloadopensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.zip
opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.gz
opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.bz2
opensim-SC_OLD-b3b1f74485882c14478a6e74de0f7c9da13ff7d2.tar.xz
* Started the ardous task to rename the TribalMedia.Framework.Data to OpenSim.Framework.Data.Base
It's you !! How are you gentlemen !!
Diffstat (limited to 'ThirdParty')
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs127
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs142
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs163
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs60
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs68
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs280
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs66
-rw-r--r--ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snkbin596 -> 0 bytes
8 files changed, 0 insertions, 906 deletions
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs
deleted file mode 100644
index 67fb7c1..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDataReader.cs
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System;
28using System.Data;
29using System.IO;
30
31namespace TribalMedia.Framework.Data
32{
33 public class BaseDataReader
34 {
35 private readonly IDataReader m_source;
36
37 public BaseDataReader(IDataReader source)
38 {
39 m_source = source;
40 }
41
42 public object Get(string name)
43 {
44 return m_source[name];
45 }
46
47 public ushort GetUShort(string name)
48 {
49 return (ushort)m_source.GetInt32(m_source.GetOrdinal(name));
50 }
51
52 public byte GetByte(string name)
53 {
54 int ordinal = m_source.GetOrdinal(name);
55 byte value = (byte)m_source.GetInt16(ordinal);
56 return value;
57 }
58
59 public sbyte GetSByte(string name)
60 {
61 return (sbyte)m_source.GetInt16(m_source.GetOrdinal(name));
62 }
63
64 public float GetFloat(string name)
65 {
66 return m_source.GetFloat(m_source.GetOrdinal(name));
67 }
68
69 public byte[] GetBytes(string name)
70 {
71 int ordinal = m_source.GetOrdinal(name);
72
73 if (m_source.GetValue(ordinal) == DBNull.Value)
74 {
75 return null;
76 }
77
78 byte[] buffer = new byte[16384];
79
80 MemoryStream memStream = new MemoryStream();
81
82 long totalRead = 0;
83
84 int bytesRead;
85 do
86 {
87 bytesRead = (int)m_source.GetBytes(ordinal, totalRead, buffer, 0, buffer.Length);
88 totalRead += bytesRead;
89
90 memStream.Write(buffer, 0, bytesRead);
91 } while (bytesRead == buffer.Length);
92
93 return memStream.ToArray();
94 }
95
96 public string GetString(string name)
97 {
98 int ordinal = m_source.GetOrdinal(name);
99 object value = m_source.GetValue(ordinal);
100
101 if (value is DBNull)
102 {
103 return null;
104 }
105
106 return (string)value;
107 }
108
109 public bool Read()
110 {
111 return m_source.Read();
112 }
113
114 public Guid GetGuid(string name)
115 {
116 string guidString = GetString(name);
117 if (String.IsNullOrEmpty(guidString))
118 {
119 return Guid.Empty;
120 }
121 else
122 {
123 return new Guid(guidString);
124 }
125 }
126 }
127} \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs
deleted file mode 100644
index 45ca650..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseDatabaseConnector.cs
+++ /dev/null
@@ -1,142 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System;
28using System.Collections.Generic;
29using System.Data;
30using System.Data.Common;
31
32namespace TribalMedia.Framework.Data
33{
34 public abstract class BaseDatabaseConnector
35 {
36 protected string m_connectionString;
37
38 public BaseDatabaseConnector(string connectionString)
39 {
40 m_connectionString = connectionString;
41 }
42
43 public abstract DbConnection GetNewConnection();
44 public abstract string CreateParamName(string fieldName);
45
46 public DbCommand CreateSelectCommand(BaseTableMapper mapper, DbConnection connection, string fieldName, object key)
47 {
48 string table = mapper.TableName;
49
50 DbCommand command = connection.CreateCommand();
51
52 string conditionString = CreateCondition(mapper, command, fieldName, key);
53
54 string query =
55 String.Format("select * from {0} where {1}", table, conditionString);
56
57 command.CommandText = query;
58 command.CommandType = CommandType.Text;
59
60 return command;
61 }
62
63 public string CreateCondition(BaseTableMapper mapper, DbCommand command, string fieldName, object key)
64 {
65 string keyFieldParamName = mapper.CreateParamName(fieldName);
66
67 DbParameter param = command.CreateParameter();
68 param.ParameterName = keyFieldParamName;
69 param.Value = ConvertToDbType(key);
70 command.Parameters.Add(param);
71
72 return String.Format("{0}={1}", fieldName, keyFieldParamName);
73 }
74
75 public DbCommand CreateUpdateCommand(BaseTableMapper mapper, DbConnection connection, object rowMapper, object primaryKey)
76 {
77 string table = mapper.TableName;
78
79 List<string> fieldNames = new List<string>();
80
81 DbCommand command = connection.CreateCommand();
82
83 foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values)
84 {
85 if (fieldMapper != mapper.KeyFieldMapper)
86 {
87 fieldMapper.ExpandField(rowMapper, command, fieldNames);
88 }
89 }
90
91 List<string> assignments = new List<string>();
92
93 foreach (string field in fieldNames)
94 {
95 assignments.Add(String.Format("{0}={1}", field, mapper.CreateParamName(field)));
96 }
97
98 string conditionString = mapper.CreateCondition(command, mapper.KeyFieldMapper.FieldName, primaryKey);
99
100 command.CommandText =
101 String.Format("update {0} set {1} where {2}", table, String.Join(", ", assignments.ToArray()),
102 conditionString);
103
104 return command;
105 }
106
107 public DbCommand CreateInsertCommand(BaseTableMapper mapper, DbConnection connection, object obj)
108 {
109 string table = mapper.TableName;
110
111 List<string> fieldNames = new List<string>();
112
113 DbCommand command = connection.CreateCommand();
114
115 foreach (BaseFieldMapper fieldMapper in mapper.Schema.Fields.Values)
116 {
117 fieldMapper.ExpandField(obj, command, fieldNames);
118 }
119
120 List<string> paramNames = new List<string>();
121
122 foreach (string field in fieldNames)
123 {
124 paramNames.Add(mapper.CreateParamName(field));
125 }
126
127 command.CommandText =
128 String.Format("insert into {0} ({1}) values ({2})", table, String.Join(", ", fieldNames.ToArray()),
129 String.Join(", ", paramNames.ToArray()));
130
131 return command;
132 }
133
134 public virtual object ConvertToDbType(object value)
135 {
136 return value;
137 }
138
139 public abstract BaseDataReader CreateReader(IDataReader reader);
140 }
141
142} \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs
deleted file mode 100644
index 20f919a..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseFieldMapper.cs
+++ /dev/null
@@ -1,163 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System;
28using System.Collections.Generic;
29using System.Data.Common;
30
31namespace TribalMedia.Framework.Data
32{
33 public delegate TField ObjectGetAccessor<TObj, TField>(TObj obj);
34 public delegate void ObjectSetAccessor<TObj, TField>(TObj obj, TField value);
35
36 public abstract class BaseFieldMapper
37 {
38 private readonly BaseTableMapper m_tableMapper;
39 private readonly string m_fieldName;
40
41 public string FieldName
42 {
43 get { return m_fieldName; }
44 }
45
46 protected Type m_valueType;
47
48 public Type ValueType
49 {
50 get { return m_valueType; }
51 }
52
53 public abstract object GetParamValue(object obj);
54
55 public BaseFieldMapper(BaseTableMapper tableMapper, string fieldName, Type valueType)
56 {
57 m_fieldName = fieldName;
58 m_valueType = valueType;
59 m_tableMapper = tableMapper;
60 }
61
62 public abstract void SetPropertyFromReader(object mapper, BaseDataReader reader);
63
64 public void RawAddParam(DbCommand command, List<string> fieldNames, string fieldName, object value)
65 {
66 string paramName = m_tableMapper.CreateParamName(fieldName);
67 fieldNames.Add(fieldName);
68
69 DbParameter param = command.CreateParameter();
70 param.ParameterName = paramName;
71 param.Value = value;
72
73 command.Parameters.Add(param);
74 }
75
76 public virtual void ExpandField<TObj>(TObj obj, DbCommand command, List<string> fieldNames)
77 {
78 string fieldName = FieldName;
79 object value = GetParamValue(obj);
80
81 RawAddParam(command, fieldNames, fieldName, m_tableMapper.ConvertToDbType(value));
82 }
83
84 protected virtual object GetValue(BaseDataReader reader)
85 {
86 object value;
87
88 if (ValueType == typeof(Guid))
89 {
90 value = reader.GetGuid(m_fieldName);
91 }
92 else if (ValueType == typeof(bool))
93 {
94 uint boolVal = reader.GetUShort(m_fieldName);
95 value = (boolVal == 1);
96 }
97 else
98 if (ValueType == typeof(byte))
99 {
100 value = reader.GetByte(m_fieldName);
101 }
102 else if (ValueType == typeof(sbyte))
103 {
104 value = reader.GetSByte(m_fieldName);
105 }
106 else if (ValueType == typeof(ushort))
107 {
108 value = reader.GetUShort(m_fieldName);
109 }
110 else if (ValueType == typeof(byte[]))
111 {
112 value = reader.GetBytes(m_fieldName);
113 }
114 else
115 {
116 value = reader.Get(m_fieldName);
117 }
118
119 if (value is DBNull)
120 {
121 value = default(ValueType);
122 }
123
124 return value;
125 }
126 }
127
128 public class ObjectField<TObject, TField> : BaseFieldMapper
129 {
130 private readonly ObjectGetAccessor<TObject, TField> m_fieldGetAccessor;
131 private readonly ObjectSetAccessor<TObject, TField> m_fieldSetAccessor;
132
133 public override object GetParamValue(object obj)
134 {
135 return m_fieldGetAccessor((TObject)obj);
136 }
137
138 public override void SetPropertyFromReader(object obj, BaseDataReader reader)
139 {
140 object value;
141
142 value = GetValue(reader);
143
144 if (value == null)
145 {
146 m_fieldSetAccessor((TObject)obj, default(TField));
147 }
148 else
149 {
150 m_fieldSetAccessor((TObject)obj, (TField)value);
151 }
152 }
153
154
155 public ObjectField(BaseTableMapper tableMapper, string fieldName, ObjectGetAccessor<TObject, TField> rowMapperGetAccessor,
156 ObjectSetAccessor<TObject, TField> rowMapperSetAccessor)
157 : base(tableMapper, fieldName, typeof(TField))
158 {
159 m_fieldGetAccessor = rowMapperGetAccessor;
160 m_fieldSetAccessor = rowMapperSetAccessor;
161 }
162 }
163} \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs
deleted file mode 100644
index e8292fd..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseRowMapper.cs
+++ /dev/null
@@ -1,60 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using TribalMedia.Framework.Data;
28
29namespace TribalMedia.Framework.Data
30{
31 public abstract class BaseRowMapper
32 {
33 public abstract void FillObject(BaseDataReader reader);
34 }
35
36 public class BaseRowMapper<TObj> : BaseRowMapper
37 {
38 private readonly BaseSchema m_schema;
39 private readonly TObj m_obj;
40
41 public TObj Object
42 {
43 get { return m_obj; }
44 }
45
46 public BaseRowMapper(BaseSchema schema, TObj obj)
47 {
48 m_schema = schema;
49 m_obj = obj;
50 }
51
52 public override void FillObject(BaseDataReader reader)
53 {
54 foreach (BaseFieldMapper fieldMapper in m_schema.Fields.Values)
55 {
56 fieldMapper.SetPropertyFromReader(this, reader);
57 }
58 }
59 }
60} \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs
deleted file mode 100644
index a6740c2..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseSchema.cs
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System.Collections.Generic;
28using TribalMedia.Framework.Data;
29
30namespace TribalMedia.Framework.Data
31{
32 public class BaseSchema
33 {
34 protected BaseTableMapper m_tableMapper;
35 protected Dictionary<string, BaseFieldMapper> m_mappings;
36
37 public Dictionary<string, BaseFieldMapper> Fields
38 {
39 get { return m_mappings; }
40 }
41
42 public BaseSchema(BaseTableMapper tableMapper)
43 {
44 m_mappings = new Dictionary<string, BaseFieldMapper>();
45 m_tableMapper = tableMapper;
46 }
47 }
48
49 public class BaseSchema<TObj> : BaseSchema
50 {
51 public BaseSchema(BaseTableMapper tableMapper)
52 : base(tableMapper)
53 {
54 }
55
56 public ObjectField<TObj, TField> AddMapping<TField>(string fieldName,
57 ObjectGetAccessor<TObj, TField> rowMapperGetAccessor,
58 ObjectSetAccessor<TObj, TField> rowMapperSetAccessor)
59 {
60 ObjectField<TObj, TField> rowMapperField =
61 new ObjectField<TObj, TField>(m_tableMapper, fieldName, rowMapperGetAccessor, rowMapperSetAccessor);
62
63 m_mappings.Add(fieldName, rowMapperField);
64
65 return rowMapperField;
66 }
67 }
68} \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
deleted file mode 100644
index d69fcbb..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/BaseTableMapper.cs
+++ /dev/null
@@ -1,280 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System;
28using System.Data;
29using System.Data.Common;
30using TribalMedia.Framework.Data;
31
32namespace TribalMedia.Framework.Data
33{
34 public abstract class BaseTableMapper
35 {
36 private readonly BaseDatabaseConnector m_database;
37 private readonly object m_syncRoot = new object();
38
39 protected void WithConnection(Action<DbConnection> action)
40 {
41 lock (m_syncRoot)
42 {
43 DbConnection m_connection = m_database.GetNewConnection();
44
45 if (m_connection.State != ConnectionState.Open)
46 {
47 m_connection.Open();
48 }
49
50 action(m_connection);
51
52 if (m_connection.State == ConnectionState.Open)
53 {
54 m_connection.Close();
55 }
56 }
57 }
58
59 private readonly string m_tableName;
60 public string TableName
61 {
62 get { return m_tableName; }
63 }
64
65 protected BaseSchema m_schema;
66 public BaseSchema Schema
67 {
68 get { return m_schema; }
69 }
70
71 protected BaseFieldMapper m_keyFieldMapper;
72 public BaseFieldMapper KeyFieldMapper
73 {
74 get { return m_keyFieldMapper; }
75 }
76
77 public BaseTableMapper(BaseDatabaseConnector database, string tableName)
78 {
79 m_database = database;
80 m_tableName = tableName.ToLower(); // Stupid MySQL hack.
81 }
82
83 public string CreateParamName(string fieldName)
84 {
85 return m_database.CreateParamName(fieldName);
86 }
87
88 protected DbCommand CreateSelectCommand(DbConnection connection, string fieldName, object primaryKey)
89 {
90 return m_database.CreateSelectCommand(this, connection, fieldName, primaryKey);
91 }
92
93 public string CreateCondition(DbCommand command, string fieldName, object key)
94 {
95 return m_database.CreateCondition(this, command, fieldName, key);
96 }
97
98 public DbCommand CreateInsertCommand(DbConnection connection, object obj)
99 {
100 return m_database.CreateInsertCommand(this, connection, obj);
101 }
102
103 public DbCommand CreateUpdateCommand(DbConnection connection, object rowMapper, object primaryKey)
104 {
105 return m_database.CreateUpdateCommand(this, connection, rowMapper, primaryKey);
106 }
107
108 public object ConvertToDbType(object value)
109 {
110 return m_database.ConvertToDbType(value);
111 }
112
113 protected virtual BaseDataReader CreateReader(IDataReader reader)
114 {
115 return m_database.CreateReader(reader);
116 }
117 }
118
119 public abstract class BaseTableMapper<TRowMapper, TPrimaryKey> : BaseTableMapper
120 {
121 public BaseTableMapper(BaseDatabaseConnector database, string tableName)
122 : base(database, tableName)
123 {
124 }
125
126 // HACK: This is a temporary function used by TryGetValue().
127 // Due to a bug in mono 1.2.6, delegate blocks cannot contain
128 // a using() block. This has been fixed in SVN, so the next
129 // mono release should work.
130 private void TryGetConnectionValue(DbConnection connection, TPrimaryKey primaryKey, ref TRowMapper result, ref bool success)
131 {
132 using (
133 DbCommand command =
134 CreateSelectCommand(connection, KeyFieldMapper.FieldName, primaryKey))
135 {
136 using (IDataReader reader = command.ExecuteReader())
137 {
138 if (reader.Read())
139 {
140 result = FromReader( CreateReader(reader));
141 success = true;
142 }
143 else
144 {
145 success = false;
146 }
147 }
148 }
149 }
150
151 public bool TryGetValue(TPrimaryKey primaryKey, out TRowMapper value)
152 {
153 TRowMapper result = default(TRowMapper);
154 bool success = false;
155
156 WithConnection(delegate(DbConnection connection)
157 {
158 TryGetConnectionValue(connection, primaryKey, ref result, ref success);
159 });
160
161 value = result;
162
163 return success;
164 }
165
166 // HACK: This is a temporary function used by Remove().
167 // Due to a bug in mono 1.2.6, delegate blocks cannot contain
168 // a using() block. This has been fixed in SVN, so the next
169 // mono release should work.
170 protected virtual void TryDelete(DbConnection connection, TPrimaryKey id, ref int deleted)
171 {
172 using (
173 DbCommand command =
174 CreateDeleteCommand(connection, KeyFieldMapper.FieldName, id))
175 {
176 deleted = command.ExecuteNonQuery();
177 }
178 }
179
180 public virtual bool Remove(TPrimaryKey id)
181 {
182 int deleted = 0;
183
184 WithConnection(delegate(DbConnection connection)
185 {
186 TryDelete(connection, id, ref deleted);
187 });
188
189 if (deleted == 1)
190 {
191 return true;
192 }
193 else
194 {
195 return false;
196 }
197 }
198
199 public DbCommand CreateDeleteCommand(DbConnection connection, string fieldName, TPrimaryKey primaryKey)
200 {
201 string table = TableName;
202
203 DbCommand command = connection.CreateCommand();
204
205 string conditionString = CreateCondition(command, fieldName, primaryKey);
206
207 string query =
208 String.Format("delete from {0} where {1}", table, conditionString);
209
210 command.CommandText = query;
211 command.CommandType = CommandType.Text;
212
213 return command;
214 }
215
216 // HACK: This is a temporary function used by Update().
217 // Due to a bug in mono 1.2.6, delegate blocks cannot contain
218 // a using() block. This has been fixed in SVN, so the next
219 // mono release should work.
220 protected void TryUpdate(DbConnection connection, TPrimaryKey primaryKey, TRowMapper value, ref int updated)
221 {
222 using (DbCommand command = CreateUpdateCommand(connection, value, primaryKey))
223 {
224 updated = command.ExecuteNonQuery();
225 }
226 }
227
228 public virtual bool Update(TPrimaryKey primaryKey, TRowMapper value)
229 {
230 int updated = 0;
231
232 WithConnection(delegate(DbConnection connection)
233 {
234 TryUpdate(connection, primaryKey, value, ref updated);
235 });
236
237 if (updated == 1)
238 {
239 return true;
240 }
241 else
242 {
243 return false;
244 }
245 }
246
247 // HACK: This is a temporary function used by Add().
248 // Due to a bug in mono 1.2.6, delegate blocks cannot contain
249 // a using() block. This has been fixed in SVN, so the next
250 // mono release should work.
251 protected void TryAdd(DbConnection connection, TRowMapper value, ref int added)
252 {
253 using (DbCommand command = CreateInsertCommand(connection, value))
254 {
255 added = command.ExecuteNonQuery();
256 }
257 }
258
259 public virtual bool Add(TRowMapper value)
260 {
261 int added = 0;
262
263 WithConnection(delegate(DbConnection connection)
264 {
265 TryAdd(connection, value, ref added);
266 });
267
268 if (added == 1)
269 {
270 return true;
271 }
272 else
273 {
274 return false;
275 }
276 }
277
278 public abstract TRowMapper FromReader(BaseDataReader reader);
279 }
280} \ 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
deleted file mode 100644
index 457624e..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,66 +0,0 @@
1/*
2* Copyright (c) Tribal Media AB, http://tribalmedia.se/
3*
4* Redistribution and use in source and binary forms, with or without
5* modification, are permitted provided that the following conditions are met:
6* * Redistributions of source code must retain the above copyright
7* notice, this list of conditions and the following disclaimer.
8* * Redistributions in binary form must reproduce the above copyright
9* notice, this list of conditions and the following disclaimer in the
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
12* derived from this software without specific prior written permission.
13*
14* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
15* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
18* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
23* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24*
25*/
26
27using System.Reflection;
28using System.Runtime.InteropServices;
29using System.Security;
30
31// General Information about an assembly is controlled through the following
32// set of attributes. Change these attribute values to modify the information
33// associated with an assembly.
34
35[assembly : AssemblyTitle("TribalMedia.Framework.Data")]
36[assembly : AssemblyDescription("Generic Database Abstraction Layer")]
37[assembly : AssemblyConfiguration("")]
38[assembly : AssemblyCompany("TribalMedia")]
39[assembly : AssemblyProduct("TribalMedia.Framework.Data")]
40[assembly: AssemblyCopyright("Copyright © 2007 Tribal Media")]
41[assembly : AssemblyTrademark("")]
42[assembly : AssemblyCulture("")]
43
44// Setting ComVisible to false makes the types in this assembly not visible
45// to COM components. If you need to access a type in this assembly from
46// COM, set the ComVisible attribute to true on that type.
47
48[assembly : ComVisible(false)]
49
50// The following GUID is for the ID of the typelib if this project is exposed to COM
51
52[assembly : Guid("9269f421-19d9-4eea-bfe3-c0ffe426fada")]
53
54// Version information for an assembly consists of the following four values:
55//
56// Major Version
57// Minor Version
58// Build Number
59// Revision
60//
61// You can specify all the values or you can default the Revision and Build Numbers
62// by using the '*' as shown below:
63
64[assembly : AssemblyVersion("1.0.0.0")]
65[assembly : AssemblyFileVersion("1.0.0.0")]
66[assembly : AllowPartiallyTrustedCallers] \ No newline at end of file
diff --git a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk b/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk
deleted file mode 100644
index fc71027..0000000
--- a/ThirdParty/TribalMedia/TribalMedia.Framework.Data/TribalMedia.Framework.Data.snk
+++ /dev/null
Binary files differ