Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


ReflectionÀ» ÀÌ¿ëÇÑ Value Objectºñ±³
 
VOÆÐÅÏÀ» »ç¿ëÇÏ¿´À» °æ¿ì º¯°æÀ̷µîÀÇ ±â·ÏÀ» À§ÇÑ VO¸¦ ºñ±³ÇÏ¿© µ¥ÀÌÅͺ£À̽º¿¡ º¯°æµÈ »çÇ×À» ¹Ý¿µÇÒ ¼ö ÀÖµµ·Ï °£´ÜÇÏ°Ô °í¾ÈÇÑ ³»¿ëÀÌ´Ù. ( 2003/07/01 ) 327
Written by ienvyou - ÃÖÁö¿õ
1 of 1
 

¾È³çÇϽʴϱî? ³î»õ~ÀÔ´Ï´Ù.
À̹ø ¾ÆƼŬ¿¡¼­´Â Á¦°¡ ÇÑ ÇÁ·ÎÁ§Æ®½Ã¿¡ ÇÊ¿äÇß¾ú´ø º¯°æÀ̷¿¡ ´ëÇÑ ·Î±×¸¦ ³²±â±â À§ÇÏ¿©
¸¸µé¾ú´ø VO ºñ±³±âÀÔ´Ï´Ù.


¢º »ý¼ºµ¿±â

ÀÏÀü ÇÁ·ÎÁ§Æ®´Â XX»çÀÌÆ®ÀÇ Äݼ¾Å;÷¹«±¸ÃàÀ» ÇÏ´Â °ÍÀ̾ú´Âµ¥ (»ç½Ç »ý°¢¸¸ Çϸé Ä¡°¡ ¶³¸²´Ù~)
°í°´¿¡ ´ëÇÑ ¸¶½ºÅÍÁ¤º¸¸¦ ´©°¡ ¾ðÁ¦ ¾î¶»°Ô ¹Ù²Ù¾ú´ÂÁö¸¦ ±â·ÏÀ» Çسõ¾Æ¾ß ´ÙÀ½¿¡ ÇØ´ç
°í°´ÀÇ ¹®ÀÇ°¡ ´Ù½Ã µé¾î¿ÔÀ» °æ¿ìÀÇ ÀÀ´ë¸¦ ½±°Ô Çϱâ À§ÇÏ¿© ¸¸µé¾ú´ø ³»¿ëÀÔ´Ï´Ù.

½Ç·ÂÀÌ ¾Æ´Ñ ÀÚÁ¸½É¿¡ °¡µæÂù S¸ð ȸ»çÀÇ »ç¶÷µéÀÌ Â®´ø ³»¿ëÀÌ ÀÖ¾ú´Âµ¥ pro*C·Î ÇØ´ç µ¥ÀÌÅÍ
º£À̽º¸¦ Àо TableBeanÀ» ¸¸µé¾î ¸ðµç Çʵ带 º¯¼ö·Î ¼±¾ðÇÏ¿© ½è½À´Ï´Ù.

°¡·É EMP¶ó´Â table¿¡ EMPNO, EMP_NAME µîµîÀÌ ÀÖÀ»¶§ »ý¼ºµÆ´ø BeanÃøÀº
// ±¸ µ¥ÀÌÅͺ¸Á¸¿ë
private String old_emp_no;
private String old_emp_name;

// º¯°æµÈ µ¥ÀÌÅÍ
private String new_emp_no;
private String old_emp_name;

ó·³ ÀÛ¼ºÇß¾ú½À´Ï´Ù.

Èì~ ¾Æ¹«¸® ºÁµµ º¯¼ö¼±¾ð¿¡ ºÒÇÊ¿äÇÑ ³»¿ë±îÁö ÀÖ¾ú´ø Áö¶ó º¯°æÀ» Çغ¸°íÀÚ ³î»õ~´Â °á½ÉÇß½À´Ï´Ù.

¢º Àü·«Â¥±â

Èì~.. º¯°æµÈ µ¥ÀÌÅ͸¸À» ¾Ë¾Æ³»¾î ÇØ´ç ÇʵåÀÇ X->Y·Î ÀüÀÌµÈ °á°ú°ªÀ» ¾î¶»°Ô º¸Á¸ÇÒ¼ö ÀÖ°Ú½À´Ï±î?
Çѹø »ý°¢À» Çغ¾½Ã´Ù.
¿©·¯ºÐµé °°À¸¸é ¾î¶»°Ô ¸¸µå´Â °ÍÀÌ ÃÖ¼±ÀÇ ¹æ¹ýÀϱî¿ä?

