Download
Logo
Overview
News
Download
Motivation
Examples
Troubleshoot

Videos

This section provides some tutorial videos showing the usage of the anqu method Eclipse plug-in.

Even More Auto Completion

New field name auto completion functionality:

preview auto complete
Play or download

JPA 2.2 and Auto Complete Example

See anqu's JPA 2.2 support in combination with the auto completion:

preview auto complete
Play or download

Auto Complete Example

The fastest implementation of a simple @NamedQuery so far, powered by auto completion.

preview auto complete
Play or download

Basic Example

See how easy the implementation of a simple @NamedQuery can be - with the context menu.

preview simple demo
Play or download

Dao Example

See how the glue code can be generated into an existing Dao (data acess object) class. The video also demonstrates the Single Result Generation.

preview dao
Play or download

Overwriting and Tests Example

If the query name stays the same, re-generating the glue code (e.g. with another style or mode) will automatically replace the existing code. Tests verifying the contract can be generated.

preview pagination
Play or download

Removing a Query and its Code

Removing a query completely requires to remove the corresponding code, too. Anqu provides this functionality.

preview remove
Play or download

Common Entity Setup

Just a hint: Now there's also a video tutorial available including most of the examples covered here.

All examples use the entity User as seen below. It has several fields, especially an Address having some fields itself.
@Entity
public class User {

    @Id
    private int id;

    private String name;
    private int loginCount;
    private Address address;

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLogin;

    @Temporal(TemporalType.DATE)
    private Date birthday;
}
The Address class is simple as well:
@Embeddable
public class Address {

    private String town;
    private String street;
}

Ex 1: The Pure Anqu Method Pattern

If the default preferences are used, the most important ones are as follows
  • visibility modifier is public static
  • comment generation is on
  • the entity manager is provided as parameter
You provide
  • nothing - it's the lazy way
You execute Anqu Method -> Execution -> Method to Source. The method is generated into User class source code.

Query

@NamedQuery(name = "User.findByName", 
            query = "SELECT u FROM User u WHERE u.name = :name")

Result

@Entity
public class User {

    // Generated code starts here --------------------------

    /**
     * Executes the query 'User.findByName' returning a list of result objects.
     *
     * @param entityManager the entityManager
     * @param name the name
     * @return List of result objects
     */
    public static List<User> findByName(EntityManager entityManager, String name)
    {
        Query query = entityManager.createNamedQuery("User.findByName");
        query = query.setParameter("name", name);
        return query.getResultList();
    }

    // Generated code ends here --------------------------

    @Id
    private int id;

    private String name;
    private int loginCount;
    private Address address;

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLogin;

    @Temporal(TemporalType.DATE)
    private Date birthday;
}

Ex 2: DAO Method Generation

Generating code to an existing DAO class could be done using the following preferences:
  • visibility modifier is public, but not static
  • comment generation is off
  • the entity manager is provided by the surrounding class
  • the entity manager field name is entMan
You provide
  • UserService class
  • EntityManager field, its name has to match the preferences
  • imports after method insertion (e.g. Query class, result type, parameter types, List class)
You execute Anqu Method -> Execution -> Method to Clipboard and paste the generated code into UserService.

Query

@NamedQuery(name = "User.findByName", 
            query = "SELECT u FROM User u WHERE u.name = :name")

Result

@Stateless
public class UserService {

    @PersistenceContext
    private EntityManager entMan;

    // Generated code starts here --------------------------
    
    public List<User> findByName(String name)
    {
        Query query = entMan.createNamedQuery("User.findByName");
        query = query.setParameter("name", name);
        return query.getResultList();
    }

    // Generated code ends here --------------------------

}

Ex 3: Method with Pagination

This example shows the usage of positional parameters in the query with the firstResult/maxResults method generation. The recognition of type parameters is demonstrated as well.
  • visibility modifier is static
  • comment generation is off
  • fully qualified names are off
  • the entity manager is provided as parameter
  • query defines positional parameters ?1, ?2
  • ?2 defines a parameter of type TemporalType.DATE
  • query returns list of embedded objects
  • execution can be configured concerning firstResult and maxResults at runtime (e.g. for paging)
  • compiler warning suppression is on
You provide
  • imports after method insertion (e.g. Query class, List class)
You execute Anqu Method -> First/Max Execution -> Method to Source. The method is generated into User class source code.

Query

@NamedQuery(name = "User.getAddressesByNameAndAgeExtended", 
           query = "SELECT u.address FROM User u WHERE u.name = ?1 "
                                  + " AND u.birthday < ?2")

Result

@Entity
public class User {

    // Generated code starts here --------------------------

    @SuppressWarnings("unchecked")
    // Result type is List of Address
    static List<Address> getAddressesByNameAndAgeExtended(
            EntityManager entityManager, 
            String positional1,  // positional parameter
            Date positional2,    // date parameter
            int firstResult,     // pagination parameters
            int maxResults)
    {
        Query query = entityManager.createNamedQuery(
                                   "User.getAddressesByNameAndAgeExtended");
        query = query.setParameter(2, 
                                    positional2, 
                                    javax.persistence.TemporalType.DATE);
        query = query.setParameter(1, positional1);
        query = query.setFirstResult(firstResult);
        query = query.setMaxResults(maxResults);
        return query.getResultList();
    }
    // Generated code ends here --------------------------
}


top