An "astronaut" came and also had to test nucleic acids

Source: Xinhua News Agency

recently

A new round of COVID-19 has emerged in many places

Moments of war

Medical staff and volunteers from all over the world rushed to the front line

There is also such a group of people

Their actions are heartwarming

4-year-old boy nucleic acid live than "yay" ✌️

A nucleic acid test site in Zunyi, Guizhou

A 4-year-old boy is tested in a "spacesuit."

Happy than "Yay" ✌️

After the killing work

Volunteers dance to relieve stress

In Lanzhou, Gansu

"Post-90s" volunteer Mr. Zhang

After a day of killing, I danced street dance

Mr. Zhang introduced

"Dancing is all about making everyone happy

Relieve the stress of the day

Hope more people join the volunteer team."

An "astronaut" came and also had to test nucleic acids

And some people

They have taken practical actions to support the fight against the epidemic in their hometown

Lanzhou, Gansu

A number of beef noodle merchants have launched an initiative

For frontline medical workers, volunteers and other staff

Beef noodles are provided free of charge

Zhang Xin, owner of one of the beef noodle restaurants, said

Evening hours will also be extended

Let these shift shift volunteers

You can eat a hot meal

An "astronaut" came and also had to test nucleic acids

In Zhangye, Gansu

From the evening of October 21 to 23

A restaurant is a frontline epidemic prevention personnel for 3 consecutive days

Thousands of free love meals were delivered

An "astronaut" came and also had to test nucleic acids

In Zunyi, Guizhou

An "astronaut" came and also had to test nucleic acids

Citizens for healthcare workers and volunteers

Make dumplings and cook noodles

Braving the cold wind

Bring hot rice hot dishes to their hands

Some people come forward, some people go against the grain

Medical staff and volunteers braved the cold wind

Rush to the front line of the epidemic

"I'm fighting!"

Ten thousand college students in Gansu rushed to the "epidemic" line

"I sign up" "I can"

Under the severe epidemic situation in Gansu

Lanzhou University, Gansu University of Traditional Chinese Medicine

Northwest University for Nationalities, Gansu Health Vocational and Technical College, etc

More than 10,000 student volunteers

Please fight on the front line of the fight against the epidemic at the first time

In just a few hours

The volunteer WeChat group was full of registrations

At the scene of the expedition, they swore an oath and pressed their handprints

An "astronaut" came and also had to test nucleic acids

在OFBIZ中使用多個資料庫的方法

要在OFBIZ中使用多個資料庫,我們就需要知道OFBIZ實體與資料庫的關聯關系。然後要知道實體分組。 我們每定義一個實體就應該明确的将該實體分到對應的實體分組中,一個實體分組可以包含多個實體。每個分組又可以單獨的定義它所使用的資料庫。是以,我們就要可以通過将實作進行分組,然後使用不同的資料庫。實體分組的定義在%OFBIZ_HOME%/framework/entity/conf/entityengine.xml檔案中定義。預設情況下,實體被分組到了 org.ofbiz分組中。

    <entity-group group="org.ofbiz.olap" entity="SalesInvoiceItemFact"/>

<entity-group group="org.ofbiz.olap" entity="SalesInvoiceItemStarSchema"/>

Entity-group(一般定義在各個子產品的\entitydef\entitygroupXXX.xml中) 對實體進行分組,使不同的實體分屬不同的entity-group。

也許你會發現并不是每個entity都進行了entity-group 分組。事實上如果你沒有對實體進行分組歸類的話,系統啟動的時候他會将實體預設歸類到"org.ofbiz"中。

檢視資料庫定義檔案%ofbiz_home%/framework/entity/config/entityengine.xml

可以發現:

<delegator name="default" entity-model-reader="main" entity-group-reader="main" entity-eca-reader="main" distributed-cache-clear-enabled="false">

        <group-map group-name="org.ofbiz" datasource-name="localderby"/>

        <group-map group-name="org.ofbiz.olap" datasource-name="localderbyolap"/>

        <group-map group-name="org.ofbiz.tenant" datasource-name="localderbytenant"/>

</delegator>

可以發現delegator 将多個group-name組織到一起并将group-name與datasource-name對應起來,datasource-name又是什麼?通過檢視 entityengine.xml 我們可以發現:

<datasource name="localderby"

            helper-class="org.ofbiz.entity.datasource.GenericHelperDAO"

            schema-name="OFBIZ"

            field-type-name="derby"

            check-on-start="true"

            add-missing-on-start="true"

            use-pk-constraint-names="false"

            use-indices-unique="false"

            alias-view-columns="false"

            use-order-by-nulls="true">

        <read-data reader-name="seed"/>

        <read-data reader-name="seed-initial"/>

        <read-data reader-name="demo"/>

        <read-data reader-name="ext"/>

        <inline-jdbc

                jdbc-driver="org.apache.derby.jdbc.EmbeddedDriver"

                jdbc-uri="jdbc:derby:ofbiz;create=true"

                jdbc-username="ofbiz"

                jdbc-password="ofbiz"

                isolation-level="ReadCommitted"

                pool-minsize="2"

                pool-maxsize="250"

                time-between-eviction-runs-millis="600000"/>

</datasource>

Datasource定義了資料庫驅動,資料庫使用者名、密碼等,是以datasource就是我們說的資料庫。 

總結一下:我們通過entity-group将各個實體和資料庫之間關聯起來,然後再将一個或多個資料庫歸屬到一個delegator 中,這樣我們就可以通過相同的delegator從不同的資料庫中取值了。

那我們又是怎麼使用資料庫進行資料庫操作的呢??檢視每個子產品應用底下的web.xml 我們可以發現:

<context-param>

        <param-name>entityDelegatorName</param-name>

        <param-value>default</param-value>

        <description>The Name of the Entity Delegator to use, defined in entityengine.xml</description>

</context-param>

針對不同的應用,我們可以使用不同的delegator .如果不定義則使用default.

在啟動各個應用子產品的時候,系統會根據web.xml 中的 entityDelegatorName 

生成delegator 對象,然後将delegator 對象存放到servletContext 中備用。

我們就是使用這個delegator對象執行資料庫操作,以後會介紹如何使用。

delegator = DelegatorFactory.getDelegator(delegatorName);

    servletContext.setAttribute("delegator", delegator);

繼續閱讀