¸Þ¸ð¸®? ÆÄÀÏ? DB reload?

ÂÁ~ ½±°Ô °áÁ¤ÇÒ ¸¸ÇÑ »çÇ×ÀÌ ¾Æ´Ï°Ú³×¿ä.
¸Þ¸ð¸®·Î ÇÏÀÚ´Ï ¸¹Àº ¼öÀÇ Äݼ¾ÅÍÁ÷¿øÀÌ ÇÏ·ç¿¡ Á÷¿øÀÌ ³»¿ëÀ» ¹Ù²Ù´Âµ¥¸¸ ÇÏ´õ¶óµµ ¾î¸¶¾î¸¶ÇÑ
¾çÀÇ µ¥ÀÌÅÍ°¡ ½×Àϼö°¡ ÀÖÀ¸´Ï À§ÇèÇϱ⵵ ÇÒ°Í °°½À´Ï´Ù.

±×¸®°í ¸¸¾à ÇØ´ç °í°´¿¡ ´ëÇÑ ½ÇÁ¦ update°¡ ÀÌ·ç¾îÁöÁö ¾Ê¾ÒÀ» °æ¿ìÀÇ ´ëÃ¥À» ¾î¶»°Ô ¼¼¿ï°ÍÀÎÁöµµ
±Ã±ÝÇϳ׿ä.

±×·¯¸é ¹èÄ¡ÀÛ¾÷À» µ¹¸±¼ö ÀÖµµ·Ï filtering engineÀ» žÀçÇÑ ÆÄÀϽýºÅÛ¿¡ ÀúÀåÀ» ÇÏÀÚ?
¾î¶ó...ÀÌ°Ç ½Ç½Ã°£ ¾÷¹«À̱⠶§¹®¿¡ °¡´É¼ºÀ» ÀÖÀ¸³ª ¾÷¹«¿¡ ´ëÇÑ ÀûÇÕ¼º Ãø¸é¿¡¼­ ¾à°£Àº 
¹«¸®¼öÀÏµíµµ ÇÕ´Ï´Ù.

±×·¸´Ù¸é DB select¸¦ Çѹø ´õ ?
Èì.. ÀÌ°Ç ¶ÇÇÑ ¸Þ¸ð¸®Ã³·³ DB°¡ °ÆÁ¤µÇ±ä ÇÏÁö¸¸ ±×¸® ½É°¢ÇÒ °Í °°Áö´Â ¾Ê°í..

È£~ ¹«¾ùÀ¸·Î °áÁ¤À» ÇØ¾ß ÇÒ±î¿ä? ´õ ÁÁÀº ¹æ¹ýÀ» ¾Ë°í °è½Å°¡¿ä?
±×·¯¸é ¹æ¸í·Ï¿¡Á» ³²°ÜÁÖ½ÉÀÌ~~ ^^

°á±¹Àº ½Ã°£ÀÌ ¾ø¾î¼­ °¡Àå ½±°Ô °¥¼ö ÀÖ´Â µ¥ÀÌÅͺ£À̽º¸¦ ÀÌ¿ëÇϱâ·Î ÇÏ¿´½À´Ï´Ù. 

ÀÚ. Çö¾÷ÀÇ ¿äû»çÇ×Àº ´ÙÀ½°ú °°½À´Ï´Ù.

1. °í°´¿¡ ´ëÇÑ ¸ðµç º¯°æÁ¤º¸¸¦ ÀÌ·ÂÀ¸·Î¼­ È­¸é¿¡ º¸¿©Áú¼ö ÀÖ¾î¾ß ÇÕ´Ï´Ù.
2. º¯°æÀÌ µÈ´ÙÇÏ´õ¶óµµ ±âÁ¸ÀÇ µ¥ÀÌÅͺ£À̽º¿Í ºñ±³ÇÏ¿© ½ÇÁ¦ ¹Ù²î¾îÁø Çʵ常 ã¾Æ³»¾ß ÇÕ´Ï´Ù.
3. °¢ Å×ÀÌºí¿¡ ´ëÇÑ Á¤º¸ ¹× Çʵ忡 ´ëÇÑ Á¤º¸¸¦ ÇÔ²² º¸°í ½Í½À´Ï´Ù.
4. ÄÚµå °ªÀÌ ÀÖÀ»¶§ »ó´ã¿øÀÌ ½Äº°ÇÒ ¼ö ÀÖ´Â ÇüÅÂÀÇ ½ÇÁ¦ °ªÀ¸·Î º¯È¯µÇ¾îÁ®¾ß ÇÕ´Ï´Ù.

