糟糕的代码设计真的让人很心烦..

刚进公司不到一个月, 现在正在进行一个项目开发,项目里使用 Hibernate2 + Struts1.2,正常情况下这是一个相当好的组

 

合,但是现在由于DAO层代码几乎全由MyExclipse 生成,不知是否由于MyExclipse 版本过低,生成的代码中大量使用了继

 

承,而且最主要的,项目管理人几乎没有进行重写的想法,他们的意思是:这些我们都用了很久,都很熟悉了;但是项目项目进度的

 

发展,这些问题也越来越突出,由于采用MyEclipse 自动生成的代码,在调用DAO对象前要先执行初始化,如:

try {
	_BaseRootDAO.initialize();
	dao = XXXDAO.getInstance();
} catch (HibernateException e) {
	e.printStackTrace();
}

 

然后才能调用,我想对它做个封装,可是对它这个初始化实在束手无测,现在我只能简单的把这些业务单独做个类来封闭,让它

 

不与WEB层混淆在一起,但是这样并不能彻底解决问题,我封闭的这些类中重复的代码实在太多,我也试过对这些代码进行重

 

构,可是由于现在项目也经进行到一半了,项目开发由多个人一同进行,我如果更改了原始代码结构,必然会引起别人代码不能

 

正常运行,可是每次自己读到这些代码,特别是自己还要参与到其中,真的很心烦.....

 

我应该如何做呢,难道企业里开发都这样吗? 大家能否给点建议..

展开阅读全文

缓存过期不回调,这真的让人很郁闷

01-11

来看一个最简单的rn void Application_End(object sender, EventArgs e) rn rn // 在应用程序关闭时运行的代码rnrn rn rn void Application_Error(object sender, EventArgs e) rn rn // 在出现未处理的错误时运行的代码rnrn rnrn void Session_Start(object sender, EventArgs e) rn rn // 在新会话启动时运行的代码rnrn rnrn void Session_End(object sender, EventArgs e) rn rn // 在会话结束时运行的代码。 rn // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为rn // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer rn // 或 SQLServer,则不会引发该事件。rnrn rnrnrn static void onRemove(string key, Object item, CacheItemRemovedReason reason)rn rnrnrn StreamWriter sw = File.AppendText(HttpContext.Current.Server.MapPath(".") + "\\IPRecord.txt");rn sw.Write("key:");rn sw.Write(key);rn sw.Write(" value:");rn sw.Write(item.ToString());rn sw.Write(" 移除 时间: ");rn sw.Write(System.DateTime.Now.ToString());rn sw.Write(".");rn sw.Write(System.DateTime.Now.Millisecond.ToString());rn sw.WriteLine("");rn sw.Flush();rn sw.Close();rn rn HttpRuntime.Cache.Insert("Key", DateTime.Now, null, DateTime.Now.AddSeconds(10),rn Cache.NoSlidingExpiration, CacheItemPriority.Default,rn new CacheItemRemovedCallback(onRemove));rn rn rn rnrn void Application_Start(Object sender, EventArgs e)rn rn StreamWriter sw = File.AppendText(HttpContext.Current.Server.MapPath(".") + "\\IPRecord.txt");rn sw.Write("key:");rn sw.Write(" Key ");rn sw.Write(" value:");rn sw.Write(DateTime.Now.ToString());rn sw.Write(" 建立 时间: ");rn sw.Write(System.DateTime.Now.ToString());rn sw.Write(".");rn sw.Write(System.DateTime.Now.Millisecond.ToString());rn sw.WriteLine("");rn sw.Flush();rn sw.Close();rn rn HttpRuntime.Cache.Insert("Key", DateTime.Now, null, DateTime.Now.AddSeconds(10),rn Cache.NoSlidingExpiration, CacheItemPriority.Default,rn new CacheItemRemovedCallback(onRemove));rn rnrnrn//rn运行rnrn结果 IPRecord.txt中就一条,无论多长时间就一条,只有建立时的日志rnrnkey: Key value:2008-1-11 9:31:16 建立 时间: 2008-1-11 9:31:16.859rnrnrn没脾气了.把MSDN的例子拷到vs2005里面,把时间调成10秒过期,方便调试.....rnrnpublic static class ReportManagerrnrn private static bool _reportRemovedFromCache = false;rn static ReportManager()rn rnrn public static String GetReport()rn rn lock (typeof(ReportManager))rn rn if (HttpContext.Current.Cache["MyReport"] != null)rn return (string)HttpRuntime.Cache["MyReport"];rn elsern rn CacheReport();rn return (string)HttpRuntime.Cache["MyReport"];rn rn rn rnrn public static void CacheReport()rn rn lock (typeof(ReportManager))rn rn HttpContext.Current.Cache.Add("MyReport",rn CreateReport(), null, DateTime.Now.AddSeconds(10),rn TimeSpan.Zero,rn System.Web.Caching.CacheItemPriority.Default,rn ReportRemovedCallback);rnrn StreamWriter sw = File.AppendText(HttpContext.Current.Server.MapPath(".") + "\\IPRecord.txt");rn //记录建立rn sw.Write(" MyReport 创建 时间: ");rn sw.Write(System.DateTime.Now.ToString());rn sw.Write(".");rn sw.Write(System.DateTime.Now.Millisecond.ToString());rn sw.WriteLine("");rn sw.Flush();rn sw.Close();rn rn rnrn private static string CreateReport()rn rn System.Text.StringBuilder myReport =rn new System.Text.StringBuilder();rn myReport.Append("Sales Report ");rn myReport.Append("2005 Q2 Figures ");rn myReport.Append("Sales NE Region - $2 million ");rn myReport.Append("Sales NW Region - $4.5 million ");rn myReport.Append("Report Generated: " + DateTime.Now.ToString()rn + " ");rn myReport.Append("Report Removed From Cache: " +rn _reportRemovedFromCache.ToString());rn return myReport.ToString();rn rnrn public static void ReportRemovedCallback(String key, object value,rn CacheItemRemovedReason removedReason)rn rn //记录移除rn StreamWriter sw = File.AppendText(HttpContext.Current.Server.MapPath(".") + "\\IPRecord.txt");rn sw.Write("key:");rn sw.Write(key);rn sw.Write(" value:");rn sw.Write(value.ToString());rn sw.Write(" 移除 时间: ");rn sw.Write(System.DateTime.Now.ToString());rn sw.Write(".");rn sw.Write(System.DateTime.Now.Millisecond.ToString());rn sw.WriteLine("");rn sw.Flush();rn sw.Close();rnrn _reportRemovedFromCache = true;rn CacheReport();rn rnrnrnrn结果一样..rn还是只能跟踪到缓存建立时的记录rnrn....什么破玩意,真怀疑这些人有没有测试rnrn 论坛

没有更多推荐了,返回首页