congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
DBI.setStatementLocator
Code IndexAdd Tabnine to your IDE (free)

How to use
setStatementLocator
method
in
org.skife.jdbi.v2.DBI

Best Java code snippets using org.skife.jdbi.v2.DBI.setStatementLocator (Showing top 13 results out of 315)

origin: com.nesscomputing.components/ness-jdbi

  @Override
  @Nullable
  public DBI apply(@Nullable DBI input)
  {
    if (input == null)
    {
      return null;
    }

    input.setStatementLocator(new AnnotatedStatementLocator(annotatedClass, input.getStatementLocator()));
    return input;
  }
}
origin: io.kazuki/kazuki-db

public static DBI getDBI(Class<?> clazz, DataSource datasource) {
 DBI dbi = new DBI(datasource);
 final ClasspathGroupLoader theLoader =
   new ClasspathGroupLoader(AngleBracketTemplateLexer.class, clazz.getPackage().getName()
     .replaceAll("\\.", "/"));
 dbi.setStatementLocator(new StatementLocator() {
  private final StringTemplateGroupLoader loader = theLoader;
  public String locate(String name, StatementContext ctx) throws Exception {
   if (ClasspathStatementLocator.looksLikeSql(name)) {
    return name;
   }
   final StringTokenizer tok = new StringTokenizer(name, ":");
   final String group_name = tok.nextToken();
   final String template_name = tok.nextToken();
   final StringTemplateGroup group = loader.loadGroup(group_name);
   final StringTemplate template = group.getInstanceOf(template_name);
   template.setAttributes(ctx.getAttributes());
   return template.toString();
  }
 });
 return dbi;
}
origin: com.ning.billing/killbill-osgi-bundles-analytics

/**
 * See org.springframework.beans.factory.FactoryBean#getObject
 */
public Object getObject() throws Exception
{
  final DBI dbi = new DBI(new SpringDataSourceConnectionFactory(dataSource));
  if (statementLocator != null) {
    dbi.setStatementLocator(statementLocator);
  }
  for (Map.Entry<String, Object> entry : globalDefines.entrySet()) {
    dbi.define(entry.getKey(), entry.getValue());
  }
  return dbi;
}
origin: org.kill-bill.commons/killbill-jdbi

/**
 * See org.springframework.beans.factory.FactoryBean#getObject
 */
@Override
public Object getObject() throws Exception
{
  final DBI dbi = new DBI(new SpringDataSourceConnectionFactory(dataSource));
  if (statementLocator != null) {
    dbi.setStatementLocator(statementLocator);
  }
  for (Map.Entry<String, Object> entry : globalDefines.entrySet()) {
    dbi.define(entry.getKey(), entry.getValue());
  }
  return dbi;
}
origin: org.kill-bill.commons/killbill-jdbi

@Test(groups = "slow")
public void testMultipleInvocationsWithoutLiterals() throws IOException {
  dbi.setStatementLocator(new ReusableStringTemplate3StatementLocator("/org/killbill/commons/jdbi/SomethingNonLiteralSqlDao.sql.stg", true, true));
  final SomethingNonLiteralSqlDao somethingNonLiteralSqlDao = dbi.onDemand(SomethingNonLiteralSqlDao.class);
  somethingNonLiteralSqlDao.delete(TABLE_NAME);
  somethingNonLiteralSqlDao.delete(TABLE_NAME);
}
origin: com.ning.billing.commons/killbill-jdbi

@Test(groups = "slow")
public void testMultipleInvocationsWithLiterals() throws IOException {
  dbi.setStatementLocator(new ReusableStringTemplate3StatementLocator(SomethingLiteralSqlDao.class, true, true));
  final SomethingLiteralSqlDao somethingLiteralSqlDao = dbi.onDemand(SomethingLiteralSqlDao.class);
  somethingLiteralSqlDao.delete(TABLE_NAME);
  somethingLiteralSqlDao.delete(TABLE_NAME);
}
origin: org.kill-bill.commons/killbill-jdbi

@Test(groups = "slow")
public void testMultipleInvocationsWithLiterals() throws IOException {
  dbi.setStatementLocator(new ReusableStringTemplate3StatementLocator(SomethingLiteralSqlDao.class, true, true));
  final SomethingLiteralSqlDao somethingLiteralSqlDao = dbi.onDemand(SomethingLiteralSqlDao.class);
  somethingLiteralSqlDao.delete(TABLE_NAME);
  somethingLiteralSqlDao.delete(TABLE_NAME);
}
origin: com.ning.billing.commons/killbill-jdbi

@Test(groups = "slow")
public void testMultipleInvocationsWithoutLiterals() throws IOException {
  dbi.setStatementLocator(new ReusableStringTemplate3StatementLocator("/com/ning/billing/commons/jdbi/SomethingNonLiteralSqlDao.sql.stg", true, true));
  final SomethingNonLiteralSqlDao somethingNonLiteralSqlDao = dbi.onDemand(SomethingNonLiteralSqlDao.class);
  somethingNonLiteralSqlDao.delete(TABLE_NAME);
  somethingNonLiteralSqlDao.delete(TABLE_NAME);
}
origin: org.kill-bill.commons/killbill-jdbi

@Test
@Category(JDBITests.class)
public void testFoo() throws Exception {
  DBI dbi = new DBI(h2);
  dbi.setStatementLocator(ST4StatementLocator.fromClasspath("/explicit/sql.stg"));
  Dao dao = dbi.onDemand(Dao.class);
  dao.create();
  dao.insert(1, "Brian");
  String brian = dao.findNameById(1);
  assertThat(brian).isEqualTo("Brian");
}
origin: org.kill-bill.commons/killbill-jdbi

