Giter VIP home page Giter VIP logo

acolyte's Introduction

Acolyte

Acolyte is a JDBC driver designed for cases like mockup, testing, or any case you would like to be able to handle JDBC query by hand (or maybe that's only Chmeee's son on the Ringworld).

Motivation

Persistence layer not only apply changes and retrieve raw data. It usually gathers those data from several sources (e.g. various queries), but also converts data types (e.g. integer to boolean) and maps it to structured information.

Automated testing about that is not trivial. Using test DB requires tools (scripts) to set up environment repeatly, for each time tests are executed.

Considering integration testing that's fine. It's different for unit testing.

Unit tests must be isolated from each others so each unit can be validated independently.

A unit test can alter database as executed. Thus tests coming after would have to cope with this altered environment, without asserting which one is runned first (no order assumption).

As tests can be runned in parallel while considering code accessing same data spaces. Without extra attention to isolation/transaction management, this can lead to tests conflicting between them.

With Acolyte, connection behaviour can be built, defining which statement is supported with which (query or update) result.

Each prepared connection can supports only queries and updates your code is interested in, and there is no need to simulate a whole data store structure/schema.

As soon as Acolyte connections don't rely on data store, statement executions are isolated without extra effort.

As a JDBC driver is provided you can simply update test configuration, so that Acolyte connections are resolved by persistence code without change throught standard mechanisms (JDBC URL, JNDI, ...).

It also makes simple testing of DB edge cases (e.g. unrecoverable/unexpected error). It's easy to throw an exception from Acolyte connection, so that it can be validated persistence code is properly handling such case.

You can also use Acolyte to fully benefit from data access abstraction, not only not having to wait persistence (DB) being setup to code accesses, but also not having to wait persistence to code tests for access code.

You can get a quick interactive tour of Acolyte, online at tour.acolyte.eu.org.

Usage

Acolyte is usable with any code relying on JDBC. It makes it available for any JVM language:

You can get connection defined by Acolyte using the well-known java.sql.DriverManager.getConnection(jdbcUrl) (see connection management).

final String jdbcUrl = "jdbc:acolyte:anything-you-want?handler=my-unique-id";

StatementHandler handler = new CompositeHandler().
  withQueryDetection("^SELECT "). // regex test from beginning
  withQueryDetection("EXEC that_proc"). // second detection regex
  withUpdateHandler(new CompositeHandler.UpdateHandler() {
    // Handle execution of update statement (not query)
    public UpdateResult apply(String sql, List<Parameter> parameters) {
      // ...
    }
  }).withQueryHandler(new CompositeHandler.QueryHandler () {
    public QueryResult apply(String sql, List<Parameter> parameters) {
      // ...
    }
  });

// Register prepared handler with expected ID 'my-unique-id'
acolyte.jdbc.Driver.register("my-unique-id", handler);

// then when existing code do ...
Connection con = DriverManager.getConnection(jdbcUrl);

// ... Connection |con| is managed through Acolyte |handler|

You can use Acolyte with various JVM test and persistence frameworks (see Integration guide).

With Studio, you can use data extracted from existing database with Acolyte handler.

Projects using Acolyte:

To share questions, answers & ideas, you can go to the mailing list.

Requirements

  • Java 1.6+

Limitations

  • Limited datatype conversions.
  • Binary datatype are not currently supported.
  • Pseudo-support for transaction.
  • Currency types.

Related applications

acolyte's People

Contributors

cchantep avatar guilgaly avatar scala-steward avatar stankoua avatar yoeight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

acolyte's Issues

ReactiveMongo FindAndModify pattern matching

import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import reactivemongo.api._
import reactivemongo.bson._
import acolyte.reactivemongo._
import AcolyteDSL._

def result = withFlatDriver { implicit drv =>
  AcolyteDSL.withFlatQueryHandler({
    case req => sys.error(s"----------------------- Unexpected : $req")
  }) { con =>
    con.database("db").flatMap { db =>
      val x = db("coll").findAndUpdate(
        BSONDocument("id" -> 1),
        BSONDocument("$set" -> BSONDocument("lorem" -> "ipsum"))).map(_ => {})

      x
    }
  }
}

scala.concurrent.Await.result(result, 5.seconds)

Make writing generic SQL wrappers easier with RowList.append(R)

Hi,
Hope you had another great day.

I'm using acolyte to intercept calls to my SQL driver, wrap them, execute remotely and return results back through JDBC.
Reasoning: implementing my own ResultSet and Connection and other JDBC classes is way to painful.

It was non-trivial to write it as I need to be able to convert matrix of data into QueryResult. I achieved it with: my own Update- and QueryHandler and my own RowList implementations.
Main reason for my own implementations: I can not reuse deprecated RowList.append(R row), I need to use one of the specific classes, but I do not know in advance number of and type of columns in the result as I'm writing generic wrapper.

Can I have generic implementation for RowList that I can reuse that allows me to use Iterator for row data generation or at least use append(R row) to add data?

Thanks for the consideration.

Question: How to use multiple StatementHandler for one connection.

I have a some code that perform two select statement and my test is suppose to return different results. How do I register multiple StatementHandler for one connection id?
The only way I found to do that is to return a different result base on a counter which smell bad.
Could be something like new SequentialHandler().next(query, updateHandler, queryHandler).next(... ??

publish acolyte to maven central repository

Hi,
i can not build playframework because acolyte is not in central:

sbt.ResolveException: unresolved dependency: acolyte#acolyte-scala_2.10;1.0.10: not found

can you publish artefacts to central?

More typesafe RowList

Turn RowList as abstract + getColumnClasses . Sub-classes up to RowList of Row22, with appropriate getColumnClasses .

New core module

Separate JDBC and core classes, move core classes to new core module (outside of jdbc-driver).

RowResultSet hashCode

The RowResultSet hashCode contains last field which is changed when iterating through a cursor.
During a transaction C3P0 stores resultset in a HashSet and when the transaction finishes, then it removes it from the set. As hashCode changes, the resultset can not be removed from the HashSet any more.
Would it be possible to remove last field from hashCode implementation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.