auto generate dao-beans.xml

This commit is contained in:
xingchaowang 2015-03-06 16:29:09 +08:00
parent 1e546e7413
commit 7e42bc17be
9 changed files with 346 additions and 37 deletions

15
pom.xml
View file

@ -61,16 +61,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-http</artifactId>
<version>${jersey.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-jetty-servlet</artifactId>
<version>${jersey.version}</version>
</dependency>
<!-- Jersey End -->
<!-- Spring -->
@ -177,6 +167,11 @@
<artifactId>archaius-core</artifactId>
<version>0.6.5</version>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.22</version>
</dependency>
</dependencies>
<build>
<plugins>

View file

@ -1,7 +1,10 @@
package com.ctrip.zeus.build;
import com.sun.javafx.binding.StringFormatter;
import org.unidal.dal.jdbc.AbstractDao;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
/**
@ -10,13 +13,34 @@ import java.util.List;
*/
public class GenerateDaoBeansConfig {
public static void main(String[] args) {
String daoPackage="com.ctrip.zeus.dal.core";
public static void main(String[] args) throws IOException {
StringBuilder builder = new StringBuilder();
builder.append("<beans xmlns=\"http://www.springframework.org/schema/beans\"\n" +
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd\">\n\n");
builder.append(" <bean id=\"daoFactory\" class=\"com.ctrip.zeus.support.DaoFactory\"/>\n\n");
String daoPackage="com.ctrip.zeus.dal.core";
List<Class<?>> list = ClassFinder.find(daoPackage);
for (Class<?> clazz : list) {
if(AbstractDao.class.isAssignableFrom(clazz))
System.out.println(clazz.getName());
if(AbstractDao.class.isAssignableFrom(clazz)){
builder.append(String.format("" +
" <bean id=\"%s\" factory-bean=\"daoFactory\" factory-method=\"getDao\">\n" +
" <constructor-arg type=\"java.lang.Class\" value=\"%s\"/>\n" +
" </bean>\n\n",
uncapitalize(clazz.getSimpleName()), clazz.getName()));
}
}
builder.append("</beans>");
FileWriter writer = new FileWriter("src/main/resources/dao-beans.xml");
writer.write(builder.toString());
writer.close();
}
static String uncapitalize(String str) {
String first = new String(str.substring(0,1));
return str.replaceFirst(first,first.toLowerCase());
}
}

View file

@ -11,6 +11,7 @@
<member name="last-modified" field="last_modified" value-type="Date" nullable="false" />
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="application_id" unique="true" members="application_id ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -50,6 +51,7 @@
<member name="last-modified" field="last_modified" value-type="Date" nullable="false" />
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="application_id" unique="true" members="application_id ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
@ -94,6 +96,47 @@
<member name="last-modified" field="last_modified" value-type="Date" nullable="false" />
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="application_id_server_id" unique="true" members="application_id ASC, server_id ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>
<updatesets>
<updateset name="FULL" all="true" />
</updatesets>
<query-defs>
<query name="find-by-PK" type="SELECT">
<param name="key-id" />
<statement><![CDATA[SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
<query name="insert" type="INSERT">
<statement><![CDATA[INSERT INTO <TABLE/>(<FIELDS/>)
VALUES(<VALUES/>)]]></statement>
</query>
<query name="update-by-PK" type="UPDATE">
<param name="key-id" />
<statement><![CDATA[UPDATE <TABLE/>
SET <FIELDS/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
<query name="delete-by-PK" type="DELETE">
<param name="key-id" />
<statement><![CDATA[DELETE FROM <TABLE/>
WHERE <FIELD name='id'/> = ${key-id}]]></statement>
</query>
</query-defs>
</entity>
<entity name="app-slb" table="app_slb" alias="as2">
<member name="id" field="id" value-type="long" length="19" nullable="false" key="true" auto-increment="true" />
<member name="application-id" field="application_id" value-type="long" length="19" nullable="false" />
<member name="slb-virtual-server-id" field="slb_virtual_server_id" value-type="long" length="19" nullable="false" />
<member name="path" field="path" value-type="String" length="200" nullable="false" />
<member name="created-time" field="created_time" value-type="Date" />
<member name="last-modified" field="last_modified" value-type="Date" nullable="false" />
<var name="key-id" value-type="long" key-member="id" />
<primary-key name="PRIMARY" members="id" />
<index name="application_id_slb_virtual_server_id" unique="true" members="application_id ASC, slb_virtual_server_id ASC" />
<readsets>
<readset name="FULL" all="true" />
</readsets>

View file

@ -34,11 +34,15 @@
<entity name="application">
<attribute name="name" value-type="String" />
<attribute name="app-id" value-type="int" />
<entity-ref name="virtual-server" />
<entity-ref name="app-virtual-server" type="list" names="app-virtual-servers" xml-indent="true" />
<entity-ref name="health-check" />
<entity-ref name="load-balancing-method" />
<entity-ref name="app-server" type="list" names="app-servers" xml-indent="true" />
</entity>
<entity name="app-virtual-server">
<element name="path" value-type="String" />
<entity-ref name="virtual-server" />
</entity>
<entity name="health-check">
<attribute name="interval" value-type="int" />
<attribute name="fails" value-type="int" />
@ -54,14 +58,14 @@
<attribute name="weight" value-type="int" />
<attribute name="max-fails" value-type="int" />
<attribute name="fail-timeout" value-type="int" />
<attribute name="healthy" value-type="String" />
<attribute name="enable" value-type="String" />
<attribute name="healthy" value-type="boolean" />
<attribute name="enable" value-type="boolean" />
<entity-ref name="server" />
</entity>
<entity name="server">
<attribute name="ip" value-type="String" />
<attribute name="host-name" value-type="String" />
<attribute name="up" value-type="String" />
<attribute name="up" value-type="boolean" />
</entity>
</model>

View file

@ -10,17 +10,207 @@
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>demo</role-hint>
<role-hint>app-health-check</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>demo</logical-table-name>
<physical-table-name>demo</physical-table-name>
<logical-table-name>app-health-check</logical-table-name>
<physical-table-name>app_health_check</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>com.ctrip.zeus.dal.core.DemoDao</role>
<implementation>com.ctrip.zeus.dal.core.DemoDao</implementation>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>app-load-balancing-method</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>app-load-balancing-method</logical-table-name>
<physical-table-name>app_load_balancing_method</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>app-server</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>app-server</logical-table-name>
<physical-table-name>app_server</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>app-slb</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>app-slb</logical-table-name>
<physical-table-name>app_slb</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>application</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>application</logical-table-name>
<physical-table-name>application</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>server</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>server</logical-table-name>
<physical-table-name>server</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>slb-cluster</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>slb-cluster</logical-table-name>
<physical-table-name>slb_cluster</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>slb-domain</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>slb-domain</logical-table-name>
<physical-table-name>slb_domain</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>slb-server</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>slb-server</logical-table-name>
<physical-table-name>slb_server</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>slb-vip</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>slb-vip</logical-table-name>
<physical-table-name>slb_vip</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>org.unidal.dal.jdbc.mapping.TableProvider</role>
<role-hint>slb-virtual-server</role-hint>
<implementation>org.unidal.dal.jdbc.mapping.SimpleTableProvider</implementation>
<configuration>
<logical-table-name>slb-virtual-server</logical-table-name>
<physical-table-name>slb_virtual_server</physical-table-name>
<data-source-name>zeus</data-source-name>
</configuration>
</component>
<component>
<role>com.ctrip.zeus.dal.core.AppHealthCheckDao</role>
<implementation>com.ctrip.zeus.dal.core.AppHealthCheckDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.AppLoadBalancingMethodDao</role>
<implementation>com.ctrip.zeus.dal.core.AppLoadBalancingMethodDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.AppServerDao</role>
<implementation>com.ctrip.zeus.dal.core.AppServerDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.AppSlbDao</role>
<implementation>com.ctrip.zeus.dal.core.AppSlbDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.ApplicationDao</role>
<implementation>com.ctrip.zeus.dal.core.ApplicationDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.ServerDao</role>
<implementation>com.ctrip.zeus.dal.core.ServerDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.SlbClusterDao</role>
<implementation>com.ctrip.zeus.dal.core.SlbClusterDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.SlbDomainDao</role>
<implementation>com.ctrip.zeus.dal.core.SlbDomainDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.SlbServerDao</role>
<implementation>com.ctrip.zeus.dal.core.SlbServerDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.SlbVipDao</role>
<implementation>com.ctrip.zeus.dal.core.SlbVipDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>
</requirement>
</requirements>
</component>
<component>
<role>com.ctrip.zeus.dal.core.SlbVirtualServerDao</role>
<implementation>com.ctrip.zeus.dal.core.SlbVirtualServerDao</implementation>
<requirements>
<requirement>
<role>org.unidal.dal.jdbc.QueryEngine</role>

View file

@ -19,6 +19,7 @@
<table name="slb_server"/>
<table name="slb_vip"/>
<table name="slb_virtual_server"/>
<table name="app_slb"/>
</group>
</jdbc>
</wizard>

View file

@ -0,0 +1,51 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
<bean id="daoFactory" class="com.ctrip.zeus.support.DaoFactory"/>
<bean id="appHealthCheckDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.AppHealthCheckDao"/>
</bean>
<bean id="applicationDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.ApplicationDao"/>
</bean>
<bean id="appLoadBalancingMethodDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.AppLoadBalancingMethodDao"/>
</bean>
<bean id="appServerDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.AppServerDao"/>
</bean>
<bean id="appSlbDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.AppSlbDao"/>
</bean>
<bean id="serverDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.ServerDao"/>
</bean>
<bean id="slbClusterDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.SlbClusterDao"/>
</bean>
<bean id="slbDomainDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.SlbDomainDao"/>
</bean>
<bean id="slbServerDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.SlbServerDao"/>
</bean>
<bean id="slbVipDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.SlbVipDao"/>
</bean>
<bean id="slbVirtualServerDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.SlbVirtualServerDao"/>
</bean>
</beans>

View file

@ -16,13 +16,5 @@
<context:component-scan base-package="com.ctrip.zeus"/>
<aop:aspectj-autoproxy/>
<bean id="daoFactory" class="com.ctrip.zeus.support.DaoFactory"/>
<bean id="applicationDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.ApplicationDao"/>
</bean>
<bean id="AppHealthCheckDao" factory-bean="daoFactory" factory-method="getDao">
<constructor-arg type="java.lang.Class" value="com.ctrip.zeus.dal.core.AppHealthCheckDao"/>
</bean>
<import resource="dao-beans.xml"/>
</beans>

View file

@ -30,7 +30,16 @@
</slb-cluster>
<application name="gateway" app-id="921822">
<virtual-server/>
<app-virtual-servers>
<app-virtual-server>
<path>/hotel</path>
<virtual-server/>
</app-virtual-server>
<app-virtual-server>
<path>/hotel</path>
<virtual-server/>
</app-virtual-server>
</app-virtual-servers>
<health-check interval="10" fails="2" passes="2">
<uri>/health-check</uri>
</health-check>
@ -38,11 +47,11 @@
<value>uri</value>
</load-balancing-method>
<app-servers>
<app-server port="80" weight="5" max-fails="5" fail-timeout="30" healthy="true|false" enable="true|false">
<server ip="192.168.1.10" host-name="vms002" up="true|false"/>
<app-server port="80" weight="5" max-fails="5" fail-timeout="30" healthy="true" enable="true">
<server ip="192.168.1.10" host-name="vms002" up="true"/>
</app-server>
<app-server port="80" weight="5" max-fails="5" fail-timeout="30" healthy="true|false" enable="true|false">
<server ip="192.168.1.11" host-name="vms002" up="true|false"/>
<app-server port="80" weight="5" max-fails="5" fail-timeout="30" healthy="true" enable="true">
<server ip="192.168.1.11" host-name="vms002" up="true"/>
</app-server>
</app-servers>
</application>