Áï 
Å×ÀÌºí        À̸§          Çʵå¸í         Çʵ弳¸í         ±âÁ¸      º¯°æ       ´©°¡     ¾ðÁ¦
============================================================================
XXX1     °í°´¸¶½ºÅÍ     CUST_CD      °í°´À¯Çü       °³ÀÎ        ¹ýÀÎ     ³î»õ~   07-01 2½Ã

¿ä±¸»çÇ×Àº À§¿Í °°Àºµ¥ ¸Å¿ì °£´ÜÇÏÁÒ?
±×·¸´Ù¸é ¸ðµç ¾ÖÇø®ÄÉÀ̼ǿ¡¼­ »ç¿ëÇÒ ¼ö ÀÖ´Â ÇüÅ·Π¸¸µé¾î³»¾ß ÇÒÅÍÀε¥..

ÂÁ..Áï °£´ÜÇÑ º¯°æÀÌ·Â¿ë °øÅë ¸ðµâÁ¤µµ°¡ µÇ°Ú±º¿ä...

¢º ¾î¶»°Ô ©°ÍÀΰ¡?
ÃÖÃÊÀÇ ¾ÆÅ°ÅØÃÄ´Â JSP-Model1µµ ¾Æ´Ï°í ¾ÆÁÖ °íÀüÀûÀÎ JSP¿´´Âµ¥ µ¥ÀÌÅͺ£À̽º Á¢¼ÓºÎÅÍ
¸ðµç °ÍÀ» JSPÄÚµå ¾È¿¡¼­ ¸ðµÎ ó¸®ÇÏ°Ô ÇÑ ³Ê¹«³ªµµ ¶Ù¾î³­(?) ÇÁ·Î±×·¥À̾ú½À´Ï´Ù.
±×·¡¼­ Model-2±îÁö´Â ¾Æ´Ï´õ¶óµµ ÃÖ¼ÒÇÑ beanÀ» ÀÌ¿ëÇÏ¿© ÄÚµùÀ» Çϵµ·Ï °³¹ßÀڵ鿡°Ô
¿ä±¸¸¦ Çß°í, Front tier´ÜÀÇ VO(Value Object)¿Í DAO(Data Access Object)ÆÐÅÏÀ» ÀÌ¿ëÇÏ¿© ÄÚµùÀ»
Çϵµ·Ï ÁÖ¹®Çß¾ú½À´Ï´Ù.

¿©±â¼­ ³î»õ~°¡ »ý°¢ÇÑ°ÍÀº "Èì~ VO¸¦ ¾²´Â±º~ º¸Åë VO´Â database table schemaÀÇ ¹Ý¿µÀÌÁö"
¿´½À´Ï´Ù.

µ¥ÀÌÅͺ£À̽ºÀÇ Çʵ忡 ´ëÇÑ ³»¿ëÀº ÇØ´ç µ¥ÀÌÅͺ£À̽º°¡ ÁÖ¼®ÀÌ Àß ´Þ¸°°æ¿ì´Â ¹®Á¦°¡ 
¾ø°Ú´Âµ¥ ÁÖ¼®ÀÌ ¾È´Þ¸° ÇʵåµéÀÌ ¸¹¾Æ¼­ ÀÚ¹ÙÃø¿¡¼­ metadata¸¦ ¾´´ÙÇصµ ¸ø°¡Á®¿Ã È®·üÀÌ 
¸¹¾Æ Çʵ弳¸í¿¡ ´ëÇÑ °ÍÀ» ó¸®ÇϱⰡ »ó´çÈ÷ ¾Ö¸Å¸ðÈ£ÇÑ Ãø¸éÀ» º¸ÀÌ°í ÀÖ½À´Ï´Ù.

±×·¡¼­ ÇÏ´Â ¼ö ¾øÀÌ ÇØ´ç Çʵ带 ó¸®ÇÒ¼ö ÀÖ´Â µ¥ÀÌÅͺ£À̽º Å×À̺íÀ» Ãß°¡ÇÏ°Ô µË´Ï´Ù.

