001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.dao.orm.hibernate.event;
016    
017    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
018    import com.liferay.portal.model.BaseModel;
019    import com.liferay.portal.model.MVCCModel;
020    
021    import org.hibernate.event.PostUpdateEvent;
022    import org.hibernate.event.PostUpdateEventListener;
023    
024    /**
025     * @author Shuyang Zhou
026     */
027    public class MVCCSynchronizerPostUpdateEventListener
028            implements PostUpdateEventListener {
029    
030            public static final MVCCSynchronizerPostUpdateEventListener INSTANCE =
031                    new MVCCSynchronizerPostUpdateEventListener();
032    
033            @Override
034            public void onPostUpdate(PostUpdateEvent postUpdateEvent) {
035                    Object entity = postUpdateEvent.getEntity();
036    
037                    if (entity instanceof MVCCModel) {
038                            BaseModel<?> baseModel = (BaseModel<?>)entity;
039    
040                            EntityCacheUtil.putResult(
041                                    baseModel.isEntityCacheEnabled(), entity.getClass(),
042                                    baseModel.getPrimaryKeyObj(), baseModel, false);
043                    }
044            }
045    
046    }