aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/NHibernate/NHibernateInventoryData.cs
diff options
context:
space:
mode:
authorSean Dague2008-04-24 15:00:42 +0000
committerSean Dague2008-04-24 15:00:42 +0000
commit56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41 (patch)
tree22196fac1f26c205be8e404103d6ff4a80aaf196 /OpenSim/Data/NHibernate/NHibernateInventoryData.cs
parentreplace hard tabs with 4 spaces to be consistant in the source. (diff)
downloadopensim-SC_OLD-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.zip
opensim-SC_OLD-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.gz
opensim-SC_OLD-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.bz2
opensim-SC_OLD-56ef67ec6d6cdc4c09dc7147d82c5dbe1400ef41.tar.xz
auto table creation for nhibernate backends
Diffstat (limited to 'OpenSim/Data/NHibernate/NHibernateInventoryData.cs')
-rw-r--r--OpenSim/Data/NHibernate/NHibernateInventoryData.cs29
1 files changed, 29 insertions, 0 deletions
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;
29using System.Collections.Generic; 29using System.Collections.Generic;
30using System.IO; 30using System.IO;
31using System.Reflection; 31using System.Reflection;
32using System.Text.RegularExpressions;
32using libsecondlife; 33using libsecondlife;
33using log4net; 34using log4net;
34using NHibernate; 35using NHibernate;
35using NHibernate.Cfg; 36using NHibernate.Cfg;
36using NHibernate.Expression; 37using NHibernate.Expression;
37using NHibernate.Mapping.Attributes; 38using NHibernate.Mapping.Attributes;
39using NHibernate.Tool.hbm2ddl;
38using OpenSim.Framework; 40using OpenSim.Framework;
39using Environment=NHibernate.Cfg.Environment; 41using 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