private static IAuxiliaryDatabaseObject CreateSimpleObject(HbmDatabaseObject databaseObjectSchema) { string createText = databaseObjectSchema.FindCreateText(); string dropText = databaseObjectSchema.FindDropText(); IAuxiliaryDatabaseObject simpleObject = new SimpleAuxiliaryDatabaseObject(createText, dropText); foreach (string dialectName in databaseObjectSchema.FindDialectScopeNames()) { simpleObject.AddDialectScope(dialectName); } return simpleObject; }
private static IAuxiliaryDatabaseObject CreateHighLowScript(IDomainInspector orm) { var script = new StringBuilder(1500); script.AppendLine("DELETE FROM NextHighValues;"); script.AppendLine("ALTER TABLE NextHighValues ADD Entity VARCHAR(128);"); script.AppendLine("CREATE INDEX IdxNextHighVauesEntity ON NextHighValues (Entity ASC);"); foreach (var entity in MapConfiguration.DomainEntities().Where(orm.IsRootEntity)) { script.AppendLine(string.Format("INSERT INTO NextHighValues (Entity, NextHigh) VALUES ('{0}',1);", entity.Name)); } var sql = new SimpleAuxiliaryDatabaseObject(script.ToString(), null, new HashSet<string> { typeof (MsSql2005Dialect).FullName, typeof (MsSql2008Dialect).FullName, typeof (SQLiteDialect).FullName, typeof (Oracle10gDialect).FullName }); return sql; }
public static void CreateHighLowTable(NHibernate.Cfg.Configuration config, HiloTable hiloTable) { StringBuilder stringBuilder1 = new StringBuilder(); stringBuilder1.AppendFormat("DELETE FROM {0};", (object)hiloTable.Name); stringBuilder1.AppendLine(); stringBuilder1.AppendFormat("ALTER TABLE {0} ADD {1} VARCHAR(128);", (object)hiloTable.Name, (object)hiloTable.TableNameColumn); stringBuilder1.AppendLine(); StringBuilder stringBuilder2 = new StringBuilder(); foreach (string str in Enumerable.Distinct<string>(Enumerable.Select<PersistentClass, string>(Enumerable.Where<PersistentClass>((IEnumerable<PersistentClass>)config.ClassMappings, (Func<PersistentClass, bool>)(m => m.IdentifierProperty.Type.ReturnedClass == typeof(long))), (Func<PersistentClass, string>)(m => m.Table.Name)))) { stringBuilder2.AppendFormat(string.Format("INSERT INTO [{0}] ({1}, {2}) VALUES ('{3}', 1);", (object)hiloTable.Name, (object)hiloTable.TableNameColumn, (object)hiloTable.NextHiColumn, (object)str), new object[0]); stringBuilder2.AppendLine(); } NHibernate.Cfg.Configuration configuration1 = config; string sqlCreateString1 = ((object)stringBuilder1).ToString(); // ISSUE: variable of the null type HashedSet<string> hashedSet1 = new HashedSet<string>(); hashedSet1.Add(typeof(MsSql2005Dialect).FullName); hashedSet1.Add(typeof(MsSql2008Dialect).FullName); hashedSet1.Add(typeof(MySQL5Dialect).FullName); hashedSet1.Add(typeof(SQLiteDialect).FullName); HashedSet<string> dialectScopes1 = hashedSet1; SimpleAuxiliaryDatabaseObject auxiliaryDatabaseObject1 = new SimpleAuxiliaryDatabaseObject(sqlCreateString1, (string)"", dialectScopes1); configuration1.AddAuxiliaryDatabaseObject((IAuxiliaryDatabaseObject)auxiliaryDatabaseObject1); NHibernate.Cfg.Configuration configuration2 = config; string sqlCreateString2 = ((object)stringBuilder2).ToString(); // ISSUE: variable of the null type HashedSet<string> hashedSet2 = new HashedSet<string>(); hashedSet2.Add(typeof(MsSql2005Dialect).FullName); hashedSet2.Add(typeof(MsSql2008Dialect).FullName); hashedSet2.Add(typeof(MySQL5Dialect).FullName); hashedSet2.Add(typeof(SQLiteDialect).FullName); HashedSet<string> dialectScopes2 = hashedSet2; SimpleAuxiliaryDatabaseObject auxiliaryDatabaseObject2 = new SimpleAuxiliaryDatabaseObject(sqlCreateString2, (string)"", dialectScopes2); configuration2.AddAuxiliaryDatabaseObject((IAuxiliaryDatabaseObject)auxiliaryDatabaseObject2); }
private static void BindAuxiliaryDatabaseObject(XmlNode auxDbObjectNode, Mappings mappings) { IAuxiliaryDatabaseObject auxDbObject; XmlNode definitionNode = auxDbObjectNode.SelectSingleNode(HbmConstants.nsDefinition, nsmgr); if (definitionNode != null) { string className = XmlHelper.GetAttributeValue(definitionNode, "class"); try { auxDbObject = (IAuxiliaryDatabaseObject) Activator.CreateInstance(ReflectHelper.ClassForName(className)); Hashtable parameters = new Hashtable(); foreach (XmlNode childNode in definitionNode.ChildNodes) { parameters.Add(childNode.Attributes["name"].Value, childNode.InnerText.Trim()); } auxDbObject.SetParameterValues(parameters); } catch (TypeLoadException e) { throw new MappingException( "could not locate custom database object class [" + className + "]", e ); } catch (Exception t) { throw new MappingException( "could not instantiate custom database object class [" + className + "]", t ); } } else { auxDbObject = new SimpleAuxiliaryDatabaseObject( XmlHelper.ElementTextTrim(auxDbObjectNode, HbmConstants.nsCreate, nsmgr), XmlHelper.ElementTextTrim(auxDbObjectNode, HbmConstants.nsDrop, nsmgr) ); } foreach (XmlNode dialectScoping in auxDbObjectNode.SelectNodes(HbmConstants.nsDialectScope, nsmgr)) { auxDbObject.AddDialectScope(XmlHelper.GetAttributeValue(dialectScoping, "name")); } mappings.AddAuxiliaryDatabaseObject(auxDbObject); }