-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: Interceptor: default value for getEntity and getEntityName
PostPosted: Mon Apr 04, 2005 9:42 am 
Newbie

Joined: Thu Feb 03, 2005 5:49 am
Posts: 19
Hibernate version: 3 rc1

Name and version of the database you are using:Oracle 8.1.7

I would like to implement the Interceptor interface but I haven't found in hibernate docs the default values for the getEntity and getEntityName methods

What must I use as default values?

thanks in advanced.

Sambuko.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 2:16 pm 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
It really depends on your implementation. If you provide more details as to what you are looking to use the Interceptor for, we can help you out.

_________________
Matt Veitas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 05, 2005 9:44 am 
Newbie

Joined: Thu Feb 03, 2005 5:49 am
Posts: 19
hello mveitas

I would like to implement Interceptor interface in order to assign value for two date columns: "Creation" and "LastUpdate".

I have seen hibernate reference documentation and I have found the following example:

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 < 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<propertyNames.length; i++ ) {
if ( "createTimestamp".equals( propertyNames[i] ) ) {
state[i] = new Date();
return true;
}
}
}
return false;
}

public void postFlush(Iterator entities) {
System.out.println("Creations: " + creates + ", Updates: " + updates);
}

public void preFlush(Iterator entities) {
updates=0;
creates=0;
}

...

}

After thar I have seem the API documentation and JavaDoc for org.hibernate.Interceptor interface and I haven't found out the default values for those methods.

Could you help me?

Thanks in advanced.

Sambuko


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 5:29 pm 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
Return either null or false in Interceptor methods that you do not care to implement.

I vote for an InterceptorAdapter BTW.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 07, 2005 8:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Sounds like a great Wiki thing...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 9:46 am 
Regular
Regular

Joined: Wed Nov 17, 2004 11:49 am
Posts: 65
Location: Pittsburgh
point taken.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 10:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
looks good ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 08, 2005 10:40 am 
Regular
Regular

Joined: Mon Feb 23, 2004 10:42 pm
Posts: 102
Location: Washington DC
There is the EmptyInterceptor that is a static final class in org.hibernate.cfg.Configuration. Why no expose this to the world?

_________________
Matt Veitas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.