Å×À̺í¸íÀº HT001(½ÇÁ¦ º¯°æÀÌ·ÂÁ¤º¸), HT002(Å×ÀÌºí¼³¸í), HT003(Çʵå)À¸·Î °£´ÜÇÏ°Ô ¸í¸íÇÏ°í

HT001 : HISTORY_NO, HISTORY_TYPE, CUSTOMER_NO, TABLE_NAME, 
            TABLE_COMMENT, COLUMN_NAME, COLUMN_COMMENT, 
            BEFORE_DATA, AFTER_DATA, UPDATE_DATE, WORKER

HT002 : TABLE_NO,  TABLE_NAME,  VO_NAME, TABLE_COMMENTS

HT003 : TABLE_NO, COLUMN_NAME, METHOD_NAME, COLUMN_COMMENT

HT002Å×À̺íÀÇ Å×À̺íÀº ½ÇÁ¦ ¾î¶² VO¿ÍÀÇ ¿¬°áÀÌ µÇ¾î ÀÖ´ÂÁö¸¦ Ç¥ÇöÇϸç, HT003Å×À̺íÀº
ÇØ´ç VO°¡ ¾î¶² columnÀ̸§ÀÇ method¿¡ ¸ÅÇÎÀÌ µÇ´ÂÁö¸¦ »ìÆ캻 °ÍÀÔ´Ï´Ù.

Áï ¾î¶°ÇÑ ¾ÖÇø®ÄÉÀ̼ÇÀÌ´øÁö ÇØ´ç comparator¸¦ È£ÃâÇÏ°Ô µÇ¸é ÀÚµ¿À¸·Î VOÀÇ ÇüŸ¦
ã¾Æ³»¾î reflectionÀ» ÀÌ¿ëÇÏ¿© method¸¦ ÀÌ¿ëÇÏ¿© »Ì¾Æ³»¸é ½±°Ô µÉ°Í °°ÁÒ?

CM_001 Å×À̺íÀÌ °í°´¸¶½ºÅÍÀÌ°í Çʵå´Â CUST_NAME, CUST_UUIDÀ̶ó°í °¡Á¤Çغ¸ÁÒ

HT002ÀÇ µ¥ÀÌÅÍ´Â ´ÙÀ½°ú °°½À´Ï´Ù. °í°´¸¶½ºÅÍ Å×À̺íÀÇ Å×À̺í¸íÀÌ CM_001À̶ó°í ÇßÀ»¶§

TABLE_NO -> 1
TABLE_NAME -> CM_001
VO_NAME -> CM001VO
TABLE_COMMENTS -> °í°´¸¶½ºÅÍ

¶ÇÇÑ HT003ÀÇ µ¥ÀÌÅÍ´Â ´ÙÀ½°ú °°½À´Ï´Ù.

RECORD-1
====================================
TABLE_NO -> 1
COLUMN_NAME -> CUST_NAME
METOHD_NAME -> getCustName
COLUMN_COMMENT -> °í°´À̸§

RECORD-2
====================================
TABLE_NO -> 1
COLUMN_NAME -> CUST_UUID
METOHD_NAME -> getCustUuid
COLUMN_COMMENT -> °í°´À¯ÀÏID

ÀÚ. À§¿Í °°ÀÌ ÇØ´ç table¿¡ ´ëÇÑ field¹× vo¿¡ ´ëÇÑ mappingÁ¤º¸¸¦ ÀÔ·ÂÇÕ´Ï´Ù.

ÀÌÁ¦ ºñ±³ÇÒ ¼ö ÀÖ´Â Äڵ带 °£´ÜÇÏ°Ô º¸µµ·Ï ÇÏ°Ú½À´Ï´Ù.


package com.javapattern.util;

import java.sql.*;
import java.lang.reflect.*;
import java.util.*;
import javax.transaction.*;

import com.javapattern.call.vo.HT003VO;
import com.javapattern.call.vo.HT002VO;
import com.javapattern.call.vo.HT001VO;

public class HistoryUpdator extends ComponentDAO{
    private static HistoryUpdator updator;

    private HistoryUpdator() {}

