⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.html

📁 是一个中文的Hibernate库文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><head>      <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">   <title>&#31532;&nbsp;13&nbsp;&#31456;&nbsp;	&#25318;&#25130;&#22120;&#19982;&#20107;&#20214;(Interceptors and events)	</title><link rel="stylesheet" href="../shared/css/html.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.65.1"><link rel="home" href="index.html" title="HIBERNATE - &#31526;&#21512;Java&#20064;&#24815;&#30340;&#20851;&#31995;&#25968;&#25454;&#24211;&#25345;&#20037;&#21270;"><link rel="up" href="index.html" title="HIBERNATE - &#31526;&#21512;Java&#20064;&#24815;&#30340;&#20851;&#31995;&#25968;&#25454;&#24211;&#25345;&#20037;&#21270;"><link rel="previous" href="transactions.html" title="&#31532;&nbsp;12&nbsp;&#31456;&nbsp;&#20107;&#21153;&#21644;&#24182;&#21457;"><link rel="next" href="batch.html" title="&#31532;&nbsp;14&nbsp;&#31456;&nbsp;&#25209;&#37327;&#22788;&#29702;&#65288;Batch processing&#65289;"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">&#31532;&nbsp;13&nbsp;&#31456;&nbsp;	&#25318;&#25130;&#22120;&#19982;&#20107;&#20214;(Interceptors and events)	</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="transactions.html">&#19978;&#19968;&#39029;</a>&nbsp;</td><th width="60%" align="center">&nbsp;</th><td width="20%" align="right">&nbsp;<a accesskey="n" href="batch.html">&#19979;&#19968;&#39029;</a></td></tr></table><hr></div><div class="chapter" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title"><a name="events"></a>&#31532;&nbsp;13&nbsp;&#31456;&nbsp;	&#25318;&#25130;&#22120;&#19982;&#20107;&#20214;(Interceptors and events)	</h2></div></div><div></div></div><p>	    &#24212;&#29992;&#31243;&#24207;&#33021;&#22815;&#21709;&#24212;Hibernate&#20869;&#37096;&#20135;&#29983;&#30340;&#29305;&#23450;&#20107;&#20214;&#26159;&#38750;&#24120;&#26377;&#29992;&#30340;&#12290;&#36825;&#26679;&#23601;&#20801;&#35768;&#23454;&#29616;&#26576;&#20123;&#36890;&#29992;&#30340;&#21151;&#33021;		&#20197;&#21450;&#20801;&#35768;&#23545;Hibernate&#21151;&#33021;&#36827;&#34892;&#25193;&#23637;&#12290;    </p><div class="sect1" lang="zh-cn"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="objectstate-interceptors"></a>13.1.&nbsp;		&#25318;&#25130;&#22120;(Interceptors)		</h2></div></div><div></div></div><p>            <tt class="literal">Interceptor</tt>&#25509;&#21475;&#25552;&#20379;&#20102;&#20174;&#20250;&#35805;(session)&#22238;&#35843;(callback)&#24212;&#29992;&#31243;&#24207;(application)&#30340;&#26426;&#21046;&#65292;                        &#36825;&#31181;&#22238;&#35843;&#26426;&#21046;&#21487;&#20197;&#20801;&#35768;&#24212;&#29992;&#31243;&#24207;&#22312;&#25345;&#20037;&#21270;&#23545;&#35937;&#34987;&#20445;&#23384;&#12289;&#26356;&#26032;&#12289;&#21024;&#38500;&#25110;&#26159;&#21152;&#36733;&#20043;&#21069;&#65292;&#26816;&#26597;&#24182;&#65288;&#25110;&#65289;&#20462;&#25913;&#20854;			&#23646;&#24615;&#12290;&#19968;&#20010;&#21487;&#33021;&#30340;&#29992;&#36884;&#65292;&#23601;&#26159;&#29992;&#26469;&#36319;&#36394;&#23457;&#26680;(auditing)&#20449;&#24687;&#12290;&#20363;&#22914;&#65306;&#19979;&#38754;&#30340;&#36825;&#20010;<tt class="literal">&#25318;&#25130;&#22120;</tt>&#65292;&#20250;&#22312;&#19968;&#20010;&#23454;&#29616;&#20102;			<tt class="literal">Auditable</tt>&#25509;&#21475;&#30340;&#23545;&#35937;&#34987;&#21019;&#24314;&#26102;&#33258;&#21160;&#22320;&#35774;&#32622;<tt class="literal">createTimestamp</tt>&#23646;&#24615;&#65292;&#24182;&#22312;&#23454;&#29616;&#20102;			<tt class="literal">Auditable</tt>&#25509;&#21475;&#30340;&#23545;&#35937;&#34987;&#26356;&#26032;&#26102;&#65292;&#21516;&#27493;&#26356;&#26032;<tt class="literal">lastUpdateTimestamp</tt>&#23646;&#24615;&#12290;        </p><pre class="programlisting">package org.hibernate.test;import java.io.Serializable;import java.util.Date;import java.util.Iterator;import org.hibernate.Interceptor;import org.hibernate.type.Type;public class AuditInterceptor implements Interceptor, Serializable {    private int updates;    private int creates;    public void onDelete(Object entity,                         Serializable id,                         Object[] state,                         String[] propertyNames,                         Type[] types) {        // do nothing    }    public boolean onFlushDirty(Object entity,                                Serializable id,                                Object[] currentState,                                Object[] previousState,                                String[] propertyNames,                                Type[] types) {        if ( entity instanceof Auditable ) {            updates++;            for ( int i=0; i &lt; propertyNames.length; i++ ) {                if ( "lastUpdateTimestamp".equals( propertyNames[i] ) ) {                    currentState[i] = new Date();                    return true;                }            }        }        return false;    }    public boolean onLoad(Object entity,                          Serializable id,                          Object[] state,                          String[] propertyNames,                          Type[] types) {        return false;    }    public boolean onSave(Object entity,                          Serializable id,                          Object[] state,                          String[] propertyNames,                          Type[] types) {        if ( entity instanceof Auditable ) {            creates++;            for ( int i=0; i&lt;propertyNames.length; i++ ) {                if ( "createTimestamp".equals( propertyNames[i] ) ) {                    state[i] = new Date();                    return true;                }            }        }        return false;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -