Oracle Self-augmentation configuration __oracle in MyBatis

Source: Internet
Author: User

We can use Oracle's growth in MyBatis, and we can use configuration files and Java code to get the maximum value of the current self increase.

First, you need to create a self augmentation in Oracle, as follows.

CREATE SEQUENCE "  commontrade". Ucf_recharge_suborder_seq "  minvalue 10000000000 MAXVALUE 99999999999 INCREMENT by 1 START with 10000007200 CACHE N Oorder  nocycle;


Step two: Use Spring's support configuration for Oracle sequences. Need to be configured in Applicationcontext.xml.

	<bean id= "Oraclesequencemaxvalueincrementer"
		class= " Org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer ">
		<property name=" Incrementername "value=" "></property>
		<property name=" DataSource "ref=" DataSource "></" Property>
	</bean>

Step three: Write the tool class that gets the sequence.

Import org.springframework.beans.factory.annotation.Autowired;
Import Org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
Import Org.springframework.stereotype.Service;

Import Com.ucf.trade.util.enums.TradeEnum;

@Service public
class Sequencegenerator {
	private static final String Ucf_recharge_trade_order_seq = "ucf_ Recharge_trade_order_seq ";
 
	
	@Autowired public
	oraclesequencemaxvalueincrementer oraclesequencemaxvalueincrementer;
 
	public string Nextrechargeorderseq (string bizproduct, String txntype) {
		Oraclesequencemaxvalueincrementer.setincrementername (UCF_RECHARGE_TRADE_ORDER_SEQ);
		String currval = Oraclesequencemaxvalueincrementer.nextstringvalue ();
		Return Timeutil.getcurrentdatetime14 () +bizproduct+ txntype  + currval;
		20140328175835 10000002814  Total 30 bits
	 
	}

Fourth Step: Use

Inject this tool class as a service

	@Autowired public
	Sequencegenerator sequencegenerator;

Add in the method you want

  String ID =sequencegenerator.nextrechargeorderseq ();

By using the sequence in Oracle, we can use this sequence to stitch up some meaningful numbers.


Related Article

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.