人要有夢想

          為夢想努力

          常用鏈接

          統(tǒng)計

          j2ee

          最新評論

          2006年5月23日 #

          架構之web framework- struts

          []?

          Martin.guo

          ?

          J2ee 架構中一般都要考慮 Web Framework 的選擇。很多人選擇比較流行的 Struts 。項目組中遇到過這樣的情況,有些人不熟悉 Struts ,而有些人又對 Struts 青睞有加。有沒有一個折中的辦法來滿足所有的人呢?

          ?

          我是這樣設計的:

          通過攔截提交到 ActionServlet 上的 http 請求,經(jīng)過 Http Parse 來收集請求參數(shù),以 Name-Value 的形式存放為請求值對象,并且放在請求線程相關的上下文中。這個時候你就可以在 Action 執(zhí)行結束前的任何地方拿到這些請求數(shù)據(jù)了。

          ?

          在這個基礎上,我們保留了 Struts Action ,并且規(guī)定 Action execute 方法里不能出現(xiàn)任何跟業(yè)務相關的代碼 , 僅僅是負責頁面的流轉(zhuǎn)。

          ?

          那么業(yè)務怎么辦呢?我們定義了一個接口 Command, 它也只有一個方法 , 我們也取名字為 execute, 并且沒有任何參數(shù)和返回數(shù)值。該方法的職責就是執(zhí)行業(yè)務邏輯。這個時候你就要問了。 Action 里抽離業(yè)務邏輯,怎么調(diào)用 Command 呢?請求提交的數(shù)據(jù)怎么給 Command ?Command 執(zhí)行完后的業(yè)務數(shù)據(jù)怎么返回?

          ?

          我們設計了一個業(yè)務執(zhí)行器,它的功能就是執(zhí)行 Command 的業(yè)務邏輯實現(xiàn) . 而把執(zhí)行器的執(zhí)行寫到了 Action 里面。這樣就隔離了頁面流轉(zhuǎn)和業(yè)務執(zhí)行。 Action 的代碼顯的很簡練和模板化。

          ?

          由于請求數(shù)據(jù)是放在請求線程相關的上下文中,所以可以很方便的拿到。同時 Command 執(zhí)行完畢的返回數(shù)據(jù)也是通過這個上下文返回給 Action 或者其他跟此請求線程相關的組件,說白一點就是此線程能夠跑到的任何代碼處都可以去跟上下文交互,存取線程相關的數(shù)據(jù)和服務。

          ?

          設計到此為止,已經(jīng)可以回答開頭的問題了。

          ?

          對于熟悉 Struts 的人呢,可以積極放心的使用 Struts 標簽,使用 Formbean, 但有一點就是自己要把 FormBean 放到線程相關的上下文中,這樣你就可以在 Command 里面去拿出來工作了,同時 Command 執(zhí)行完畢后,你就可以順手把返回數(shù)據(jù)填充到這個 FormBean 里面去了。跟你平時使用沒有太大區(qū)別。

          ?

          而對于不熟悉的人呢,你可能不喜歡寫 Struts 標簽,也可能不喜歡死板的 Formbean, 那么 OK ,你完全不用關心這些,你只要直接在 Command 里面去寫邏輯代碼就可以了。但有一點就是要,你要手工把返回的數(shù)據(jù)集合放到 request 里面去,然后到流轉(zhuǎn)的 JSP 里面取出來展示。

          ?

          OK ,皆大歡喜。

          ?

          ?

          msn:gdq123@hotmail.com

          posted @ 2006-06-07 19:29 人要有夢想 閱讀(1174) | 評論 (3)編輯 收藏

          軟件架構師之架構過程概要

          軟件架構是軟件系統(tǒng)一個高層次的結構體現(xiàn),顯示了系統(tǒng)分解后組件的布局和組件之間的關系。好的架構描述應該包含架構的多個視角,組件的設計和擴展描述,以及為滿足功能性需求和非功能性需求的設計原則。
          一般說,軟件架構分為5個步驟,
          1.建立架構的任務并且形成架構團隊。
          2.建立并且文檔化架構需求。
          3.設計架構
          4.驗證架構是否達到需求
          5.發(fā)布架構到開發(fā)團隊

          然后我們細說這五步驟
          第一,架構是需要有目標的,一般是為了滿足長期的業(yè)務需求。然后去制定任務并且明確里程碑。讓架構組的每個人都明確架構的目標以及任務的進行和任務之間的關系。總體架構設想這個時候需要出來了。關鍵組件設想也應該有了。
          第二,這個時候就需要按照目標去分開整理架構的需求了。開始可能是很多的需求索引,每個索引就是一兩句話的表達。對于索引要給出簡單的描述。索引評審之后需要細化需求,是一個更為詳細的需求整理,除了文字描述,還可以配置圖形等。然后要做的就是建立use case去覆蓋這些需求。
          第三,設計架構可以分為概要設計和詳細設計階段。概要設計需要給出一個比較輪廓性的設計說明,能夠比較簡要的通過這些設計元素去闡述use case,在總體上把故事講完整。然后評審,進入詳細設計階段,細化的設計更為完整和貼近實現(xiàn)。同樣需要一個說故事的過程,把use case通過詳細設計的元素說的更為生動和形象。然后去實現(xiàn)和整合。
          第四,驗證的過程是測試的一個過程,在需求階段會確立很多測試計劃和用例。對需求進行一個掃蕩,看實現(xiàn)是否到達了承諾。
          第五,不斷測試并且反饋修改之后,穩(wěn)定版本就可以發(fā)布到開發(fā)團隊了。


          個人觀點,請大家多討論。


          架構的設計部分
          1。更應該側重組建的分解以及組件之間的接口關系。比一般的軟件設計過程,更突出組件的接口特性和使用描述。組件的功能列表,生命周期,并發(fā)情況說明,通訊消息格式等。
          2。架構中的組件是有統(tǒng)一的架構思想和原則。組件是要被約束的。
          3。組件需要提供事例代碼,典型應用場景,異常以及測試說明。
          4。組件有時候是要映射到物理視圖中的進程。
          5。側重架構系統(tǒng)的動態(tài)特性,組件之間的協(xié)作關系。



          msn:gdq123@hotmail.com

          posted @ 2006-06-01 11:34 人要有夢想 閱讀(2700) | 評論 (5)編輯 收藏

          軟件架構師

          軟件架構師是什么?需要什么樣的知識體系?如何成為優(yōu)秀的軟件架構師呢?

          第一個問題:
          軟件架構師一詞應該是對應系統(tǒng)架構師,都是架構師,但側重不同。在4+1視圖中,我覺得如果把架構師分為這兩種的話,軟件架構師應該是站在邏輯視圖和開發(fā)視圖的角度,而系統(tǒng)架構師則更多的是過程視圖和物理視圖。當然,這兩個角色就象是人的兩個眼睛,缺少一個都會定位不準確,容易是系統(tǒng)目標偏離。

          當然了,現(xiàn)實世界中,一般這兩中角色集中在一個人身上體現(xiàn)出來,或者一個小組。很多公司都不設置此類職位;有的公司則分工很細。

          第二個問題:
          知識體系不好說,只說重點的吧。
          軟件架構師的職責是把需求轉(zhuǎn)換為軟件世界的模型。4+1視圖中以use case作為核心,其中功能性需求以及部分非功能性需求會被軟件架構師通過分析和設計,映射為各種軟件設計模型。從OOA/OOD角度說,use case 在這個過程中是要轉(zhuǎn)換為各種UML,其中類圖,序列圖,狀態(tài)圖是最常用到的。這個轉(zhuǎn)換過程是需要智慧的,use case是目的,各種OO的原則是指導,設計模式是經(jīng)驗,靈活運用是能力。里面蘊涵了設計的美感,我覺得這個過程是衡量一個軟件架構師的最重要的指標。

          當然這個過程是迭代和反饋的,我覺得概要設計和詳細設計只是思考同一個問題的粒度不同而已。

          另外就是我們要熟悉語言,詳細設計是要轉(zhuǎn)換為代碼的,而且跟語言是有關系的。語言比如java/c++等,詳細設計的模型是有很多不同的。就需要軟件架構師有過這個過程,并且是非常良好的映射。

          除了語言就是要熟悉某個技術領域,比如J2EE/DOTnet.從J2ee來說,可能需要了解比如jsp/servlet/ejb/jndi/jta/jdbc等。還需要了解各種web framework,o/rmapping,ioc/aop容器等等。還有的就是一些技術組件和業(yè)務組件,不如workflow,rules engine等等。另外比如各種database.熟悉這些東西的目的,是把這些軟件和組件合理并且有機的組織起來成為一個開發(fā)的架構。這個過程是需要創(chuàng)造力和想象力的。可能很多人認為這個地方正是軟件架構師體現(xiàn)能力的地方。

          第三個問題:
          我不是很清楚,但我認為意志和想象力能夠使每個有目標的人達到彼岸。




          msn:gdq123@hotmail.com

          posted @ 2006-05-30 13:31 人要有夢想 閱讀(5638) | 評論 (1)編輯 收藏

          SQL 例子 轉(zhuǎn)載

          -1、查找員工的編號、姓名、部門和出生日期,如果出生日期為空值,
          --顯示日期不詳,并按部門排序輸出,日期格式為yyyy-mm-dd。
          select emp_no ,emp_name ,dept ,
          isnull(convert(char(10),birthday,120),'日期不詳') birthday
          from employee
          order by dept
          --2、查找與喻自強在同一個單位的員工姓名、性別、部門和職稱
          select emp_no,emp_name,dept,title
          from employee
          where emp_name<>'喻自強' and dept in
          (select dept from employee
          where emp_name='喻自強')

          --3、按部門進行匯總,統(tǒng)計每個部門的總工資
          select dept,sum(salary)
          from employee
          group by dept

          --4、查找商品名稱為14寸顯示器商品的銷售情況,
          --顯示該商品的編號、銷售數(shù)量、單價和金額
          select a.prod_id,qty,unit_price,unit_price*qty totprice
          from sale_item a,product b
          where a.prod_id=b.prod_id and prod_name='14寸顯示器'

          --5、在銷售明細表中按產(chǎn)品編號進行匯總,統(tǒng)計每種產(chǎn)品的銷售數(shù)量和金額
          select prod_id,sum(qty) totqty,sum(qty*unit_price) totprice
          from sale_item
          group by prod_id

          --6、使用convert函數(shù)按客戶編號統(tǒng)計每個客戶1996年的訂單總金額
          select cust_id,sum(tot_amt) totprice
          from sales
          where convert(char(4),order_date,120)='1996'
          group by cust_id

          --7、查找有銷售記錄的客戶編號、名稱和訂單總額
          select a.cust_id,cust_name,sum(tot_amt) totprice
          from customer a,sales b
          where a.cust_id=b.cust_id
          group by a.cust_id,cust_name

          --8、查找在1997年中有銷售記錄的客戶編號、名稱和訂單總額
          select a.cust_id,cust_name,sum(tot_amt) totprice
          from customer a,sales b
          where a.cust_id=b.cust_id and convert(char(4),order_date,120)='1997'
          group by a.cust_id,cust_name

          --9、查找一次銷售最大的銷售記錄
          select order_no,cust_id,sale_id,tot_amt
          from sales
          where tot_amt=
          (select max(tot_amt)
          from sales)

          --10、查找至少有3次銷售的業(yè)務員名單和銷售日期
          select emp_name,order_date
          from employee a,sales b
          where emp_no=sale_id and a.emp_no in
          (select sale_id
          from sales
          group by sale_id
          having count(*)>=3)
          order by emp_name

          --11、用存在量詞查找沒有訂貨記錄的客戶名稱
          select cust_name
          from customer a
          where not exists
          (select *
          from sales b
          where a.cust_id=b.cust_id)

          --12、使用左外連接查找每個客戶的客戶編號、名稱、訂貨日期、訂單金額
          --訂貨日期不要顯示時間,日期格式為yyyy-mm-dd
          --按客戶編號排序,同一客戶再按訂單降序排序輸出
          select a.cust_id,cust_name,convert(char(10),order_date,120),tot_amt
          from customer a left outer join sales b on a.cust_id=b.cust_id
          order by a.cust_id,tot_amt desc

          --13、查找16M DRAM的銷售情況,要求顯示相應的銷售員的姓名、
          --性別,銷售日期、銷售數(shù)量和金額,其中性別用男、女表示
          select emp_name 姓名, 性別= case a.sex when 'm' then '男'
          when 'f' then '女'
          else '未'
          end,
          銷售日期= isnull(convert(char(10),c.order_date,120),'日期不詳'),
          qty 數(shù)量, qty*unit_price as 金額
          from employee a, sales b, sale_item c,product d
          where d.prod_name='16M DRAM' and d.prod_id=c.prod_id and
          a.emp_no=b.sale_id and b.order_no=c.order_no

          --14、查找每個人的銷售記錄,要求顯示銷售員的編號、姓名、性別、
          --產(chǎn)品名稱、數(shù)量、單價、金額和銷售日期
          select emp_no 編號,emp_name 姓名, 性別= case a.sex when 'm' then '男'
          when 'f' then '女'
          else '未'
          end,
          prod_name 產(chǎn)品名稱,銷售日期= isnull(convert(char(10),c.order_date,120),'日期不詳'),
          qty 數(shù)量, qty*unit_price as 金額
          from employee a left outer join sales b on a.emp_no=b.sale_id , sale_item c,product d
          where d.prod_id=c.prod_id and b.order_no=c.order_no

          --15、查找銷售金額最大的客戶名稱和總貨款
          select cust_name,d.cust_sum
          from customer a,
          (select cust_id,cust_sum
          from (select cust_id, sum(tot_amt) as cust_sum
          from sales
          group by cust_id ) b
          where b.cust_sum =
          ( select max(cust_sum)
          from (select cust_id, sum(tot_amt) as cust_sum
          from sales
          group by cust_id ) c )
          ) d
          where a.cust_id=d.cust_id

          --16、查找銷售總額少于1000元的銷售員編號、姓名和銷售額
          select emp_no,emp_name,d.sale_sum
          from employee a,
          (select sale_id,sale_sum
          from (select sale_id, sum(tot_amt) as sale_sum
          from sales
          group by sale_id ) b
          where b.sale_sum <1000
          ) d
          where a.emp_no=d.sale_id

          --17、查找至少銷售了3種商品的客戶編號、客戶名稱、商品編號、商品名稱、數(shù)量和金額
          select a.cust_id,cust_name,b.prod_id,prod_name,d.qty,d.qty*d.unit_price
          from customer a, product b, sales c, sale_item d
          where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
          c.order_no=d.order_no and a.cust_id in (
          select cust_id
          from (select cust_id,count(distinct prod_id) prodid
          from (select cust_id,prod_id
          from sales e,sale_item f
          where e.order_no=f.order_no) g
          group by cust_id
          having count(distinct prod_id)>=3) h )

          --18、查找至少與世界技術開發(fā)公司銷售相同的客戶編號、名稱和商品編號、商品名稱、數(shù)量和金額
          select a.cust_id,cust_name,d.prod_id,prod_name,qty,qty*unit_price
          from customer a, product b, sales c, sale_item d
          where a.cust_id=c.cust_id and d.prod_id=b.prod_id and
          c.order_no=d.order_no and not exists
          (select f.*
          from customer x ,sales e, sale_item f
          where cust_name='世界技術開發(fā)公司' and x.cust_id=e.cust_id and
          e.order_no=f.order_no and not exists
          ( select g.*
          from sale_item g, sales h
          where g.prod_id = f.prod_id and g.order_no=h.order_no and
          h.cust_id=a.cust_id)
          )

          19、查找表中所有姓劉的職工的工號,部門,薪水
          select emp_no,emp_name,dept,salary
          from employee
          where emp_name like '劉%'

          20、查找所有定單金額高于2000的所有客戶編號
          select cust_id
          from sales
          where tot_amt>2000

          21、統(tǒng)計表中員工的薪水在4000-6000之間的人數(shù)
          select count(*)as 人數(shù)
          from employee
          where salary between 4000 and 6000

          22、查詢表中的同一部門的職工的平均工資,但只查詢"住址"是"上海市"的員工
          select avg(salary) avg_sal,dept
          from employee
          where addr like '上海市%'
          group by dept

          23、將表中住址為"上海市"的員工住址改為"北京市"
          update employee
          set addr like '北京市'
          where addr like '上海市'

          24、查找業(yè)務部或會計部的女員工的基本信息。
          select emp_no,emp_name,dept
          from employee
          where sex='F'and dept in ('業(yè)務','會計')

          25、顯示每種產(chǎn)品的銷售金額總和,并依銷售金額由大到小輸出。
          select prod_id ,sum(qty*unit_price)
          from sale_item
          group by prod_id
          order by sum(qty*unit_price) desc

          26、選取編號界于'C0001'和'C0004'的客戶編號、客戶名稱、客戶地址。
          select CUST_ID,cust_name,addr
          from customer
          where cust_id between 'C0001' AND 'C0004'

          27、計算出一共銷售了幾種產(chǎn)品。
          select count(distinct prod_id) as '共銷售產(chǎn)品數(shù)'
          from sale_item

          28、將業(yè)務部員工的薪水上調(diào)3%。
          update employee
          set salary=salary*1.03
          where dept='業(yè)務'

          29、由employee表中查找出薪水最低的員工信息。
          select *
          from employee
          where salary=
          (select min(salary )
          from employee )

          30、使用join查詢客戶姓名為"客戶丙"所購貨物的"客戶名稱","定單金額","定貨日期","電話號碼"
          select a.cust_id,b.tot_amt,b.order_date,a.tel_no
          from customer a join sales b
          on a.cust_id=b.cust_id and cust_name like '客戶丙'

          31、由sales表中查找出訂單金額大于"E0013業(yè)務員在1996/10/15這天所接每一張訂單的金額"的所有訂單。
          select *
          from sales
          where tot_amt>all
          (select tot_amt
          from sales
          where sale_id='E0013'and order_date='1996/10/15')
          order by tot_amt

          32、計算'P0001'產(chǎn)品的平均銷售單價
          select avg(unit_price)
          from sale_item
          where prod_id='P0001'

          33、找出公司女員工所接的定單
          select sale_id,tot_amt
          from sales
          where sale_id in
          (select sale_id from employee
          where sex='F')

          34、找出同一天進入公司服務的員工
          select a.emp_no,a.emp_name,a.date_hired
          from employee a
          join employee b
          on (a.emp_no!=b.emp_no and a.date_hired=b.date_hired)
          order by a.date_hired

          35、找出目前業(yè)績超過232000元的員工編號和姓名。
          select emp_no,emp_name
          from employee
          where emp_no in
          (select sale_id
          from sales
          group by sale_id
          having sum(tot_amt)<232000)

          36、查詢出employee表中所有女職工的平均工資和住址在"上海市"的所有女職工的平均工資
          select avg(salary)
          from employee
          where sex like 'f'
          union
          select avg(salary)
          from employee
          where sex like 'f' and addr like '上海市%'

          37、在employee表中查詢薪水超過員工平均薪水的員工信息。
          Select *
          from employee
          where salary>( select avg(salary)
          from employee)

          38、 找出目前銷售業(yè)績超過10000元的業(yè)務員編號及銷售業(yè)績,并按銷售業(yè)績從大到小排序。
          Select sale_id ,sum(tot_amt)
          from sales
          group by sale_id
          having sum(tot_amt)>10000
          order by sum(tot_amt) desc

          39、 找出公司男業(yè)務員所接且訂單金額超過2000元的訂單號及訂單金額。
          Select order_no,tot_amt
          From sales ,employee
          Where sale_id=emp_no and sex='M' and tot_amt>2000

          40、 查詢sales表中訂單金額最高的訂單號及訂單金額。
          Select order_no,tot_amt from sales
          where tot_amt=(select max(tot_amt) from sales)

          41、 查詢在每張訂單中訂購金額超過4000元的客戶名及其地址。
          Select cust_name,addr from customer a,sales b
          where a.cust_id=b.cust_id and tot_amt>4000

          42、 求出每位客戶的總訂購金額,顯示出客戶號及總訂購金額,并按總訂購金額降序排列。
          Select cust_id,sum(tot_amt) from sales
          Group by cust_id
          Order by sum(tot_amt) desc

          43、 求每位客戶訂購的每種產(chǎn)品的總數(shù)量及平均單價,并按客戶號,產(chǎn)品號從小到大排列。
          Select cust_id,prod_id,sum(qty),sum(qty*unit_price)/sum(qty)
          From sales a, sale_item b
          Where a.order_no=b.order_no
          Group by cust_id,prod_id
          Order by cust_id,prod_id

          44、 查詢訂購了三種以上產(chǎn)品的訂單號。
          Select order_no
          from sale_item
          Group by order_no
          Having count(*)>3

          45、 查詢訂購的產(chǎn)品至少包含了訂單3號中所訂購產(chǎn)品的訂單。
          Select distinct order_no
          From sale_item a
          Where order_no<>'3'and not exists (
          Select * from sale_item b where order_no ='3' and not exists
          (select * from sale_item c where c.order_no=a.order_no and c.prod_id=b.prod_id))

          46、 在sales表中查找出訂單金額大于"E0013業(yè)務員在1996/11/10這天所接每一張訂單的金額"的所有訂單,并顯示承接這些訂單的業(yè)務員和該訂單的金額。
          Select sale_id,tot_amt from sales
          where tot_amt>all(select tot_amt
          from sales
          where sale_id='E0013' and order_date='1996-11-10')

          47、 查詢末承接業(yè)務的員工的信息。
          Select *
          From employee a
          Where not exists
          (select * from sales b where a.emp_no=b.sale_id)

          48、 查詢來自上海市的客戶的姓名,電話、訂單號及訂單金額。
          Select cust_name,tel_no,order_no,tot_amt
          From customer a ,sales b
          Where a.cust_id=b.cust_id and addr='上海市'

          49、 查詢每位業(yè)務員各個月的業(yè)績,并按業(yè)務員編號、月份降序排序。
          Select sale_id,month(order_date), sum(tot_amt)
          from sales
          group by sale_id,month(order_date)
          order by sale_id,month(order_date) desc

          50、 求每種產(chǎn)品的總銷售數(shù)量及總銷售金額,要求顯示出產(chǎn)品編號、產(chǎn)品名稱,總數(shù)量及總金額,并按產(chǎn)品號從小到大排列。
          Select a.prod_id,prod_name,sum(qty),sum(qty*unit_price)
          From sale_item a,product b
          Where a.prod_id=b.prod_id
          Group by a.prod_id,prod_name
          Order by a.prod_id
          51、 查詢總訂購金額超過'C0002'客戶的總訂購金額的客戶號,客戶名及其住址。
          Select cust_id, cust_name,addr
          From customer
          Where cust_id in (select cust_id from sales
          Group by cust_id
          Having sum(tot_amt)>
          (Select sum(tot_amt) from sales where cust_id='C0002'))

          52、 查詢業(yè)績最好的的業(yè)務員號、業(yè)務員名及其總銷售金額。
          select emp_no,emp_name,sum(tot_amt)
          from employee a,sales b
          where a.emp_no=b.sale_id
          group by emp_no,emp_name
          having sum(tot_amt)=
          (select max(totamt)
          from (select sale_id,sum(tot_amt) totamt
          from sales
          group by sale_id) c)

          53、 查詢每位客戶所訂購的每種產(chǎn)品的詳細清單,要求顯示出客戶號,客戶名,產(chǎn)品號,產(chǎn)品名,數(shù)量及單價。
          select a.cust_id, cust_name,c.prod_id,prod_name,qty, unit_price
          from customer a,sales b, sale_item c ,product d
          where a.cust_id=b.cust_id and b.order_no=c.order_no and c.prod_id=d.prod_id

          54、 求各部門的平均薪水,要求按平均薪水從小到大排序。
          select dept,avg(salary)
          from employee
          group by dept
          order by avg(salary)

          posted @ 2006-05-23 15:10 人要有夢想 閱讀(1727) | 評論 (2)編輯 收藏

          主站蜘蛛池模板: 武宁县| 白河县| 高台县| 潍坊市| 峡江县| 手机| 团风县| 通辽市| 枣阳市| 新巴尔虎右旗| 盱眙县| 商洛市| 松原市| 莒南县| 祁阳县| 荥经县| 绵阳市| 丁青县| 大邑县| 隆回县| 象州县| 广河县| 汾阳市| 庐江县| 乌兰察布市| 泰州市| 和田县| 阿勒泰市| 本溪市| 隆子县| 仙游县| 呼图壁县| 万山特区| 阳东县| 文水县| 来凤县| 汉沽区| 高密市| 西昌市| 贡觉县| 平山县|