基于xml配置插入数据库数据例子(三)

前端之家收集整理的这篇文章主要介绍了基于xml配置插入数据库数据例子(三)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


16.Util
package net.atpco.dds.offline.filing.common.datamapper.binder;

public class Util {
private static String userId;
public static String getUserId() {
return userId;
}

public static void setUserId(String userId) {
Util.userId = userId;
}
}

17.SpringDataLoadConfiguration.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd">


<bean id="dataLoadDAO" class="net.atpco.dds.offline.filing.common.datamapper.binder.DataLoadDAO"/>
</beans>

package net.atpco.dds.offline.filing.common.datamapper.parser;
18.ClassConfig
package net.atpco.dds.offline.filing.common.datamapper.parser;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "classConfig")
public class ClassConfig implements Cloneable {
private String id;
private String schemaName;
private String schemaPropName;
private String tableName;
private String className;

private List<PropertyConfig> propertyConfigs = new ArrayList<PropertyConfig>();

public String getId() {
return id;
}

@XmlAttribute(name = "id")
public void setId(final String id) {
this.id = id;
}

public String getSchemaName() {
return schemaName;
}

/**
* Used to hold the schema name fetched from the property schema property name
* @param schemaName
*/
public void setSchemaName(final String schemaName) {
this.schemaName = schemaName;
}


public String getSchemaPropName() {
return schemaPropName;
}

@XmlAttribute(name = "schemaPropName")
public void setSchemaPropName(final String schemaPropName) {
this.schemaPropName = schemaPropName;
}

public String getTableName() {
return tableName;
}

@XmlAttribute(name = "tableName")
public void setTableName(final String tableName) {
this.tableName = tableName.trim().toUpperCase();
}

public String getClassName() {
return className;
}

@XmlAttribute(name = "className")
public void setClassName(final String className) {
this.className = className;
}

public List<PropertyConfig> getPropertyConfigs() {
return propertyConfigs;
}

@XmlElement(name = "propertyConfig",type = PropertyConfig.class)
public void setPropertyConfigs(final List<PropertyConfig> propertyConfigs) {
this.propertyConfigs = propertyConfigs;
}

@Override
public String toString() {
final StringBuilder obj = new StringBuilder(512);
obj.append(" \n\n Id : ");
obj.append(getId());
obj.append(" schemaName: ");
obj.append(getSchemaName());
obj.append(" tableName: " );
obj.append(getTableName());
obj.append(" className: " );
obj.append(getClassName());
obj.append(" \n Property Configurations : \n [");
for (final PropertyConfig config : getPropertyConfigs()) {
obj.append("\n \tProperty Name: ").append(config.getName());
obj.append(" \tColumn Name: ").append(config.getColumnName());
obj.append(" \tJava Type: ").append(config.getJavaType());
obj.append(" \tInclude Clause: ").append(config.getIncludeClause());
}
obj.append(" \n] ");
return obj.toString();
}
}

19.PropertyConfig
package net.atpco.dds.offline.filing.common.datamapper.parser;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Holds the property information like method name,sql type and java type
*
* @author atp1axi
* @version 1.0
*
*/

@XmlRootElement(name = "propertyConfig")
public class PropertyConfig {
private String name;
private String columnName;
private String javaType;
private String sqlType;
private String includeClause = "false";

public String getName() {
return name;
}

@XmlAttribute(name = "name")
public void setName(final String propertyName) {
this.name = propertyName;
}

public String getColumnName() {
return columnName;
}

@XmlAttribute(name = "columnName")
public void setColumnName(final String columnName) {
this.columnName = columnName.trim().toUpperCase();
}

public String getJavaType() {
return javaType;
}

@XmlAttribute(name = "javaType")
public void setJavaType(final String javaType) {
this.javaType = javaType;
}

public String getsqlType() {
return sqlType;
}

@XmlAttribute(name = "sqlType")
public void setsqlType(final String sqlType) {
this.sqlType = sqlType.trim().toUpperCase();
}

public String getIncludeClause() {
return includeClause;
}

@XmlAttribute(name = "includeClause")
public void setIncludeClause(final String includeClause) {
this.includeClause = includeClause;
}


@Override
public String toString() {
final StringBuilder stringBuilder = new StringBuilder(256);
stringBuilder.append(" propertyName - ").append(getName());
stringBuilder.append(" columnName - ").append(getColumnName());
stringBuilder.append(" javaType - ").append(getJavaType());
stringBuilder.append(" sqlType - ").append(getsqlType());
stringBuilder.append(" includeClause - ").append(getIncludeClause());
return stringBuilder.toString();
}
}

package net.atpco.dds.offline.filing.common.model;
20.FilingFCSegmentCorrection
package net.atpco.dds.offline.filing.common.model;


