Search in sources :

Example 21 with Foo

use of com.liferay.blade.samples.servicebuilder.model.Foo in project liferay-blade-samples by liferay.

the class FooPersistenceImpl method findByField2_Last.

/**
 * Returns the last foo in the ordered set where field2 = ?.
 *
 * @param field2 the field2
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the last matching foo
 * @throws NoSuchFooException if a matching foo could not be found
 */
@Override
public Foo findByField2_Last(boolean field2, OrderByComparator<Foo> orderByComparator) throws NoSuchFooException {
    Foo foo = fetchByField2_Last(field2, orderByComparator);
    if (foo != null) {
        return foo;
    }
    StringBundler msg = new StringBundler(4);
    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
    msg.append("field2=");
    msg.append(field2);
    msg.append(StringPool.CLOSE_CURLY_BRACE);
    throw new NoSuchFooException(msg.toString());
}
Also used : NoSuchFooException(com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException) Foo(com.liferay.blade.samples.servicebuilder.model.Foo) StringBundler(com.liferay.portal.kernel.util.StringBundler)

Example 22 with Foo

use of com.liferay.blade.samples.servicebuilder.model.Foo in project liferay-blade-samples by liferay.

the class FooPersistenceImpl method fetchByUUID_G.

/**
 * Returns the foo where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
 *
 * @param uuid the uuid
 * @param groupId the group ID
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the matching foo, or <code>null</code> if a matching foo could not be found
 */
