4

I'm currently working on a game server for a turn-based persistent world game primarily targeted at smartphones, and I'm currently beginning to implement the persistence layer and I'm looking for some tips/advice.

I originally planned to use mybatis for the persistance layer and the mybatis-guice addon implemented a simple @Transactional annotation that is similar to Spring's but without the weight of that entire framework. Unfortunately I ditched mybatis since I found I was fighting with the ORM too much and my relational design doesn't normalize particularly well. Now I'm basically using JDBC and I'm really trying to avoid writing tons of boilerplate code for managing transactions and connections within a string of DAO calls.

I'm also avoiding using any application server here or adding using spring since they don't seem to fit in, the server runs in straight up java on top of netty. Given these conditions are there any simple transaction managers or am I stuck trying to roll my own? Something like mybatis-guice's @Transactional would be great.

Prince John Wesley
  • 62,492
  • 12
  • 87
  • 94
cris.h
  • 233
  • 2
  • 7

2 Answers2

1

If you are looking for a better way to do database work without going for a full-blown ORM, you might look at JDBI. It is a very light wrapper around JDBC that fixes a lot of the warts, omissions, and hair-pulling moments.

Steven Schlansker
  • 37,580
  • 14
  • 81
  • 100
  • 2
    This isn't a transaction manager but I am hoping to address your "my code doesn't fit into an ORM well" issue. I've also not found the need for a transaction manager at all with JDBI. – Steven Schlansker Oct 25 '11 at 06:34
0

Spring and Hibernate combination is best IMO both are quite light depending on your needs.

Currently we are using OpenJPA and quite happy with that too.

How light does it need to be ?? Go with Spring and Hibernate they are light. Guice is simple and light weight DI framework which I am sure you are aware of but by adding on stuff like transaction management etc you will end up with too many lower end opensource products*(I am not saying that Guice is lower end by any means)* which you will find are not any lighter than other opensource alternatives and will have less community support since not many people will be using them.

Shahzeb
  • 4,745
  • 4
  • 27
  • 40
  • Spring seems to be primarily used for web based applications no? I'm using a custom tcp protocol over netty to serve my clients, the server is meant to be used for an online game. How well does this integrate into spring? – cris.h Oct 25 '11 at 03:09
  • While I did not know that it's not a webapp , spring works perfectly well outside web apps as well and is not meant to be a web only architecture . Give it a go and I am sure you will love it. Are there better options ? probably not but may be just as good as spring . I have used spring in chat client I wrote many years ago for a client using sockets . I guess bottom line is that you will have to gauge for yourself but simple answer is yes it will be perfectly fine. – Shahzeb Oct 25 '11 at 03:16
  • Spring is good in most cases, though i have to warn you. @Transactional will only work on beans created directly from spring context. Moreover it won't work for local calls even inside of annotated bean. Though there is an option: you can use TransactionTemplate – SirVaulterScoff Oct 25 '11 at 04:45
  • I'm not sure if you're already using spring. But if don't - take a look at JdbcTemplate as well. You may like it for your application. – SirVaulterScoff Oct 25 '11 at 04:48
  • 1
    I wound up using Spring and it's JDBC abstractions, works great for my current needs. – cris.h Nov 01 '11 at 23:10