public class FilingFCSegmentCorrection {

/**inEffYr*/
privateIntegerinEffYr;
/**carrierCode*/
privateString carrierCode;
/**ruleTariffCode*/
privateString ruleTariffCode;
/**ruleCode*/
privateString ruleCode;
private Integer seqNo;
private Integer zoneNO;
public Integer getSeqNo() {
return seqNo;
}
public void setSeqNo(Integer seqNo) {
this.seqNo = seqNo;
}
public Integer getZoneNO() {
return zoneNO;
}
public void setZoneNO(Integer zoneNO) {
this.zoneNO = zoneNO;
}
public Integer getInEffYr() {
return inEffYr;
}
public void setInEffYr(Integer inEffYr) {
this.inEffYr = inEffYr;
}
public String getCarrierCode() {
return carrierCode;
}
public void setCarrierCode(String carrierCode) {
this.carrierCode = carrierCode;
}
public String getRuleTariffCode() {
return ruleTariffCode;
}
public void setRuleTariffCode(String ruleTariffCode) {
this.ruleTariffCode = ruleTariffCode;
}
public String getRuleCode() {
return ruleCode;
}
public void setRuleCode(String ruleCode) {
this.ruleCode = ruleCode;
}

@Override
public String toString() {
StringBuffer sb=new StringBuffer();
sb.append("inEffYr="+inEffYr+",carrierCode="+carrierCode+
",ruleTariffCode="+ruleTariffCode+",ruleCode="+ruleCode
+",seqNo="+seqNo+",zoneNO="+zoneNO);
return sb.toString();
}


}

21.object-data-mappings.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">


<bean id="dateMappingConfigurer"
class="net.atpco.dds.offline.filing.common.datamapper.binder.DataMappingConfigurer">
<constructor-arg index="0" ref="configPaths" />
<constructor-arg index="1" type="org.springframework.core.io.Resource"
value="classpath:/spring/DataLoadSchema.xsd"/>
</bean>


<util:list id="configPaths">
<value>classpath:/spring/fc_segment_crrn.xml</value>
<value>classpath:/spring/cat_segment_crrn.xml</value>
<value>classpath:/spring/cat_govt_filing_crrn.xml</value>
</util:list>


</beans>

22.fc_segment_crrn.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<classConfig id="fcSegmentCRRN" schemaPropName="gfsSchema"
tableName="FC_SEG_CRRN" className="net.atpco.dds.offline.filing.common.model.FilingFCSegmentCorrection">

<propertyConfig name="inEffYr" columnName="IN_EFF_YR" javaType="java.lang.Integer" sqlType="SMALLINT" includeClause="true"/>
<propertyConfig name="carrierCode" columnName="CXR_CD" javaType="java.lang.String" sqlType="CHAR" includeClause="true"/>
<propertyConfig name="ruleTariffCode" columnName="RULE_TAR_CD" javaType="java.lang.String" sqlType="CHAR" includeClause="true"/>
<propertyConfig name="ruleCode" columnName="RULE_CD" javaType="java.lang.String" sqlType="CHAR" includeClause="true"/>
<propertyConfig name="CREATE_SYSTEM" columnName="CREATE_ID" javaType="java.lang.String" sqlType="CHAR" />
</classConfig>

23.DataLoadSchema.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:element name="classConfig">
<xs:complexType>
<xs:sequence>
<xs:element name="propertyConfig" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="name" use="required"/>
<xs:attribute type="xs:string" name="columnName" use="required"/>
<xs:attribute type="xs:string" name="javaType" use="required"/>
<xs:attribute type="xs:string" name="sqlType" use="required"/>
<xs:attribute type="xs:string" name="includeClause" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="id" use="required"/>
<xs:attribute type="xs:string" name="schemaPropName" use="required"/>
<xs:attribute type="xs:string" name="tableName" use="required"/>
<xs:attribute type="xs:string" name="className" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>

23.filingConfig.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
<!-- This doesn't work in batch container,for BatchContainerContext.xml in batchContainer auto scan net.atpco -->
<context:component-scan base-package="net.atpco.dds" >
</context:component-scan>

<import resource="classpath:/spring/filingDataQueries.xml" />
<import resource="classpath:/spring/object-data-mappings.xml" />

<bean id="properties" class="org.springframework.beans.factory.config.Propertiesfactorybean">
<property name="locations">
<list>
<value>classpath:/gfs0.properties</value>
</list>
</property>
</bean>

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/gfs0.properties</value>
</list>
</property>
</bean>

</beans>

24.object-data-mappings.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">


<bean id="dateMappingConfigurer"
class="net.atpco.dds.offline.filing.common.datamapper.binder.DataMappingConfigurer">
<constructor-arg index="0" ref="configPaths" />
<constructor-arg index="1" type="org.springframework.core.io.Resource"
value="classpath:/spring/DataLoadSchema.xsd"/>
</bean>


<util:list id="configPaths">
<value>classpath:/spring/fc_segment_crrn.xml</value>
<value>classpath:/spring/cat_segment_crrn.xml</value>
<value>classpath:/spring/cat_govt_filing_crrn.xml</value>
</util:list>


