add mysql code
parent
e0ff4ffbdf
commit
f60094505b
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
<ReferencePath>../../../bin</ReferencePath>
|
<ReferencePath>../../../bin</ReferencePath>
|
||||||
<Reference name="System" localCopy="false"/>
|
<Reference name="System" localCopy="false"/>
|
||||||
|
<Reference name="System.Data"/>
|
||||||
<Reference name="System.Xml"/>
|
<Reference name="System.Xml"/>
|
||||||
<Reference name="log4net.dll" path="../../../bin"/>
|
<Reference name="log4net.dll" path="../../../bin"/>
|
||||||
<Reference name="Nini.dll" path="../../../bin"/>
|
<Reference name="Nini.dll" path="../../../bin"/>
|
||||||
|
@ -25,6 +26,7 @@
|
||||||
<Reference name="OpenSim.Services.Interfaces" path="../../../bin"/>
|
<Reference name="OpenSim.Services.Interfaces" path="../../../bin"/>
|
||||||
<Reference name="OpenSim.Server.Base" path="../../../bin"/>
|
<Reference name="OpenSim.Server.Base" path="../../../bin"/>
|
||||||
<Reference name="OpenSim.Data" path="../../../bin"/>
|
<Reference name="OpenSim.Data" path="../../../bin"/>
|
||||||
|
<Reference name="MySQL.Data" path="../../../bin"/>
|
||||||
<Files>
|
<Files>
|
||||||
<Match pattern="*.cs" recurse="true"/>
|
<Match pattern="*.cs" recurse="true"/>
|
||||||
</Files>
|
</Files>
|
||||||
|
|
|
@ -98,6 +98,8 @@ namespace OpenSim.Modules.DataValue
|
||||||
if (m_storage == null)
|
if (m_storage == null)
|
||||||
m_storage = new Memory();
|
m_storage = new Memory();
|
||||||
|
|
||||||
|
m_log.Info("[" + Name + "] Using '" + m_storageTyp + "' as Storage.");
|
||||||
|
|
||||||
m_scriptModule = m_scene.RequestModuleInterface<IScriptModuleComms>();
|
m_scriptModule = m_scene.RequestModuleInterface<IScriptModuleComms>();
|
||||||
if (m_scriptModule != null)
|
if (m_scriptModule != null)
|
||||||
{
|
{
|
||||||
|
@ -122,16 +124,16 @@ namespace OpenSim.Modules.DataValue
|
||||||
{
|
{
|
||||||
if(m_storage != null)
|
if(m_storage != null)
|
||||||
{
|
{
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
||||||
|
|
||||||
|
if (_element != null)
|
||||||
|
return _element.get();
|
||||||
|
|
||||||
|
checkRateLimit();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
|
||||||
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
|
||||||
|
|
||||||
if (_element != null)
|
|
||||||
return _element.get();
|
|
||||||
|
|
||||||
checkRateLimit();
|
|
||||||
|
|
||||||
String _data = m_storage.get(_host.GroupID.ToString(), key);
|
String _data = m_storage.get(_host.GroupID.ToString(), key);
|
||||||
|
|
||||||
if (_data == null)
|
if (_data == null)
|
||||||
|
@ -155,19 +157,19 @@ namespace OpenSim.Modules.DataValue
|
||||||
{
|
{
|
||||||
if (m_storage != null)
|
if (m_storage != null)
|
||||||
{
|
{
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
||||||
|
|
||||||
|
if (_element != null)
|
||||||
|
{
|
||||||
|
_element.save(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkRateLimit();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
|
||||||
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
|
||||||
|
|
||||||
if (_element != null)
|
|
||||||
{
|
|
||||||
_element.save(value);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkRateLimit();
|
|
||||||
|
|
||||||
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, value, m_storage));
|
m_cache.Add(new StorageElement(_host.GroupID.ToString(), key, value, m_storage));
|
||||||
m_storage.save(_host.GroupID.ToString(), key, value);
|
m_storage.save(_host.GroupID.ToString(), key, value);
|
||||||
return;
|
return;
|
||||||
|
@ -183,15 +185,15 @@ namespace OpenSim.Modules.DataValue
|
||||||
[ScriptInvocation]
|
[ScriptInvocation]
|
||||||
public void osDeleteDataValue(UUID hostID, UUID scriptID, string key, string value)
|
public void osDeleteDataValue(UUID hostID, UUID scriptID, string key, string value)
|
||||||
{
|
{
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
||||||
|
|
||||||
|
checkRateLimit();
|
||||||
|
|
||||||
if (m_storage != null)
|
if (m_storage != null)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
|
||||||
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
|
||||||
|
|
||||||
checkRateLimit();
|
|
||||||
|
|
||||||
if (_element != null)
|
if (_element != null)
|
||||||
m_cache.Remove(_element);
|
m_cache.Remove(_element);
|
||||||
|
|
||||||
|
@ -212,16 +214,16 @@ namespace OpenSim.Modules.DataValue
|
||||||
{
|
{
|
||||||
if (m_storage != null)
|
if (m_storage != null)
|
||||||
{
|
{
|
||||||
|
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
||||||
|
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
||||||
|
|
||||||
|
if (_element != null)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
checkRateLimit();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SceneObjectGroup _host = m_scene.GetSceneObjectGroup(hostID);
|
|
||||||
StorageElement _element = m_cache.Find(X => X.Group == _host.GroupID.ToString() && X.Index == key);
|
|
||||||
|
|
||||||
if (_element != null)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
checkRateLimit();
|
|
||||||
|
|
||||||
if (m_storage.check(_host.GroupID.ToString(), key))
|
if (m_storage.check(_host.GroupID.ToString(), key))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using MySql.Data.MySqlClient;
|
||||||
using Nini.Config;
|
using Nini.Config;
|
||||||
using OpenSim.Region.Framework.Scenes;
|
using OpenSim.Region.Framework.Scenes;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Data;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
|
|
||||||
namespace OpenSim.Modules.DataValue.Storage
|
namespace OpenSim.Modules.DataValue.Storage
|
||||||
{
|
{
|
||||||
|
@ -15,30 +18,106 @@ namespace OpenSim.Modules.DataValue.Storage
|
||||||
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
|
|
||||||
private Scene m_scene = null;
|
private Scene m_scene = null;
|
||||||
|
private Timer m_timer = null;
|
||||||
|
private String m_connectionString = null;
|
||||||
|
|
||||||
|
private MySqlConnection m_mySQLClient = null;
|
||||||
|
|
||||||
public MySQL(Scene scene, IConfig config)
|
public MySQL(Scene scene, IConfig config)
|
||||||
{
|
{
|
||||||
m_scene = scene;
|
m_scene = scene;
|
||||||
|
|
||||||
|
m_connectionString = config.GetString("DataValueConnectionString", String.Empty).ToUpper().Trim();
|
||||||
|
|
||||||
|
if (m_connectionString == String.Empty)
|
||||||
|
return;
|
||||||
|
|
||||||
|
m_timer = new Timer();
|
||||||
|
m_timer.Interval = 10000;
|
||||||
|
m_timer.Elapsed += mysqlping;
|
||||||
|
m_timer.Start();
|
||||||
|
|
||||||
|
m_mySQLClient = new MySqlConnection(m_connectionString);
|
||||||
|
m_mySQLClient.Open();
|
||||||
|
createEmptyTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mysqlping(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
if (!m_mySQLClient.Ping())
|
||||||
|
m_mySQLClient.Open();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool check(String storageID, string key)
|
public bool check(String storageID, string key)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using (MySqlCommand _mysqlCommand = m_mySQLClient.CreateCommand())
|
||||||
|
{
|
||||||
|
_mysqlCommand.CommandText = "Select StorageID, StorageKey FROM ?mysqlTable WHERE StorageID = ?mysqlStorage AND StorageKey = ?mysqlStorageKey";
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlTable", "StorageData");
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorage", storageID);
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorageKey", key);
|
||||||
|
|
||||||
|
using (IDataReader _mysqlReader = _mysqlCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (_mysqlReader["StorageKey"] != null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string get(String storageID, string key)
|
public string get(String storageID, string key)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using (MySqlCommand _mysqlCommand = m_mySQLClient.CreateCommand())
|
||||||
|
{
|
||||||
|
_mysqlCommand.CommandText = "Select StorageID, StorageKey, StorageData FROM ?mysqlTable WHERE StorageID = ?mysqlStorage AND StorageKey = ?mysqlStorageKey";
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlTable", "StorageData");
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorage", storageID);
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorageKey", key);
|
||||||
|
|
||||||
|
using (IDataReader _mysqlReader = _mysqlCommand.ExecuteReader())
|
||||||
|
{
|
||||||
|
if (_mysqlReader["StorageData"] != null)
|
||||||
|
return _mysqlReader["StorageData"].ToString();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove(string storageID, string key)
|
public void remove(string storageID, string key)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using (MySqlCommand _mysqlCommand = m_mySQLClient.CreateCommand())
|
||||||
|
{
|
||||||
|
_mysqlCommand.CommandText = "DELETE FROM ?mysqlTable WHERE StorageID = ?mysqlStorage AND StorageKey = ?mysqlStorageKey";
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlTable", "StorageData");
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorage", storageID);
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorageKey", key);
|
||||||
|
_mysqlCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(String storageID, string key, string data)
|
public void save(String storageID, string key, string data)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
using (MySqlCommand _mysqlCommand = m_mySQLClient.CreateCommand())
|
||||||
|
{
|
||||||
|
_mysqlCommand.CommandText = "REPLACE INTO ?mysqlTable (StorageID, StorageKey, StorageData) VALUES (?mysqlStorage, ?mysqlStorageKey, ?mysqlStorageData)";
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlTable", "StorageData");
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorage", storageID);
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorageKey", key);
|
||||||
|
_mysqlCommand.Parameters.AddWithValue("?mysqlStorageData", data);
|
||||||
|
_mysqlCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createEmptyTable()
|
||||||
|
{
|
||||||
|
using (MySqlCommand _mysqlCommand = m_mySQLClient.CreateCommand())
|
||||||
|
{
|
||||||
|
_mysqlCommand.CommandText = "CREATE TABLE IF NOT EXISTS `StorageData` (`StorageID` VARCHAR(36) NOT NULL, `StorageKey` VARCHAR(256) NOT NULL, `StorageData` TEXT NOT NULL DEFAULT '', PRIMARY KEY(`StorageID`, `StorageKey`)) COLLATE = 'utf8_general_ci'; ";
|
||||||
|
_mysqlCommand.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue