Persistence Archives - Kai Waehner https://www.kai-waehner.de/blog/category/persistence/ Technology Evangelist - Big Data Analytics - Middleware - Apache Kafka Thu, 19 Sep 2013 09:41:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.7.2 https://www.kai-waehner.de/wp-content/uploads/2020/01/cropped-favicon-32x32.png Persistence Archives - Kai Waehner https://www.kai-waehner.de/blog/category/persistence/ 32 32 Slides online: “NoSQL takes over! Alternatives for Integration of NoSQL databases” – NoSQL Roadshow Zurich https://www.kai-waehner.de/blog/2013/09/19/slides-online-nosql-takes-over-alternatives-for-integration-of-nosql-databases-nosql-roadshow-zurich/ Thu, 19 Sep 2013 09:41:38 +0000 http://www.kai-waehner.de/blog/?p=723 Slides from my talk at NoSQL Roadshow 2013 in Zurich are online. NoSQL Roadshow is a great event series by Trifork, which offers a lot of NoSQL sessions and events all over the world.

The post Slides online: “NoSQL takes over! Alternatives for Integration of NoSQL databases” – NoSQL Roadshow Zurich appeared first on Kai Waehner.

]]>
Slides from my talk at NoSQL Roadshow 2013 in Zurich are online. NoSQL Roadshow is a great event series by Trifork, which offers a lot of NoSQL sessions and events all over the world.

Presentation: “NoSQL takes over! Alternatives for Integration of NoSQL databases”

SQL cannot solve several problems emerging with big data. NoSQL comes to the rescue, but therefore it does not use SQL as its query language or give full ACID guarantees. Thus, in the future you will have to integrate these NoSQL databases as you integrate SQL databases today.

Different open source frameworks and tools are already prepared for this challenging task. This session demonstrates elegant alternatives for NoSQL integration without writing a lot of boilerplate  glue code and complex mapping. Several examples are shown for all different concepts of NoSQL databases by integrating MongoDB (Document Store), HBase (Column-oriented), Neo4j (Graph), Amazon Web Services S3 (Key Value Store), and others.

The post Slides online: “NoSQL takes over! Alternatives for Integration of NoSQL databases” – NoSQL Roadshow Zurich appeared first on Kai Waehner.

]]>
“Present, past and future of NoSQL, Big Data and Hadoop” – Speaker Interview with Kai Wähner at NoSQL Roadshow https://www.kai-waehner.de/blog/2013/09/13/present-past-and-future-of-nosql-big-data-and-hadoop-speaker-interview-with-kai-wahner-at-nosql-roadshow/ Fri, 13 Sep 2013 15:37:31 +0000 http://www.kai-waehner.de/blog/?p=714 Just a short blog post with a link to an interview which I gave for NoSQL Roadshow 2013…

The post “Present, past and future of NoSQL, Big Data and Hadoop” – Speaker Interview with Kai Wähner at NoSQL Roadshow appeared first on Kai Waehner.

]]>
Just a short blog post with a link to an interview which I gave for NoSQL Roadshow 2013 in Zurich. I talk about present, past and future of NoSQL…

Here is the link to the NoSQL interview: http://nosqlroadshow.com/nosql-zurich-2013/interviewkai

I appreciate every feedback or discussions via @KaiWaehner, konktakt@kai-waehner.de, or social networks (LinkedIn, Xing).

The post “Present, past and future of NoSQL, Big Data and Hadoop” – Speaker Interview with Kai Wähner at NoSQL Roadshow appeared first on Kai Waehner.

]]>
Big Data beyond Hadoop – How to integrate ALL data with Apache Camel and Talend => Video from NoSQL matters 2013 online https://www.kai-waehner.de/blog/2013/06/04/big-data-beyond-hadoop-how-to-integrate-all-data-with-apache-camel-and-talend-video-from-nosql-matters-2013-online/ Tue, 04 Jun 2013 16:25:50 +0000 http://www.kai-waehner.de/blog/?p=651 Just a short reference to a video of my talk “Big Data beyond Hadoop – How to integrate…

The post Big Data beyond Hadoop – How to integrate ALL data with Apache Camel and Talend => Video from NoSQL matters 2013 online appeared first on Kai Waehner.

]]>
Just a short reference to a video of my talk “Big Data beyond Hadoop – How to integrate ALL data” at NoSQL matters 2013 in Cologne, Germany. I already posted the slides in a former blog post here.

I hate watching myself, and I know that I am speaking too fast in this talk, but maybe you still want to take a look:

 