@Test
@Category(JDBITests.class)
public void testFallbackTemplate() throws Exception {
  StatementLocator sl = ST4StatementLocator.perType(ST4StatementLocator.UseSTGroupCache.YES,
                           "/explicit/sql.stg");
  DBI dbi = new DBI(h2);
  dbi.setStatementLocator(sl);
  dbi.withHandle(new HandleCallback<Object>() {
    @Override
    public Object withHandle(final Handle h) throws Exception {
      h.execute("create");
      h.execute("insert", 1, "Brian");
      String brian = h.createQuery("findNameById").bind("0", 1).mapTo(String.class).first();
      assertThat(brian).isEqualTo("Brian");
      return null;
    }
  });
}
origin: org.kill-bill.commons/killbill-jdbi

@Test
@Category(JDBITests.class)
public void testFluent() throws Exception {
  DBI dbi = new DBI(h2);
  dbi.setStatementLocator(ST4StatementLocator.fromClasspath("/org/skife/jdbi/v2/st4/ExampleTest.Dao.sql.stg"));
  dbi.withHandle(new HandleCallback<Object>() {
    @Override
    public Object withHandle(final Handle h) throws Exception {
      h.execute("createSomethingTable");
      int numCreated = h.createStatement("insertSomething")
               .bind("0", 0)
               .bind("1", "Jan")
               .execute();
      assertThat(numCreated).as("number of rows inserted").isEqualTo(1);
      String name = h.createQuery("findById")
              .bind("0", 0)
              .define("columns", "name")
              .mapTo(String.class)
              .first();
      assertThat(name).as("Jan's Name").isEqualTo("Jan");
      return null;
    }
  });
}
origin: org.kill-bill.commons/killbill-jdbi

@Test
@Category(JDBIQuarantineTests.class)
public void testNoFallback() throws Exception {
  StatementLocator sl = ST4StatementLocator.perType(ST4StatementLocator.UseSTGroupCache.YES);
  DBI dbi = new DBI(h2);
  dbi.setStatementLocator(sl);
  dbi.withHandle(new HandleCallback<Object>() {
    @Override
    public Object withHandle(final Handle h) throws Exception {
      h.createStatement("create table <name> (id int primary key, name text)")
       .define("name", "something")
       .execute();
      h.execute("insert into something (id, name) values (3, 'Carlos')");
      return null;
    }
  });
  Dao dao = dbi.onDemand(Dao.class);
  dao.insertFixtures();
  Something francisco = dao.findById(1);
  assertThat(francisco.getName()).isEqualTo("Francisco");
}
origin: org.kill-bill.commons/killbill-jdbi

  @Test
  @Category(JDBITests.class)
  public void testFoo() throws Exception {
    final DBI dbi = new DBI(this.h2.getDataSource());
    dbi.setStatementLocator(new ST4StatementLocator(new STGroupFile("org/skife/jdbi/v2/st4/DaoTest.InnerDao.sql.stg")));
    dbi.withHandle(new HandleCallback<Object>() {
      @Override
      public Object withHandle(final Handle h) throws Exception {
        h.execute("createSomething");
        h.createStatement("insert")
         .define("table", "something")
         .bind("id", 1)
         .bind("name", "Ven")
         .execute();

        final Something s = h.createQuery("findById")
                   .bind("id", 1)
                   .map(new ResultSetMapper<Something>() {
                     @Override
                     public Something map(final int index, final ResultSet r, final StatementContext ctx) throws SQLException {
                       return new Something(r.getInt("id"), r.getString("name"));
                     }
                   })
                   .first();
        assertThat(s).isEqualTo(new Something(1, "Ven"));
        return null;
      }
    });
  }
}
org.skife.jdbi.v2DBIsetStatementLocator

Javadoc

Use a non-standard StatementLocator to look up named statements for all handles created from this DBi instance.

Popular methods of DBI

  • <init>
    Constructor used to allow for obtaining a Connection in a customized manner. The org.skife.jdbi.v2.t
  • open
  • onDemand
    Create a new sql object which will obtain and release connections from this dbi instance, as it need
  • registerMapper
    Register a result set mapper which will have its parameterized type inspected to determine what it m
  • withHandle
    A convenience function which manages the lifecycle of a handle and yields it to a callback for use b
  • registerArgumentFactory
  • inTransaction
  • setSQLLog
    Specify the class used to log sql statements. Will be passed to all handles created from this instan
  • registerContainerFactory
  • setStatementRewriter
    Use a non-standard StatementRewriter to transform SQL for all Handle instances created by this DBI.
  • setTransactionHandler
    Specify the TransactionHandler instance to use. This allows overriding transaction semantics, or map
  • setTimingCollector
    Add a callback to accumulate timing information about the queries running from this data source.
  • setTransactionHandler,
  • setTimingCollector,
  • useHandle,
  • define,
  • close,
  • getStatementLocator,
  • getTransactionHandler,
  • registerColumnMapper

Popular in Java

  • Reactive rest calls using spring rest template
  • setScale (BigDecimal)
  • onRequestPermissionsResult (Fragment)
  • getContentResolver (Context)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • ResultSet (java.sql)
    An interface for an object which represents a database table entry, returned as the result of the qu
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Notification (javax.management)
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Best IntelliJ plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now