    public static HistoryUpdator newInstance() {
        if( updator == null ) {
            synchronized(HistoryUpdator.class) {
                updator = new HistoryUpdator();
            }
        }
        return updator;
    }
    /**
    *  »óź¯°æÀÌ·ÂÀ» °ü¸®Çϱâ À§ÇÏ¿© Å×À̺íÄÚµå, ÀÛ¾÷ÀÚ¿Í ¿øº» µ¥ÀÌÅÍ¿Í ¼öÁ¤µ¥ÀÌÅÍ¿¡ 
    *  ´ëÇÑ reflection
    *  ºñ±³¸¦ ÇÑÈÄ º¯°æµÈ µ¥ÀÌÅÍÀÇ Ä÷³¿¡ ´ëÇÏ¿© ÀúÀåÇϵµ·Ï ÇÑ´Ù.
    *  select½Ã¿¡´Â Á¦¿ÜµÇ¸é insert, update, delete transactionÀÌ ¹ß»ýÇßÀ» °æ¿ì¿¡ 󸮰¡ 
    *  µÇµµ·Ï ÇÑ´Ù.
    */
    public boolean historyUpdate(int customerNo, 
                                              int tableCode, 
                                              String historyType, 
                                              int workerNo, 
                                              Object before, 
                                              Object after) throws Exception {
        Connection conn = null;
        PreparedStatement pstmt = null;
        ResultSet rset = null;

        ArrayList reflectionMethod = new ArrayList(30);

        boolean result = false;
        int tableNo = 0;
        String tableName = null;
        String voName = null;
        String tableComment = null;
        try{
            StringBuffer query = new StringBuffer();

            // ÇØ´çÅ×ÀÌºí¿¡ ¾î¶°ÇÑ VO¿Í ¸ÅÇεÈÁö È®ÀÎ
            query.append("SELECT TABLE_NO,  TABLE_NAME,  VO_NAME, ");
            query.append(" TABLE_COMMENTS FROM HT002 ");

            conn = getConnection();
            pstmt = conn.prepareStatement(query.toString());
            rset = pstmt.executeQuery();
            if( rset.next() ) {
                tableNo = rset.getInt(1);
                tableName = rset.getString(2);
                voName = rset.getString(3);
                tableComment = rset.getString(4);
            }
        }catch(Exception e) {
            e.printStackTrace();
        }finally{
            close(rset);
            close(pstmt);
            close(conn);
        }
        // 1. ¸ÕÀú ÀԷ¹ÞÀº ¿øº»°ú µ¥ÀÌÅͺ£À̽ºÀÇ vo°¡ °°ÀºÁö È®ÀÎÇÑ´Ù.
        if( !before.getClass().getName().equals(after.getClass().getName()) ) 
            throw new Exception("¿øº»VO¿Í º¯°æVO°¡ °°Áö ¾Ê½À´Ï´Ù");
        

        if( !before.getClass().getName().equals(voName) ) 
            throw new Exception("Å×À̺í°ü·Ã VO¿Í ÀÔ·ÂÇϽŠVO°¡ °°Áö ¾Ê½À´Ï´Ù");

        // ÇØ´ç Å×ÀÌºí¿¡ ´ëÇÑ reflectionÀ» È£ÃâÇÒ ¼ö ÀÖµµ·Ï Å×À̺í°ú ¸ÅÇÎµÈ vo method¸¦ 
        // °¡Á®¿Àµµ·Ï ÇÑ´Ù.
        try{
            StringBuffer query = new StringBuffer();
            query.append("SELECT COLUMN_NAME, METHOD_NAME, COLUMN_COMMENT ");
            query.append(" FROM HT003 WHERE TABLE_NO = ?");

            conn = getConnection();
            pstmt = conn.prepareStatement(query.toString());
            pstmt.setInt(1, tableNo);

            rset = pstmt.executeQuery();
            HT003VO ht003 = null;
            while(rset.next()) {
                ht003 = new HT003VO();
                ht003.setColumnName(rset.getString(1));
                ht003.setMethodName(rset.getString(2));
                ht003.setColumnComment(rset.getString(3));
                reflectionMethod.add(ht003);
            }
            System.out.println(reflectionMethod);
        }catch(Exception e) {
            e.printStackTrace();
        }finally{
            close(rset);
            close(pstmt);
            close(conn);
        }

        // 3. º¯°æµÈ ´ë»óÀÇ ¸®½ºÆ®¸¦ ã¾Æ³½´Ù.
        ArrayList changeList = compareObject(reflectionMethod, before, after);
        System.out.println(changeList);
        insertToHT001Table(customerNo, 
                                      historyType, 
                                      workerNo, 
                                      tableName, 
                                      tableComment, 
                                      changeList);
        return result;
    }

