diff options
author | Sean Dague | 2008-04-24 15:00:42 +0000 |
---|---|---|
committer | Sean Dague | 2008-04-24 15:00:42 +0000 |
commit | 56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41 (patch) | |
tree | 22196fac1f26c205be8e404103d6ff4a80aaf196 /OpenSim | |
parent | replace hard tabs with 4 spaces to be consistant in the source. (diff) | |
download | opensim-SC-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.zip opensim-SC-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.gz opensim-SC-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.bz2 opensim-SC-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.xz |
auto table creation for nhibernate backends
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateAssetData.cs | 29 | ||||
-rw-r--r-- | OpenSim/Data/NHibernate/NHibernateInventoryData.cs | 29 |
2 files changed, 57 insertions, 1 deletions
diff --git a/OpenSim/Data/NHibernate/NHibernateAssetData.cs b/OpenSim/Data/NHibernate/NHibernateAssetData.cs index beac693..740868b 100644 --- a/OpenSim/Data/NHibernate/NHibernateAssetData.cs +++ b/OpenSim/Data/NHibernate/NHibernateAssetData.cs | |||
@@ -28,11 +28,13 @@ | |||
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Text.RegularExpressions; | ||
31 | using libsecondlife; | 32 | using libsecondlife; |
32 | using log4net; | 33 | using log4net; |
33 | using NHibernate; | 34 | using NHibernate; |
34 | using NHibernate.Cfg; | 35 | using NHibernate.Cfg; |
35 | using NHibernate.Mapping.Attributes; | 36 | using NHibernate.Mapping.Attributes; |
37 | using NHibernate.Tool.hbm2ddl; | ||
36 | using OpenSim.Framework; | 38 | using OpenSim.Framework; |
37 | using Environment=NHibernate.Cfg.Environment; | 39 | using Environment=NHibernate.Cfg.Environment; |
38 | 40 | ||
@@ -58,6 +60,10 @@ namespace OpenSim.Data.NHibernate | |||
58 | // Split out the dialect, driver, and connect string | 60 | // Split out the dialect, driver, and connect string |
59 | char[] split = {';'}; | 61 | char[] split = {';'}; |
60 | string[] parts = connect.Split(split); | 62 | string[] parts = connect.Split(split); |
63 | if (parts.Length != 3) { | ||
64 | // TODO: make this a real exception type | ||
65 | throw new Exception("Malformed Inventory connection string '" + connect + "'"); | ||
66 | } | ||
61 | 67 | ||
62 | // NHibernate setup | 68 | // NHibernate setup |
63 | cfg = new Configuration(); | 69 | cfg = new Configuration(); |
@@ -75,13 +81,34 @@ namespace OpenSim.Data.NHibernate | |||
75 | HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly())) | 81 | HbmSerializer.Default.Serialize(Assembly.GetExecutingAssembly())) |
76 | cfg.AddInputStream(stream); | 82 | cfg.AddInputStream(stream); |
77 | 83 | ||
84 | factory = cfg.BuildSessionFactory(); | ||
85 | |||
78 | // If uncommented this will auto create tables, but it | 86 | // If uncommented this will auto create tables, but it |
79 | // does drops of the old tables, so we need a smarter way | 87 | // does drops of the old tables, so we need a smarter way |
80 | // to acturally manage this. | 88 | // to acturally manage this. |
81 | 89 | ||
82 | // new SchemaExport(cfg).Create(true, true); | 90 | // new SchemaExport(cfg).Create(true, true); |
83 | 91 | ||
84 | factory = cfg.BuildSessionFactory(); | 92 | InitDB(); |
93 | } | ||
94 | |||
95 | private void InitDB() | ||
96 | { | ||
97 | string regex = @"no such table: Assets"; | ||
98 | Regex RE = new Regex(regex, RegexOptions.Multiline); | ||
99 | try { | ||
100 | using(ISession session = factory.OpenSession()) { | ||
101 | session.Load(typeof(AssetBase), LLUUID.Zero); | ||
102 | } | ||
103 | } catch (ObjectNotFoundException e) { | ||
104 | // yes, we know it's not there, but that's ok | ||
105 | } catch (ADOException e) { | ||
106 | Match m = RE.Match(e.ToString()); | ||
107 | if(m.Success) { | ||
108 | // We don't have this table, so create it. | ||
109 | new SchemaExport(cfg).Create(true, true); | ||
110 | } | ||
111 | } | ||
85 | } | 112 | } |
86 | 113 | ||
87 | override public AssetBase FetchAsset(LLUUID uuid) | 114 | override public AssetBase FetchAsset(LLUUID uuid) |
diff --git a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs index 938f47c..08d9dc1 100644 --- a/OpenSim/Data/NHibernate/NHibernateInventoryData.cs +++ b/OpenSim/Data/NHibernate/NHibernateInventoryData.cs | |||
@@ -29,12 +29,14 @@ using System; | |||
29 | using System.Collections.Generic; | 29 | using System.Collections.Generic; |
30 | using System.IO; | 30 | using System.IO; |
31 | using System.Reflection; | 31 | using System.Reflection; |
32 | using System.Text.RegularExpressions; | ||
32 | using libsecondlife; | 33 | using libsecondlife; |
33 | using log4net; | 34 | using log4net; |
34 | using NHibernate; | 35 | using NHibernate; |
35 | using NHibernate.Cfg; | 36 | using NHibernate.Cfg; |
36 | using NHibernate.Expression; | 37 | using NHibernate.Expression; |
37 | using NHibernate.Mapping.Attributes; | 38 | using NHibernate.Mapping.Attributes; |
39 | using NHibernate.Tool.hbm2ddl; | ||
38 | using OpenSim.Framework; | 40 | using OpenSim.Framework; |
39 | using Environment=NHibernate.Cfg.Environment; | 41 | using Environment=NHibernate.Cfg.Environment; |
40 | 42 | ||
@@ -55,6 +57,10 @@ namespace OpenSim.Data.NHibernate | |||
55 | // Split out the dialect, driver, and connect string | 57 | // Split out the dialect, driver, and connect string |
56 | char[] split = {';'}; | 58 | char[] split = {';'}; |
57 | string[] parts = connect.Split(split); | 59 | string[] parts = connect.Split(split); |
60 | if (parts.Length != 3) { | ||
61 | // TODO: make this a real exception type | ||
62 | throw new Exception("Malformed Inventory connection string '" + connect + "'"); | ||
63 | } | ||
58 | 64 | ||
59 | // Establish NHibernate Connection | 65 | // Establish NHibernate Connection |
60 | cfg = new Configuration(); | 66 | cfg = new Configuration(); |
@@ -79,8 +85,31 @@ namespace OpenSim.Data.NHibernate | |||
79 | // new SchemaExport(cfg).Create(true, true); | 85 | // new SchemaExport(cfg).Create(true, true); |
80 | 86 | ||
81 | factory = cfg.BuildSessionFactory(); | 87 | factory = cfg.BuildSessionFactory(); |
88 | |||
89 | InitDB(); | ||
82 | } | 90 | } |
83 | 91 | ||
92 | |||
93 | private void InitDB() | ||
94 | { | ||
95 | string regex = @"no such table: Inventory"; | ||
96 | Regex RE = new Regex(regex, RegexOptions.Multiline); | ||
97 | try { | ||
98 | using(ISession session = factory.OpenSession()) { | ||
99 | session.Load(typeof(InventoryItemBase), LLUUID.Zero); | ||
100 | } | ||
101 | } catch (ObjectNotFoundException e) { | ||
102 | // yes, we know it's not there, but that's ok | ||
103 | } catch (ADOException e) { | ||
104 | Match m = RE.Match(e.ToString()); | ||
105 | if(m.Success) { | ||
106 | // We don't have this table, so create it. | ||
107 | new SchemaExport(cfg).Create(true, true); | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | |||
112 | |||
84 | /***************************************************************** | 113 | /***************************************************************** |
85 | * | 114 | * |
86 | * Basic CRUD operations on Data | 115 | * Basic CRUD operations on Data |