Package org.sqlite

Class Collation


  • public abstract class Collation
    extends java.lang.Object
    Provides an interface for creating SQLite user-defined collations.

    A subclass of org.sqlite.Collation can be registered with Collation.create() and called by the name it was given. All collations must implement xCompare(String, String), which is called when SQLite compares two strings using the custom collation. Eg.

          Class.forName("org.sqlite.JDBC");
          Connection conn = DriverManager.getConnection("jdbc:sqlite:");
    
          Collation.create(conn, "REVERSE", new Collation() {
              protected int xCompare(String str1, String str2) {
                  return str1.compareTo(str2) * -1;
              }
          });
    
          conn.createStatement().execute("select c1 from t order by c1 collate REVERSE;");
      
    • Constructor Summary

      Constructors 
      Constructor Description
      Collation()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static void create​(java.sql.Connection conn, java.lang.String name, Collation f)
      Registers a given collation with the connection.
      static void destroy​(java.sql.Connection conn, java.lang.String name)
      Removes a named collation from the given connection.
      protected abstract int xCompare​(java.lang.String str1, java.lang.String str2)
      Called by SQLite as a custom collation to compare two strings.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Collation

        public Collation()
    • Method Detail

      • create

        public static final void create​(java.sql.Connection conn,
                                        java.lang.String name,
                                        Collation f)
                                 throws java.sql.SQLException
        Registers a given collation with the connection.
        Parameters:
        conn - The connection.
        name - The name of the collation.
        f - The collation to register.
        Throws:
        java.sql.SQLException
      • destroy

        public static final void destroy​(java.sql.Connection conn,
                                         java.lang.String name)
                                  throws java.sql.SQLException
        Removes a named collation from the given connection.
        Parameters:
        conn - The connection to remove the collation from.
        name - The name of the collation.
        Throws:
        java.sql.SQLException
      • xCompare

        protected abstract int xCompare​(java.lang.String str1,
                                        java.lang.String str2)
        Called by SQLite as a custom collation to compare two strings.
        Parameters:
        str1 - the first string in the comparison
        str2 - the second string in the comparison
        Returns:
        an integer that is negative, zero, or positive if the first string is less than, equal to, or greater than the second, respectively