001 /*
002 * Copyright 2004 Chris Nelson
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing,
008 * software distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and limitations under the License.
011 */
012 /*
013 * Created on Apr 27, 2004
014 *
015 * To change the template for this generated file go to
016 * Window>Preferences>Java>Code Generation>Code and Comments
017 */
018 package org.tynamo.hibernate;
019
020 import org.hibernate.CallbackException;
021 import org.hibernate.EmptyInterceptor;
022 import org.hibernate.Interceptor;
023 import org.hibernate.type.Type;
024
025 import java.io.Serializable;
026
027
028 /**
029 * Class required by Hibernate when you have an object with composite primary key. The isUnsaved() method is what we're
030 * interested in here.
031 */
032 public class TynamoInterceptor extends EmptyInterceptor implements Interceptor, Serializable
033 {
034
035 /**
036 * (non-Javadoc)
037 *
038 * @see org.hibernate.Interceptor#onLoad(java.lang.Object, java.io.Serializable, java.lang.Object[],
039 * java.lang.String[], org.hibernate.type.Type[])
040 */
041 public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
042 {
043 return entity instanceof Interceptable && ((Interceptable) entity).onLoad(id, state, propertyNames, types);
044 }
045
046 /**
047 * (non-Javadoc)
048 *
049 * @see org.hibernate.Interceptor#onFlushDirty(java.lang.Object, java.io.Serializable, java.lang.Object[],
050 * java.lang.Object[], java.lang.String[], org.hibernate.type.Type[])
051 */
052 public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState,
053 Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException
054 {
055 return entity instanceof Interceptable && ((Interceptable) entity).onUpdate(id, currentState, previousState, propertyNames, types);
056 }
057
058 /**
059 * (non-Javadoc)
060 *
061 * @see org.hibernate.Interceptor#onSave(java.lang.Object, java.io.Serializable, java.lang.Object[],
062 * java.lang.String[], org.hibernate.type.Type[])
063 */
064 public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
065 throws CallbackException
066 {
067 return entity instanceof Interceptable && ((Interceptable) entity).onInsert(id, state, propertyNames, types);
068 }
069
070 /**
071 * (non-Javadoc)
072 *
073 * @see org.hibernate.Interceptor#isTransient(java.lang.Object)
074 */
075 public Boolean isTransient(Object arg0)
076 {
077 if (arg0 instanceof HasAssignedIdentifier)
078 {
079 return !((HasAssignedIdentifier) arg0).isSaved();
080 } else
081 {
082 return null;
083 }
084 }
085 }