    public void insertToHT001Table(int customerNo, 
                                                  String historyType, 
                                                  int workerNo, 
                                                  String tableName, 
                                                  String tableComment, 
                                                  ArrayList changeList){
        Connection conn = null;
        PreparedStatement pstmt = null;
        try{
            StringBuffer query = new StringBuffer();
            query.append("insert into HT001(history_no, history_type, customer_no, table_name, ");
            query.append(" table_comment, column_name, column_comment, before_data, ");
            query.append(" after_data, update_date, worker ) ");
            query.append(" values ");
            query.append(" ( (select max(history_no) + 1 from HT001) , ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
            
            conn = getConnection();
            conn.setAutoCommit(false);

            pstmt = conn.prepareStatement(query.toString());
            
            HT001VO ht001 = null;
            for( int i = 0 ; i < changeList.size() ; i++) {
                ht001 = (HT001VO) changeList.get(i);
                pstmt.setString(1, historyType);
                pstmt.setInt(2, customerNo);
                pstmt.setString(3, tableName);
                pstmt.setString(4, tableComment);
                pstmt.setString(5, ht001.getColumnName());
                pstmt.setString(6, ht001.getColumnComment());
                pstmt.setString(7, ht001.getBeforeData());
                pstmt.setString(8, ht001.getAfterData());
                pstmt.setTimestamp(9, new Timestamp(System.currentTimeMillis()));
                pstmt.setInt(10, workerNo);
                pstmt.execute();
            } 
            conn.commit();
        }catch(Exception e) {
            e.printStackTrace();
            try{
                conn.rollback();
            }catch(Exception e2) {}
        }finally{
            close(pstmt);
            close(conn);
        }
    }

    public ArrayList compareObject(ArrayList reflectionMethod, Object before, Object after) {
        ArrayList changeList = new ArrayList(10);
        Class [] argsType = {};
        Object [] argsValue = {};
        Method beforeMethod = null;
        Method afterMethod = null;
        HT003VO ht003 = null;
        
        Object beforeObject = null;
        Object afterObject = null;

        try{
            HT001VO ht001 = null;
            for( int i = 0 ; i < reflectionMethod.size(); i++ ) {
                ht003 = (HT003VO) reflectionMethod.get(i);
                beforeMethod = before.getClass().getDeclaredMethod(ht003.getMethodName() , 
                                                                                               new Class[0]);
                afterMethod = after.getClass().getDeclaredMethod(ht003.getMethodName() , 
                                                                                            new Class[0]);

                beforeObject = beforeMethod.invoke(before, argsValue);
                afterObject = afterMethod.invoke(after, argsValue);

                if( beforeObject != null && afterObject != null && 
                    beforeObject.getClass() == String.class ) {
                    String str1 = (String)beforeObject;
                    String str2 = (String)afterObject;

                    if( ! str1.equals(str2) ) {
                        ht001 = new HT001VO();
                        ht001.setColumnName(ht003.getColumnName());
                        ht001.setColumnComment(ht003.getColumnComment());
                        ht001.setBeforeData(str1);
                        ht001.setAfterData(str2);
                        changeList.add(ht001);
                    }
                } else if( beforeObject != null && afterObject != null && 
                              beforeObject.getClass() == Integer.class ) {
                    int int1 = ((Integer)beforeObject).intValue();
                    int int2 = ((Integer)afterObject).intValue(); 
                    if( int1 != int2 ) {
                        ht001 = new HT001VO();
                        ht001.setColumnName(ht003.getColumnName());
                        ht001.setColumnComment(ht003.getColumnComment());
                        ht001.setBeforeData("" + int1);
                        ht001.setAfterData("" + int2);
                        changeList.add(ht001);
                    }
                } else if( beforeObject != null && afterObject != null && 
                             beforeObject.getClass() == Long.class ) {
                    long long1 = ((Long)beforeObject).longValue();
                    long long2 = ((Long)afterObject).longValue();
                    if( long1 != long2 ) {
                        ht001 = new HT001VO();
                        ht001.setColumnName(ht003.getColumnName());
                        ht001.setColumnComment(ht003.getColumnComment());
                        ht001.setBeforeData("" + long1);
                        ht001.setAfterData("" + long2);
                        changeList.add(ht001);
                    }
                } else if( beforeObject != null && afterObject != null && 
                             beforeObject.getClass() == java.util.Date.class ) {
                    java.util.Date date1 = (java.util.Date)beforeObject;
                    java.util.Date date2 = (java.util.Date)afterObject;
                    if( date1.getTime() != date2.getTime() ) {
                        ht001 = new HT001VO();
                        ht001.setColumnName(ht003.getColumnName());
                        ht001.setColumnComment(ht003.getColumnComment());
                        ht001.setBeforeData(date1.toString());
                        ht001.setAfterData(date2.toString());
                        changeList.add(ht001);
                    }
                } // end of if
            
                
            } // end of for

        }catch(Exception e) {
            e.printStackTrace();
        }
        return changeList;
    }
}
À§ÀÇ Äڵ带 º¸°Ô µÇ¸é historyUpdate(int customerNo, int tableCode, String historyType, int workerNo, Object before, Object after) ÀÇ ¸Þ¼Òµå¸¦ ÀÏ¹Ý ¾ÖÇø®ÄÉÀ̼ǿ¡¼­ È£ÃâÇϵµ·Ï ÇÏ°í ÀÖ½À´Ï´Ù. ¾î¶² °í°´ÀÇ Á¤º¸, Å×À̺íÀÇ ÄÚµå, INSERT, UPDATE, DELETE¿©ºÎ, ÀÛ¾÷ÀÚ, ÀÌÀüVO, º¯°æVO¸¦ Àμö·Î ÃëÇÏ°í ÀÖ½À´Ï´Ù. ½ÇÇàµÇ´Â ¼ø¼­¸¦ º¸°Ô µÇ¸é 1. µé¾î¿Â VOÀÇ reflectionÀ» ÅëÇÏ¿© °°Àº VOÀÎÁö¸¦ È®ÀÎÇÑ´Ù. 2. °°Àº VO°¡ °°´Ù¸é ÇØ´ç Å×À̺íÄڵ带 ÀÌ¿ëÇÏ¿© ±× VO¿¡ ¾î¶°ÇÑ ¸Þ¼Òµå°¡ ÀÖ´ÂÁö È®ÀÎÇÑ´Ù. 3. ±âÁ¸VO¿Í º¯°æµÈ VO¸¦ ÀÌ¿ëÇÏ¿© ¾î¶°ÇÑ ÇʵåÀÇ °ªÀÌ º¯°æµÇ¾ú´ÂÁö¸¦ reflectionÀ»ÅëÇÏ¿© È®ÀÎÇÑ´Ù. 4. ½ÇÁ¦ º¯°æµÈ ³»¿ëÀ» ÀúÀåÇÏ°í ÀÖ´Â ArrayList°´Ã¼ÀÇ ³»¿ëÀ» È÷½ºÅ丮 ¸¶½ºÅÍÅ×ÀÌºí¿¡ »ðÀÔÇÑ´Ù. ½ÇÁ¦ ÇÙ½ÉÀûÀÎ ºñ±³ºÎºÐÀº compareObject¶ó´Â ¸Þ¼Òµå¾È¿¡ Á¸ÀçÇÏ¿© °´Ã¼ÀÇ reflectionÀ» ÀÌ¿ëÇÏ¿© µ¥ÀÌÅÍŸÀÔ ¹× º¯¼öÀÇ °ªµéÀ» ÀÌ¿ëÇÏ¿© Å×½ºÆ®ÇÏ°í ÀÖ½À´Ï´Ù. ´Ü¼ø °´Ã¼ºñ±³¿Í °°Àº °æ¿ì ComparatorÀÎÅÍÆäÀ̽º¸¦ »ç¿ëÇÒ ¼ö ÀÖÁö¸¸ À§¿Í °°Àº °æ¿ì »óȲÀÌ ¾Ö¸Å¸ðÈ£ÇϹǷΠ½ÇÁ¦ °ªºñ±³¿¡¸¸ ÁßÁ¡À» µÎ¾ú½À´Ï´Ù. Ŭ·¡½º Çϳª·Î ¾ÆÁÖ °£´ÜÇÏ°Ô ¸¸µé¾úÀ¸¹Ç·Î ÀÌÇØÇϴµ¥ º°·Î ¾î·Á¿òÀÌ ¾øÀ» µíÇÕ´Ï´Ù. ±Ã±ÝÇϽŠ»çÇ×ÀÌ ÀÖÀ¸½Ã¸é ¸ÞÀÏÁÖ¼¼¿ä.. ^^ ¹ä¸ÔÀ¸·¯ °¥½Ã°£À̳׿ä.. ^^ ¾Æ½Î..
 
1
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD