Kripton ORM component use the DAO pattern to gain access to generated data source. Developer need to define DAO interfaces, Kripton will generate for every interface a specific implementation.

As you known, there are 4 kind of SQL you need to work with a database. Every query can be defined in two way:

  • a compact mode, that allows to define only needed part of SQL statement.
  • a JQL mode, that allow to specify SQL using java classes and fields name. Kripton will convert at compile time java names in SQLite table and column names.

SQL parameters are define with a ${name} syntax. As SQL parameter it is possible to use an instance of DAO managed bean or a Kripton support type parameter.

SQL Select

To define a SELECT operation in a DAO interface, you have to decorate a method with @BindSqlSelect. A compact SELECT need to define only where conditions.

In this case, we specify a SELECT for Artist table filtered by id field. The next example do the same query, but use JQL mode and use a Artist bean as parameter.

SQL Insert

To define a INSERT operation in a DAO interface, you have to decorate a method with @BindSqlInsert. If we want to use an INSERT in compact mode, just write:

If we want to use JQL mode, just use

SQL Update

To define a UPDATE operation in a DAO interface, you have to decorate a method with @BindSqlUpdate. If we want to use an UPDATE in compact mode, just write:

In the above example, field id is used in where condition. All other field of bean Artist will be used to update table. An example of JQL mode to define UPDATE SQL:

SQL Delete

To define a DELETE operation in a DAO interface, you have to decorate a method with @BindSqlDelete.

 

Using a base interface

As we said, for every SQL statement we just write an interface method. It’s quite easy and fast.. but imagine that you need to work with a datasource with many entities/tables. It can be boring define same methods for every DAO. Kripton allows to define a base DAO in which put commons DAO methods. This works only for query in compact mode, because we don’t need to specify table name.

The BaseDao code will be:

More information on Kripton and its ORM component can be found:

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close