Spring JdbcTemplate enables intermediate library synchronization of data

Source: Internet
Author: User

Intermediate Library mode synchronizing Data

Configure a JdbcTemplate bean in the Spring IoC container, inject the DataSource into it, and then inject jdbctemplate into the custom DAO.

Requirements: Write archives, Department base data to Intermediate library, take archives as an example

    1. Trigger

      View all trigger, view trigger Create statement


Show Create TRIGGER Trg_staffinfo_deleteselect * from INFORMATION_SCHEMA. ' TRIGGERS '


When creating, modifying, and deleting profile information, add data to the synchronization state table, trigger create the following statement:

#档案创建CREATE   TRIGGER  ' trg_staffinfo_insert '  AFTER INSERT ON  ' T_per_ Staffinfo '  for each row begin insert into t_att_userorg_sync_mark (ID, Relateid,relatename,relatetype,synchro,synctype,domain,createtime) VALUES (UUID (), new.staffid,new.staffname,1, ' N ', 1, ' C6 ', now ()); end# file update create  trigger  ' trg_staffinfo_update '  AFTER UPDATE ON  ' T_per_ Staffinfo '  FOR EACH ROW BEGIN if new.staffId          !=old.staffId OR      new.staffName       !=old.staffNameOR  new.sex              !=old.sex  OR           new.recruitsdate    !=old.recruitsdate ornew.persontype       !=old.persontype OR   new.leaveDate       !=old.leaveDate OR    new.techLevel       !=old.techLevel OR    new.postname        !=old.postname or    new.postdirection   !=old.postdirection ornew.cengjipcode     != Old.cengjipcode or  new.deptcode        !=old.deptcode  or     new.deptname        != old.deptname or new.staffstatus     !=old.staffstatus or          new.officeAddress   !=old.officeAddress  Ornew.sfcb !=old.sfcbthen insert into t_att_userorg_sync_mark (Id,relateID,relateName, Relatetype,synchro,synctype,domain,createtime) VALUES (UUID (), old.staffid,old.staffname,1, ' N ', 2, ' C6 ', now ()); end if; end# file Delete create trigger  ' trg_staffinfo_delete '  AFTER DELETE ON  ' t_per_staffinfo '  for each row begin insert into t_att_userorg_sync_mark (Id,relateID, Relatename,relatetype,synchro,synctype,domain,createtime) VALUES (UUID (), old.staffid,old.staffname,1, ' N ', 3, ' C6 ', Now ()); END

Timed task--Take Easyschedulejava code (add as example)

Public int addhremp (final hremppo t)  {return jdbctemplate.update ("INSERT  Into hr_emp (c_code,c_name,c_gender,c_idcard,c_hiredate,c_employeestatus,lizhidate,c_jobname,jibie,c_ unitcode,c_unitname,leibie,synchflagid,officeadd,c_isputmoney,c_isputeffdate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?, ?,?,?); ", New  preparedstatementsetter () {@Overridepublic  void setvalues (preparedstatement  PS)  throws sqlexception {ps.setstring (1, t.getccode ());p s.setstring (2,  T.getcname ());p s.setstring (3, t.getcgender ());p s.setstring (4, t.getidcard ());p s.setstring (5,  T.getchiredate ());p s.setstring (6, t.getcemployeestatus ());p s.setstring (7, t.getlizhidate ()); Ps.setstring (8, t.getcjobname ());p s.setstring (9, t.getjibie ());p s.setstring (10, t.getcunitcode ( ));p s.setstring (11, t.getcunitname ());p s.setstring (12, t.getleibie ());p s.setstring (13,  T.getsynchflagid ());p s.setstring (14, t.gEtofficeaddress ());p s.setstring (15, t.getc_isputmoney ());p s.setdate (16, new date (t.getC_ Isputeffdate (). GetTime ()));});

Spring-jdbc configuration file

<context:property-placeholder location= "Classpath:jdbc.properties"  ignore-unresolvable= "true"  /><bean id= "Hrempdao"  class= "Com.fx.oa.module.att.attendance.server.dao.impl.HrEmpDao" ><property name= "JdbcTemplate"  ref= "jdbcTemplateC6"  /></bean><bean id= " JdbcTemplateC6 " class=" Org.springframework.jdbc.core.JdbcTemplate "><property name=" DataSource "  ref= "DataSourceC6"  /></bean><!-- c6 Interactive Intermediate Library data source  --><bean id= " DataSourceC6 " class=" Com.mchange.v2.c3p0.ComboPooledDataSource "><property name=" Driverclass "  value= "${c6.jdbc.driverclassname}"  /><property name= "Jdbcurl"  value= "${c6.jdbc.url} " /><property name=" user " value=" ${c6.jdbc.username} " /><property name=" Password " value=" ${c6.jdbc.password} " /><property name=" Autocommitonclose " value=" True " /><property&nbSp;name= "Checkouttimeout"  value= "${hpool.checkouttimeout}"  /><property name= " Initialpoolsize " value=" ${hpool.minpoolsize} " /><property name=" MinPoolSize " value=" ${hpool.minpoolsize} " /><property name=" Maxpoolsize " value=" ${hpool.maxPoolSize} " / ><property name= "MaxIdleTime"  value= "${hpool.maxidletime}"  /><property name= " Acquireincrement " value=" ${hpool.acquireincrement} " /><property name=" Maxidletimeexcessconnections " value=" ${hpool.maxidletimeexcessconnections} " /></bean>


This article is from the "Jiangnan Miner Technology Space" blog, please be sure to keep this source http://jncumter.blog.51cto.com/812546/1851199

Spring JdbcTemplate enables intermediate library synchronization of data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.