kr.co.hit.live.query
Class SqlQueryParser

java.lang.Object
  extended by org.xml.sax.helpers.DefaultHandler
      extended by kr.co.hit.live.query.SqlQueryParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class SqlQueryParser
extends org.xml.sax.helpers.DefaultHandler

다음과 같은 형태로 정의된 SQL 문장을 파싱하여 Sqls 객체를 반환한다. 파라메터는 #name:mode:type@format# 형태로 정의하며 mode,type,format은 생략할 수 있다.

다음은 SimpleDateFormat에서 정의하는 포멧에 대한 설명이다. 주의할 점은 날짜(일)은 MM 이며 분은 mm, 밀리초는 SSS로 표현된다는 점이다.
Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
M Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800

동적으로 파라메터 값에 따라서 조립되는 Sql 문장 작성도 가능하다.

    <sqls>
        <resultMap id="datemap">
            <result column="regdy"
                    reader="kr.co.hit.live.dao.reader.FormattedDateColumnReader"
                    format="yyyyMMdd">
            <result column="updtym"
                    reader="kr.co.hit.live.dao.reader.FormattedDateColumnReader"
                    format="yyyyMM">
        </resultMap>
        <statement id="getEmpNo"><![CDATA[
          SELECT -- himed.com.comcodemgr.comcodedao
                 id, name, dept
            FROM emp_table
           WHERE id = #emp_id# ]]>
           <isNotEmpty property="emp_nm"><![CDATA[
                 and name = #emp_nm# ]]>
           </isNotEmpty>
        </statement>

        <statement id="setComCode" resultmap="datemap"><![CDATA[
          INSERT -- himed.com.comcodemgr.comcodedao
            INTO comcdeptm
                 (deptcd       ,
                  todd         ,
                  fromdd       ,
                  deptnm       ,
                  lastupdtdt   ,
                  regid )
          VALUES (#deptcd#       ,
                  NVL(#todd#     , '29991231'),
                  #fromdd#       ,
                  #deptnm#       ,
                  #updtdt::DATE@yyyy-MM-dd#,
                  #$userid#) ]]>
        </statement>

        <statement id="exeSwapEmail"><![CDATA[
          {call swapEmail(#email1:INOUT:VARCHAR#, #email2:INOUT:VARCHAR#)}
          ]]>
        </statement>

    </sqls>
 

동적 SQL문을 위하여 다음과 같은 element들을 제공한다.

위 element들은 nested 되어 사용이 가능하다.

SQL 문장내에서 사용할 상수값들을 정의할 수 있는 <defintion> 기능을 정의한다.

정의된 definition들은 동적 SQL문의 조건으로 사용될 수 있다. 이때 동적 SQL element에서 property 속성 명 대신에 defintion을 사용하면 된다.

Since:
4.0
Author:
김형도

Constructor Summary
SqlQueryParser(ClassLoader loader)
           
 
Method Summary
 void characters(char[] buf, int offset, int len)
           
 void endDocument()
           
 void endElement(String namespaceURI, String sName, String qName)
           
 Sqls parse(String path, Set<String> include)
          File 객체로 주어진 Sql 정의 파일을 파싱하여 Sqls 객체를 생성한다.
 Sqls parse2(InputStream is)
          InputStream으로 주어진 Sql 정의 파일을 파싱하여 Sqls 객체를 생성한다.
 void startDocument()
           
 void startElement(String namespaceURI, String sName, String qName, Attributes attrs)
           
 
Methods inherited from class org.xml.sax.helpers.DefaultHandler
endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startPrefixMapping, unparsedEntityDecl, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SqlQueryParser

public SqlQueryParser(ClassLoader loader)
Method Detail

parse

public Sqls parse(String path,
                  Set<String> include)
           throws SAXException
File 객체로 주어진 Sql 정의 파일을 파싱하여 Sqls 객체를 생성한다.

Parameters:
mapFile -
Returns:
Throws:
SAXException

parse2

public Sqls parse2(InputStream is)
            throws SAXException
InputStream으로 주어진 Sql 정의 파일을 파싱하여 Sqls 객체를 생성한다. 주어진 Inpustream는 내부에서 close 된다.

Parameters:
mapFile -
Returns:
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

startElement

public void startElement(String namespaceURI,
                         String sName,
                         String qName,
                         Attributes attrs)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

endElement

public void endElement(String namespaceURI,
                       String sName,
                       String qName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException

characters

public void characters(char[] buf,
                       int offset,
                       int len)
                throws SAXException
Specified by:
characters in interface ContentHandler
Overrides:
characters in class org.xml.sax.helpers.DefaultHandler
Throws:
SAXException


Copyright © 2014. All Rights Reserved.