</beans>

////////////////////////////Test Project/////////////////////////////////////////////////
25.TestFilingTextDataLoadService
/*
* Created on Jul 31,2014
*
* Copyright 2014 ATPCO Confidential and Proprietary. All Rights Reserved.
*/
package net.atpco.dds.offline.filing.textload.service;

import java.util.List;

import junit.framework.Assert;
import net.atpco.dds.offline.filing.common.AbstractJUnitFilingIntegration;
import net.atpco.dds.offline.filing.common.datamapper.binder.DataLoadRequest;
import net.atpco.dds.offline.filing.common.datamapper.binder.DataLoadService;
import net.atpco.dds.offline.filing.common.datamapper.binder.Mode;
import net.atpco.dds.offline.filing.common.model.FilingFCSegmentCorrection;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
@ContextConfiguration(locations = {"classpath:/net/atpco/dds/offline/filing/textload/service/TestFilingTextDataLoadService.xml" })
@SuppressWarnings("unchecked")
public class TestFilingTextDataLoadService extends
AbstractJUnitFilingIntegration {

/** dataLoadService */
@Autowired
@Qualifier("dataLoadService")
private transient DataLoadService dataLoadService;

@Test
public void test() throws Exception {
final List<FilingFCSegmentCorrection> filingDataList = (List<FilingFCSegmentCorrection>) applicationContext
.getBean("fcSegCorrectionList");
DataLoadRequest dataLoadRequest = new DataLoadRequest(Mode.INSERT,
"fcSegmentCRRN",filingDataList);
boolean result = dataLoadService.update(dataLoadRequest);
Assert.assertTrue(result);
}
}

26.TestFilingTextDataLoadService.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://www.springframework.org/schema/c"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd">

<util:list id="fcSegCorrectionList">
<ref bean="fcSegCorrection1"></ref>
<ref bean="fcSegCorrection2"></ref>
</util:list>

<bean id="fcSegCorrection1"
class="net.atpco.dds.offline.filing.common.model.FilingFCSegmentCorrection">
<property name="inEffYr" value="3019"></property>
<property name="carrierCode" value="AA"></property>
<property name="ruleTariffCode" value="AATCP"></property>
<property name="ruleCode" value="C"></property>
</bean>
<bean id="fcSegCorrection2"
class="net.atpco.dds.offline.filing.common.model.FilingFCSegmentCorrection">
<property name="inEffYr" value="3019"></property>
<property name="carrierCode" value="BB"></property>
<property name="ruleTariffCode" value="AATCP"></property>
<property name="ruleCode" value="C"></property>
</bean>

</beans>

27.AbstractJUnitFilingIntegration
package net.atpco.dds.offline.filing.common;

import net.atpco.dds.offline.filing.common.datamapper.binder.Util;

import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:/spring/filingConfig.xml"
})
public class AbstractJUnitFilingIntegration extends GFSJunit {

static{
Util.setUserId(System.getProperty("user.name"));
}

}
28.GFSJunit
package net.atpco.dds.offline.filing.common;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
import org.springframework.test.context.transaction.TransactionConfiguration;


@ContextConfiguration(locations = {
"classpath:/spring/net/atpco/dds/offline/common/gfs-jdbc-config.xml" })
@TransactionConfiguration(transactionManager = "txManager",defaultRollback = false)
public abstract class GFSJunit extends
AbstractTransactionalJUnit4SpringContextTests {
}

29.gfs-jdbc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<tx:annotation-driven transaction-manager="txManager" />

<bean id="txManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>

<bean id="namedJdbcTemplate" lazy-init="true"
class="org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate">
<constructor-arg index="0" ref="dataSource" />
</bean>

<!-- ?????? -->
<bean id="dataSource1111111"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.MysqL.jdbc.Driver"/>
<property name="url" value="${Url}"/>
<property name="username" value="${username}"/>
<property name="password" ref="ddns_password" />
</bean>

<!-- ??log4jdbc??????sql?? -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
<property name="url" value="jdbc:log4jdbc:MysqL://localhost:3306/atpco"/>
<property name="username" value="${username}"/>
<property name="password" ref="ddns_password" />
</bean>

<bean id="dataSource2222222"
class="com.p6spy.engine.spy.P6DataSource" >
<constructor-arg>
<bean
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="com.MysqL.jdbc.Driver" />
<property name="url" value="${Url}" />
<property name="username" value="${username}" />
<property name="password" ref="ddns_password" />
</bean>
</constructor-arg>
</bean>

<bean id="ddns_password" factory-bean="app_textEncrypter"
factory-method="decrypt">
<!-- ??????? -->
<constructor-arg index="0" value="${pass}" />
</bean>

<bean id="app_textEncrypter" class="com.atpco.textload.util.TextEncrypter">
<!-- ????????? -->
<constructor-arg index="0" value="t" />
</bean>

</beans>

猜你在找的XML相关文章