Implementing Pagination in Database connector - mule

Is there anyway to set pagination using configurations in select statement of in-built database connector of AnyPoint studio in mule?
I have tried reading the doc and I could not find any configurations to achieve pagination. If not should I write my own custom connector to achieve the same?

You need to implement this yourself.
Best way is to take in the query params you use for pagination, store them as variables and use those flowVariables in your select statement.
Depending on the DB you are connecting to you can then use mechanism such as LIMIT and OFFSET for MySQL as explained here
Another option would be to filter a specific range in DataWeave, but in terms of performance that is unnecessary data fetching, that may not be the nicest option because you still fetch all the data and filter it to a range later.

Related

How to write query result to persistent store

I did some query against a cache, and I want to save the query result to a persist store, eg, mysql db.
I would ask what's the recommended way to accomplish this? Is there some code example for reference? Thanks!
If you need this data in cache as well, use write-through. Otherwise, just update your DB directly. I don't see how Ignite can participate in this process.

How should I store SQL queries in my API server?

I'm making an API server that require SQL queries that has something like 20-40 lines.
I want it to be a simple server so I'm using NodeJS, express, body-parser and a database connector.
In other environments, I understand that you either use final constants or import SQL files but I don't know what's the best method in Node.
I think reading in individual SQL file for every query will be slow and since JavaScript does not support multiline string, saving them in a json object would seem tedious.
(I know ES6/Babel exists but it seems like an overkill for just one functionality).
So the question is what's the best and the most common way to store SQL queries in the context of node/express?
20-40 lines seems like a lot... Have you considered making those queries views or stored procedures?
The other thing is that if you are using at least NodeJS 4.6.1 you can use template literals out of the box

H2 Database: Abort Query

I have a long running select query on an embedded H2 Database and want to allow the user to cancel the query.
How can this be done? I cannot find anything about this.
[UPDATE]
To be more specific I'm running my query using JPA. How can the query be stopped?
H2 supports a query timeout setting. You can set this in the database URL as follows: jdbc:h2:~/db/test;query_timeout=10000. (Maybe this is not the right approach for you, but it might be for others that read this question.)
You can also cancel a query running in another connection (session) using the cancel_session function. But for this you need to enable the multi-threaded mode, which is currently not recommended for production use (it is still experimental in version 1.3.175).
If you have a few queries which might take very long, then don't use JPA for them. Create your own statement so you can cancel it.
Alternatively, get the source code for a JDBC proxy like log4jdbc and add code that allows you to get connections and statements per thread. That would allow you to get the statement after JPA has sent it to the proxy.

Using SQLQuery.uniqueResult() to perform native SQL INSERTs and UPDATEs

I am using Hibernate in my project and there is a certain scenario where I want to use the uniqueResult() method on the org.hibernate.SQLQuery class to perform native SQL INSERT and UPDATE operations.
I did try using the executeUpdate() method on the same class. But I get an error saying that they are used for HQL updates only.
Please advice if this is effective and reliable way of ensuring data being saved/updated in the database.
session.createSQLQuery() is for querying, not manipulation. If you want to do raw SQL insert, use session.connection() and straight JDBC code.
Not sure why you need this exactly but I'd also suggest to check 16.3. Custom SQL for create, update and delete.

Using NHibernate with output parameters

Does anyone know if NHibernate supports returning output parameters from stored procedures? I've had a search in the documentation but can't really find anything that confirms either way.
I was facing the same problem. NHibernate does not let you use stored procedures in this manner. But it does allow a way to make calls using the plain old ADO.NET API. Here's an example -
http://refactoringaspnet.blogspot.com/2009/06/how-to-use-legacy-stored-procedures-in.html
I can't officially confirm for you, but as far as I know, not directly. Stored procedure use in NHibernate is very specific to doing standard CRUD.
If you want to grab output paramaters (that are't the standard row count output parameter for INSERT, UPDATE, and DELETE), you could fall back to a different (or the standard) database access tools that give you direct access to SQL and the result set. (Assuming you can get by with bypassing NHibernate's cache. You'll want to make sure you flush NHibernate before you run the query too, etc.)