~raginggoblin/infolog/infolog

« back to all changes in this revision

Viewing changes to InfologServer/lib/hibernate-distribution-3.3.2.GA/project/documentation/manual/old/ko-KR/src/main/docbook/content/filters.xml

  • Committer: Raging Goblin
  • Date: 2013-11-16 16:51:32 UTC
  • Revision ID: raging_goblin-20131116165132-weujnptzc88uy4ah
Mavenized the project, now using shared project InfologSync

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?xml version='1.0' encoding="UTF-8"?>
2
 
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
3
 
 
4
 
<chapter id="filters">
5
 
    <title>데이터 필터링하기</title>
6
 
    
7
 
    <para>
8
 
        Hibernate3은 혁신적인 "가시성(visibility)" 규칙들로서 데이터를 처리하는 새로운 접근법을 제공한다. <emphasis>Hibernate 
9
 
                필터</emphasis>는 특정 Hibernate 세션에 대해 이용 가능하게 되거나 이용 불가능하게 될 수도 있는 전역, 명명된 파라미터화 된 필터이다.
10
 
    </para>
11
 
 
12
 
    <sect1 id="objectstate-filters" revision="1">
13
 
        <title>Hibernate 필터들</title>
14
 
 
15
 
        <para>
16
 
            Hibernate3은 필터 기준(criteria)을 미리 정의하고 클래스 레벨과 콜렉션 레벨 양자에서 그들 필터들을 첨부할 능력을 추가시킨다. 
17
 
                        필터 기준(criteria)은 클래스 요소와 다양한 콜렉션 요소들에 대해 이용 가능한 기존의 "where" 속성과 매우 유사한 하나의 제한 절을 
18
 
                        정의하는 능력이다. 이것들을 제외하면 필터 조건들은 파라미터화 될 수 있다. 그때 어플리케이션은 주어진 필터들이 이용 가능한지 여부 
19
 
                        그리고 그들 파라미터 값들이 무엇이어야 하는지를 실행 시에 결정할 수 있다. 필터들은 데이터베이스 뷰들 처럼 사용될 수 있지만, 
20
 
                        어플리케이션 내부에 파라미터화 된다.
21
 
        </para>
22
 
 
23
 
        <para>
24
 
                        필터들을 사용하기 위해서, 그것들은 먼저 정의되고 나서 적절한 매핑 요소들에 첨가되어야 한다. 필터를 정의하기 위해, 
25
 
            <literal>&lt;hibernate-mapping/&gt;</literal> 요소 내부에 <literal>&lt;filter-def/&gt;</literal> 요소를 
26
 
                        사용하라:
27
 
        </para>
28
 
 
29
 
        <programlisting><![CDATA[<filter-def name="myFilter">
30
 
    <filter-param name="myFilterParam" type="string"/>
31
 
</filter-def>]]></programlisting>
32
 
 
33
 
        <para>
34
 
                       그때 이 필터는 클래스에 첨가될 수 있다:
35
 
        </para>
36
 
 
37
 
        <programlisting><![CDATA[<class name="myClass" ...>
38
 
    ...
39
 
    <filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
40
 
</class>]]></programlisting>
41
 
 
42
 
        <para>
43
 
                        또는 콜렉션에 첨가될 수 있다:
44
 
        </para>
45
 
 
46
 
        <programlisting><![CDATA[<set ...>
47
 
    <filter name="myFilter" condition=":myFilterParam = MY_FILTERED_COLUMN"/>
48
 
</set>]]></programlisting>
49
 
 
50
 
        <para>
51
 
                        또는 동시에 양자에(또는 각각의 여러번) 첨가될 수 있다.
52
 
        </para>
53
 
 
54
 
        <para>
55
 
            <literal>Session</literal> 상의 메소드들은 다음과 같다: <literal>enableFilter(String filterName)</literal>, 
56
 
            <literal>getEnabledFilter(String filterName)</literal>, <literal>disableFilter(String filterName)</literal>. 
57
 
                        디폴트로, 필터들은 주어진 세션에 대해 이용 가능하지 <emphasis>않다</emphasis>; 그것들은 <literal>Session.enableFilter()</literal> 
58
 
                        메소드의 사용을 통해 명시적으로 이용 가능하게 되어야 한다. <literal>Session.enableFilter()</literal>는 
59
 
            <literal>Filter</literal> 인터페이스의 인스턴스를 반환한다. 위에 정의된 간단한 필터를 사용하면, 이것은 다음과 같을 것이다:
60
 
        </para>
61
 
 
62
 
        <programlisting><![CDATA[session.enableFilter("myFilter").setParameter("myFilterParam", "some-value");]]></programlisting>
