spring-data pagination and sorting - pagination

I have a question for the Pagination and Sorting of the spring-data project. I like so much this project.
The function findAll() returns all the Database Table. It's possible implement a function with Page<T> page findAll(SearchObject <T>, Pageable pageable), the SearchObject with the filters.
I read in the SpringDataa Book one example like this: Page<Customer> findByLastName(String lastname, Pageable pageable) if i need a Advanced Search, Is the solution QueryDSL?
Thanks for you time. ;)

Related

Liferay service builder get last modified

Somebody know how to get the last row modified from a table?
For example:
I have a Service Builder with a "Car" entity, this entity has a column called "LastModified". I want something that get the one "Car" (the last cart modified).
I don't know if create a finder with where clause is a good practice.
Thank you!
First off, service builder entities have a column called "modifiedDate" by default. Just want to make sure you're aware of that so you aren't creating redundant columns: "LastModified" and "modifiedDate".
Secondly, you could use either a custom SQL query or a dynamic query to get the Car with the most recent modifiedDate. Both approaches are documented:
https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/developing-custom-sql-queries
https://dev.liferay.com/develop/tutorials/-/knowledge_base/6-2/leveraging-hibernates-criteria-api
Personally, I'd try the dynamic query approach (leveraging hibernate's criteria API) first. I think it's slightly simpler.
In your finder method, you could do something like this:
Order order = OrderFactoryUtil.desc("modifiedDate");
DynamicQuery carQuery = DynamicQueryFactoryUtil.forClass(Car.class).addOrder(order).setLimit(0, 1);
List<Car> cars = CarLocalServiceUtil.dynamicQuery(carQuery);
The setLimit(0, 1) limits the result of the query to only the first Car.

How to sort the OrderItems in the cart by its category on Broadleaf Commerce?

Broadleaf Commerce site
I need to sort the OrderItems in the cart by its product category. Currently, I am using the comparator to sort the OrderItems.
What is the best or right way to customize the default sort for Cart OrderItems?
I assume that you are currently doing something like this:
List<OrderItem> items = cart.getOrderItems();
Collections.sort(items, comparator);
and I also assume that by "default sort" you mean that you want to change the behavior when you call cart.getOrderItems().
Unfortunately, there is no way to change the behavior of the query that occurs when you call getOrderItems() as this is a JPA-generated query on the OrderItem collection within OrderImpl:
#OneToMany(mappedBy = "order", targetEntity = OrderItemImpl.class, cascade = {CascadeType.ALL})
#Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region="blOrderElements")
#AdminPresentationCollection(friendlyName="OrderImpl_Order_Items",
tab = TabName.General)
protected List<OrderItem> orderItems = new ArrayList<>();
Because of this you really only have 3 options:
Override the OrderImpl class and change the implementation of the getOrderItems() method. Unless you really needed to extend this (like to add another column to BLC_ORDER) then this isn't a great solution since it will add another table to the database that isn't actually used. See the Broadleaf extending entities tutorial. You can also technically avoid the multi-table inheritance by switching to single-table inheritance which is detailed at the bottom of that doc
Add your own query somewhere in a service method that manually queries for OrderItem for the order with a JPA query
Do what you are currently doing and sort the order items manually after retrieval with your comparator. You might consider adding a Thymeleaf utility method to have it available to you in your templates

How to Combine Multiple View Updates Into One ListView?

I have multiple views in multiple nsf databases that I want to perform a view.update on, build an array of records, and show the results in one ListView. What would be the best way to do this in regards to performance? One idea that came to mind was to:
Perform .update() method on views
In callback of each update, push records to a (global?) array
Set array to ListView
Am I thinking about this correctly? Is there an example of doing this in Domino To Go?
Thanks for any tips.
I would chain the .update() methods on the views and in the callback of the final update I would sue a DTGDatabase object with getAllEntriesByKey() method to get the records, it's faster than using NotesView.getAllEntriesByKey of each view.
Or use DTGDatabase.getAllEntriesBySQL with a proper SQL statement, that way you can do a JOIN and it's the fastest option.

SharePoint returns extra system columns

I do query to SherePoint. I have created query, viewquery and query options.
Web services returns me great results, but it include some other system columns such as:
ows_Modified , ows_DocIcon, ows_Editor. I don't want them. How do I return only those which is in ViewQuery string?
My queryoptions is:
#"<QueryOptions>
<IncludeMandatoryColumns>False</IncludeMandatoryColumns><ViewAttributes Scope='Recursive' />
</QueryOptions>";
Thanks!
In order to return only selected columns (and not all of them) use ViewFields property of SPQuery object. You can find some more information about it and a sample code here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewfields.aspx.
In order to do it from javascript, you can try code as written here (that post is on another topic, but it still shows how to specify fields to select): https://sharepoint.stackexchange.com/questions/33683/spservices-today-not-returning-correct-results.

ExecuteJoinedDataSet but with Where()

I did some searching and see that ExecuteJoinedDataSet will not work with the Where clause in 2.1. If I want to query a table with WHERE, but want the FK objects values to be bindable is the easiest way to just create a custom class(my table has tons of FK references).
Could you give us an example of what kind of query you are trying to write? If you are just trying to return a DataTable without creating a custom class just write your query and use the ExecuteReader which Returns an IDataReader. The IDataReader is bindable and if you need more you can just load it into a DataTable.

Resources