The post Big Data beyond Hadoop – How to integrate ALL data with Apache Camel and Talend => Video from NoSQL matters 2013 online appeared first on Kai Waehner.

]]>
Book Review: “Getting Started with NoSQL” by Gaurav Vaish (Packt Publishing) https://www.kai-waehner.de/blog/2013/04/24/book-review-getting-started-with-nosql-by-gaurav-vaish-packt-publishing/ Wed, 24 Apr 2013 12:56:47 +0000 http://www.kai-waehner.de/blog/?p=632 "Getting Started with NoSQL" is a new book by PACKT PUBLISHING. It gives an introduction to different NoSQL concepts and products. Besides, it explains the differences to SQL databases and when to use which one. With 150 pages, the book is not extensive, but sufficient. It is a good introduction to NoSQL databases for developers, architects and decision makers.

The post Book Review: “Getting Started with NoSQL” by Gaurav Vaish (Packt Publishing) appeared first on Kai Waehner.

]]>
Getting Started with NoSQL” is a new book by PACKT PUBLISHING. It gives an introduction to different NoSQL concepts and products. Besides, it explains the differences to SQL databases and when to use which one.

First, the book defines NoSQL and explains what it is and what it is not. Especially, the characteristics and differences compared to SQL are described. The next chapter explains most important NoSQL storage types: Column-oriented databases, document stores, key-value stores, and graph databases. Advantages and disadvantages of these concepts are explained in detail, before comparing most important NoSQL products such as Cassandra, Neo4j, MongoDB or Redis. A case study (which uses MongoDB) concludes the book to show how an implementation with a NoSQL database is different from using a relational database.

What I was missing in this book is a section about other NoSQL concepts such as XML databases or file-based storages such as HDFS (Hadoop Distributed File System).

With 150 pages, the book is not extensive, but sufficient. It is a good introduction to NoSQL databases for developers, architects and decision makers. If you dot not have any experiences with NoSQL databases, then this book is for you. If you are already familiar with different NoSQL concepts and products, you will not learn much new stuff, as the book is not going into deep details. Though, it is still a good overview for NoSQL concepts and products.

 

Best regards,

Kai Wähner (Twitter: @KaiWaehner)

The post Book Review: “Getting Started with NoSQL” by Gaurav Vaish (Packt Publishing) appeared first on Kai Waehner.

]]>
Systems Integration in the NoSQL Era with Apache Camel and Talend (MongoDB, Neo4j, HBase, AWS S3, Hazelcast, CouchDB) https://www.kai-waehner.de/blog/2013/02/28/systems-integration-in-the-nosql-era-with-apache-camel-and-talend-mongodb-neo4j-hbase-aws-s3-hazelcast-couchdb/ Thu, 28 Feb 2013 21:03:21 +0000 http://www.kai-waehner.de/blog/?p=574 In February 2013, I was at ApacheCon NA 2013 in Portland, Oregon, USA. My session was named "Systems Integration in the NoSQL Era with Apache Camel". I showed how to integrate several different NoSQL databases such as MongoDB (document), Neo4j (graph), HBase (column), AWS S3 (key-value), or Hazelcast (in-memory).

The post Systems Integration in the NoSQL Era with Apache Camel and Talend (MongoDB, Neo4j, HBase, AWS S3, Hazelcast, CouchDB) appeared first on Kai Waehner.

]]>
In February 2013, I was at ApacheCon NA 2013 in Portland, Oregon, USA. It was a small, but great conference. I met so many awesome Apache experts and learned a lot about several Apache projects.

Besides all of the Hadoop related projects, I was especially interested in Apache Syncope, an open source system for managing digital identities in enterprise environments, and Apache Streams, a new Incubator project that aims to develop a scalable server for the publication, aggregation, filtering and re-exposure of enterprise social activities.

My session was named “Systems Integration in the NoSQL Era with Apache Camel“. I showed how to integrate several different NoSQL databases such as MongoDB (document), Neo4j (graph), HBase (column), AWS S3 (key-value), or Hazelcast (in-memory). I used Apache Camel with text editor and IDE. Besides, I showed some open source tooling on top of Camel with Talend ESB. With Talend, you  can use a graphical user interface, all Camel code is generated. You have just to configure your routes.

Here are the slides from my talk:

If you have any further questions, feel free to write a comment or contact me via Twitter, email or social networks (LinkedIn, Xing).

 

Best regards,

Kai Wähner (Twitter: @KaiWaehner)

 

