Example usage for com.liferay.portal.kernel.util ProxyUtil isProxyClass

List of usage examples for com.liferay.portal.kernel.util ProxyUtil isProxyClass

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util ProxyUtil isProxyClass.

Prototype

public static boolean isProxyClass(Class<?> clazz) 

Source Link

Usage

From source file:com.liferay.docs.guestbook.service.persistence.impl.EntryPersistenceImpl.java

License:Open Source License

@Override
public Entry updateImpl(Entry entry) {
    boolean isNew = entry.isNew();

    if (!(entry instanceof EntryModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(entry.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(entry);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in entry proxy " + invocationHandler.getClass());
        }/* w  w w .j a v  a2 s  .c o  m*/

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom Entry implementation " + entry.getClass());
    }

    EntryModelImpl entryModelImpl = (EntryModelImpl) entry;

    if (Validator.isNull(entry.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        entry.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (entry.getCreateDate() == null)) {
        if (serviceContext == null) {
            entry.setCreateDate(now);
        } else {
            entry.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!entryModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            entry.setModifiedDate(now);
        } else {
            entry.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (entry.isNew()) {
            session.save(entry);

            entry.setNew(false);
        } else {
            entry = (Entry) session.merge(entry);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!EntryModelImpl.COLUMN_BITMASK_ENABLED) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { entryModelImpl.getUuid() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);

        args = new Object[] { entryModelImpl.getUuid(), entryModelImpl.getCompanyId() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);

        args = new Object[] { entryModelImpl.getGroupId(), entryModelImpl.getGuestbookId() };

        finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);

        finderCache.removeResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY);
        finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL, FINDER_ARGS_EMPTY);
    }

    else {
        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalUuid() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);

            args = new Object[] { entryModelImpl.getUuid() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID, args);
        }

        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalUuid(),
                    entryModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);

            args = new Object[] { entryModelImpl.getUuid(), entryModelImpl.getCompanyId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C, args);
        }

        if ((entryModelImpl.getColumnBitmask()
                & FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G.getColumnBitmask()) != 0) {
            Object[] args = new Object[] { entryModelImpl.getOriginalGroupId(),
                    entryModelImpl.getOriginalGuestbookId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);

            args = new Object[] { entryModelImpl.getGroupId(), entryModelImpl.getGuestbookId() };

            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_G, args);
            finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_G, args);
        }
    }

    entityCache.putResult(EntryModelImpl.ENTITY_CACHE_ENABLED, EntryImpl.class, entry.getPrimaryKey(), entry,
            false);

    clearUniqueFindersCache(entryModelImpl, false);
    cacheUniqueFindersCache(entryModelImpl);

    entry.resetOriginalValues();

    return entry;
}

From source file:com.liferay.docs.guestbook.service.persistence.impl.GuestbookEntryPersistenceImpl.java

License:Open Source License