@Override
public Foo fetchByUUID_G(String uuid, long groupId, boolean retrieveFromCache) {
    Object[] finderArgs = new Object[] { uuid, groupId };
    Object result = null;
    if (retrieveFromCache) {
        result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, this);
    }
    if (result instanceof Foo) {
        Foo foo = (Foo) result;
        if (!Objects.equals(uuid, foo.getUuid()) || (groupId != foo.getGroupId())) {
            result = null;
        }
    }
    if (result == null) {
        StringBundler query = new StringBundler(4);
        query.append(_SQL_SELECT_FOO_WHERE);
        boolean bindUuid = false;
        if (uuid == null) {
            query.append(_FINDER_COLUMN_UUID_G_UUID_1);
        } else if (uuid.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
        String sql = query.toString();
        Session session = null;
        try {
            session = openSession();
            Query q = session.createQuery(sql);
            QueryPos qPos = QueryPos.getInstance(q);
            if (bindUuid) {
                qPos.add(uuid);
            }
            qPos.add(groupId);
            List<Foo> list = q.list();
            if (list.isEmpty()) {
                finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, list);
            } else {
                Foo foo = list.get(0);
                result = foo;
                cacheResult(foo);
                if ((foo.getUuid() == null) || !foo.getUuid().equals(uuid) || (foo.getGroupId() != groupId)) {
                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, foo);
                }
            }
        } catch (Exception e) {
            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    if (result instanceof List<?>) {
        return null;
    } else {
        return (Foo) result;
    }
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) Foo(com.liferay.blade.samples.servicebuilder.model.Foo) List(java.util.List) QueryPos(com.liferay.portal.kernel.dao.orm.QueryPos) StringBundler(com.liferay.portal.kernel.util.StringBundler) NoSuchFooException(com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 23 with Foo

use of com.liferay.blade.samples.servicebuilder.model.Foo in project liferay-blade-samples by liferay.

the class FooModelImpl method toModel.

/**
 * Converts the soap model instance into a normal model instance.
 *
 * @param soapModel the soap model instance to convert
 * @return the normal model instance
 */
public static Foo toModel(FooSoap soapModel) {
    if (soapModel == null) {
        return null;
    }
    Foo model = new FooImpl();
    model.setUuid(soapModel.getUuid());
    model.setFooId(soapModel.getFooId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setField1(soapModel.getField1());
    model.setField2(soapModel.getField2());
    model.setField3(soapModel.getField3());
    model.setField4(soapModel.getField4());
    model.setField5(soapModel.getField5());
    return model;
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo)

Example 24 with Foo

use of com.liferay.blade.samples.servicebuilder.model.Foo in project liferay-blade-samples by liferay.

the class SpringMVCPortletViewController method updateFoo.

/**
 * Handles the action when the action key is <code>updateFoo</code>. This is
 * the case when Foo is added and updated.
 *
 * @param  actionRequest the action request
 * @param  response the action response
 * @throws Exception if an exception occurred
 */
@ActionMapping(params = "action=updateFoo")
public void updateFoo(ActionRequest actionRequest, ActionResponse response) throws Exception {
    // See if there is an existing Foo ID.
    long fooId = ParamUtil.getLong(actionRequest, "fooId");
    // Extract the form field values.
    String field1 = ParamUtil.getString(actionRequest, "field1");
    boolean field2 = ParamUtil.getBoolean(actionRequest, "field2");
    int field3 = ParamUtil.getInteger(actionRequest, "field3");
    String field5 = ParamUtil.getString(actionRequest, "field5");
    // Convert the calendar details into a date.
    int dateMonth = ParamUtil.getInteger(actionRequest, "field4Month");
    int dateDay = ParamUtil.getInteger(actionRequest, "field4Day");
    int dateYear = ParamUtil.getInteger(actionRequest, "field4Year");
    int dateHour = ParamUtil.getInteger(actionRequest, "field4Hour");
    int dateMinute = ParamUtil.getInteger(actionRequest, "field4Minute");
    int dateAmPm = ParamUtil.getInteger(actionRequest, "field4AmPm");
    if (dateAmPm == Calendar.PM) {
        dateHour += 12;
    }
    Date field4 = PortalUtil.getDate(dateMonth, dateDay, dateYear, dateHour, dateMinute, PortalException.class);
    if (fooId <= 0) {
        if (_log.isInfoEnabled()) {
            _log.info("Adding a new foo...");
        }
        // Create the Foo.
        Foo foo = FooLocalServiceUtil.createFoo(0);
        // Set the Foo's fields.
        foo.setField1(field1);
        foo.setField2(field2);
        foo.setField3(field3);
        foo.setField4(field4);
        foo.setField5(field5);
        // Invoke the service layer to add the foo.
        FooLocalServiceUtil.addFooWithoutId(foo);
    } else {
        if (_log.isInfoEnabled()) {
            _log.info("Updating a new foo...");
        }
        // Retrieve the current Foo during the update.
        Foo foo = FooLocalServiceUtil.fetchFoo(fooId);
        // Update the Foo's fields.
        foo.setFooId(fooId);
        foo.setField1(field1);
        foo.setField2(field2);
        foo.setField3(field3);
        foo.setField4(field4);
        foo.setField5(field5);
        // Invoke the service layer to update the Foo.
        FooLocalServiceUtil.updateFoo(foo);
    }
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo) Date(java.util.Date) ActionMapping(org.springframework.web.portlet.bind.annotation.ActionMapping)

Example 25 with Foo

use of com.liferay.blade.samples.servicebuilder.model.Foo in project liferay-blade-samples by liferay.

the class FooModelImpl method equals.

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    if (!(obj instanceof Foo)) {
        return false;
    }
    Foo foo = (Foo) obj;
    long primaryKey = foo.getPrimaryKey();
    if (getPrimaryKey() == primaryKey) {
        return true;
    } else {
        return false;
    }
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo)

Aggregations

Foo (com.liferay.blade.samples.servicebuilder.model.Foo)48 NoSuchFooException (com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException)18 Test (org.junit.Test)17 StringBundler (com.liferay.portal.kernel.util.StringBundler)16 Session (com.liferay.portal.kernel.dao.orm.Session)11 Query (com.liferay.portal.kernel.dao.orm.Query)9 QueryPos (com.liferay.portal.kernel.dao.orm.QueryPos)7 Date (java.util.Date)7 FooImpl (com.liferay.blade.samples.servicebuilder.model.impl.FooImpl)6 ActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ActionableDynamicQuery)5 Serializable (java.io.Serializable)5 DynamicQuery (com.liferay.portal.kernel.dao.orm.DynamicQuery)4 FinderPath (com.liferay.portal.kernel.dao.orm.FinderPath)4 HashSet (java.util.HashSet)3 List (java.util.List)2 ManifestSummary (com.liferay.exportimport.kernel.lar.ManifestSummary)1 StagedModelType (com.liferay.exportimport.kernel.lar.StagedModelType)1 DefaultActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.DefaultActionableDynamicQuery)1 ExportActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.ExportActionableDynamicQuery)1 IndexableActionableDynamicQuery (com.liferay.portal.kernel.dao.orm.IndexableActionableDynamicQuery)1