Rene Dudfield: Draft 2 of, ^Let's write a unit test!^

So, I started writing this for people who want to ‘contribute’ to Community projects, and also Free Libre or Open source projects. Maybe you’d like to get involved, but are unsure of where to begin? Follow along with this tutorial, and peek at the end in the “what is a git for?” section for explanations of what some of the words mean. Draft 1, 2018/07/18 – initial draft.Draft 2, 2019/11/04 – two full unit test examples, assertions, making a pull request, use python 3 unittest substring search, “good first issue”…

Read More

How to Write Multiset Conditions With Oracle VARRAY Types

Oracle is one of the few databases that implements the SQL standard ORDBMS extensions, which essentially allow for nested collections. Other databases that have these features to some extent are CUBRID, Informix, PostgreSQL. Oracle has two types of nested collections: — Nested tables CREATE TYPE t1 AS TABLE OF VARCHAR2(10); / — Varrays CREATE TYPE t2 AS VARRAY(10) OF VARCHAR2(10); / The main difference at first is that a nested table can be of arbitrary size, whereas a varray has a fixed maximum size. Other than that, they behave in…

Read More

How to Write a Multiplication Aggregate Function in SQL

Everyone knows the SQL SUM() aggregate function (and many people also know its window function variant). When querying the Sakila database, we can get the daily revenue (using PostgreSQL syntax): WITH p AS ( SELECT CAST (payment_date AS DATE) AS date, amount FROM payment ) SELECT date, SUM (amount) AS daily_revenue, SUM (SUM (amount)) OVER (ORDER BY date) AS cumulative_revenue FROM p GROUP BY date ORDER BY date The result will look something like this: date |daily_revenue |cumulative_revenue ———–|————–|——————- 2005-05-24 |29.92 |29.92 2005-05-25 |573.63 |603.55 2005-05-26 |754.26 |1357.81 2005-05-27 |685.33…

Read More

How to write JPA Criteria API queries using Codota

Introduction Writing JPA Criteria API queries is not very easy. The Codota IDE plugin can guide you on how to write such queries, which greatly simplifies the process. In this article, we are going to see how Codota works and how it can help you discover a given API. Codota Codota is a free Java IDE plugin which you install on IntelliJ IDEA or Eclipse. The plugin provides you with suggestions related to what methods to call for a given Java object reference. Behind the scenes, Codota uses AI to…

Read More
java 

How to Write a Simple, yet Extensible API

How to write a simple API is already an art on its own. I didn’t have time to write a short letter, so I wrote a long one instead. ― Mark Twain But keeping an API simple for beginners and most users, and making it extensible for power users seems even more of a challenge. But is it? What does “extensible” mean? Imagine an API like, oh say, jOOQ. In jOOQ, you can write SQL predicates like this: ctx.select(T.A, T.B) .from(T) .where(T.C.eq(1)) // Predicate with bind value here .fetch(); By…

Read More

How to write a compact DTO projection query with JPA

Introduction In this article, we are going to see how we can write the best DTO projection JPQL query by omitting the package name when using JPA, Hibernate, and Spring. As I already explained, DTO projections are the most efficient way of fetching data when using JPA and Hibernate. Domain Model Let’s consider the following Post entity and its associated PostDTO Value Object. We can see that the Post entity has seven attributes, while PostDTO has only two of those. If our business use case requires just the two attributes…

Read More