субота, 27 квітня 2013 р.

Isolation level in RDBMS

In the famous ACID abbreviation, I means Isolation (Isolation level). According to wikipedia, isolation is a property that defines how/when the changes made by one operation become visible to other concurrent operations.

To understand isolations level better, lets review the main colitions that may happend in concurrent
  • lost update - A second transaction writes a second value of a data on top of a first value written by a first concurrent transaction, and the first value is lost to other transactions running concurrently which need, by their precedence, to read the first value.
  • dirty read - insert or update data by transaction that will be rollbacked further
  • non-repeatable read - first transaction read data, then read them again and the same data is modified
  • phantom reads - on the second read in transaction, new data is appearing

So, now that's easy to describe isolation levels with the following table:
Isolation levelJDBC equivalentDirty readsNon-repeatable readsPhantomsLost update
NoneTRANSACTION_NONEmay occurmay occurmay occurmay occur
Read UncommittedTRANSACTION_READ_UNCOMMITTEDmay occurmay occurmay occur-
Read CommittedTRANSACTION_READ_COMMITTED-may occurmay occur-
Repeatable ReadTRANSACTION_REPEATABLE_READ--may occur-

nginx postaction

Some time ago I thought how is it possible to count downloaded files from resource. I mean, you have a set of files and you need to gather some real-rime statistics on file downloading or just page visiting. I know it's easy to analyze log file. But what if it doesn't enough for you and you want to trigger some another service... with ngnix solution is pretty simple

There is post action functionality that makes ability to call any resource after another resource was called. It is like TRIGGER in regular RDBMS, so simple and self-described example:

вівторок, 16 квітня 2013 р.

Maven assembly plugin fuck up on Spring project making

Yesterday just bumped into Maven assembly plugin issue. I tried to build one-jar project with a log of spring dependencies. It was successful, however I got error on start:
 Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [spring-context.xml]
According to error, I tried to find issue with namespace in spring configuration files... However, it was correct and without issues. But I found spring-related files in my jar which were located in META-INF directory: spring.schemas and spring.handlers, and they have completely strange content - only several namespace, the most of namespaces were lost. So, the problem is with maven assembly plugin. Fortunately, this plugin is enough flexible and gives possibility to manage each step of building.
The correct version (doesn't perform broken merge) is:
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">

четвер, 11 квітня 2013 р.

NoSQL unit testing

Definitely, TDD and unit testing are amazing inventions and this is very high recommended to use it during development. That's very usual to have persistence layer in your application. Several years ago it was RDBMS as standard solution. No surprise, it is good idea to test your persistence layer, unit and integration.
So, as result there are a lot of an in-memory databases for unit testing, and there is prefect tool DBUnit for integration testing.
So, when you write integration test you can use DBUnit, which manipulates dataset. It works in the next way:

  • before test method: set db content (set state) 
  • execute test method
  • after test method compare result in db with expected one

What about NoSQL? For example, if you are using MongoDB or HBase, how is it possible to create unit tests without dependencies on standalone server? How is it possible to make integration test with minimum effort to keep data consistency?
I know the answer: NoSQLUnit - NoSQL Unit is a JUnit extension that helps you write NoSQL unit tests. Available on GitHub https://github.com/lordofthejars/nosql-unit

This perfect amazing breathtaking framework provides possibility to create elegant in-memory unit tests and powerful integration tests in DBUnit way! Moreover, it supports a lot of nosql databases:

  • MongoDB (not only one instance, but also replica set and sharding!)
  • Neo4j
  • Cassandra
  • HBase
  • Redis
  • CouchDB
  • Infispran engine (never heart about that before)
  • ElasticSearch

And what is the most important, documentation is perfect!

So, I want to say THANK YOU VERY MUCH, Alex Soto, you made amazing job!

Do you know any other tools for unit/integration testing for Nosql? Give me a link, please!

вівторок, 9 квітня 2013 р.

SQuirreL - a database administration tool

JPA is a popular way to communicate with database in java world, JPA via Hibernata, JPA vi EclipseLink, whatever... however there is instants cumbersome way to test your JPQL queries.
SQuirreL help you! Overview on wiki

When you have a project with JPA and you want to test several jpa queries (aka jpql), you can use SquirreL. Build you project first, then you need to tune SquirreL a bit: go to Squirrel File –> Global Preferences –> Hibernate,
then click Add classpath entity, and add your JDBC driver jar and all project's jars.
Then specify your persistence unit name, and you are ready to run JPQL queries from this tool for your application.
That's much easy than experiments from java code

Moreover, there is a set of useful plugins which helps you to compare databases, create ER-diagrams or execute a specific code on session start

Also, the is possible to query HBase with https://github.com/forcedotcom/phoenix