aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSean Dague2007-08-09 02:26:34 +0000
committerSean Dague2007-08-09 02:26:34 +0000
commitb097d89f38d24e9e5ceac6bf3d0d641d7559514d (patch)
tree633dfd354b92342e5a131b465b596507b8e2fbe1
parentintermediate checkin of code that compiles before I do something (diff)
downloadopensim-SC_OLD-b097d89f38d24e9e5ceac6bf3d0d641d7559514d.zip
opensim-SC_OLD-b097d89f38d24e9e5ceac6bf3d0d641d7559514d.tar.gz
opensim-SC_OLD-b097d89f38d24e9e5ceac6bf3d0d641d7559514d.tar.bz2
opensim-SC_OLD-b097d89f38d24e9e5ceac6bf3d0d641d7559514d.tar.xz
decrease insanity level significantly by factoring all the columns into
a Dictionary, and programatically building up sql commands for our dataset. Prims done, prim shapes next
-rw-r--r--OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs148
1 files changed, 46 insertions, 102 deletions
diff --git a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
index 0a73880..60736aa 100644
--- a/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
+++ b/OpenSim/Region/Storage/OpenSim.DataStore.MonoSqlite/MonoSqliteDataStore.cs
@@ -114,11 +114,50 @@ namespace OpenSim.DataStore.MonoSqliteStorage
114 return data; 114 return data;
115 } 115 }
116 116
117 private SqliteCommand createInsertCommand(Dictionary<string, DbType> defs) 117 private SqliteCommand createPrimInsertCommand(Dictionary<string, DbType> defs)
118 { 118 {
119 SqliteCommand cmd = new SqliteCommand(); 119 /**
120 * This is subtle enough to deserve some commentary.
121 * Instead of doing *lots* and *lots of hardcoded strings
122 * for database definitions we'll use the fact that
123 * realistically all insert statements look like "insert
124 * into A(b, c) values(:b, :c) on the parameterized query
125 * front. If we just have a list of b, c, etc... we can
126 * generate these strings instead of typing them out.
127 */
128 string[] cols = new string[defs.Keys.Count];
129 defs.Keys.CopyTo(cols, 0);
130
120 string sql = "insert into prims("; 131 string sql = "insert into prims(";
132 sql += String.Join(", ", cols);
133 // important, the first ':' needs to be here, the rest get added in the join
134 sql += ") values (:";
135 sql += String.Join(", :", cols);
136 sql += ")";
137 SqliteCommand cmd = new SqliteCommand(sql);
121 138
139 // this provides the binding for all our parameters, so
140 // much less code than it used to be
141 foreach (KeyValuePair<string, DbType> kvp in defs) {
142 cmd.Parameters.Add(createSqliteParameter(kvp.Key, kvp.Value));
143 }
144 return cmd;
145 }
146
147 private SqliteCommand createPrimUpdateCommand(Dictionary<string, DbType> defs)
148 {
149 string sql = "update prims set ";
150 foreach (string key in defs.Keys) {
151 sql += key + "= :" + key + ", ";
152 }
153 sql += " where UUID=:UUID";
154 SqliteCommand cmd = new SqliteCommand(sql);
155
156 // this provides the binding for all our parameters, so
157 // much less code than it used to be
158 foreach (KeyValuePair<string, DbType> kvp in defs) {
159 cmd.Parameters.Add(createSqliteParameter(kvp.Key, kvp.Value));
160 }
122 return cmd; 161 return cmd;
123 } 162 }
124 163
@@ -126,111 +165,16 @@ namespace OpenSim.DataStore.MonoSqliteStorage
126 { 165 {
127 Dictionary<string, DbType> primDataDefs = createPrimDataDefs(); 166 Dictionary<string, DbType> primDataDefs = createPrimDataDefs();
128 167
129 da.InsertCommand = createInsertCommand(primDataDefs); 168 da.InsertCommand = createPrimInsertCommand(primDataDefs);
130 /* 169 da.InsertCommand.Connection = conn;
131 * Create all the bound parameters. Try to keep these in the same order
132 * as the sql file, with comments in the same places, or your head will probably
133 * explode trying to do corolations
134 */
135 SqliteParameter UUID = createSqliteParameter("UUID", DbType.String);
136 SqliteParameter ParentID = createSqliteParameter("ParentID", DbType.Int32);
137 SqliteParameter CreationDate = createSqliteParameter("CreationDate", DbType.Int32);
138 SqliteParameter Name = createSqliteParameter("Name", DbType.String);
139 // various text fields
140 SqliteParameter Text = createSqliteParameter("Text", DbType.String);
141 SqliteParameter Description = createSqliteParameter("Description", DbType.String);
142 SqliteParameter SitName = createSqliteParameter("SitName", DbType.String);
143 SqliteParameter TouchName = createSqliteParameter("TouchName", DbType.String);
144 // permissions
145 SqliteParameter CreatorID = createSqliteParameter("CreatorID", DbType.String);
146 SqliteParameter OwnerID = createSqliteParameter("OwnerID", DbType.String);
147 SqliteParameter GroupID = createSqliteParameter("GroupID", DbType.String);
148 SqliteParameter LastOwnerID = createSqliteParameter("LastOwnerID", DbType.String);
149 SqliteParameter OwnerMask = createSqliteParameter("OwnerMask", DbType.Int32);
150 SqliteParameter NextOwnerMask = createSqliteParameter("NextOwnerMask", DbType.Int32);
151 SqliteParameter GroupMask = createSqliteParameter("GroupMask", DbType.Int32);
152 SqliteParameter EveryoneMask = createSqliteParameter("EveryoneMask", DbType.Int32);
153 SqliteParameter BaseMask = createSqliteParameter("BaseMask", DbType.Int32);
154 // vectors
155 SqliteParameter PositionX = createSqliteParameter("PositionX", DbType.Double);
156 SqliteParameter PositionY = createSqliteParameter("PositionY", DbType.Double);
157 SqliteParameter PositionZ = createSqliteParameter("PositionZ", DbType.Double);
158 SqliteParameter VelocityX = createSqliteParameter("VelocityX", DbType.Double);
159 SqliteParameter VelocityY = createSqliteParameter("VelocityY", DbType.Double);
160 SqliteParameter VelocityZ = createSqliteParameter("VelocityZ", DbType.Double);
161 SqliteParameter AngularVelocityX = createSqliteParameter("AngularVelocityX", DbType.Double);
162 SqliteParameter AngularVelocityY = createSqliteParameter("AngularVelocityY", DbType.Double);
163 SqliteParameter AngularVelocityZ = createSqliteParameter("AngularVelocityZ", DbType.Double);
164 SqliteParameter AccelerationX = createSqliteParameter("AccelerationX", DbType.Double);
165 SqliteParameter AccelerationY = createSqliteParameter("AccelerationY", DbType.Double);
166 SqliteParameter AccelerationZ = createSqliteParameter("AccelerationZ", DbType.Double);
167 // quaternions
168 SqliteParameter RotationX = createSqliteParameter("RotationX", DbType.Double);
169 SqliteParameter RotationY = createSqliteParameter("RotationY", DbType.Double);
170 SqliteParameter RotationZ = createSqliteParameter("RotationZ", DbType.Double);
171 SqliteParameter RotationW = createSqliteParameter("RotationW", DbType.Double);
172 170
171 da.UpdateCommand = createPrimUpdateCommand(primDataDefs);
172 da.UpdateCommand.Connection = conn;
173 173
174 SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID"); 174 SqliteCommand delete = new SqliteCommand("delete from prims where UUID = :UUID");
175 delete.Parameters.Add(createSqliteParameter("UUID", DbType.String));
175 delete.Connection = conn; 176 delete.Connection = conn;
176
177 SqliteCommand insert =
178 new SqliteCommand("insert into prims(" +
179 "UUID, ParentID, CreationDate, Name, " +
180 "Text, Description, SitName, TouchName, " +
181 "CreatorID, OwnerID, GroupID, LastOwnerID, " +
182 "OwnerMask, NextOwnerMask, GroupMask, EveryoneMask, BaseMask, " +
183 "PositionX, PositionY, PositionZ, " +
184 "VelocityX, VelocityY, VelocityZ, " +
185 "AngularVelocityX, AngularVelocityY, AngularVelocityZ, " +
186 "AccelerationX, AccelerationY, AccelerationZ, " +
187 "RotationX, RotationY, RotationZ, RotationW" +
188 ") values (" +
189 ":UUID, :ParentID, :CreationDate, :Name, " +
190 ":Text, :Description, :SitName, :TouchName, " +
191 ":CreatorID, :OwnerID, :GroupID, :LastOwnerID, " +
192 ":OwnerMask, :NextOwnerMask, :GroupMask, :EveryoneMask, :BaseMask, " +
193 ":PositionX, :PositionY, :PositionZ, " +
194 ":VelocityX, :VelocityY, :VelocityZ, " +
195 ":AngularVelocityX, :AngularVelocityY, :AngularVelocityZ, " +
196 ":AccelerationX, :AccelerationY, :AccelerationZ, " +
197 ":RotationX, :RotationY, :RotationZ, :RotationW)");
198
199 insert.Connection = conn;
200
201 SqliteCommand update =
202 new SqliteCommand("update prims set " +
203 "UUID = :UUID, ParentID = :ParentID, CreationDate = :CreationDate, Name = :Name, " +
204 "Text = :Text, Description = :Description, SitName = :SitName, TouchName = :TouchName, " +
205 "CreatorID = :CreatorID, OwnerID = :OwnerID, GroupID = :GroupID, LastOwnerID = :LastOwnerID, " +
206 "OwnerMask = :OwnerMask, NextOwnerMask = :NextOwnerMask, GroupMask = :GroupMask, = :EveryoneMask, = :BaseMask, " +
207 " = :PositionX, = :PositionY, = :PositionZ, " +
208 " = :VelocityX, = :VelocityY, = :VelocityZ, " +
209 " = :AngularVelocityX, = :AngularVelocityY, = :AngularVelocityZ, " +
210 " = :AccelerationX, = :AccelerationY, = :AccelerationZ, " +
211 " = :RotationX, = :RotationY, = :RotationZ, = :RotationW " +
212 "where UUID = :UUID");
213 update.Connection = conn;
214
215 delete.Parameters.Add(UUID);
216
217 insert.Parameters.Add(UUID);
218 insert.Parameters.Add(Name);
219 insert.Parameters.Add(CreationDate);
220 insert.Parameters.Add(PositionX);
221 insert.Parameters.Add(PositionY);
222 insert.Parameters.Add(PositionZ);
223
224 update.Parameters.Add(UUID);
225 update.Parameters.Add(Name);
226 update.Parameters.Add(CreationDate);
227 update.Parameters.Add(PositionX);
228 update.Parameters.Add(PositionY);
229 update.Parameters.Add(PositionZ);
230
231 da.DeleteCommand = delete; 177 da.DeleteCommand = delete;
232 da.InsertCommand = insert;
233 da.UpdateCommand = update;
234 } 178 }
235 179
236 private void StoreSceneObject(SceneObject obj) 180 private void StoreSceneObject(SceneObject obj)