Spring 에서 sequence 사용 소결

1) 간단 한 소개
sequence        ,            ,               。
  1、 create sequence
       create sequence  create any sequence  
  create sequence emp_sequence
  INCREMENT BY 1 --      
  START WITH 1 --  1    
  NOMAXVALUE --       
  NOCYCLE --     ,   
  CACHE 10;
       emp_sequence,     CURRVAL,NEXTVAL
  CURRVAL=  sequence    
  NEXTVAL=  sequence  ,    sequence 
    :
  emp_sequence.CURRVAL
  emp_sequence.NEXTVAL
      sequence   :
  -       、snapshot、VIEW  SELECT   
  - INSERT       
  - NSERT   VALUES 
  - UPDATE   SET 
         :
  INSERT INTO emp VALUES
  (empseq.nextval, 'LEWIS', 'CLERK',7902, SYSDATE, 1200, NULL, 20);
  SELECT empseq.currval FROM DUAL;
         :
  -    NEXTVAL       ;   NEXTVAL         INCREMENT BY ,         。CURRVAL       sequence  ,      NEXTVAL         CURRVAL,     。  NEXTVAL     sequence  ,                 NEXTVAL,        。
  -     CACHE ,oracle              sequence,       。
  cache      ,oracle       cache。   cache     ,           down (shutdown abort),cache  sequence    .      create sequence    nocache      。
  2、 Alter sequence
       sequence owner,   ALTER ANY sequence      sequence。   alter start      sequence  。      start ,  drop sequence re-create。  :
  ALTER sequence emp_sequence
  INCREMENT BY 10
  MAXVALUE 10000
  CYCLE --  10000     
  NOCACHE;
    sequence      :
  sequence_CACHE_ENTRIES =
        cache sequence  。
        Drop sequence
  DROP sequence order_seq;

 
 
 
 
2). Spring applicationContext   sequence
       dataSource,   sequence。  ,  “SQ_AUTHFLOW”      sequence   
	<!--   Orcale/sequence -->
	<bean id="sequence"
		class="org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer">
		<property name="incrementerName" value="SQ_AUTHFLOW" />
		<property name="dataSource" ref="dataSource" />
	</bean>
3).        
public class TAuthFlowDAOImp implements TAuthFlowDAO {	
	private OracleSequenceMaxValueIncrementer sequence;
	public OracleSequenceMaxValueIncrementer getSequence() {
		return sequence;
	}
	public void setSequence(OracleSequenceMaxValueIncrementer sequence) {
		this.sequence = sequence;
	}	
	public String save(final TAuthFlow tAuthFlow) {		
		..
		..
		OracleSequenceMaxValueIncrementer sequence = (OracleSequenceMaxValueIncrementer) AppContext.appContext.getBean("sequence");
		String irc = String.valueOf(sequence.nextIntValue());
		irc = StringUtils.leftPad(irc, 12, "0");  // irc   0  12    
		SimpleDateFormat sdf11 = new SimpleDateFormat("yyyyMMdd");
		String NowDate = sdf11.format(new Date());
		String SeqNo = NowDate + irc;
		final String IfSvrFlow = SeqNo;
		..
		..
		return SeqNo;		
	}
}
  AppContext.appContext.getBean("sequence")                。

좋은 웹페이지 즐겨찾기