Class ClasspathSqlLocator

java.lang.Object
org.jdbi.v3.core.locator.ClasspathSqlLocator

public final class ClasspathSqlLocator extends Object
Locates SQL in .sql files on the classpath. Given a class and method name, for example com.foo.Bar#query, load a classpath resource name like com/foo/Bar/query.sql. The contents are then parsed, cached, and returned for use by a statement.
  • Method Details

    • removingComments

      public static ClasspathSqlLocator removingComments()
      Return a new ClasspathSqlLocator that returns SQL with comments removed.
      Returns:
      A new ClasspathSqlLocator that returns SQL with comments removed.
    • create

      public static ClasspathSqlLocator create()
      Return a new ClasspathSqlLocator that returns SQL without modifying it.
      Returns:
      A new ClasspathSqlLocator that returns SQL without modifying it.
    • locate

      public String locate(Class<?> type, String methodName)
      Locates SQL for the given type and name. Example: Given a type com.foo.Bar and a name of baz, looks for a resource named com/foo/Bar/baz.sql on the classpath and returns its contents as a String.
      Parameters:
      type - the type that "owns" the given SQL. Dictates the directory path to the SQL resource file on the classpath.
      methodName - the SQL statement name (usually a method or field name from the type).
      Returns:
      the located SQL.
    • locate

      public String locate(String name)
      Locates SQL for the given fully-qualified name. Example: Given the name com.foo.Bar.baz, looks for a resource named com/foo/Bar/baz.sql on the classpath and returns its contents as a String.
      Parameters:
      name - fully qualified name.
      Returns:
      the located SQL.
    • getResource

      public String getResource(String path)
      Returns resource's contents as a string at the specified path. The path should point directly to the resource at the classpath. The resource is loaded by the current thread's classloader.
      Parameters:
      path - the resource path
      Returns:
      the resource's contents
      See Also:
    • getResource

      public String getResource(ClassLoader classLoader, String path)
      Returns resource's contents as a string at the specified path by the specified classloader. The path should point directly to the resource at the classpath. The classloader should have access to the resource.
      Parameters:
      classLoader - the classloader which loads the resource
      path - the resource path
      Returns:
      the resource's contents
      See Also: