Data Business Logic In Java: jOOQ VS SPL

Search for a command to run...

Java is one of the top 5 most in-demand programming languages. Its demand is still growing, and countless companies (from early-stage startups to large-size companies) use Java as a programming language to run their services. Java Brains I've watche...
AI has transformed how I work as a technical writer. Large tech companies are developing and sharpening these tools, but some of them are better than others depending on what you want to accomplish. T

I've been writing professionally for 3+ years, and on this personal blog for 5+ years. Throughout this time, I've built a large network made of developers, other technical writers, solutions engineers

I’ve been writing online for almost five years, with a professional focus on technical writing for over two years. If you struggle to create technical content that is easy to digest, this article is for you. Where do I start? If you don’t know where ...

LinkedIn is the only social networking site purposely built to help job seekers. Over the years, LinkedIn has evolved by offering two types of experiences: Job searching Content creation This article will describe how to maximize your LinkedIn fo...

In the last 12+ months as a technical writer, I've worked on several projects highlighting three technical writing elements. This article will introduce you to: Information Architecture Docs-as-code Content strategy Information Architecture (IA)...

On this page
If you're a Java Engineer, you probably know about Hibernate, an open-source object relation mapping (ORM) that helps map an object domain to a relational database.
jOOQ generates Java code from your database and lets you build type safe SQL queries through its fluent API.[jooq.org]
jOOQ is object-oriented.
It supports lambda expressions, flow control, etc.
jOOQ has excellent performance but lacks flexibility and computing power.
jOOQ creates the SQL statements after execution and sends them to the database to perform calculations and give back the result.
This process makes jOOQ poor in flexibility.
jOOQ uses the Java compiler to compile SQL syntax.
jOOQ creates Java classes from the database metadata.
jOOQ allows you to import external libraries easily.
jOOQ has its graphical IDE and debugging support.
Before you consider learning jOOQ, you should be comfortable with SQL.
jOOQ is straightforward when used during development.
However, it becomes complex when translating from SQL to jOOQ.
Since jOOQ is about SQL, it requires importing several functions.
This translates into creating a large amount of code.
Even though jOOQ supports some object-oriented features, it's inconvenient to use them. SPL, however, has a more elegant syntax.
SPL is an interpreted language. The performance is slower than jOOQ, but it has stronger computing power.
SPL has built-in data processing functions, allowing higher development efficiency and lower time complexity.
SPL has an IDE suitable for data processing.
SPL has a more relaxed learning curve since it aims to simplify Java or SQL code.
SPL is less verbose than jOOQ.
Here are some examples of jOOQ syntax compared to SPL:
// jOOQ
java.sql.Connection conn = DriverManager.getConnection(url, userName, password);
DSLContext context = DSL.using(conn, SQLDialect.MYSQL);
Result<OrdersRecord> R1=context.select().from(ORDERS).fetchInto(ORDERS);
// SPL
=conn=connect("mysql8")
=conn.query("select * from Orders")
=conn.query("select SellerID,Client,Amount from Orders")
// jOOQ
r.setValue(ORDERS.AMOUNT,r.getValue(ORDERS.AMOUNT).doubleValue()+100);
r.update();
// SPL
conn.update(NT:T,orders)
// jOOQ
R1.get(0).getClient();
R1.get(0).get(ORDERS.CLIENT);
// SPL
T(1).Client
T(1).field(2)
T(1).field("Client")
// jOOQ
context.select(ORDERS.CLIENT,year(ORDERS.ORDERDATE).as("y"),sum(ORDERS.AMOUNT).as("amt"),count(one()).as("cnt"))
.from(ORDERS)
.groupBy(ORDERS.CLIENT,year(ORDERS.ORDERDATE))
.having(field("amt").lessThan(20000)).fetch();
// SPL
Orders.groups(Client,year(OrderDate):y;sum(Amount):amt,count(1):cnt)
.select(amt<20000)
// jOOQ
WindowDefinition CA = name("CA").as(partitionBy(ORDERS.CLIENT).orderBy(ORDERS.AMOUNT));
context.select().from(select(ORDERS.ORDERID,ORDERS.CLIENT,ORDERS.SELLERID,ORDERS.AMOUNT,ORDERS.ORDERDATE,rowNumber().over(CA).as("rn")).from(ORDERS).window(CA) ).where(field("rn").lessOrEqual(3)).fetch();
// SPL
Orders.group(Client).(~.top(3;Amount)).conj()
// jOOQ
WindowDefinition woDay1 = name("woDay").as(orderBy(APPL.DAY));
Table<?>T0=table(select(APPL.DAY.as("DAY"),when(APPL.PRICE.greaterThan(lag(APPL.PRICE).over(woDay1)),0). otherwise(1).as("risingflag")).from(APPL).window(woDay1)).as("T0");
WindowDefinition woDay2 = name("woDay1").as(orderBy(T0.field("DAY")));
Table<?>T1=table(select(sum(T0.field("risingflag").cast(java.math.BigDecimal.class)).over(woDay2). as("norisingdays")).from(T0).window(woDay2)).as("T1");
Table<?>T2=table(select(count(one()).as("continuousdays")).from(T1).groupBy(T1.field("norisingdays"))).as("T2");
Result<?> result=context.select(max(T2.field("continuousdays"))).from(T2).fetch();
// SPL
APPL.sort(day).group@i(price<price[-1]).max(~.count())
P.S: in this example, jOOQ needs to calculate the number of days where the stock doesn't increase first. Then, it marks each record with a flag (risingflag) in chronological order.
// jOOQ
Orders.forEach(r->{
Double amount=r.getValue(ORDERS.AMOUNT);
if (amount>10000) {
r.setValue(ORDERS.BONUS), amount * 0.05);
}else if(amount>=5000 && amount<10000){
r.setValue(ORDERS.BONUS),amount*0.03);
}else if(amount>=2000 && amount<5000){
r.setValue(ORDERS.BONUS),amount*0.02);
}
});
// SPL
Orders.(Bonus=if(Amount>10000,Amount*0.05,
if(Amount>5000 && Amount<10000, Amount*0.03,
if(Amount>=2000 && Amount<5000, Amount*0.02)
)))
In this article, you learned about the following:
What jOOQ is.
The language features of jOOQ.
Some disadvantages of jOOQ.
jOOQ VS SPL.
How SPL syntax is simpler than jOOQ.
If you enjoyed this article, you'll definitely benefit from subscribing to my FREE weekly newsletter, where I talk about software engineering, career development, and more. I hope to see you there.
Until next time!
🙋🏾‍♀️