read-atleap-hibernate部分分析3-Page类

来源:互联网 发布:c语言的科学与艺术 编辑:程序博客网 时间:2024/05/18 02:49
 read-atleap-hibernate部分分析3-Page类

ª Page的结构与Layout的结构大致相同

 

ª 调用函数

List pageFields =contentFieldManager.findIndexedContentFieldByPageUri(identifier,

uri, locale);

public List findIndexedContentFieldByPageUri(Stringidentifier, Stringuri, String locale) {

        Stringhql = new StringBuffer("select distinct field from Page page inner join

                page.contentFields field innerjoin field.contentFieldValues value ")

                .append("where ").append("field.identifier like '")

                .append(StringUtil.dbEncode(identifier)).append("[%]' ")

                .append("and page.uri = ? ")

                .append("and (value.contentLocale.identifier = ? or

                value.contentLocale.defaultInstance= 'T')")

                .toString();

 

ª 执行的SQL

Hibernate: select distinct contentfie1_.idas id, contentfie1_.version as versio

n, contentfie1_.identifier as identifier,contentfie1_.localizable_id as localiz

a4_, contentfie1_.type as type,contentfie1_.internal as internal from page page

0_ inner join localizable page0__1_ onpage0_.localizable_id=page0__1_.id inner

join field contentfie1_ onpage0_.localizable_id=contentfie1_.localizable_id inn

er join field_value contentfie2_ oncontentfie1_.id=contentfie2_.field_id, local

e contentloc3_ where(contentfie1_.identifier like 'body[%]' )and(page0_.uri=? )

and((contentfie2_.locale_identifier=?)or(contentloc3_.default_instance='T' and

 contentfie2_.locale_identifier=contentloc3_.identifier))

 

mysql> select * from field;

+-----+---------+-------------+----------------+------+----------+

| id | version | identifier  |localizable_id | type | internal |

+-----+---------+-------------+----------------+------+----------+

|   0|       0 | title       |              2 |    0 | T

***************************************************************

Ø ContentFieldValue

ª 调用函数

ContentFieldValue findContentFieldValueByUriAndIdentifierAndLocale(Stringuri,

String identifier, StringlocaleIdentifier)

 

ª HQL

©取用户选取语言的显示内容

select valuefrom Page page innerjoin page.contentFields field inner join field.contentFieldValues valuewhere page.uri = ? and field.identifier = ? and value.contentLocale.identifier= ?

© 取默认语言的显示内容

select value from Page pageinner join page.contentFields field inner join field.contentFieldValues valuewhere page.uri = ? and field.identifier = ? and value.contentLocale.defaultInstance= 'T'

 

ª 执行的SQL

Hibernate: select contentfie2_.id as id, contentfie2_.versionas version, conten

tfie2_.locale_identifieras locale_i3_, contentfie2_.value as value,contentfie2

_.simple_valueas simple_v5_, contentfie2_.field_id asfield_id, contentfie2_.la

st_updated as last_upd7_ from page page0_ inner join localizable page0__1_ on pa

ge0_.localizable_id=page0__1_.id inner join field contentfie1_ onpage0_.localiz

able_id=contentfie1_.localizable_id inner join field_value contentfie2_on conte

ntfie1_.id=contentfie2_.field_id where (page0_.uri=? )and(contentfie1_.identifie

r=? )and(contentfie2_.locale_identifier=?)

 

ª ContentLocale.hbm.xml中的ContentFieldValue的映射关系

        <bag

            name="contentFieldValues"

            lazy="true"

            inverse="true"

            cascade="delete"

        >

              <key

                  column="locale_identifier"

              >

              </key>

              <one-to-many

                 class="com.blandware.atleap.model.core.ContentFieldValue"

              />

        </bag>

 

ª ContentFieldValue外键映射ContentLocaleidentifier主键

        <id

            name="identifier"

            column="identifier"

            type="java.lang.String"

            unsaved-value="null"

        >

ª contentFieldValue中存放着主要的显示信息            

if ( contentField.getType()== ContentField.LINE_TYPE) {

content = contentFieldValue.getSimpleValue();

                  } else if( contentField.getType()== ContentField.MULTILINE_TYPE) {

                       content = ConvertUtil.convertToString(contentFieldValue.getValue(),request.getCharacterEncoding());

                   } else /* ifHTML_TYPE */ {

                       content = ConvertUtil.convertToString(contentFieldValue.getValue(),request.getCharacterEncoding());

                   }

ª 主页显示的内容在数据库中存为一条记录

 

ª mysql> select value fromfield_value where value like '%many problems during%' l

imit 1;

 

ª 数据库中存放的内容:

 

 

|<p><strong><imgalt="" hspace="10" src="rw/resource/banner.jpg"align="right" v

space="10"/></strong>BlandwareAtLeap is a free Java multilingual CMS (Content M

anagement System) with full-text searchengine. Blandware AtLeap is a framework

which allows you to rapidly start your ownWeb application.</p>

<p>The idea of the AtLeap project isbased on my many years&rsquo; experience of

 management in the area of the sitedevelopment.&nbsp;I hope Blandware AtLeap wi

ll allow you to &quot;leap&quot;many problems during site development which I h

ave already solved.</p>

<palign="right"><i>Project owner: Andrey Grebnev&nbsp;</i></p>

<ul>

   <li>

   <div><strong><font size="2">Use login<em>admin </em>and password <em>passwo

rd</em> to&nbsp;enter into thesystem with Administrator privileges.</font></str

ong></div>

   </li>

   <li>

   <div><strong><font size="2">Use login<em>manager</em> and password <em>pass

word</em> to enter the system withManager privileges. Manager has some restrict

ions&nbsp;because of&nbsp;his role.</font></strong></div>

   </li>

   <li>

   <div><strong><font size="2">Use login<em>user</em> and password <em>passwor

d</em> to enter&nbsp; into thesystem as simple user. </font></strong></div>

   </li>

</ul>

<p><ahref="pages/about.do">Read more about AtLeap</a></p> |

 

注:主要代码在com.blandware.atleap.webapp.taglib.core.content. ContentIteratorTag