The post Systems Integration in the NoSQL Era with Apache Camel and Talend (MongoDB, Neo4j, HBase, AWS S3, Hazelcast, CouchDB) appeared first on Kai Waehner.

]]>
MyBatis (formerly called iBatis) – Examples and Hints using @SELECT, @INSERT and @UPDATE Annotations https://www.kai-waehner.de/blog/2010/10/25/mybatis-formerly-called-ibatis-examples-and-hints-using-select-insert-and-update-annotations/ Mon, 25 Oct 2010 20:07:52 +0000 http://www.kai-waehner.de/blog/?p=111 MyBatis is a lightweight persistence framework for Java and .NET. This blog entry addresses the Java side. MyBatis is an alternative positioned somewhere between plain JDBC and ORM frameworks (e.g. EclipseLink or Hibernate). MyBatis usually uses XML, but it also supports annotations since version 3.

The documentation is very detailed for XML, but lacks of annotation examples. Just the Annotations itself are described, but no examples how to use them. I could not find any good and easy examples anywhere, so I will describe some very basic examples for SELECT, INSERT and UPDATE statements by implementing a Data Access Object (DAO) using MyBatis.

The post MyBatis (formerly called iBatis) – Examples and Hints using @SELECT, @INSERT and @UPDATE Annotations appeared first on Kai Waehner.

]]>
MyBatis (formerly called iBatis) – Examples and Hints using SELECT, INSERT and UPDATE Annotations

