@ -33,31 +33,12 @@ public class MpowerUtils {
static int port = 9999 ;
static String query = "" ;
static ArrayList < String > feilds = new ArrayList < String > ( ) ;
//static String feild = "";
static String tmpFeilds = "" ;
static Boolean RowNum = false ;
static String tableNm = "" ;
static String WhereStr = "" ;
static String Orderby = "" ;
static int pageIndex = 0 ;
static int lastIndex = 10 ;
static int recordCountPerPage = 10 ;
static String beforeXml = "<?xml version='1.0' encoding='euc-kr'?><QUERYS DBNAME='" + DbName2 + "' DEBUG='true'><QUERY TYPE='select' BATCH='false'><SQL><![CDATA[" ;
static String insertXml = "<?xml version='1.0' encoding='euc-kr'?><QUERYS DBNAME='" + DbName2 + "' DEBUG='true'><QUERY TYPE='insert' BATCH='false'><SQL><![CDATA[" ;
static String updateXml = "<?xml version='1.0' encoding='euc-kr'?><QUERYS DBNAME='" + DbName2 + "' DEBUG='true'><QUERY TYPE='update' BATCH='false'><SQL><![CDATA[" ;
static String deleteXml = "<?xml version='1.0' encoding='euc-kr'?><QUERYS DBNAME='" + DbName2 + "' DEBUG='true'><QUERY TYPE='update' BATCH='false'><SQL><![CDATA[" ;
static String afterXml = "]]></SQL></QUERY></QUERYS>" ;
//Ps변수
static String Params = "" ;
static int psParamCount = 0 ;
static String psFinalFarams = "" ;
static String QueryXml = "" ;
static String vioPhoto = "" ;
static String vioPhotoBus = "" ;
static String tunullingFile = "" ;
public void setQuery ( String query ) {
MpowerUtils . query = query ;
}
@ -66,276 +47,10 @@ public class MpowerUtils {
feilds . add ( feildNm ) ;
}
public int getFirstIndex ( ) {
return ( pageIndex - 1 ) * recordCountPerPage + 1 ;
}
public int getLastIndex ( ) {
return lastIndex = pageIndex * recordCountPerPage ;
}
public List < Map < String , Object > > selectQuery ( ) {
String fileList = "" ;
for ( int cnt = 0 ; cnt < feilds . size ( ) ; cnt + + ) {
if ( cnt = = 0 ) {
fileList + = feilds . get ( cnt ) ;
} else {
fileList + = "," + feilds . get ( cnt ) ;
}
}
query = beforeXml + "select " + fileList + " from " + tableNm + WhereStr + afterXml ;
//logger.debug("=====================================================Select Query==================================================");
//logger.debug("select "+fileList +" from "+tableNm + WhereStr);
System . out . println ( "select " + fileList + " from " + tableNm + WhereStr ) ;
//List<EgovMap> mList = new ArrayList<EgovMap>();
List < Map < String , Object > > mList = new ArrayList < Map < String , Object > > ( ) ;
try {
mpower = new Client ( hostip , port ) ;
mpower . getConnection ( "MPowerXmlToQuery.xmlQuery1" ) ;
mpower . setInput ( "SQLXML" , query ) ;
mpower . Request ( ) ;
String result = mpower . getString ( "result" , 0 , 0 ) ;
System . out . println ( "#######$$$$$$$$$$$$$$$$$$" + result ) ;
int row ;
if ( result . equals ( "true" ) ) {
row = mpower . getMaxRow ( "list1" ) ;
if ( row > 0 ) {
for ( int i = 0 ; i < row ; i + + ) {
//EgovMap m = new EgovMap();
Map < String , Object > m = new HashMap < > ( ) ;
for ( int j = 0 ; j < feilds . size ( ) ; j + + ) {
m . put ( feilds . get ( j ) , mpower . getString ( "list1" , i , j ) ) ;
}
mList . add ( m ) ;
}
}
}
//logger.debug("SelectList Count :: "+mList.size()+"건");
//logger.debug("===================================================================================================================");
mpower . disconnect ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
query = "" ;
feilds = new ArrayList < String > ( ) ;
tableNm = "" ;
WhereStr = "" ;
Orderby = "" ;
}
return mList ;
}
private void clearValidation ( ) {
query = "" ;
feilds = new ArrayList < String > ( ) ;
tableNm = "" ;
WhereStr = "" ;
Orderby = "" ;
psParamCount = 0 ;
QueryXml = "" ;
Params = "" ;
psFinalFarams = "" ;
recordCountPerPage = 10 ;
//feild = "";
}
/ * *
* @ 페 이 징 처 리 SELECT 호 출
* @return
* /
public Map < String , Object > selectListQuery ( ) {
//EgovMap mListMap = new EgovMap();
Map < String , Object > mListMap = new HashMap < > ( ) ;
//배열로 넘어온 필드를 String 오브젝트로 변형
String fileList = "" ;
for ( int cnt = 0 ; cnt < feilds . size ( ) ; cnt + + ) {
if ( cnt = = 0 ) {
fileList + = feilds . get ( cnt ) ;
} else {
fileList + = "," + feilds . get ( cnt ) ;
}
}
String init = "" ;
String init2 = "" ;
init = beforeXml + "select RN," + fileList + " from(" ;
init2 = ")TB where RN BETWEEN " + getFirstIndex ( ) + " and " + getLastIndex ( ) + afterXml ;
query = init ;
query = query + "select ROWNUM RN," + fileList + " from(" ;
query = query + "select " + fileList + " " ;
query = query + "from " + tableNm + " " ;
query = query + WhereStr + " " ;
query = query + Orderby ;
query = query + ")TA" ;
query = query + init2 ;
System . out . println ( "이곳은쿼리" ) ;
System . out . println ( query ) ;
System . out . println ( "이곳은쿼리" ) ;
String Cquery = beforeXml + "select count(*) from " + tableNm + " " + WhereStr + afterXml ;
if ( RowNum = = true ) {
feilds = new ArrayList < String > ( ) ;
this . setFeilds ( "RN, " + tmpFeilds ) ;
}
//List<EgovMap> mList = new ArrayList<EgovMap>();
List < Map < String , Object > > mList = new ArrayList < > ( ) ;
System . out . println ( "mlistmlist" ) ;
System . out . println ( mList ) ;
System . out . println ( "mlistmlist" ) ;
int mListCount = 0 ;
try {
mpower = new Client ( hostip , port ) ;
mpower . getConnection ( "MPowerXmlToQuery.xmlQuery1" ) ;
mpower . setInput ( "SQLXML" , query ) ;
mpower . Request ( ) ;
String result = mpower . getString ( "result" , 0 , 0 ) ;
int row = 0 ;
if ( result . equals ( "true" ) ) {
row = mpower . getMaxRow ( "list1" ) ;
if ( row > 0 ) {
for ( int i = 0 ; i < row ; i + + ) {
//EgovMap m = new EgovMap();
Map < String , Object > m = new HashMap < > ( ) ;
for ( int j = 0 ; j < feilds . size ( ) ; j + + ) {
if ( RowNum = = false ) {
m . put ( feilds . get ( j ) , mpower . getString ( "list1" , i , j + 1 ) ) ;
} else if ( RowNum = = true ) {
m . put ( feilds . get ( j ) , mpower . getString ( "list1" , i , j ) ) ;
}
}
mList . add ( m ) ;
}
mListMap . put ( "mList" , mList ) ;
}
}
mpower . disconnect ( ) ;
if ( row > 0 ) {
mpower = new Client ( hostip , port ) ;
mpower . getConnection ( "MPowerXmlToQuery.xmlQuery1" ) ;
mpower . setInput ( "SQLXML" , Cquery ) ;
mpower . Request ( ) ;
String strList1 = mpower . getString ( "list1" , 0 , 0 ) ;
if ( ! strList1 . equals ( "" ) & & strList1 ! = null ) {
mListCount = Integer . parseInt ( strList1 ) ;
}
mpower . disconnect ( ) ;
}
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
clearValidation ( ) ;
}
System . out . println ( "엠리스트트트트트" ) ;
System . out . println ( mListCount ) ;
System . out . println ( mListMap ) ;
System . out . println ( mList ) ;
System . out . println ( "엠리스트트트트트" ) ;
mListMap . put ( "mListCount" , mListCount ) ;
return mListMap ;
}
//
/ * *
* @ 페 이 징 처 리 SELECT 호 출
* @return
* @throws SQLException
* /
public Map < String , Object > selectListQueryNew ( ) throws SQLException {
//EgovMap mListMap = new EgovMap();
Map < String , Object > mListMap = new HashMap < > ( ) ;
//배열로 넘어온 필드를 String 오브젝트로 변형
String fileList = "" ;
for ( int cnt = 0 ; cnt < feilds . size ( ) ; cnt + + ) {
if ( cnt = = 0 ) {
fileList + = feilds . get ( cnt ) ;
} else {
fileList + = "," + feilds . get ( cnt ) ;
}
}
String finalQuery = "" ;
String Cquery = beforeXml + "select count(*) from " + tableNm + " " + WhereStr + afterXml ;
// if(!"".equals(feild) && feild != null){
// finalQuery = query;
// }else{
finalQuery = "select " + fileList + " from " + tableNm + " " + WhereStr ;
//}
if ( RowNum = = true ) {
feilds = new ArrayList < String > ( ) ;
this . setFeilds ( "RN, " + tmpFeilds ) ;
}
//List<EgovMap> mList = new ArrayList<EgovMap>();
List < Map < String , Object > > mList = new ArrayList < Map < String , Object > > ( ) ;
int mListCount = 0 ;
Connection con ;
Statement stmt ; //단순 쿼리 실행
PreparedStatement pstmt = null ; //컴파일시 디비에 먼저 파싱하므로 Statement 보다 빠름
CallableStatement cstmt ; //프로시져를 호출하므로 속도가 PreparedStatement 보다 빠름
ResultSet rs = null ;
String dbURL = "jdbc:oracle:thin:@115.21.123.114:1521:ora10g" ;
String driver = "oracle.jdbc.OracleDriver" ;
try {
Class . forName ( driver ) ;
} catch ( ClassNotFoundException e1 ) {
// TODO Auto-generated catch block
e1 . printStackTrace ( ) ;
}
con = DriverManager . getConnection ( dbURL , "TRAFFIC" , "xhdgkq0" ) ;
//3.1 Statement 객체로 구문객체 생성 및 실행
int size = 0 ;
try {
System . out . println ( "Query :" + finalQuery ) ;
pstmt = con . prepareStatement ( finalQuery ) ;
rs = pstmt . executeQuery ( ) ; // 이거 왜 실행안???
System . out . println ( "rs:" + rs ) ;
boolean chpoint = false ;
while ( rs . next ( ) )
{
size = rs . getInt ( 1 ) ;
//EgovMap m = new EgovMap();
Map < String , Object > m = new HashMap < > ( ) ;
if ( ! chpoint )
{
for ( int j = 0 ; j < size ; j + + ) {
m . put ( feilds . get ( j ) , rs . getString ( feilds . get ( j ) . toString ( ) ) ) ;
}
mList . add ( m ) ;
}
}
mListMap . put ( "mList" , mList ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
try {
rs . close ( ) ;
pstmt . close ( ) ;
con . close ( ) ;
clearValidation ( ) ;
} catch ( SQLException e ) {
e . printStackTrace ( ) ;
}
}
return mListMap ;
}
//
/ * *
* @ 페 이 징 처 리 SELECT 호 출
@ -345,6 +60,7 @@ public class MpowerUtils {
List < Map < String , Object > > mList = new ArrayList < > ( ) ;
query = beforeXml + query + afterXml ;
System . out . println ( query ) ;
try {
mpower = new Client ( hostip , port ) ;
mpower . setCryptEnable ( false ) ;
@ -380,6 +96,7 @@ public class MpowerUtils {
List < T > list = new ArrayList < > ( ) ;
query = beforeXml + query + afterXml ;
System . out . println ( query ) ;
try {
mpower = new Client ( hostip , port ) ;
mpower . setCryptEnable ( false ) ;
@ -448,6 +165,7 @@ public class MpowerUtils {
if ( totalCnt < = 0 ) return rtnMap ;
query = beforeXml + query + afterXml ;
System . out . println ( query ) ;
try {
mpower = new Client ( hostip , port ) ;
mpower . setCryptEnable ( false ) ;
@ -496,61 +214,45 @@ public class MpowerUtils {
return rtnMap ;
}
public void setFeilds ( String string ) {
String [ ] m = string . split ( "," ) ;
for ( int i = 0 ; i < m . length ; i + + ) {
setFeild ( m [ i ] . trim ( ) ) ;
}
tmpFeilds = string ;
public int insertQuery ( String sql ) {
return executeQuery ( insertXml + sql + afterXml ) ;
}
//첨부파일 터널링 서버로 복사
public void fnFileUpload ( String tmpFileLocation , String realRcRilenm ) {
String fph = tunullingFile ; //터널링에 복사되는 파일경로
try {
Client mp = new Client ( "127.0.0.1" , 2500 ) ;
mp . getConnection ( "XitFile.XitUpload" ) ;
mp . setInput ( "dir" , tunullingFile ) ;
mp . setInput ( "upfile1" , tmpFileLocation + realRcRilenm , true ) ;
mp . Request ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
}
//logger.debug(fph);
public int updateQuery ( String sql ) {
return executeQuery ( updateXml + sql + afterXml ) ;
}
public int deleteQuery ( String sql ) {
return executeQuery ( deleteXml + sql + afterXml ) ;
}
//터널링에서 웹서버로 첨부파일 복사
public static void fnDownFile ( String fileName , String sessionId ) {
String serviceName = "XitFile.XitDownload" ;
String fph = MpowerUtils . class . getResource ( "" ) . getPath ( ) ;
fph = fph . replace ( "WEB-INF/classes/xit/cmmn/utill/" , "vioPhoto/" + sessionId + "/" ) ; //웹서버 저장 위치
String fphs = fph . substring ( 0 , 1 ) ;
if ( fphs . equals ( "/" ) ) {
fph = fph . substring ( 1 ) ;
}
String tmpTunullingFile = tunullingFile ; //터널링에 저장된 단속사진 경로
public int executeQuery ( String sql ) {
System . out . println ( sql ) ;
try {
Client mp = new Client ( "127.0.0.1" , 2500 ) ;
mp . getConnection ( "XitFile.XitDownload" ) ;
mp . setInput ( "dnfile1" , tmpTunullingFile + fileName ) ; //터널링에 실질 존재하는 경로,파일명
mp . Request ( ) ;
String result = mp . getString ( "result" , 0 , 0 ) ;
mpower = new Client ( hostip , port ) ;
mpower . getConnection ( "MPowerXmlToQuery.xmlQuery1" ) ;
mpower . setInput ( "SQLXML" , sql ) ;
mpower . Request ( ) ;
if ( result . equals ( "true" ) ) {
mp . getFileName ( "imageA" ) ;
mp. savefile ( "imageA" , fph ) ;
String result = mpower . getString ( "result" , 0 , 0 ) ;
if ( ! result . equals ( "true" ) ) {
System . out . println ( "<<<<<<<<<<<<===========#$#$#$$##$#$$#$#$$$$$$$====>>>>>>>>>" ) ;
}
} catch ( Exception e ) {
mpower . disconnect ( ) ;
} catch ( Exception e ) {
e . printStackTrace ( ) ;
} finally {
clearValidation ( ) ;
}
//logger.debug("웹서버 저장되는 첨부파일 위치:"+fph);
System . out . println ( "웹서버 저장되는 첨부파일 위치:" + fph ) ;
}
return 1 ;
}
public void setFeilds ( String string ) {
String [ ] m = string . split ( "," ) ;
for ( int i = 0 ; i < m . length ; i + + ) {
setFeild ( m [ i ] . trim ( ) ) ;
}
}
}