@Override
public GuestbookEntry updateImpl(GuestbookEntry guestbookEntry) {
    boolean isNew = guestbookEntry.isNew();

    if (!(guestbookEntry instanceof GuestbookEntryModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(guestbookEntry.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(guestbookEntry);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in guestbookEntry proxy " + invocationHandler.getClass());
        }/*from  w  w  w.  jav a 2s .com*/

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom GuestbookEntry implementation " + guestbookEntry.getClass());
    }

    GuestbookEntryModelImpl guestbookEntryModelImpl = (GuestbookEntryModelImpl) guestbookEntry;

    if (Validator.isNull(guestbookEntry.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        guestbookEntry.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (guestbookEntry.getCreateDate() == null)) {
        if (serviceContext == null) {
            guestbookEntry.setCreateDate(now);
        } else {
            guestbookEntry.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!guestbookEntryModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            guestbookEntry.setModifiedDate(now);
        } else {
            guestbookEntry.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (guestbookEntry.isNew()) {
            session.save(guestbookEntry);

            guestbookEntry.setNew(false);
        } else {
            guestbookEntry = (GuestbookEntry) session.merge(guestbookEntry);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!_columnBitmaskEnabled) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { guestbookEntryModelImpl.getUuid() };

        finderCache.removeResult(_finderPathCountByUuid, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

        args = new Object[] { guestbookEntryModelImpl.getUuid(), guestbookEntryModelImpl.getCompanyId() };

        finderCache.removeResult(_finderPathCountByUuid_C, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

        args = new Object[] { guestbookEntryModelImpl.getGroupId(), guestbookEntryModelImpl.getGuestbookId() };

        finderCache.removeResult(_finderPathCountByG_G, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);

        finderCache.removeResult(_finderPathCountAll, FINDER_ARGS_EMPTY);
        finderCache.removeResult(_finderPathWithoutPaginationFindAll, FINDER_ARGS_EMPTY);
    } else {
        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

            args = new Object[] { guestbookEntryModelImpl.getUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);
        }

        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid_C.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalUuid(),
                    guestbookEntryModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

            args = new Object[] { guestbookEntryModelImpl.getUuid(), guestbookEntryModelImpl.getCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);
        }

        if ((guestbookEntryModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByG_G.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookEntryModelImpl.getOriginalGroupId(),
                    guestbookEntryModelImpl.getOriginalGuestbookId() };

            finderCache.removeResult(_finderPathCountByG_G, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);

            args = new Object[] { guestbookEntryModelImpl.getGroupId(),
                    guestbookEntryModelImpl.getGuestbookId() };

            finderCache.removeResult(_finderPathCountByG_G, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByG_G, args);
        }
    }

    entityCache.putResult(entityCacheEnabled, GuestbookEntryImpl.class, guestbookEntry.getPrimaryKey(),
            guestbookEntry, false);

    clearUniqueFindersCache(guestbookEntryModelImpl, false);
    cacheUniqueFindersCache(guestbookEntryModelImpl);

    guestbookEntry.resetOriginalValues();

    return guestbookEntry;
}

From source file:com.liferay.docs.guestbook.service.persistence.impl.GuestbookPersistenceImpl.java

License:Open Source License

@Override
public Guestbook updateImpl(Guestbook guestbook) {
    boolean isNew = guestbook.isNew();

    if (!(guestbook instanceof GuestbookModelImpl)) {
        InvocationHandler invocationHandler = null;

        if (ProxyUtil.isProxyClass(guestbook.getClass())) {
            invocationHandler = ProxyUtil.getInvocationHandler(guestbook);

            throw new IllegalArgumentException(
                    "Implement ModelWrapper in guestbook proxy " + invocationHandler.getClass());
        }/*from  w w  w  .  java2  s  .  com*/

        throw new IllegalArgumentException(
                "Implement ModelWrapper in custom Guestbook implementation " + guestbook.getClass());
    }

    GuestbookModelImpl guestbookModelImpl = (GuestbookModelImpl) guestbook;

    if (Validator.isNull(guestbook.getUuid())) {
        String uuid = PortalUUIDUtil.generate();

        guestbook.setUuid(uuid);
    }

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    Date now = new Date();

    if (isNew && (guestbook.getCreateDate() == null)) {
        if (serviceContext == null) {
            guestbook.setCreateDate(now);
        } else {
            guestbook.setCreateDate(serviceContext.getCreateDate(now));
        }
    }

    if (!guestbookModelImpl.hasSetModifiedDate()) {
        if (serviceContext == null) {
            guestbook.setModifiedDate(now);
        } else {
            guestbook.setModifiedDate(serviceContext.getModifiedDate(now));
        }
    }

    Session session = null;

    try {
        session = openSession();

        if (guestbook.isNew()) {
            session.save(guestbook);

            guestbook.setNew(false);
        } else {
            guestbook = (Guestbook) session.merge(guestbook);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);

    if (!_columnBitmaskEnabled) {
        finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
    } else if (isNew) {
        Object[] args = new Object[] { guestbookModelImpl.getUuid() };

        finderCache.removeResult(_finderPathCountByUuid, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

        args = new Object[] { guestbookModelImpl.getUuid(), guestbookModelImpl.getCompanyId() };

        finderCache.removeResult(_finderPathCountByUuid_C, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

        args = new Object[] { guestbookModelImpl.getGroupId() };

        finderCache.removeResult(_finderPathCountByGroupId, args);
        finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);

        finderCache.removeResult(_finderPathCountAll, FINDER_ARGS_EMPTY);
        finderCache.removeResult(_finderPathWithoutPaginationFindAll, FINDER_ARGS_EMPTY);
    } else {
        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);

            args = new Object[] { guestbookModelImpl.getUuid() };

            finderCache.removeResult(_finderPathCountByUuid, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid, args);
        }

        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByUuid_C.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalUuid(),
                    guestbookModelImpl.getOriginalCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);

            args = new Object[] { guestbookModelImpl.getUuid(), guestbookModelImpl.getCompanyId() };

            finderCache.removeResult(_finderPathCountByUuid_C, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByUuid_C, args);
        }

        if ((guestbookModelImpl.getColumnBitmask()
                & _finderPathWithoutPaginationFindByGroupId.getColumnBitmask()) != 0) {

            Object[] args = new Object[] { guestbookModelImpl.getOriginalGroupId() };

            finderCache.removeResult(_finderPathCountByGroupId, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);

            args = new Object[] { guestbookModelImpl.getGroupId() };

            finderCache.removeResult(_finderPathCountByGroupId, args);
            finderCache.removeResult(_finderPathWithoutPaginationFindByGroupId, args);
        }
    }

    entityCache.putResult(entityCacheEnabled, GuestbookImpl.class, guestbook.getPrimaryKey(), guestbook, false);

    clearUniqueFindersCache(guestbookModelImpl, false);
    cacheUniqueFindersCache(guestbookModelImpl);

    guestbook.resetOriginalValues();

    return guestbook;
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public LayoutSetStagingHandler getLayoutSetStagingHandler(LayoutSet layoutSet) {

    if (!ProxyUtil.isProxyClass(layoutSet.getClass())) {
        return null;
    }/*from ww  w .j a va  2 s. c o m*/

    InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(layoutSet);

    if (!(invocationHandler instanceof LayoutSetStagingHandler)) {
        return null;
    }

    return (LayoutSetStagingHandler) invocationHandler;
}

From source file:com.liferay.exportimport.staging.LayoutStagingImpl.java

License:Open Source License

@Override
public LayoutStagingHandler getLayoutStagingHandler(Layout layout) {
    if (layout == null) {
        return null;
    }//w ww .j av a 2s .  co m

    if (!ProxyUtil.isProxyClass(layout.getClass())) {
        return null;
    }

    InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(layout);

    if (!(invocationHandler instanceof LayoutStagingHandler)) {
        return null;
    }

    return (LayoutStagingHandler) invocationHandler;
}

From source file:com.liferay.osb.scv.connector.internal.jsonws.SCVUserJSONWS.java

License:Open Source License

protected void initServiceTracker() throws Exception {
    _serviceTracker = ServiceTrackerFactory.open(_bundleContext, SCVModel.class,
            new ServiceTrackerCustomizer<SCVModel, SCVModel>() {

                @Override/*from  www. j  ava2 s  . c o  m*/
                public SCVModel addingService(ServiceReference<SCVModel> serviceReference) {

                    SCVModel scvModel = _bundleContext.getService(serviceReference);

                    Class<?> clazz = getModelClass(scvModel);

                    _scvModelMap.put(clazz.getSimpleName(), scvModel);
                    _modelClasses.put(clazz.getSimpleName(), getModelClass(scvModel));

                    ModelListenerRegistrationUtil.register(scvModel);

                    return scvModel;
                }

                @Override
                public void modifiedService(ServiceReference<SCVModel> serviceReference, SCVModel scvModel) {

                    removedService(serviceReference, scvModel);

                    addingService(serviceReference);
                }

                @Override
                public void removedService(ServiceReference<SCVModel> serviceReference, SCVModel scvModel) {

                    Class<?> clazz = getModelClass(scvModel);

                    _scvModelMap.remove(clazz.getSimpleName(), scvModel);
                    _modelClasses.remove(clazz.getSimpleName(), getModelClass(scvModel));

                    ModelListenerRegistrationUtil.unregister(scvModel);

                    _bundleContext.ungetService(serviceReference);
                }

                protected Class<?> getModelClass(SCVModel scvModel) {
                    Class<?> clazz = scvModel.getClass();

                    if (ProxyUtil.isProxyClass(clazz)) {
                        InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(scvModel);

                        if (invocationHandler instanceof ClassLoaderBeanHandler) {
                            ClassLoaderBeanHandler classLoaderBeanHandler = (ClassLoaderBeanHandler) invocationHandler;

                            Object bean = classLoaderBeanHandler.getBean();

                            clazz = bean.getClass();
                        }
                    }

                    return ReflectionUtil.getGenericSuperType(clazz);
                }

            });
}

From source file:com.liferay.portlet.display.template.internal.PortletDisplayTemplateImpl.java

License:Open Source License

@Override
public List<TemplateHandler> getPortletDisplayTemplateHandlers() {
    List<TemplateHandler> templateHandlers = TemplateHandlerRegistryUtil.getTemplateHandlers();

    List<TemplateHandler> portletDisplayTemplateHandlers = new ArrayList<>();

    for (TemplateHandler templateHandler : templateHandlers) {
        if (templateHandler instanceof BasePortletDisplayTemplateHandler) {
            portletDisplayTemplateHandlers.add(templateHandler);
        } else if (ProxyUtil.isProxyClass(templateHandler.getClass())) {
            InvocationHandler invocationHandler = ProxyUtil.getInvocationHandler(templateHandler);

            if (invocationHandler instanceof ClassLoaderBeanHandler) {
                ClassLoaderBeanHandler classLoaderBeanHandler = (ClassLoaderBeanHandler) invocationHandler;

                Object bean = classLoaderBeanHandler.getBean();

                if (bean instanceof BasePortletDisplayTemplateHandler) {
                    portletDisplayTemplateHandlers.add(templateHandler);
                }//from  w  w w .j ava 2 s .c  o m
            }
        }
    }

    return portletDisplayTemplateHandlers;
}