Class SQL

java.lang.Object
net.sf.persism.SQL

public final class SQL extends Object
Simple wrapper for SQL String. Mainly to allow for overloads to fetch/query methods.
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    limit(int limit)
    Specifies a limit to the query result which will translate to the specific SQL syntax when executed.
    static SQL
    proc(String storedProc)
    Static initializer for a new SQL stored procedure string.
    static SQL
    sql(String sql)
    Method to instantiate a regular SQL string.
    static SQL
    where(String where)
    Method used to specify an SQL WHERE clause for an SQL Statement.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Method Details

    • sql

      public static SQL sql(String sql)
      Method to instantiate a regular SQL string.
      
            Contact> contact;
            contact = session.fetch(Contact.class,
                      sql("SELECT * FROM CONTACTS WHERE LAST_NAME = ? AND FIRST_NAME = ?"),
                      params("Fred", "Flintstone");
       
      Parameters:
      sql - String
      Returns:
      new SQL object
    • where

      public static SQL where(String where)
      Method used to specify an SQL WHERE clause for an SQL Statement. The SELECT ... parts would be provided by Persism. Only here do we allow property names in the query
      
            List<Contact> contacts;
            contacts = session.query(Contact.class,
                       where("(:firstname = @name OR :company = @name) and :lastname = @last and :city = @city and :amountOwed > @owe ORDER BY :dateAdded"),
                       named(Map.of("name", "Fred", "last", "Flintstone", "owe", 10, "city", "Somewhere")));
       
      Parameters:
      where - String
      Returns:
      new SQL object
    • proc

      public static SQL proc(String storedProc)
      Static initializer for a new SQL stored procedure string.
      
            List<CustomerOrder> list;
            list = session.query(CustomerOrder.class, proc("[spCustomerOrders](?)"), params("123"));
       
      Parameters:
      storedProc - String
      Returns:
      new SQL object
    • limit

      public SQL limit(int limit)
      Specifies a limit to the query result which will translate to the specific SQL syntax when executed.
      
            List<PublisherTitle> publisherTitles = session.query(PublisherTitle.class, where("1=1").limit(4));
       
      Parameters:
      limit - positive integer number
      Returns:
      current SQL object
      Since:
      2.3