Package org.skife.jdbi.v2

Examples of org.skife.jdbi.v2.Handle


     * @param username User name for connection authentication
     * @param password Password for connection authentication
     */
    public DBI(final String url, final String username, final String password)
    {
        this(new ConnectionFactory()
        {
            public Connection openConnection() throws SQLException
            {
                return DriverManager.getConnection(url, username, password);
            }
View Full Code Here


     * @return Handle bound to connection
     */
    public static Handle open(final Connection connection)
    {
        assert (connection != null);
        return new DBI(new ConnectionFactory()
        {
            public Connection openConnection()
            {
                return connection;
            }
View Full Code Here

    }


    public void testNewlinesOkay() throws Exception
    {
        RewrittenStatement rws = rw.rewrite("select * from something\n where id = :id", new Binding(),
                                            new StatementContext(new HashMap<String, Object>()));
        assertEquals("select * from something\n where id = ?", rws.getSql());
    }
View Full Code Here

        assertEquals("select * from something\n where id = ?", rws.getSql());
    }

    public void testOddCharacters() throws Exception
    {
        RewrittenStatement rws = rw.rewrite(":boo ':nope' _%&^& *@ :id", new Binding(),
                                            new StatementContext(new HashMap<String, Object>()));
        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }
View Full Code Here

        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }

    public void testNumbers() throws Exception
    {
        RewrittenStatement rws = rw.rewrite(":bo0 ':nope' _%&^& *@ :id", new Binding(),
                                            new StatementContext(new HashMap<String, Object>()));
        assertEquals("? ':nope' _%&^& *@ ?", rws.getSql());
    }
View Full Code Here

        }
        catch (Exception e) {
            throw new UnableToCreateStatementException(String.format("Exception while locating statement for [%s]",
                                                                     sql), e);
        }
        final RewrittenStatement rewritten = rewriter.rewrite(my_sql, current.getParameters(), context);
        PreparedStatement stmt = null;
        try {
            try {
                stmt = connection.prepareStatement(rewritten.getSql());
            }
            catch (SQLException e) {
                throw new UnableToCreateStatementException(e);
            }

            try {
                for (PreparedBatchPart part : parts) {
                    rewritten.bind(part.getParameters(), stmt);
                    stmt.addBatch();
                }
            }
            catch (SQLException e) {
                throw new UnableToExecuteStatementException("Exception while binding parameters", e);
            }

            try {
                final long start = System.currentTimeMillis();
                final int[] rs =  stmt.executeBatch();
                log.logPreparedBatch(System.currentTimeMillis() - start,  rewritten.getSql(), parts.size());
                return rs;
            }
            catch (SQLException e) {
                throw new UnableToExecuteStatementException(e);
            }
View Full Code Here

    public void setUp() throws Exception
    {
        super.setUp();
        h = openHandle();
        logged = new ArrayList<String>();
        log = new SQLLog()
        {
            public void logBeginTransaction(Handle h)
            {
                logged.add("begin");
            }
View Full Code Here

    {
        try {
            final long start = System.currentTimeMillis();
            Connection conn = connectionFactory.openConnection();
            final long stop = System.currentTimeMillis();
            StatementBuilder cache = statementBuilderFactory.createStatementBuilder(conn);
            Handle h = new BasicHandle(transactionhandler,
                                       statementLocator,
                                       cache,
                                       statementRewriter,
                                       conn,
View Full Code Here

     *
     * @return the modified query
     */
    public Query<ResultType> setFetchSize(final int i)
    {
        this.addStatementCustomizer(new StatementCustomizer()
        {
            public void beforeExecution(PreparedStatement stmt, StatementContext ctx) throws SQLException
            {
                stmt.setFetchSize(i);
            }
View Full Code Here

     *
     * @return modified query
     */
    public Query<ResultType> setMaxRows(final int i)
    {
        this.addStatementCustomizer(new StatementCustomizer()
        {
            public void beforeExecution(PreparedStatement stmt, StatementContext ctx) throws SQLException
            {
                stmt.setMaxRows(i);
            }
View Full Code Here

TOP

Related Classes of org.skife.jdbi.v2.Handle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.