63
 
 
64
 
        <para>
65
 
            org.hibernate.Filter 인터페이스 상의 메소드들은 Hibernate에 매우 공통된 method-chaining을 허용한다는 점을 노트하라.
66
 
        </para>
67
 
 
68
 
        <para>
69
 
                        유효한 기록 날짜 패턴을 가진 시간 데이터를 사용하는 전체 예제 :
70
 
        </para>
71
 
 
72
 
        <programlisting><![CDATA[<filter-def name="effectiveDate">
73
 
    <filter-param name="asOfDate" type="date"/>
74
 
</filter-def>
75
 
 
76
 
<class name="Employee" ...>
77
 
...
78
 
    <many-to-one name="department" column="dept_id" class="Department"/>
79
 
    <property name="effectiveStartDate" type="date" column="eff_start_dt"/>
80
 
    <property name="effectiveEndDate" type="date" column="eff_end_dt"/>
81
 
...
82
 
    <!--
83
 
        Note that this assumes non-terminal records have an eff_end_dt set to
84
 
        a max db date for simplicity-sake
85
 
    -->
86
 
    <filter name="effectiveDate"
87
 
            condition=":asOfDate BETWEEN eff_start_dt and eff_end_dt"/>
88
 
</class>
89
 
 
90
 
<class name="Department" ...>
91
 
...
92
 
    <set name="employees" lazy="true">
93
 
        <key column="dept_id"/>
94
 
        <one-to-many class="Employee"/>
95
 
        <filter name="effectiveDate"
96
 
                condition=":asOfDate BETWEEN eff_start_dt and eff_end_dt"/>
97
 
    </set>
98
 
</class>]]></programlisting>
99
 
 
100
 
        <para>
101
 
                        그때 당신이 현재 유효한 레코드들을 항상 얻는 것을 확실히 하기 위해, employee 데이터를 검색하기 전에 세션 상에 필터를 
102
 
                        간단하게 이용 가능하게 하라:
103
 
        </para>
104
 
 
105
 
<programlisting><![CDATA[Session session = ...;
106
 
session.enableFilter("effectiveDate").setParameter("asOfDate", new Date());
107
 
List results = session.createQuery("from Employee as e where e.salary > :targetSalary")
108
 
         .setLong("targetSalary", new Long(1000000))
109
 
         .list();
110
 
]]></programlisting>
111
 
 
112
 
        <para>
113
 
                        위의 HQL 에서, 심지어 비록 우리가 결과들에 대한 봉급 컨스트레인트를 명시적으로 언급만 했을지라도, 이용 가능한 필터 때문에 
114
 
                        그 질의는 봉급이 백만달러 이상인 현재 채용중인 직원들만을 반환할 것이다.
115
 
        </para>
116
 
 
117
 
        <para>
118
 
                        노트: 만일 당신이 outer 조인에 대해 필터들을 사용할 계획이라면 (HQL이든 로드 페칭이든) 조건 표현식의 방향을 주의하라. 
119
 
                        이것을 left outer join으로 설정하는 것이 가장 안전하다; 일반적으로 오퍼레이터 뒤에 있는 컬럼 이름(들)이 뒤따르는 첫번째에 
120
 
                        파라미터를 위치지워라.
121
 
        </para>
122
 
 
123
 
    </sect1>
124
 
 
125
 
        <para>
126
 
            필터가 정의된 후에는 그것 자신의 조건에 대해 각각 여러 개의 엔티티들 그리고/또는 콜렉션들에 첨가될 수 있다. 
127
 
            조건들이 매번 동일할 때 그것은 지루할 수 있다. 따라서 <literal>&lt;filter-def/&gt;</literal>은 
128
 
            attribute 든 CDATA 든 어느것이든 디폴트 조건을 정의하는 것을 허용해준다:
129
 
        </para>
130
 
 
131
 
        <programlisting><![CDATA[<filter-def name="myFilter" condition="abc > xyz">...</filter-def>
132
 
<filter-def name="myOtherFilter">abc=xyz</filter-def>]]></programlisting>
133
 
 
134
 
        <para>
135
 
            그때 이 디폴트 조건은 그 필터가 어떤 조건을 지정함이 없이 어떤 것에 첨가될때마다 사용될 수 있다.
136
 
            이것은 당신이 특정한 경우에 디폴트 조건을 오버라이드 시키는 필터의 첨가 부분으로서 특정 조건을 
137
 
            부여할 수 있음을 의미함을 노트하라.
138
 
        </para>
139
 
 
140
 
</chapter>
141