Package org.jdbi.v3.core.locator
Class ClasspathSqlLocator
java.lang.Object
org.jdbi.v3.core.locator.ClasspathSqlLocator
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 Summary
Modifier and TypeMethodDescriptionstatic ClasspathSqlLocator
create()
Return a new ClasspathSqlLocator that returns SQL without modifying it.getResource
(ClassLoader classLoader, String path) Returns resource's contents as a string at the specified path by the specified classloader.getResource
(String path) Returns resource's contents as a string at the specified path.Locates SQL for the given type and name.Locates SQL for the given fully-qualified name.static ClasspathSqlLocator
Return a new ClasspathSqlLocator that returns SQL with comments removed.
-
Method Details
-
removingComments
Return a new ClasspathSqlLocator that returns SQL with comments removed.- Returns:
- A new ClasspathSqlLocator that returns SQL with comments removed.
-
create
Return a new ClasspathSqlLocator that returns SQL without modifying it.- Returns:
- A new ClasspathSqlLocator that returns SQL without modifying it.
-
locate
Locates SQL for the given type and name. Example: Given a typecom.foo.Bar
and a name ofbaz
, looks for a resource namedcom/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
Locates SQL for the given fully-qualified name. Example: Given the namecom.foo.Bar.baz
, looks for a resource namedcom/foo/Bar/baz.sql
on the classpath and returns its contents as a String.- Parameters:
name
- fully qualified name.- Returns:
- the located SQL.
-
getResource
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
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 resourcepath
- the resource path- Returns:
- the resource's contents
- See Also:
-