Search in sources :

Example 11 with Foo

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

the class BladeServiceBuilderIntegrationTest method testCreateFoo.

@Test
public void testCreateFoo() throws PortalException {
    Foo foo = FooLocalServiceUtil.createFoo(CounterLocalServiceUtil.increment());
    foo.setField1("createFooEntryField1");
    foo.setField2(true);
    foo.setField3(1);
    Date createDate = new Date();
    foo.setField4(createDate);
    foo.setField5("createFooEntryField5");
    foo.isNew();
    Foo fooEntry = FooLocalServiceUtil.addFoo(foo);
    Assert.assertTrue("Expected createFooEntryField1, but saw " + fooEntry.getField1(), fooEntry.getField1().contentEquals("createFooEntryField1"));
    Assert.assertTrue("Expected true, but saw " + fooEntry.getField2(), fooEntry.getField2() == true);
    Assert.assertTrue("Expected \"1\", but saw " + fooEntry.getField3(), fooEntry.getField3() == 1);
    Assert.assertTrue("Expected " + createDate + "but saw, " + fooEntry.getField4(), fooEntry.getField4().compareTo(createDate) == 0);
    Assert.assertTrue("Expected createFooEntryField5, but saw " + fooEntry.getField5(), fooEntry.getField5().contentEquals("createFooEntryField5"));
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo) Date(java.util.Date) Test(org.junit.Test)

Example 12 with Foo

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

the class FooPersistenceImpl method findByUuid_C.

/**
 * Returns an ordered range of all the foos where uuid = ? and companyId = ?.
 *
 * <p>
 * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link FooModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
 * </p>
 *
 * @param uuid the uuid
 * @param companyId the company ID
 * @param start the lower bound of the range of foos
 * @param end the upper bound of the range of foos (not inclusive)
 * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
 * @param retrieveFromCache whether to retrieve from the finder cache
 * @return the ordered range of matching foos
 */
@Override
public List<Foo> findByUuid_C(String uuid, long companyId, int start, int end, OrderByComparator<Foo> orderByComparator, boolean retrieveFromCache) {
    boolean pagination = true;
    FinderPath finderPath = null;
    Object[] finderArgs = null;
    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) {
        pagination = false;
        finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
        finderArgs = new Object[] { uuid, companyId };
    } else {
        finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
        finderArgs = new Object[] { uuid, companyId, start, end, orderByComparator };
    }
    List<Foo> list = null;
    if (retrieveFromCache) {
        list = (List<Foo>) finderCache.getResult(finderPath, finderArgs, this);
        if ((list != null) && !list.isEmpty()) {
            for (Foo foo : list) {
                if (!Objects.equals(uuid, foo.getUuid()) || (companyId != foo.getCompanyId())) {
                    list = null;
                    break;
                }
            }
        }
    }
    if (list == null) {
        StringBundler query = null;
        if (orderByComparator != null) {
            query = new StringBundler(4 + (orderByComparator.getOrderByFields().length * 2));
        } else {
            query = new StringBundler(4);
        }
        query.append(_SQL_SELECT_FOO_WHERE);
        boolean bindUuid = false;
        if (uuid == null) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
        } else if (uuid.equals(StringPool.BLANK)) {
            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
        } else {
            bindUuid = true;
            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
        }
        query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
        if (orderByComparator != null) {
            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator);
        } else if (pagination) {
            query.append(FooModelImpl.ORDER_BY_JPQL);
        }
        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(companyId);
            if (!pagination) {
                list = (List<Foo>) QueryUtil.list(q, getDialect(), start, end, false);
                Collections.sort(list);
                list = Collections.unmodifiableList(list);
            } else {
                list = (List<Foo>) QueryUtil.list(q, getDialect(), start, end);
            }
            cacheResult(list);
            finderCache.putResult(finderPath, finderArgs, list);
        } catch (Exception e) {
            finderCache.removeResult(finderPath, finderArgs);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return list;
}
Also used : Query(com.liferay.portal.kernel.dao.orm.Query) FinderPath(com.liferay.portal.kernel.dao.orm.FinderPath) Foo(com.liferay.blade.samples.servicebuilder.model.Foo) 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 13 with Foo

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

the class FooPersistenceImpl method create.

/**
 * Creates a new foo with the primary key. Does not add the foo to the database.
 *
 * @param fooId the primary key for the new foo
 * @return the new foo
 */
@Override
public Foo create(long fooId) {
    Foo foo = new FooImpl();
    foo.setNew(true);
    foo.setPrimaryKey(fooId);
    String uuid = PortalUUIDUtil.generate();
    foo.setUuid(uuid);
    foo.setCompanyId(companyProvider.getCompanyId());
    return foo;
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo) FooImpl(com.liferay.blade.samples.servicebuilder.model.impl.FooImpl)

Example 14 with Foo

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

the class FooPersistenceImpl method findByUuid_PrevAndNext.

/**
 * Returns the foos before and after the current foo in the ordered set where uuid = &#63;.
 *
 * @param fooId the primary key of the current foo
 * @param uuid the uuid
 * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
 * @return the previous, current, and next foo
 * @throws NoSuchFooException if a foo with the primary key could not be found
 */
@Override
public Foo[] findByUuid_PrevAndNext(long fooId, String uuid, OrderByComparator<Foo> orderByComparator) throws NoSuchFooException {
    Foo foo = findByPrimaryKey(fooId);
    Session session = null;
    try {
        session = openSession();
        Foo[] array = new FooImpl[3];
        array[0] = getByUuid_PrevAndNext(session, foo, uuid, orderByComparator, true);
        array[1] = foo;
        array[2] = getByUuid_PrevAndNext(session, foo, uuid, orderByComparator, false);
        return array;
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }
}
Also used : Foo(com.liferay.blade.samples.servicebuilder.model.Foo) FooImpl(com.liferay.blade.samples.servicebuilder.model.impl.FooImpl) NoSuchFooException(com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException) Session(com.liferay.portal.kernel.dao.orm.Session)

Example 15 with Foo

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

the class FooPersistenceImpl method fetchByPrimaryKey.

/**
 * Returns the foo with the primary key or returns <code>null</code> if it could not be found.
 *
 * @param primaryKey the primary key of the foo
 * @return the foo, or <code>null</code> if a foo with the primary key could not be found
 */
@Override
public Foo fetchByPrimaryKey(Serializable primaryKey) {
    Serializable serializable = entityCache.getResult(FooModelImpl.ENTITY_CACHE_ENABLED, FooImpl.class, primaryKey);
    if (serializable == nullModel) {
        return null;
    }
    Foo foo = (Foo) serializable;
    if (foo == null) {
        Session session = null;
        try {
            session = openSession();
            foo = (Foo) session.get(FooImpl.class, primaryKey);
            if (foo != null) {
                cacheResult(foo);
            } else {
                entityCache.putResult(FooModelImpl.ENTITY_CACHE_ENABLED, FooImpl.class, primaryKey, nullModel);
            }
        } catch (Exception e) {
            entityCache.removeResult(FooModelImpl.ENTITY_CACHE_ENABLED, FooImpl.class, primaryKey);
            throw processException(e);
        } finally {
            closeSession(session);
        }
    }
    return foo;
}
Also used : Serializable(java.io.Serializable) Foo(com.liferay.blade.samples.servicebuilder.model.Foo) FooImpl(com.liferay.blade.samples.servicebuilder.model.impl.FooImpl) NoSuchFooException(com.liferay.blade.samples.servicebuilder.exception.NoSuchFooException) Session(com.liferay.portal.kernel.dao.orm.Session)

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