Breaking Changes. Upgrade Script in Sql directory. Deployed
This commit is contained in:
1 parent
d4cfa92848
commit
9ed5843dbd
86 files changed
+2616
-2358
No files matched your search
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using System.Reflection;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
|
||||
namespace Tanshu.Accounts.SqlDAO
|
||||
{
|
||||
public static class AttributeChecker
|
||||
{
|
||||
public static bool Cascade(ICustomAttributeProvider provider)
|
||||
{
|
||||
return provider.GetCustomAttributes(typeof(CascadeAttribute), false).Length == 1;
|
||||
}
|
||||
public static bool Unique(ICustomAttributeProvider provider)
|
||||
{
|
||||
return provider.GetCustomAttributes(typeof(UniqueAttribute), false).Length == 1;
|
||||
}
|
||||
public static bool NotNull(ICustomAttributeProvider provider)
|
||||
{
|
||||
return provider.GetCustomAttributes(typeof(NotNullAttribute), false).Length == 1;
|
||||
}
|
||||
public static bool Formula(ICustomAttributeProvider provider)
|
||||
{
|
||||
return provider.GetCustomAttributes(typeof(FormulaAttribute), false).Length == 1;
|
||||
}
|
||||
public static string GetFormula(ICustomAttributeProvider provider)
|
||||
{
|
||||
var vv = (FormulaAttribute)provider.GetCustomAttributes(typeof(FormulaAttribute), false)[0];
|
||||
return vv.Formula;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using FluentNHibernate.Conventions;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
|
||||
namespace Tanshu.Accounts.SqlDAO
|
||||
{
|
||||
@@ -14,29 +17,18 @@ namespace Tanshu.Accounts.SqlDAO
|
||||
public void Apply(IManyToOneInstance instance)
|
||||
{
|
||||
var property = instance.Property;
|
||||
|
||||
if (!HasAttribute(property.MemberInfo)) return;
|
||||
|
||||
Console.WriteLine("CascadeAll on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
|
||||
if (!AttributeChecker.Cascade(property.MemberInfo)) return;
|
||||
Trace.TraceInformation("CascadeAll on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
instance.Cascade.All();
|
||||
}
|
||||
|
||||
public void Apply(IOneToManyCollectionInstance instance)
|
||||
{
|
||||
var property = instance.Member;
|
||||
|
||||
if (!HasAttribute(property)) return;
|
||||
|
||||
Console.WriteLine("CascadeAllDeleteOrphan on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
|
||||
if (!AttributeChecker.Cascade(property)) return;
|
||||
Trace.TraceInformation("CascadeAllDeleteOrphan on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
instance.Cascade.AllDeleteOrphan();
|
||||
}
|
||||
|
||||
bool HasAttribute(ICustomAttributeProvider provider)
|
||||
{
|
||||
return provider.GetCustomAttributes(typeof(CascadeAttribute), false).Length == 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,25 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using FluentNHibernate.Conventions;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tanshu.Accounts.SqlDAO
|
||||
{
|
||||
public class ClassConvention : IClassConvention
|
||||
public class ClassConvention : IClassConvention, IClassConventionAcceptance
|
||||
{
|
||||
public void Apply(IClassInstance instance)
|
||||
{
|
||||
string table = Inflector.Pluralize(instance.EntityType.Name);
|
||||
table = instance.EntityType.Namespace.Substring(instance.EntityType.Namespace.LastIndexOf('.') + 1) + "_" + table;
|
||||
Trace.TraceInformation(string.Format("Table for {0}: {1}", instance.EntityType.Name, table));
|
||||
instance.Table(table);
|
||||
//instance.Cache.NonStrictReadWrite();
|
||||
}
|
||||
|
||||
public void Accept(IAcceptanceCriteria<IClassInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => !x.EntityType.IsEnum);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using FluentNHibernate;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
@@ -16,39 +17,12 @@ namespace Tanshu.Accounts.Conventions
|
||||
|| (x.Property.PropertyType.IsGenericType &&
|
||||
x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
|
||||
x.Property.PropertyType.GetGenericArguments()[0].IsEnum)));
|
||||
//criteria.Expect(x => x.Property.PropertyType.IsEnum);
|
||||
}
|
||||
|
||||
public void Apply(IPropertyInstance target)
|
||||
{
|
||||
Trace.TraceInformation(string.Format("Custom Enum for {0}.{1}", target.EntityType.Name, target.Property.Name));
|
||||
target.CustomType(target.Property.PropertyType);
|
||||
}
|
||||
}
|
||||
|
||||
//public class EnumConvention : IPropertyConvention, IPropertyConventionAcceptance
|
||||
//{
|
||||
// #region IPropertyConvention Members
|
||||
|
||||
// public void Apply(IPropertyInstance instance)
|
||||
// {
|
||||
// instance.CustomType(instance.Property.PropertyType);
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region IPropertyConventionAcceptance Members
|
||||
|
||||
// public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
|
||||
// {
|
||||
// criteria.Expect(x => x.Property.PropertyType.IsEnum ||
|
||||
// (x.Property.PropertyType.IsGenericType &&
|
||||
// x.Property.PropertyType.GetGenericTypeDefinition() == typeof(Nullable<>) &&
|
||||
// x.Property.PropertyType.GetGenericArguments()[0].IsEnum)
|
||||
// );
|
||||
// }
|
||||
|
||||
// #endregion
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,9 @@ using Tanshu.Accounts.Entities.Auth;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using System.Reflection;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using System;
|
||||
using System.IO;
|
||||
using NHibernate.Cfg;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@@ -14,10 +17,7 @@ namespace Tanshu.Accounts.Repository
|
||||
public static bool CreateSchema()
|
||||
{
|
||||
var cfg = SessionManager.Configuration;
|
||||
new SchemaExport(cfg).Execute(true, true, true);
|
||||
new SchemaExport(cfg).Execute(true, true, false);
|
||||
// next line is just for checking how the nhibernate xml configuration files look
|
||||
//persistenceModel.WriteMappingsTo(@"C:\Temp");
|
||||
Recreate(cfg);
|
||||
Fixtures.InsertRole();
|
||||
Fixtures.InsertUser();
|
||||
Fixtures.InsertGroup();
|
||||
@@ -37,7 +37,26 @@ namespace Tanshu.Accounts.Repository
|
||||
InsertProductGroupModifier();
|
||||
return true;
|
||||
}
|
||||
private static void Recreate(Configuration cfg)
|
||||
{
|
||||
new SchemaExport(cfg).Execute(true, true, true);
|
||||
new SchemaExport(cfg).Execute(true, true, false);
|
||||
}
|
||||
private static void Update(Configuration cfg)
|
||||
{
|
||||
string path = @"C:\Users\tanshu\update.sql";
|
||||
Action<string> updateExport = x =>
|
||||
{
|
||||
using (var file = new FileStream(path, FileMode.Create, FileAccess.Write))
|
||||
using (var sw = new StreamWriter(file))
|
||||
{
|
||||
sw.Write(x);
|
||||
sw.Close();
|
||||
}
|
||||
};
|
||||
new SchemaUpdate(cfg).Execute(updateExport, true);
|
||||
|
||||
}
|
||||
#region role
|
||||
public static void InsertRole()
|
||||
{
|
||||
@@ -399,15 +418,15 @@ namespace Tanshu.Accounts.Repository
|
||||
#region settle_option
|
||||
public static void InsertSettleOption()
|
||||
{
|
||||
using (var session = SessionManager.StatelessSession)
|
||||
{
|
||||
session.Insert(SettleOptionFactory.OUnsettled);
|
||||
session.Insert(SettleOptionFactory.OCash);
|
||||
session.Insert(SettleOptionFactory.OCreditCard);
|
||||
session.Insert(SettleOptionFactory.ONoCharge);
|
||||
session.Insert(SettleOptionFactory.OBillToCompany);
|
||||
session.Insert(SettleOptionFactory.OStaff);
|
||||
}
|
||||
//using (var session = SessionManager.StatelessSession)
|
||||
//{
|
||||
// session.Insert(SettleOption.Unsettled);
|
||||
// session.Insert(SettleOption.Cash);
|
||||
// session.Insert(SettleOption.CreditCard);
|
||||
// session.Insert(SettleOption.NoCharge);
|
||||
// session.Insert(SettleOption.BillToCompany);
|
||||
// session.Insert(SettleOption.Staff);
|
||||
//}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using FluentNHibernate.Conventions;
|
||||
using System.Reflection;
|
||||
using FluentNHibernate;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
public class FormulaConvention : IPropertyConvention, IPropertyConventionAcceptance
|
||||
{
|
||||
public void Apply(IPropertyInstance instance)
|
||||
{
|
||||
var property = instance.Property;
|
||||
Trace.TraceInformation("Formula on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
instance.Formula(AttributeChecker.GetFormula(property.MemberInfo));
|
||||
instance.Generated.Always();
|
||||
}
|
||||
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => AttributeChecker.Formula(x.Property.MemberInfo));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,28 @@
|
||||
//using System;
|
||||
//using FluentNHibernate.Conventions;
|
||||
//using System.Reflection;
|
||||
//using FluentNHibernate;
|
||||
//using FluentNHibernate.Conventions.Instances;
|
||||
//using FluentNHibernate.Conventions.Inspections;
|
||||
//using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
//using Tanshu.Accounts.Contracts;
|
||||
using System;
|
||||
using FluentNHibernate.Conventions;
|
||||
using System.Reflection;
|
||||
using FluentNHibernate;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using System.Diagnostics;
|
||||
|
||||
//namespace Tanshu.Accounts.Conventions
|
||||
//{
|
||||
// public class NotNullConvention : IPropertyConvention
|
||||
// {
|
||||
// public void Apply(IPropertyInstance instance)
|
||||
// {
|
||||
// instance.Not.Nullable();
|
||||
// }
|
||||
// }
|
||||
namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
public class NotNullConvention : IPropertyConvention, IPropertyConventionAcceptance
|
||||
{
|
||||
public void Apply(IPropertyInstance instance)
|
||||
{
|
||||
var property = instance.Property;
|
||||
Trace.TraceInformation("Not Null on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
instance.Not.Nullable();
|
||||
}
|
||||
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => AttributeChecker.NotNull(x.Property.MemberInfo));
|
||||
}
|
||||
}
|
||||
|
||||
//}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ using FluentNHibernate.Conventions;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
@@ -13,6 +14,7 @@ namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
public void Apply(IIdentityInstance instance)
|
||||
{
|
||||
Trace.TraceInformation("PK on {0}.{1}", instance.EntityType.Name, instance.EntityType.Name + "ID");
|
||||
instance.Column(instance.EntityType.Name + "ID");
|
||||
//instance.GeneratedBy.Assigned();
|
||||
//instance.Access.ReadOnlyPropertyThroughCamelCaseField(CamelCasePrefix.None);
|
||||
@@ -20,8 +22,7 @@ namespace Tanshu.Accounts.Conventions
|
||||
|
||||
public void Accept(IAcceptanceCriteria<IIdentityInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => x.Name.EndsWith("ID"));
|
||||
criteria.Expect(x => x.Name == x.EntityType.Name + "ID");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using FluentNHibernate.Conventions;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using NHibernate;
|
||||
using NHibernate.SqlCommand;
|
||||
using System.Diagnostics;
|
||||
using Tanshu.Accounts.Entities;
|
||||
|
||||
namespace Tanshu.Accounts.SqlDAO
|
||||
{
|
||||
public static class SettleOptionFactory
|
||||
{
|
||||
public static SettleOption OUnsettled = new SettleOption() { SettleOptionID = 1, Name = "Unsettled" };
|
||||
public static SettleOption OCash = new SettleOption() { SettleOptionID = 2, Name = "Cash" };
|
||||
public static SettleOption OCreditCard = new SettleOption() { SettleOptionID = 3, Name = "CreditCard" };
|
||||
public static SettleOption ONoCharge = new SettleOption() { SettleOptionID = 4, Name = "NoCharge" };
|
||||
public static SettleOption OBillToCompany = new SettleOption() { SettleOptionID = 5, Name = "BillToCompany" };
|
||||
public static SettleOption OStaff = new SettleOption() { SettleOptionID = 6, Name = "Staff" };
|
||||
|
||||
public static int Unsettled = 1;
|
||||
public static int Cash = 2;
|
||||
public static int CreditCard = 3;
|
||||
public static int NoCharge = 4;
|
||||
public static int BillToCompany = 5;
|
||||
public static int Staff = 6;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace Tanshu.Accounts.Repository
|
||||
private readonly ISessionFactory factory;
|
||||
private SessionManager()
|
||||
{
|
||||
cfg = GetConfiguration();
|
||||
cfg = BuildConfiguration();
|
||||
factory = cfg.BuildSessionFactory();
|
||||
}
|
||||
|
||||
@@ -41,7 +41,11 @@ namespace Tanshu.Accounts.Repository
|
||||
internal static readonly SessionManager sessionManager = new SessionManager();
|
||||
}
|
||||
|
||||
public Configuration GetConfiguration()
|
||||
private Configuration GetConfiguration()
|
||||
{
|
||||
return cfg;
|
||||
}
|
||||
private Configuration BuildConfiguration()
|
||||
{
|
||||
var storeConfiguration = new StoreConfiguration();
|
||||
var persistenceModel = AutoMap.AssemblyOf<Voucher>(storeConfiguration)
|
||||
@@ -51,10 +55,11 @@ namespace Tanshu.Accounts.Repository
|
||||
c.Add<CustomForeignKeyConvention>();
|
||||
c.Add<ClassConvention>();
|
||||
c.Add<CascadeConvention>();
|
||||
c.Add<UniqueConvention>();
|
||||
c.Add<NotNullConvention>();
|
||||
c.Add<FormulaConvention>();
|
||||
//c.Add<AllowNullConvention>();
|
||||
//c.Add<NotNullConvention>();
|
||||
//c.Add(DefaultLazy.Never());
|
||||
//c.Add<EnumConvention>();
|
||||
c.Add<EnumConvention>();
|
||||
});
|
||||
|
||||
return Fluently.Configure()
|
||||
@@ -63,11 +68,11 @@ namespace Tanshu.Accounts.Repository
|
||||
.BuildConfiguration()
|
||||
.SetInterceptor(new NHSQLInterceptor());
|
||||
}
|
||||
public ISession GetSession()
|
||||
private ISession GetSession()
|
||||
{
|
||||
return factory.OpenSession();
|
||||
}
|
||||
public IStatelessSession GetStatelessSession()
|
||||
private IStatelessSession GetStatelessSession()
|
||||
{
|
||||
return factory.OpenStatelessSession();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using FluentNHibernate;
|
||||
using FluentNHibernate.Automapping;
|
||||
using Tanshu.Accounts.Entities;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
|
||||
namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
@@ -8,7 +10,10 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
public override bool ShouldMap(Type type)
|
||||
{
|
||||
return type.Namespace.StartsWith("Tanshu.Accounts.Entities");
|
||||
bool val = type.Namespace.StartsWith("Tanshu.Accounts.Entities");
|
||||
if (type.IsEnum)
|
||||
val = false;
|
||||
return val;
|
||||
}
|
||||
public override bool IsId(Member member)
|
||||
{
|
||||
@@ -19,5 +24,16 @@ namespace Tanshu.Accounts.Repository
|
||||
{
|
||||
return true;
|
||||
}
|
||||
public override string SimpleTypeCollectionValueColumn(Member member)
|
||||
{
|
||||
return base.SimpleTypeCollectionValueColumn(member);
|
||||
}
|
||||
public override bool ShouldMap(Member member)
|
||||
{
|
||||
//if (AttributeChecker.Formula(member.MemberInfo))
|
||||
// return false;
|
||||
//else
|
||||
return base.ShouldMap(member);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using FluentNHibernate.Conventions;
|
||||
using System.Reflection;
|
||||
using FluentNHibernate;
|
||||
using FluentNHibernate.Conventions.Instances;
|
||||
using FluentNHibernate.Conventions.Inspections;
|
||||
using FluentNHibernate.Conventions.AcceptanceCriteria;
|
||||
using Tanshu.Accounts.Contracts;
|
||||
using Tanshu.Accounts.SqlDAO;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tanshu.Accounts.Conventions
|
||||
{
|
||||
public class UniqueConvention : IPropertyConvention, IPropertyConventionAcceptance
|
||||
{
|
||||
public void Apply(IPropertyInstance instance)
|
||||
{
|
||||
var property = instance.Property;
|
||||
Trace.TraceInformation("Unique on {0}.{1}", property.DeclaringType.Name, property.Name);
|
||||
instance.Unique();
|
||||
}
|
||||
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
|
||||
{
|
||||
criteria.Expect(x => AttributeChecker.Unique(x.Property.MemberInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user