MyBatis (http://www.mybatis.org/) is a lightweight persistence framework for Java and .NET. This blog entry addresses the Java side. MyBatis is an alternative positioned somewhere between plain JDBC and ORM frameworks (e.g. EclipseLink or Hibernate). MyBatis usually uses XML, but it also supports annotations since version 3.

The documentation (http://mybatis.googlecode.com/svn/trunk/doc/en/MyBatis-3-User-Guide.pdf) is very detailed for XML, but lacks of annotation examples. Just the Annotations itself are described, but no examples how to use them. I could not find any good and easy examples anywhere, so I will describe some very basic examples for SELECT, INSERT and UPDATE statements by implementing a Data Access Object (DAO) using MyBatis.
These examples are a good starting point to create more complex MyBatis queries using a DAO. You can find the full source code  at the end of this blog.

SQL – Create Tables

I use a very simple table with two attributes. The name of the table is “simple_information”. The primary key is a Integer and may not be null (info_id). The only real data is  a character and may also not be null (info_content). That is enough “complexity” to learn the usage of MyBatis annotations.

The Java class “SimpleInformationEntity” is a POJO which contains these two attributes.

@SELECT-Statement

The @Select annotation is very easy to use, if you want to use exactly one paramter. If you need more than one paramter, use the @Param annotation (which is described below at the update example).
You do not have to map the found information to a SimpleInformationEntity object, as you would have to do with a JDBC ResultSet. The magic of the framework does this for you.

final String GET_INFO =
“SELECT * FROM simple_information WHERE info_id = #{info_id}”;

@Select(GET_INFO)
public SimpleInformationEntity getSimpleInformationById(int info_id) throws Exception;


@INSERT-Statement

You can use the object (which you want to be persist) as parameter. You do not have to use several parameters for each attribute of the object. The magic of the framework does this for you.

final String PERSIST_INFO =
“INSERT INTO simple_information(info_id, info_content) VALUES (#{infoId}, #{infoContent})”;

@Insert(PERSIST_INFO)
public int persistInformation(SimpleInformationEntity simpleInfo) throws Exception;


@UPDATE-Statement

You cannot use more than one parameter within a method. If you want to understand why, look at some MyBatis XML examples in the documenation: There you use the attribute “parameterType”, which must be exactly one “parameter”! So you will get a (strange) exception, if you use two or more parameters. Instead you have to use the @Param annotation, if you need more than one parameter.

final String UPDATE_INFO =
“UPDATE simple_information SET info_content = #{newInfo} WHERE info_id = #{infoId}”;

@Update(UPDATE_INFO)
public int updateInformation(@Param(“infoId”) int info_id, @Param(“newInfo”) String new_content) throws Exception;


Configuration

You have to add your MyBatis-Interface for the Mapper to the SQLSessionFactory:

sqlSessionFactory.getConfiguration().addMapper(InfoMapper.class);


Some Hints for developing with MyBatis

The following means helped me a lot to use MyBatis annotations despite the lack of documentation about using annotations:
– MyBatis is open source! So add the sources to your build path and use the debugging function of your IDE to enter the MyBatis source code while executing some queries. You will see what MyBatis expects as input and how it is processed.
– Read the documentation about using MyBatis XML. This does not really make any sense you think? It does! The processing deep inside MyBatis does not change if you use annotations instead of XML. It is just another way to develop persistence queries.
E.g. if you know that a XML select query may just use exactly one parameterType-attribute, then you know that you may just use one parameter in an annotation-based method too! If you need more parameters, you have to use the @Param annotation.
– If you get any strange exception that does not make any sense, then clean and re-compile your project. This often helps, because as with other persistence frameworks such as Hibernate, the bytecode enhancement sometimes confuses your IDE.

Conclusion: @MyBatis-Team: Improve and extend the documentation instead of improving the framework itself!

MyBatis is a nice lightweigt persistence framework. But the documentation is not enough detailed. Some important information is completely missing. Especially, if you are a newbie to MyBatis / iBatis, it is very tough to develop with MyBatis using annotations instead of XML.
Besides the usage of annotations, another good example for missing documentation is how to configure transactions in MyBatis by using JNDI and a J2EE / JEE Application server. You have to use google to find out, and if you are lucky you will find a mailing list or blog entry describing your problem. If not, you have to try it out.
The missing documentation makes MyBatis much more tough than it actually is. So in the next months, the MyBatis team should improve and extend the documentation instead of improving the framework itself…

Best regards,

Kai Wähner (Twitter: @KaiWaehner)

Appendix: Source Code

Here you see all the necessary source code, also including a MyBatis Connection Factory, which reads the configuration data from a XML file.

############################################################################

Connection Factory (using a static initializer)

############################################################################

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import de.waehner.kai.persistence.InfoDAO.InfoMapper;

public class MyBatisConnectionFactory {

private static SqlSessionFactory sqlSessionFactory;

static {

Reader reader = null;

try {

InputStream in = MyBatisConnectionFactory.class.getResourceAsStream(“myBatisConfiguration.xml”);

reader = new InputStreamReader(in);

if (sqlSessionFactory == null) {
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);

sqlSessionFactory.getConfiguration().addMapper(InfoMapper.class);

}

in.close();

}

catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
}

catch (IOException iOException) {
iOException.printStackTrace();
}
}

public static SqlSessionFactory getSqlSessionFactory() {

return sqlSessionFactory;
}

}

############################################################################

Data Acces Object (including the MyBatis-Mapper as inner Class)

############################################################################

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class InfoDAO {

public interface InfoMapper {

final String GET_INFO =
“SELECT * FROM simple_information WHERE info_id = #{info_id}”;

@Select(GET_INFO)
public SimpleInformationEntity getSimpleInformationById(int info_id) throws Exception;

final String PERSIST_INFO =
“INSERT INTO simple_information(info_id, info_content) VALUES (#{infoId}, #{infoContent})”;

@Insert(PERSIST_INFO)
public int persistInformation(SimpleInformationEntity simpleInfo) throws Exception;

final String UPDATE_INFO =
“UPDATE simple_information SET info_content = #{newInfo} WHERE info_id = #{infoId}”;

@Update(UPDATE_INFO)
public int updateInformation(@Param(“infoId”) int info_id, @Param(“newInfo”) String new_content) throws Exception;

}

public SimpleInformationEntity getSingleAlarm(int info_id) throws Exception {

SqlSessionFactory sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
SqlSession session = sqlSessionFactory.openSession();

try {

InfoMapper mapper = session.getMapper(InfoMapper.class);
SimpleInformationEntity simpleInfo = mapper.getSimpleInformationById(info_id);

return simpleInfo;

} finally {
session.close();
}
}

public int persistInformation(SimpleInformationEntity simpleInfo) throws Exception {

SqlSessionFactory sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
SqlSession session = sqlSessionFactory.openSession();

try {

InfoMapper mapper = session.getMapper(InfoMapper.class);
int answer = mapper.persistInformation(simpleInfo);

return answer;

} finally {
session.close();
}
}

public int updateInformation(int info_id, String new_content) throws Exception {

SqlSessionFactory sqlSessionFactory = MyBatisConnectionFactory.getSqlSessionFactory();
SqlSession session = sqlSessionFactory.openSession();

try {

InfoMapper mapper = session.getMapper(InfoMapper.class);
int answer = mapper.updateInformation(info_id, new_content);

return answer;

} finally {
session.close();
}
}
}

############################################################################

SimpleInformation Entity (a simple POJO)

############################################################################

import java.io.Serializable;

public class SimpleInformationEntity implements Serializable{

private static final long serialVersionUID = -821826330941829539L;

private int infoId;

private String infoContent;

public int getInfoId() {
return infoId;
}

public void setInfoId(int infoId) {
this.infoId = infoId;
}

public String getInfoContent() {
return infoContent;
}

public void setInfoContent(String infoContent) {
this.infoContent = infoContent;
}
}

The post MyBatis (formerly called iBatis) – Examples and Hints using @SELECT, @INSERT and @UPDATE Annotations appeared first on Kai Waehner.

]]>