Based on the spring framework, the instance is configured as a bean to get the incremental value of the sequence that already exists on Oracle. ____oracle

Source: Internet
Author: User

Import java.util.Collections;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;

Import Javax.sql.DataSource;

Import Org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;

Import com.huawei.widget.commons.dao.DBException;
Import Com.huawei.widget.commons.dao.spi.SequenceGenerator;
Import Com.huawei.widget.commons.exception.ErrorCode;

/**
* Based on the spring framework, the instance is configured as a bean to get the incremental value of the sequence that already exists on Oracle.
*
* @author g00106664
* @version C02 2009-5-14
* @since OpenEye widget_srv V100R001C02
*/
public class Oraclesequencegeneratorspringimpl implements Sequencegenerator
{
/**
* Self-Booster cache container
*/
Private map<string, oraclesequencemaxvalueincrementer> incrementermap = null;

/**
* Default constructor
*/
Public Oraclesequencegeneratorspringimpl ()
{
}

/*
* (Non-Javadoc)
*
* @see Com.huawei.widget.commons.dao.spi.sequencegenerator#init (Javax.sql.DataSource,
* java.util.List)
*/
public void Init (DataSource DataSource, list<string> sequencenames)
{
Incrementermap = Collections
. Synchronizedmap (New hashmap<string, oraclesequencemaxvalueincrementer> ());

        if (sequencenames!= null)
         {
            for String sequencename: Sequencenames)
            {
                 incrementermap.put (Sequencename,
                         New Oraclesequencemaxvalueincrementer (DataSource,
                                  sequencename));
           }
       }
   }

/*
* (Non-Javadoc)
*
* @see Com.huawei.widget.commons.dao.spi.sequencegenerator#nextintvalue (java.lang.String)
*/
public int Nextintvalue (String sequencename) throws Dbexception
{
Return Getincrementer (Sequencename). Nextintvalue ();
}

/*
* (Non-Javadoc)
*
* @see Com.huawei.widget.commons.dao.spi.sequencegenerator#nextlongvalue (java.lang.String)
*/
Public long Nextlongvalue (String sequencename) throws Dbexception
{
Return Getincrementer (Sequencename). Nextlongvalue ();
}

/*
* (Non-Javadoc)
*
* @see Com.huawei.widget.commons.dao.spi.sequencegenerator#nextstringvalue (java.lang.String)
*/
public string Nextstringvalue (String sequencename) throws Dbexception
{
Return Getincrementer (Sequencename). Nextstringvalue ();
}

Private Oraclesequencemaxvalueincrementer Getincrementer (String sequencename)
Throws Dbexception
{
Oraclesequencemaxvalueincrementer Incrementer = Incrementermap
. get (Sequencename);
if (null = = Incrementer)
{
throw new Dbexception (Errorcode.common_get_sequence_unikey_fail,
"The Incrementer of sequence:" + sequencename
+ "is not initialized.");
}

        return incrementer;
   }
}

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.