public IContext GetContext(IDomainMap domainMap) { IContext context = new Context(domainMap); SetupTransactionalContext(context); return(context); }
public String ToVisualBasicCode(IDomainMap domainMap) { VBCodeProvider provider = new VBCodeProvider(); CodeCompileUnit compileunit = ToCodeCompileUnit(domainMap); return(ToCode(compileunit, provider, domainMap)); }
public void Visit(IDomainMap domainMap) { bool isFixed = domainMap.IsFixed(); if (isFixed) domainMap.UnFixate(); Hashtable newInverseProperties = new Hashtable(); foreach (IClassMap classMap in domainMap.ClassMaps) { if (classMap.ClassType.Equals(ClassType.Class) || classMap.ClassType.Equals(ClassType.Default)) { foreach (IPropertyMap propertyMap in classMap.PropertyMaps) { CreateInverseProperty(propertyMap, newInverseProperties); } } } foreach (IClassMap classMap in newInverseProperties.Keys) { if (classMap.ClassType.Equals(ClassType.Class) || classMap.ClassType.Equals(ClassType.Default)) { IList inverseProperties = (IList)newInverseProperties[classMap]; foreach (IPropertyMap inverseProperty in inverseProperties) { inverseProperty.ClassMap = classMap; } } } if (isFixed) domainMap.Fixate(); }
public virtual void Save(IDomainMap domainMap, string fileName) { string xml = Serialize(domainMap); StreamWriter str = null; try { str = File.CreateText(fileName); str.Write(xml); str.Close(); } catch (Exception ex) { if (str != null) { try { str.Close(); } catch { } throw new IOException("Could not load npersist xml mapping file!", ex); // do not localize } } }
private void GenerateAssembly(IContext context) { try { IDomainMap domainMap = context.DomainMap; ModelToCodeTransformer modelToCodeTransformer = new ModelToCodeTransformer(); CodeDomProvider provider = null; provider = new CSharpCodeProvider(); string code = modelToCodeTransformer.ToCode(domainMap, provider); CompilerResults cr = modelToCodeTransformer.ToCompilerResults(domainMap, provider); if (cr.Errors.Count > 0) { } else { Assembly domain = cr.CompiledAssembly; context.AssemblyManager.RegisterAssembly(domain); this.DomainAssembly = domain; } } catch (Exception ex) { this.DomainAssembly = null; } }
public SessionFactory(string connectionString, IDbAdapter dbAdapter, IDomainMap domainMap, Func<ISessionCache> sessionCacheProvider) { this.connectionString = connectionString; this.dbAdapter = dbAdapter; this.domainMap = domainMap; this.sessionCacheProvider = sessionCacheProvider; }
public String ToCSharpCode(IDomainMap domainMap) { CSharpCodeProvider provider = new CSharpCodeProvider(); CodeCompileUnit compileunit = ToCodeCompileUnit(domainMap); return(ToCode(compileunit, provider, domainMap)); }
private NPathQuery CreateQuery(Type type, IDictionary <string, object> match) { IDomainMap domainMap = GetContext().DomainMap; IClassMap classMap = domainMap.MustGetClassMap(type); StringBuilder query = new StringBuilder(); query.Append("Select * From " + classMap.Name); if (match != null) { if (match.Keys.Count > 0) { query.Append(" Where "); foreach (string propertyName in match.Keys) { query.Append(propertyName + " = "); query.Append("'"); query.Append(match[propertyName].ToString()); query.Append("'"); query.Append(" And "); } query.Length -= 5; } } return(new NPathQuery(query.ToString(), type)); }
public IContext GetContext() { if (context == null) { ILoggingService loggingService = engine.GetService <ILoggingService>(); if (loggingService != null) { loggingService.LogInfo(this, "Creating NPersist context"); } IConfigurationService configurationService = engine.GetService <IConfigurationService>(); string path = configurationService.SchemaFilePath; IMapSerializer serialier = new DefaultMapSerializer(); IDomainMap domainMap = DomainMap.Load(path, serialier, false, false); context = new Context(domainMap); GenerateAssembly(context); context.SetConnectionString(configurationService.ConnectionString); context.AutoTransactions = false; } return(context); }
private bool GenerateAssembly(IContext context) { try { IDomainMap domainMap = context.DomainMap; ModelToCodeTransformer modelToCodeTransformer = new ModelToCodeTransformer(); CodeDomProvider provider = null; provider = new CSharpCodeProvider(); string code = modelToCodeTransformer.ToCode(domainMap, provider); CompilerResults cr = modelToCodeTransformer.ToCompilerResults(domainMap, provider); if (cr.Errors.Count > 0) { } else { domain = cr.CompiledAssembly; context.AssemblyManager.RegisterAssembly(domain); } } catch (Exception ex) { domain = null; } if (domain == null) { return(false); } return(true); }
public virtual void SetDomainMap(IDomainMap value) { m_DomainMap = value; foreach (ITableMap tableMap in m_TableMaps) { tableMap.SetSourceMap(this); } }
public string GetMap(string domainKey) { IContext ctx = contextFactory.GetContext(domainKey); IDomainMap domainMap = ctx.DomainMap; IDomainMap stripped = DomainMapStripper.StripDomainMap(domainMap); IMapSerializer serializer = new DefaultMapSerializer(); return(serializer.Serialize(stripped)); }
public virtual void RemoveNonInverseReferences(object obj) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(obj.GetType()); IList classMaps = this.Context.DomainMap.GetClassMapsWithUniDirectionalReferenceTo(classMap, true); NullifyUniReferences(obj, classMap, classMaps); //NullifyReferencesInCache(obj, classMap, classMaps); }
public bool CompareListsById(IList newList, IList oldList) { if (newList == null || oldList == null) { if (!((newList == null && oldList == null))) { return(false); } else { return(true); } } if (!(oldList.Count == newList.Count)) { return(false); } IObjectManager om = this.Context.ObjectManager; IDomainMap dm = this.Context.DomainMap; Hashtable ids = new Hashtable(); foreach (object value in newList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); ids[id] = id; } foreach (object value in oldList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); if (!(ids.ContainsKey(id))) { return(false); } } ids = new Hashtable(); foreach (object value in oldList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); ids[id] = id; } foreach (object value in newList) { IClassMap classMap = dm.MustGetClassMap(value.GetType()); string id = classMap.GetFullName() + om.GetObjectIdentity(value); if (!(ids.ContainsKey(id))) { return(false); } } return(true); }
public virtual IClassMap GetRootClassMap(string npath, IDomainMap domainMap) { NPathParser parser = new NPathParser() ; NPathSelectQuery query = parser.ParseSelectQuery(npath) ; string className = ((NPathClassName)query.From.Classes[0]).Name; IClassMap rootClassMap = domainMap.MustGetClassMap(className); return rootClassMap; }
public static void AddMap(string key, IDomainMap map) { lock (syncRoot) { if (!ContainsKey(key)) { cache.Add(key, map); } } }
protected virtual void SerializeInlineObjectElement(XmlNode xmlObject, object obj, XmlNode xmlInline, object value, bool creating) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(value.GetType()); SerializeObject(xmlInline, value, classMap, creating, true); //hmmmmmmmmmmmmm................... this.Context.UnitOfWork.RegisterClean(value); }
public void Done(IDomainMap domainMap) { Log.Debug("Setting list maps for entity '{0}'", EntityType.Name); var listMaps = propertyMaps.Where(x => x is IListPropertyMap <T>); foreach (IListPropertyMap <T> map in listMaps) { map.SetListMap(domainMap.GetMapFor(map.ItemTpye)); } }
public static void AddMap(string key,IDomainMap map) { lock (syncRoot) { if (!ContainsKey(key)) { cache.Add(key,map) ; } } }
public static IDomainMap StripDomainMap(IDomainMap domainMap) { IDomainMap cloneMap = (IDomainMap)domainMap.DeepClone(); foreach (IClassMap classMap in cloneMap.ClassMaps) { classMap.Table = ""; classMap.TypeColumn = ""; classMap.TypeValue = ""; classMap.DocClassMapMode = DocClassMapMode.Default; classMap.DocElement = ""; classMap.DocParentProperty = ""; classMap.DocRoot = ""; foreach (IPropertyMap propertyMap in classMap.PropertyMaps) { bool isNullable = propertyMap.GetIsNullable(); bool isAssigned = propertyMap.GetIsAssignedBySource(); int maxLength = propertyMap.GetMaxLength(); propertyMap.Table = ""; propertyMap.Column = ""; propertyMap.AdditionalColumns.Clear(); propertyMap.IdColumn = ""; propertyMap.AdditionalIdColumns.Clear(); propertyMap.DocAttribute = ""; propertyMap.DocElement = ""; propertyMap.DocPropertyMapMode = DocPropertyMapMode.Default; propertyMap.InheritInverseMappings = false; propertyMap.IsNullable = isNullable; propertyMap.MaxLength = maxLength; propertyMap.IsAssignedBySource = isAssigned; } } foreach (ISourceMap sourceMap in cloneMap.SourceMaps) { sourceMap.ConnectionString = ""; sourceMap.Catalog = ""; sourceMap.DocPath = ""; sourceMap.DocEncoding = ""; sourceMap.DocRoot = ""; sourceMap.ProviderAssemblyPath = ""; sourceMap.ProviderConnectionTypeName = ""; sourceMap.ProviderType = ProviderType.SqlClient; sourceMap.Schema = ""; sourceMap.TableMaps.Clear(); } return(cloneMap); }
private IContext GetContext(string mapPath) { IMapSerializer serialier = new DefaultMapSerializer(); IDomainMap domainMap = DomainMap.Load(mapPath, serialier, false, false); IContext context = new Context(domainMap); GenerateAssembly(context); return(context); }
public static IDomainMap StripDomainMap(IDomainMap domainMap) { IDomainMap cloneMap = (IDomainMap) domainMap.DeepClone(); foreach (IClassMap classMap in cloneMap.ClassMaps) { classMap.Table = ""; classMap.TypeColumn = "" ; classMap.TypeValue = "" ; classMap.DocClassMapMode = DocClassMapMode.Default; classMap.DocElement = "" ; classMap.DocParentProperty = "" ; classMap.DocRoot = "" ; foreach (IPropertyMap propertyMap in classMap.PropertyMaps) { bool isNullable = propertyMap.GetIsNullable(); bool isAssigned = propertyMap.GetIsAssignedBySource(); int maxLength = propertyMap.GetMaxLength(); propertyMap.Table = ""; propertyMap.Column = ""; propertyMap.AdditionalColumns.Clear() ; propertyMap.IdColumn = ""; propertyMap.AdditionalIdColumns.Clear() ; propertyMap.DocAttribute = ""; propertyMap.DocElement = ""; propertyMap.DocPropertyMapMode = DocPropertyMapMode.Default; propertyMap.InheritInverseMappings = false; propertyMap.IsNullable = isNullable; propertyMap.MaxLength = maxLength; propertyMap.IsAssignedBySource = isAssigned; } } foreach (ISourceMap sourceMap in cloneMap.SourceMaps) { sourceMap.ConnectionString = ""; sourceMap.Catalog = ""; sourceMap.DocPath = ""; sourceMap.DocEncoding = ""; sourceMap.DocRoot = ""; sourceMap.ProviderAssemblyPath = ""; sourceMap.ProviderConnectionTypeName = ""; sourceMap.ProviderType = ProviderType.SqlClient; sourceMap.Schema = ""; sourceMap.TableMaps.Clear() ; } return cloneMap; }
private NPathQuery CreateQuery(Type type, string where) { IDomainMap domainMap = GetContext().DomainMap; IClassMap classMap = domainMap.MustGetClassMap(type); StringBuilder query = new StringBuilder(); query.Append("Select * From " + classMap.Name); query.Append(" Where " + where); return(new NPathQuery(query.ToString(), type)); }
public CodeCompileUnit ToCodeCompileUnit(IDomainMap domainMap) { CodeCompileUnit codeCompileUnit = new CodeCompileUnit(); foreach (IClassMap classMap in domainMap.ClassMaps) { codeCompileUnit.Namespaces.Add(ClassMapToCodeNamespace(classMap)); } return(codeCompileUnit); }
public virtual IClassMap GetRootClassMap(string npath, IDomainMap domainMap) { NPathParser parser = new NPathParser(); NPathSelectQuery query = parser.ParseSelectQuery(npath); string className = ((NPathClassName)query.From.Classes[0]).Name; IClassMap rootClassMap = domainMap.MustGetClassMap(className); return(rootClassMap); }
public String ToCode(CodeCompileUnit compileunit, CodeDomProvider provider, IDomainMap domainMap) { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); IndentedTextWriter tw = new IndentedTextWriter(sw, " "); ICodeGenerator gen = provider.CreateGenerator(tw); gen.GenerateCodeFromCompileUnit(compileunit, tw, new CodeGeneratorOptions()); string code = sb.ToString(); if (domainMap != null) { foreach (ICodeMap codeMap in domainMap.CodeMaps) { if (provider is CSharpCodeProvider && codeMap.CodeLanguage == CodeLanguage.CSharp) { code = GetDomainCodeMap(domainMap, codeMap) + code; } else if (provider is VBCodeProvider && codeMap.CodeLanguage == CodeLanguage.VB) { code = GetDomainCodeMap(domainMap, codeMap) + code; } // if (provider is DelphiCodeProvider && codeMap.CodeLanguage == CodeLanguage.Delphi) // { // code = GetDomainCodeMap(code, classMap, codeMap) + code; // } } foreach (IClassMap classMap in domainMap.ClassMaps) { foreach (ICodeMap codeMap in classMap.CodeMaps) { if (provider is CSharpCodeProvider && codeMap.CodeLanguage == CodeLanguage.CSharp) { code = InsertCodeMap(code, classMap, codeMap); } else if (provider is VBCodeProvider && codeMap.CodeLanguage == CodeLanguage.VB) { code = InsertCodeMap(code, classMap, codeMap); } // if (provider is DelphiCodeProvider && codeMap.CodeLanguage == CodeLanguage.Delphi) // { // code = InsertCodeMap(code, classMap, codeMap); // } } } } return(code); }
public void Abort() { if (domainMap != null) { ILoggingService loggingService = engine.GetService<ILoggingService>(); if (loggingService != null) loggingService.LogInfo(this, "Discarding changes to NPersist mapping file."); domainMap = null; } }
protected virtual void RemoveInsertedReferences(object obj) { IDomainMap domainMap = this.Context.DomainMap; IClassMap classMap = domainMap.MustGetClassMap(obj.GetType()); IUnitOfWork uow = this.Context.UnitOfWork; foreach (object test in uow.GetCreatedObjects()) { NullifyReferencesInInsertedObject(obj, classMap, test); } }
private string GetNamespaceDeclaration(IDomainMap domainMap, ICodeMap codeMap) { if (codeMap.CodeLanguage == CodeLanguage.CSharp) { return("namespace " + domainMap.RootNamespace + " {"); } if (codeMap.CodeLanguage == CodeLanguage.VB) { return("Namespace " + domainMap.RootNamespace); } throw new IAmOpenSourcePleaseImplementMeException(""); }
private static Assembly GetDomain(IDomainMap domainMap) { IContext context = null; if (domainMap != null) { context = new Context(domainMap); return(GenerateAssembly(context)); } return(null); }
private IContext GetContext() { //Assembly asm = this.GetType().Assembly; //string path = "Puzzle.FastForward.Web.Test.npersist"; string path = @"C:\Berlioz\Puzzle\FastForward\Puzzle.FastForward.Web\Test.npersist"; IMapSerializer serialier = new DefaultMapSerializer(); IDomainMap domainMap = DomainMap.Load(path, serialier, false, false); IContext context = new Context(domainMap); GenerateAssembly(context); return(context); }
/// <summary> /// Writes the generic DAO. /// </summary> /// <param name="path">The path.</param> /// <param name="domain">The domain.</param> private static void WriteGenericDao(string path, IDomainMap domain) { string fileName = path + "IGenericDao.cs"; using (StreamWriter file = new StreamWriter(fileName, false)) { ClassUtility.AppendHeader(file); file.WriteLine("using System.Collections.Generic;"); file.WriteLine(); file.WriteLine("namespace DOL.Database.DataAccessInterfaces"); file.WriteLine("{"); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Generic interface with base DAO methods."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <typeparam name=\"TTransferObject\">The transfer object's type.</typeparam>"); file.WriteLine(" public interface IGenericDao<TTransferObject> : IDataAccessObject"); file.WriteLine(" {"); file.WriteLine(); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Creates an object in a database."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <param name=\"obj\">The object to save.</param>"); file.WriteLine(" void Create(ref TTransferObject obj);"); file.WriteLine(); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Updates the persistent instance with data from transfer object."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <param name=\"obj\">The data.</param>"); file.WriteLine(" void Update(TTransferObject obj);"); file.WriteLine(); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Deletes an object from a database."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <param name=\"obj\">The object to delete.</param>"); file.WriteLine(" void Delete(TTransferObject obj);"); file.WriteLine(); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Gets all stored objects."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <value>all objects.</value>"); file.WriteLine(" IList<TTransferObject> SelectAll();"); file.WriteLine(); file.WriteLine(" /// <summary>"); file.WriteLine(" /// Gets the count of all stored objects."); file.WriteLine(" /// </summary>"); file.WriteLine(" /// <value>The count of all objects.</value>"); file.WriteLine(" long CountAll();"); file.WriteLine(" }"); file.WriteLine("}"); file.WriteLine(); } }
/// <summary> /// Generates all the DAO files. /// </summary> /// <param name="path">The path.</param> /// <param name="domain">The domain.</param> public virtual void GenerateAll(string path, IDomainMap domain) { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (IClassMap classMap in domain.ClassMaps) { GenerateDao(path, classMap); } }
private string GetDomainCodeMap(IDomainMap domainMap, ICodeMap codeMap) { if (codeMap.Code.Length > 0) { if (domainMap.RootNamespace.Length > 0) { string declaration = GetNamespaceDeclaration(domainMap, codeMap); string endDeclaration = GetNamespaceEndDeclaration(codeMap); return(AddCode(declaration, endDeclaration, codeMap)); } } return(""); }
public void Abort() { if (domainMap != null) { ILoggingService loggingService = engine.GetService <ILoggingService>(); if (loggingService != null) { loggingService.LogInfo(this, "Discarding changes to NPersist mapping file."); } domainMap = null; } }
public void Commit() { if (domainMap != null) { ILoggingService loggingService = engine.GetService<ILoggingService>(); if (loggingService != null) loggingService.LogInfo(this, "Saving NPersist mapping file."); string path = @"C:\Test\test.xml"; IMapSerializer serialiser = new DefaultMapSerializer(); domainMap.Save(path, serialiser); domainMap = null; } }
/// <summary> /// Generates all entity files. /// </summary> /// <param name="path">The path.</param> /// <param name="domain">The domain.</param> public static void GenerateAll(string path, IDomainMap domain) { path += "Entities\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (IClassMap classMap in domain.ClassMaps) { GenerateEntity(path, classMap); } }
public static void GenerateDaos(IDomainMap domMap) { if (Directory.Exists(MySqlConstants.BASE_PATH)) { Directory.Delete(MySqlConstants.BASE_PATH, true); } Directory.CreateDirectory(MySqlConstants.BASE_PATH); DataAccessInterfaceGenerator.GenerateAll(MySqlConstants.BASE_PATH, domMap); EntityGenerator.GenerateAll(MySqlConstants.BASE_PATH, domMap); MySqlDataAccessObjectGenerator gen = new MySqlDataAccessObjectGenerator(); gen.GenerateAll(MySqlConstants.BASE_PATH + "MySqlDAO\\", domMap); }
/// <summary> /// Generates all the DAO interface files. /// </summary> /// <param name="path">The path.</param> /// <param name="domain">The domain.</param> public static void GenerateAll(string path, IDomainMap domain) { path += "DataAccessInterfaces\\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } WriteGenericDao(path, domain); foreach (IClassMap classMap in domain.ClassMaps) { GenerateDai(path, classMap); } }
public virtual void SetDomainMap(IDomainMap value) { m_DomainMap = (DomainMap) value; foreach (IPropertyMap propertyMap in m_PropertyMaps) { propertyMap.SetClassMap(this); } }
protected virtual void DeserializeClassMap(IDomainMap domainMap, XmlNode xmlClass) { IClassMap classMap = new ClassMap(); XmlNodeList xmlProps; string str; string[] arr; classMap.DomainMap = domainMap; if (!(xmlClass.Attributes["name"] == null)) { classMap.Name = xmlClass.Attributes["name"].Value; } if (!(xmlClass.Attributes["type"] == null)) { classMap.ClassType = (ClassType) Enum.Parse(typeof (ClassType), xmlClass.Attributes["type"].Value); } if (!(xmlClass.Attributes["assembly"] == null)) { classMap.AssemblyName = xmlClass.Attributes["assembly"].Value; } if (!(xmlClass.Attributes["load-span"] == null)) { classMap.LoadSpan = xmlClass.Attributes["load-span"].Value; } if (!(xmlClass.Attributes["validate"] == null)) { classMap.ValidateMethod = xmlClass.Attributes["validate"].Value; } if (!(xmlClass.Attributes["source-class"] == null)) { classMap.SourceClass = xmlClass.Attributes["source-class"].Value; } if (!(xmlClass.Attributes["source"] == null)) { classMap.Source = xmlClass.Attributes["source"].Value; } if (!(xmlClass.Attributes["doc-source"] == null)) { classMap.DocSource = xmlClass.Attributes["doc-source"].Value; } if (!(xmlClass.Attributes["table"] == null)) { classMap.Table = xmlClass.Attributes["table"].Value; } if (!(xmlClass.Attributes["doc-element"] == null)) { classMap.DocElement = xmlClass.Attributes["doc-element"].Value; } if (!(xmlClass.Attributes["doc-root"] == null)) { classMap.DocRoot = xmlClass.Attributes["doc-root"].Value; } if (!(xmlClass.Attributes["doc-mode"] == null)) { classMap.DocClassMapMode = (DocClassMapMode) Enum.Parse(typeof (DocClassMapMode), xmlClass.Attributes["doc-mode"].Value); } if (!(xmlClass.Attributes["type-column"] == null)) { classMap.TypeColumn = xmlClass.Attributes["type-column"].Value; } if (!(xmlClass.Attributes["type-value"] == null)) { classMap.TypeValue = xmlClass.Attributes["type-value"].Value; } if (!(xmlClass.Attributes["doc-parent"] == null)) { classMap.DocParentProperty = xmlClass.Attributes["doc-parent"].Value; } if (!(xmlClass.Attributes["read-only"] == null)) { classMap.IsReadOnly = ParseBool(xmlClass.Attributes["read-only"].Value); } if (!(xmlClass.Attributes["abstract"] == null)) { classMap.IsAbstract = ParseBool(xmlClass.Attributes["abstract"].Value); } if (!(xmlClass.Attributes["inherits"] == null)) { classMap.InheritsClass = xmlClass.Attributes["inherits"].Value; } if (!(xmlClass.Attributes["id-separator"] == null)) { classMap.IdentitySeparator = xmlClass.Attributes["id-separator"].Value; } if (!(xmlClass.Attributes["key-separator"] == null)) { classMap.KeySeparator = xmlClass.Attributes["key-separator"].Value; } if (!(xmlClass.Attributes["inheritance"] == null)) { classMap.InheritanceType = (InheritanceType) Enum.Parse(typeof (InheritanceType), xmlClass.Attributes["inheritance"].Value); } if (!(xmlClass.Attributes["base"] == null)) { classMap.InheritsTransientClass = xmlClass.Attributes["base"].Value; } if (!(xmlClass.Attributes["ttl"] == null)) { classMap.TimeToLive = Int32.Parse(xmlClass.Attributes["ttl"].Value); } if (!(xmlClass.Attributes["ttl-behavior"] == null)) { classMap.TimeToLiveBehavior = (TimeToLiveBehavior) Enum.Parse(typeof (TimeToLiveBehavior), xmlClass.Attributes["ttl-behavior"].Value); } if (!(xmlClass.Attributes["load"] == null)) { classMap.LoadBehavior = (LoadBehavior) Enum.Parse(typeof (LoadBehavior), xmlClass.Attributes["load"].Value); } if (!(xmlClass.Attributes["implements"] == null)) { str = xmlClass.Attributes["implements"].Value; if (str.Length > 0) { arr = str.Split(','); foreach (string iStr in arr) { str = iStr.Trim(); if (str.Length > 0) { classMap.ImplementsInterfaces.Add(str); } } } } if (!(xmlClass.Attributes["imports"] == null)) { str = xmlClass.Attributes["imports"].Value; if (str.Length > 0) { arr = str.Split(','); foreach (string iStr in arr) { str = iStr.Trim(); if (str.Length > 0) { classMap.ImportsNamespaces.Add(str); } } } } if (!(xmlClass.Attributes["merge"] == null)) { classMap.MergeBehavior = (MergeBehaviorType) Enum.Parse(typeof (MergeBehaviorType), xmlClass.Attributes["merge"].Value); } if (!(xmlClass.Attributes["refresh"] == null)) { classMap.RefreshBehavior = (RefreshBehaviorType) Enum.Parse(typeof (RefreshBehaviorType), xmlClass.Attributes["refresh"].Value); } if (!(xmlClass.Attributes["validation"] == null)) { classMap.ValidationMode = (ValidationMode) Enum.Parse(typeof (ValidationMode), xmlClass.Attributes["validation"].Value); } if (!(xmlClass.Attributes["optimistic-delete"] == null)) { classMap.DeleteOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlClass.Attributes["optimistic-delete"].Value); } if (!(xmlClass.Attributes["optimistic-update"] == null)) { classMap.UpdateOptimisticConcurrencyBehavior = (OptimisticConcurrencyBehaviorType) Enum.Parse(typeof (OptimisticConcurrencyBehaviorType), xmlClass.Attributes["optimistic-update"].Value); } ArrayList metaData = classMap.MetaData; DeserializeMetaData(xmlClass, ref metaData); xmlProps = xmlClass.SelectNodes("property"); foreach (XmlNode xmlProp in xmlProps) { DeserializePropertyMap(classMap, xmlProp); } XmlNodeList xmlCodeMaps = xmlClass.SelectNodes("code"); foreach (XmlNode xmlCodeMap in xmlCodeMaps) { DeserializeCodeMap(classMap, xmlCodeMap); } XmlNodeList xmlEnumValueMaps = xmlClass.SelectNodes("enum-value"); foreach (XmlNode xmlEnumValueMap in xmlEnumValueMaps) { DeserializeEnumValueMap(classMap, xmlEnumValueMap); } }
protected virtual void CreateTypeColumnForClass(IClassMap classMap, IDomainMap targetDomainMap, bool generateMappings) { ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IColumnMap columnMap = null; string tableName = ""; string name = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (classMap.Table.Length > 0) { tableName = classMap.Table; } else { tableName = GetTableNameForClass(classMap); } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } if (classMap.TypeColumn.Length > 0) { name = classMap.TypeColumn; } else { name = GetTypeColumnNameForClass(classMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; if (generateMappings & classMap.TypeColumn.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } classMapClone.TypeColumn = name; } }
protected virtual void DoDeepCopy(IDomainMap domainMap) { IClassMap cloneClassMap; ISourceMap cloneSourceMap; ICodeMap cloneCodeMap; foreach (IClassMap classMap in this.ClassMaps) { cloneClassMap = (IClassMap) classMap.DeepClone(); cloneClassMap.DomainMap = domainMap; } foreach (ISourceMap sourceMap in this.SourceMaps) { cloneSourceMap = (ISourceMap) sourceMap.DeepClone(); cloneSourceMap.DomainMap = domainMap; } foreach (ICodeMap codeMap in this.CodeMaps) { cloneCodeMap = (ICodeMap) codeMap.DeepClone(); domainMap.CodeMaps.Add(cloneCodeMap); //cloneCodeMap.DomainMap = domainMap; } }
protected virtual void CreateIDColumnForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings, IClassMap ownerClassMap) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; IColumnMap columnMap = null; string classTableName = ""; string ownerClassTableName = ""; string name = ""; string forColName = ""; string tableName = ""; string foreignKeyName = ""; bool isClassTableOrConcrete = false; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.ClassMap.Table.Length > 0) { classTableName = propertyMap.ClassMap.Table; } else { classTableName = GetTableNameForClass(propertyMap.ClassMap); } if (propertyMap.Table.Length > 0) { tableName = propertyMap.Table; } else if (propertyMap.IsCollection) { tableName = GetTableNameForProperty(propertyMap); } else { if (IsOutbrokenByInheritance(propertyMap, ownerClassMap)) { isClassTableOrConcrete = true; ownerClassTableName = GetTableNameForClass(ownerClassMap, true); tableName = ownerClassTableName; } else { tableName = classTableName; } } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } foreignKeyName = "FK_" + tableMap.Name; foreach (IPropertyMap idPropertyMap in propertyMap.ClassMap.GetIdentityPropertyMaps()) { if (idPropertyMap.Column.Length > 0) { forColName = idPropertyMap.Column; } else { forColName = GetColumnNameForProperty(idPropertyMap); } foreignKeyName += "_" + forColName; } if (!(classMap.InheritanceType == InheritanceType.None)) { if (classMap.TypeColumn.Length > 0) { foreignKeyName += "_" + classMap.TypeColumn; } else { foreignKeyName += "_" + GetTypeColumnNameForClass(classMap); } } foreach (IPropertyMap idPropertyMap in propertyMap.ClassMap.GetIdentityPropertyMaps()) { if (idPropertyMap.Column.Length > 0) { forColName = idPropertyMap.Column; } else { forColName = GetColumnNameForProperty(idPropertyMap); } if (propertyMap.IdColumn.Length > 0) { name = propertyMap.IdColumn; } else { name = forColName; } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(idPropertyMap); columnMap.Length = GetColumnLengthForProperty(idPropertyMap); columnMap.Precision = GetColumnPrecisionForProperty(idPropertyMap); columnMap.Scale = GetColumnScaleForProperty(idPropertyMap); if (!(propertyMap.IsCollection)) { columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; } if (propertyMap.IsCollection || propertyMap.Table.Length > 0 || isClassTableOrConcrete) { columnMap.IsForeignKey = true; columnMap.PrimaryKeyTable = classTableName; columnMap.PrimaryKeyColumn = forColName; columnMap.ForeignKeyName = foreignKeyName; } if (generateMappings & propertyMap.IdColumn.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.IdColumn = columnMap.Name; if (tableMap.Name != classTableName) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } } if (classMap.InheritanceType != InheritanceType.None) { if (classMap.TypeColumn.Length > 0) { name = classMap.TypeColumn; } else { name = GetTypeColumnNameForClass(classMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; if (!(propertyMap.IsCollection)) { columnMap.IsPrimaryKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.AllowNulls = false; } columnMap.IsForeignKey = true; columnMap.PrimaryKeyTable = classTableName; columnMap.PrimaryKeyColumn = name; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } foreach (string iterName in propertyMapClone.AdditionalIdColumns) { if (iterName == columnMap.Name) { return; } } propertyMapClone.AdditionalIdColumns.Add(columnMap.Name); } } }
protected virtual string SerializeDomainMap(IDomainMap domainMap) { StringBuilder xml = new StringBuilder(); xml.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n"); // do not localize xml.Append("<domain name=\"" + domainMap.Name + "\""); // do not localize if (domainMap.AssemblyName.Length > 0) { xml.Append(" assembly=\"" + domainMap.AssemblyName + "\""); // do not localize } if (!(domainMap.CodeLanguage == CodeLanguage.CSharp)) { xml.Append(" language=\"" + domainMap.CodeLanguage.ToString() + "\""); // do not localize } if (domainMap.RootNamespace.Length > 0) { xml.Append(" root=\"" + domainMap.RootNamespace + "\""); // do not localize } if (domainMap.Source.Length > 0) { xml.Append(" source=\"" + domainMap.Source + "\""); // do not localize } if (domainMap.DocSource.Length > 0) { xml.Append(" doc-source=\"" + domainMap.DocSource + "\""); // do not localize } if (domainMap.IsReadOnly) { xml.Append(" read-only=\"true\""); } if (domainMap.FieldPrefix.Length > 0) { if (!(domainMap.FieldPrefix == "m_")) { xml.Append(" field-prefix=\"" + domainMap.FieldPrefix + "\""); // do not localize } } else { xml.Append(" field-prefix=\"\""); } if (!(domainMap.FieldNameStrategy == FieldNameStrategyType.None)) { xml.Append(" field-strategy=\"" + domainMap.FieldNameStrategy.ToString() + "\""); // do not localize } if (!(domainMap.MergeBehavior == MergeBehaviorType.DefaultBehavior)) { xml.Append(" merge=\"" + domainMap.MergeBehavior.ToString() + "\""); // do not localize } if (!(domainMap.RefreshBehavior == RefreshBehaviorType.DefaultBehavior)) { xml.Append(" refresh=\"" + domainMap.RefreshBehavior.ToString() + "\""); // do not localize } if (!(domainMap.UpdateOptimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior)) { xml.Append(" optimistic-update=\"" + domainMap.UpdateOptimisticConcurrencyBehavior.ToString() + "\""); // do not localize } if (!(domainMap.DeleteOptimisticConcurrencyBehavior == OptimisticConcurrencyBehaviorType.DefaultBehavior)) { xml.Append(" optimistic-delete=\"" + domainMap.DeleteOptimisticConcurrencyBehavior.ToString() + "\""); // do not localize } if (!(domainMap.ValidationMode == ValidationMode.Default)) { xml.Append(" validation=\"" + domainMap.ValidationMode.ToString() + "\""); // do not localize } if (!(domainMap.TimeToLive < 0)) { xml.Append(" ttl=\"" + domainMap.TimeToLive.ToString() + "\""); // do not localize } if (!(domainMap.TimeToLiveBehavior == TimeToLiveBehavior.Default)) { xml.Append(" ttl-behavior=\"" + domainMap.TimeToLiveBehavior.ToString() + "\""); // do not localize } if (!(domainMap.LoadBehavior == LoadBehavior.Default)) { xml.Append(" load=\"" + domainMap.LoadBehavior.ToString() + "\""); // do not localize } if (!(BareBones)) { if (domainMap.InheritsTransientClass.Length > 0) { xml.Append(" base=\"" + domainMap.InheritsTransientClass + "\""); // do not localize } if (domainMap.ImplementsInterfaces.Count > 0) { xml.Append(" implements=\""); foreach (string str in domainMap.ImplementsInterfaces) { xml.Append(str + ", "); // do not localize } xml.Length -= 2; xml.Append("\""); } if (domainMap.ImportsNamespaces.Count > 0) { xml.Append(" imports=\""); // do not localize foreach (string str in domainMap.ImportsNamespaces) { xml.Append(str + ", "); } xml.Length -= 2; xml.Append("\""); } if (domainMap.VerifyCSharpReservedWords || domainMap.VerifyVbReservedWords || domainMap.VerifyDelphiReservedWords) { xml.Append(" target-languages=\""); // do not localize if (domainMap.VerifyCSharpReservedWords) { xml.Append("cs, "); // do not localize } if (domainMap.VerifyVbReservedWords) { xml.Append("vb, "); // do not localize } if (domainMap.VerifyDelphiReservedWords) { xml.Append("delphi, "); // do not localize } xml.Length -= 2; xml.Append("\""); } if (!(domainMap.MapSerializer == MapSerializer.DefaultSerializer)) { if (domainMap.MapSerializer == MapSerializer.DotNetSerializer) { xml.Append(" serializer=\"dotnet\""); // do not localize } else if (domainMap.MapSerializer == MapSerializer.CustomSerializer) { xml.Append(" serializer=\"custom\""); // do not localize } } } xml.Append(">\r\n"); xml.Append(SerializeMetaData(domainMap.MetaData, " ")); foreach (IClassMap classMap in domainMap.ClassMaps) { xml.Append(SerializeClassMap(classMap)); } foreach (ISourceMap sourceMap in domainMap.SourceMaps) { xml.Append(SerializeSourceMap(sourceMap)); } foreach (ICodeMap codeMap in domainMap.CodeMaps) { if (codeMap.Code.Length > 0) { xml.Append(SerializeCodeMap(codeMap)); } } xml.Append("</domain>\r\n"); return xml.ToString(); }
public override string Serialize(IDomainMap domainMap) { return SerializeDomainMap(domainMap); }
protected virtual void DeserializeSourceMap(IDomainMap domainMap, XmlNode xmlSource) { ISourceMap sourceMap = new SourceMap(); XmlNode xmlConnStr; XmlNodeList xmlTables; sourceMap.DomainMap = domainMap; if (!(xmlSource.Attributes["persistence-type"] == null)) { sourceMap.PersistenceType = (PersistenceType) Enum.Parse(typeof (PersistenceType), xmlSource.Attributes["persistence-type"].Value); } if (!(xmlSource.Attributes["name"] == null)) { sourceMap.Name = xmlSource.Attributes["name"].Value; } if (!(xmlSource.Attributes["schema"] == null)) { sourceMap.Schema = xmlSource.Attributes["schema"].Value; } if (!(xmlSource.Attributes["catalog"] == null)) { sourceMap.Catalog = xmlSource.Attributes["catalog"].Value; } if (!(xmlSource.Attributes["provider"] == null)) { sourceMap.ProviderType = (ProviderType) Enum.Parse(typeof (ProviderType), xmlSource.Attributes["provider"].Value); } if (!(xmlSource.Attributes["type"] == null)) { sourceMap.SourceType = (SourceType) Enum.Parse(typeof (SourceType), xmlSource.Attributes["type"].Value); } if (!(xmlSource.Attributes["provider-path"] == null)) { sourceMap.ProviderAssemblyPath = xmlSource.Attributes["provider-path"].Value; } if (!(xmlSource.Attributes["provider-conn"] == null)) { sourceMap.ProviderConnectionTypeName = xmlSource.Attributes["provider-conn"].Value; } if (!(xmlSource.Attributes["doc-path"] == null)) { sourceMap.DocPath = xmlSource.Attributes["doc-path"].Value; } if (!(xmlSource.Attributes["doc-root"] == null)) { sourceMap.DocRoot = xmlSource.Attributes["doc-root"].Value; } if (!(xmlSource.Attributes["doc-encoding"] == null)) { sourceMap.DocEncoding = xmlSource.Attributes["doc-encoding"].Value; } if (!(xmlSource.Attributes["url"] == null)) { sourceMap.Url = xmlSource.Attributes["url"].Value; } if (!(xmlSource.Attributes["domain-key"] == null)) { sourceMap.DomainKey = xmlSource.Attributes["domain-key"].Value; } ArrayList metaData = sourceMap.MetaData; DeserializeMetaData(xmlSource, ref metaData); xmlConnStr = xmlSource.SelectSingleNode("connection-string"); if (xmlConnStr != null) { sourceMap.ConnectionString = xmlConnStr.InnerText; } xmlTables = xmlSource.SelectNodes("table"); foreach (XmlNode xmlTable in xmlTables) { DeserializeTableMap(sourceMap, xmlTable); } }
protected virtual void DeserializeCodeMap(IDomainMap domainMap, XmlNode xmlCodeMap) { ICodeMap codeMap = new CodeMap(); //codeMap.ClassMap = classMap; domainMap.CodeMaps.Add(codeMap); if (!(xmlCodeMap.Attributes["language"] == null)) { codeMap.CodeLanguage = (CodeLanguage) Enum.Parse(typeof (CodeLanguage), xmlCodeMap.Attributes["language"].Value); } codeMap.Code = xmlCodeMap.InnerText ; }
public virtual void GenerateTablesForClasses(IDomainMap sourceDomainMap, IDomainMap targetDomainMap, bool generateMappings) { GenerateTablesForClasses(sourceDomainMap, targetDomainMap, false, false); }
protected static void Init(IDomainMap domainMap) { ISourceListMap srcListMap; IClassListMap clsListMap; if (domainMap.SourceListMapPaths.Count > 0) { foreach (string filePath in domainMap.SourceListMapPaths) { srcListMap = SourceListMap.Load(filePath); foreach (ISourceMap sourceMap in srcListMap.SourceMaps) { domainMap.SourceMaps.Add(sourceMap); } } } if (domainMap.ClassListMapPaths.Count > 0) { foreach (string filePath in domainMap.ClassListMapPaths) { clsListMap = ClassListMap.Load(filePath); foreach (IClassMap classMap in clsListMap.ClassMaps) { domainMap.ClassMaps.Add(classMap); } } } domainMap.Setup(); }
public virtual void GenerateTablesForClasses(IDomainMap sourceDomainMap, IDomainMap targetDomainMap, bool generateMappings, bool onlyForComputed) { IList propertyMaps = new ArrayList(); IList allPropertyMaps; bool ok = false; IList classMaps = sourceDomainMap.GetPersistentClassMaps(); foreach (IClassMap classMap in classMaps) { if (!(classMap.SourceClass.Length > 0)) { ISourceMap sourceMap = classMap.GetSourceMap(); if (onlyForComputed && sourceMap != null && sourceMap.Compute) { if (!((classMap.IsAbstract & (classMap.InheritanceType == InheritanceType.None || (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance & !(classMap.GetInheritedClassMap() == null)))))) { if (classMap.GetTableMap() == null) { CreateTableForClass(classMap, targetDomainMap, generateMappings); } if (classMap.TypeColumn.Length > 0 || classMap.InheritanceType != InheritanceType.None) { if (classMap.GetTypeColumnMap() == null) { CreateTypeColumnForClass(classMap, targetDomainMap, generateMappings); } } } } } } foreach (IClassMap classMap in classMaps) { if (!(classMap.SourceClass.Length > 0)) { ISourceMap sourceMap = classMap.GetSourceMap(); if (onlyForComputed && sourceMap != null && sourceMap.Compute) { if (!((classMap.IsAbstract & (classMap.InheritanceType == InheritanceType.None || (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance & !(classMap.GetInheritedClassMap() == null)))))) { if (classMap.InheritanceType == InheritanceType.None) { propertyMaps = classMap.GetAllPropertyMaps(); } else if (classMap.InheritanceType == InheritanceType.SingleTableInheritance || classMap.InheritanceType == InheritanceType.ClassTableInheritance) { propertyMaps = classMap.GetNonInheritedPropertyMaps(); } else if (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance) { if (classMap.GetInheritedClassMap() == null) { propertyMaps = classMap.GetAllPropertyMaps(); } else { allPropertyMaps = classMap.GetAllPropertyMaps(); propertyMaps = new ArrayList(); foreach (IPropertyMap addPropertyMap in allPropertyMaps) { if (!(addPropertyMap.IsIdentity)) { propertyMaps.Add(addPropertyMap); } } } } foreach (IPropertyMap propertyMap in propertyMaps) { ISourceMap propSourceMap = propertyMap.GetSourceMap(); if (onlyForComputed && propSourceMap != null && propSourceMap.Compute) { if (!(propertyMap.InheritInverseMappings)) { if (propertyMap.Table.Length > 0 || propertyMap.IsCollection || IsOutbrokenByInheritance(propertyMap, classMap)) { ok = true; if (propertyMap.IsCollection) { if (propertyMap.ReferenceType == ReferenceType.ManyToOne) { ok = false; } } if (ok) { if (propertyMap.GetTableMap() == null) { CreateTableForProperty(propertyMap, targetDomainMap, generateMappings); } } } } } } } } } } foreach (IClassMap classMap in classMaps) { if (!(classMap.SourceClass.Length > 0)) { ISourceMap sourceMap = classMap.GetSourceMap(); if (onlyForComputed && sourceMap != null && sourceMap.Compute) { if (!((classMap.IsAbstract & (classMap.InheritanceType == InheritanceType.None || (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance & !(classMap.GetInheritedClassMap() == null)))))) { if (classMap.InheritanceType == InheritanceType.None) { propertyMaps = classMap.GetAllPropertyMaps(); } else if (classMap.InheritanceType == InheritanceType.SingleTableInheritance || classMap.InheritanceType == InheritanceType.ClassTableInheritance) { propertyMaps = classMap.GetNonInheritedPropertyMaps(); } else if (classMap.InheritanceType == InheritanceType.ConcreteTableInheritance) { if (classMap.GetInheritedClassMap() == null) { propertyMaps = classMap.GetAllPropertyMaps(); } else { allPropertyMaps = classMap.GetAllPropertyMaps(); propertyMaps = new ArrayList(); foreach (IPropertyMap addPropertyMap in allPropertyMaps) { if (!(addPropertyMap.IsIdentity)) { propertyMaps.Add(addPropertyMap); } } } } foreach (IPropertyMap propertyMap in propertyMaps) { ISourceMap propSourceMap = propertyMap.GetSourceMap(); if (onlyForComputed && propSourceMap != null && propSourceMap.Compute) { if (!(propertyMap.InheritInverseMappings)) { ok = true; if (propertyMap.IsCollection) { if (propertyMap.ReferenceType == ReferenceType.ManyToOne) { ok = false; } } if (ok) { if (propertyMap.IdColumn.Length > 0 || propertyMap.IsCollection || propertyMap.Table.Length > 0 || IsOutbrokenByInheritance(propertyMap, classMap)) { if (propertyMap.GetIdColumnMap() == null) { CreateIDColumnForProperty(propertyMap, targetDomainMap, generateMappings, classMap); } } if (propertyMap.GetColumnMap() == null) { CreateColumnForProperty(propertyMap, targetDomainMap, generateMappings, classMap); } } } } } } } } } }
private void Connect(IDomainMap domainMap) { bool hasSource = false; Context = GetContext(domainMap, ref hasSource); SetQuerySource(hasSource); }
protected virtual void CreateTableForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; string name = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.Table.Length > 0) { name = propertyMap.Table; } else { name = GetTableNameForProperty(propertyMap); } tableMap = addToSourceMap.GetTableMap(name); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = name; tableMap.SourceMap = addToSourceMap; } if (generateMappings & propertyMap.Table.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } }
public virtual string Serialize(IDomainMap domainMap) { return ""; }
protected virtual void CreateColumnForProperty(IPropertyMap propertyMap, IDomainMap targetDomainMap, bool generateMappings, IClassMap ownerClassMap) { IClassMap classMap = propertyMap.ClassMap; ITableMap tableMap = null; ISourceMap sourceMap = null; ISourceMap addToSourceMap = null; IClassMap classMapClone = null; IPropertyMap propertyMapClone = null; IColumnMap columnMap = null; string classTableName = ""; string name = ""; string tableName = ""; bool allowNulls = false; IClassMap refClassMap = null; string forTableName = ""; string forColumnName = ""; int cnt = 0; bool found = false; string primColName = ""; string ownerClassTableName = ""; string foreignKeyName = ""; sourceMap = classMap.GetSourceMap(); if (sourceMap == null) { sourceMap = classMap.DomainMap.GetSourceMap(); if (sourceMap == null) { throw new Exception("No default data source specified for domain model! Can't add table for class!"); } } addToSourceMap = targetDomainMap.GetSourceMap(sourceMap.Name); if (addToSourceMap == null) { addToSourceMap = (ISourceMap) sourceMap.Clone(); addToSourceMap.DomainMap = targetDomainMap; } if (propertyMap.ClassMap.Table.Length > 0) { classTableName = propertyMap.ClassMap.Table; } else { classTableName = GetTableNameForClass(propertyMap.ClassMap); } if (propertyMap.Table.Length > 0) { tableName = propertyMap.Table; } else if (propertyMap.IsCollection) { tableName = GetTableNameForProperty(propertyMap); } else { if (IsOutbrokenByInheritance(propertyMap, ownerClassMap)) { ownerClassTableName = GetTableNameForClass(ownerClassMap, true); tableName = ownerClassTableName; } else { tableName = classTableName; } } tableMap = addToSourceMap.GetTableMap(tableName); if (tableMap == null) { tableMap = new TableMap(); tableMap.Name = tableName; tableMap.SourceMap = addToSourceMap; } if (propertyMap.Column.Length > 0) { name = propertyMap.Column; } else { name = GetColumnNameForProperty(propertyMap); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(propertyMap); columnMap.Length = GetColumnLengthForProperty(propertyMap); columnMap.Precision = GetColumnPrecisionForProperty(propertyMap); columnMap.Scale = GetColumnScaleForProperty(propertyMap); allowNulls = propertyMap.IsNullable; if (propertyMap.IsIdentity) { allowNulls = false; } columnMap.AllowNulls = allowNulls; if (propertyMap.IsIdentity) { columnMap.IsPrimaryKey = true; columnMap.AllowNulls = false; if (propertyMap.ReferenceType == ReferenceType.None) { if (columnMap.DataType == DbType.Int16 || columnMap.DataType == DbType.Int32 || columnMap.DataType == DbType.Int64) { if (propertyMap.ClassMap.GetIdentityPropertyMaps().Count == 1) { if (propertyMap.GetIsAssignedBySource()) { columnMap.IsAutoIncrease = true; columnMap.Seed = 1; columnMap.Increment = 1; } } } } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { foreignKeyName = "FK_" + columnMap.TableMap.Name + "_" + columnMap.Name; refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (cnt > 0) { if (idProp.Column.Length > 0) { name = idProp.Column; } else { name = GetColumnNameForProperty(idProp); } foreignKeyName += "_" + name; } } } primColName = ""; if (refClassMap.TypeColumn.Length > 0) { primColName = refClassMap.TypeColumn; } else { if (!(refClassMap.InheritanceType == InheritanceType.None)) { primColName = GetTypeColumnNameForClass(refClassMap); } } if (primColName.Length > 0) { name = propertyMap.Name + "_" + primColName; foreignKeyName += "_" + name; } else { name = propertyMap.Name; } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { if (refClassMap.Table.Length > 0) { forTableName = refClassMap.Table; } else { forTableName = GetTableNameForClass(refClassMap); } columnMap.PrimaryKeyTable = forTableName; foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (idProp.Column.Length > 0) { forColumnName = idProp.Column; } else { forColumnName = GetColumnNameForProperty(idProp); } break; } columnMap.PrimaryKeyColumn = forColumnName; } } if (generateMappings & propertyMap.Column.Length < 1) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; } propertyMapClone.Column = columnMap.Name; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } if (!(propertyMap.ReferenceType == ReferenceType.None)) { refClassMap = propertyMap.GetReferencedClassMap(); if (!(refClassMap == null)) { foreach (IPropertyMap idProp in refClassMap.GetIdentityPropertyMaps()) { if (cnt > 0) { if (idProp.Column.Length > 0) { name = idProp.Column; } else { name = GetColumnNameForProperty(idProp); } columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = GetColumnTypeForProperty(idProp); columnMap.Length = GetColumnLengthForProperty(idProp); columnMap.Precision = GetColumnPrecisionForProperty(idProp); columnMap.Scale = GetColumnScaleForProperty(idProp); columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.PrimaryKeyTable = forTableName; if (idProp.Column.Length > 0) { forColumnName = idProp.Column; } else { forColumnName = GetColumnNameForProperty(idProp); } columnMap.PrimaryKeyColumn = forColumnName; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } found = false; foreach (string iterName in propertyMapClone.AdditionalColumns) { if (iterName == columnMap.Name) { found = true; } } if (!(found)) { propertyMapClone.AdditionalColumns.Add(columnMap.Name); } } } cnt += 1; } if (refClassMap.InheritanceType != InheritanceType.None) { if (refClassMap.TypeColumn.Length > 0) { primColName = refClassMap.TypeColumn; } else { primColName = GetTypeColumnNameForClass(refClassMap); } name = propertyMap.Name + "_" + primColName; columnMap = tableMap.GetColumnMap(name); if (columnMap == null) { columnMap = new ColumnMap(); columnMap.Name = name; columnMap.TableMap = tableMap; } columnMap.DataType = DbType.AnsiStringFixedLength; columnMap.Length = 1; columnMap.Precision = 1; columnMap.Scale = 0; columnMap.AllowNulls = true; if (propertyMap.IsIdentity) { columnMap.AllowNulls = false; } columnMap.IsForeignKey = true; columnMap.ForeignKeyName = foreignKeyName; columnMap.PrimaryKeyTable = forTableName; columnMap.PrimaryKeyColumn = primColName; if (generateMappings) { classMapClone = targetDomainMap.GetClassMap(classMap.Name); if (classMapClone == null) { classMapClone = (IClassMap) classMap.Clone(); if (tableMap.Name == classTableName) { classMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == targetDomainMap.Source)) { classMapClone.Source = addToSourceMap.Name; } } classMapClone.DomainMap = targetDomainMap; } propertyMapClone = classMapClone.GetPropertyMap(propertyMap.Name); if (propertyMapClone == null) { propertyMapClone = (IPropertyMap) propertyMap.Clone(); propertyMapClone.ClassMap = classMapClone; if (!(tableMap.Name == classTableName)) { propertyMapClone.Table = tableMap.Name; if (!(addToSourceMap.Name == classMapClone.Source)) { if (!(addToSourceMap.Name == targetDomainMap.Source)) { propertyMapClone.Source = addToSourceMap.Name; } } } } found = false; foreach (string iterName in propertyMapClone.AdditionalColumns) { if (iterName == columnMap.Name) { found = true; } } if (!(found)) { propertyMapClone.AdditionalColumns.Add(columnMap.Name); } } } } } }
private void Start(IDomainMap domainMap) { LoadDomainMap(domainMap); }