Spring jdbc vs iBatis - ibatis

For Spring 2.5.6 and above the two reasons that I can think of for choosing spring jdbc are :
BeanPropertySqlParameterSource - for
insert/update
ParameterizedBeanPropertyRowMapper -
for select
These two give you the power of basic orm as you don't need to code your rowmappers.
Thoughts/Comments?

IBatis gives you caching out of the box which SpringJDBC doesn't. Some people might rather prefer using a declarative approach (in IBatis it's XML) to define their queries. Using left joins to populate 1:n relationships without running n+1 selects might be easier to do with IBatis. In the end you can use both approaches in the same project and cherry-pick the framework of your choice based on the problem you want to solve.

Related

Need for using EF 6 or any ORM for Datawarehouse DB with REST API?

Scenario:
1. Exists a Datawarehouse DB which dimensions and measures
2. Need to develop a dashboard app with either React or Angular
3. Intending to develop API which would interact with Datawarehouse DB which would be consumed by AngularJS
Questions
1. Considering the Star Schema/Snowflake scenarios in the DB would it be advisable to use ORM such as ORM Lite/EF 6/NHibernate
2. Any architectural suggestions on such implementation.
Considering the Star Schema/Snowflake scenarios in the DB would it be advisable to use ORM such as ORM Lite/EF 6/NHibernate ?
After various analysis considering the fact the it might be requiring to handle native queries for extracting data for various data warehouse scenarios and limitations on entity relationships finalized to use Dapper ORM
Architecture Suggestions ?
With my experience I have used to Plain Web API without MVC along with Dapper ORM. This comes handy for the following reasons:
Direct integration of data queries in the controller using SQL Queries
No complication in terms of additional POCO classes rather directly provide JSON Response.
Simple and easy to build.
Maybe over a period of time based on the scale of database growth or performance bottleneck arises this needs to be revisited.

EF: Code first constraints

I'am developing Windows form application using EF 5 and start building DB with Code First method.
My question is:"Does Code first method has some constraints compare to Data base first,or Model first" ?
any suggestions ?
Just specifically (I'll skip the general ovewview),
what's bothering me the most - is the lack of native support for
various Db objects, views, UDF, sp-s.
Meaning - sure, you can use them - but you have to 'inject' SQL and synchronize with 'C# POCO'
You can now work-around most of this - e.g. UDF, SP-s you can call through SQL queries - and map back.
Having said that - w/o a true support and if you're used to working from the Db side - that can be a bit of pain. I.e. you have to give up a bit of the 'full-control', when you're deciding about every single aspect of your database, and can tweak and adjust. You can do most of that, but it ain't easy keeping it in sync.
Other 'first' options - are more advanced in that sense.
On the performance side - code-first is the most involved - i.e. it has nothing pre-generated (out of the box) and that adds to the loading times. However, comparing to other EF options, this is less and less of an issue - the EF Power Tools can improve performance by using sort of views (nothing to do w/ Db views) to code-generated some of it.
Overall, I'm also using it a lot - as it's the most 'flexible' and IMO it's worth the extra effort.
A quick search revealed the following answer (from the go-to-guy with regards EF):
Code-first vs Model/Database-first
While the question asks about EF 4.1, the answer should deliver enough information to allow you to make your own decision.

Is there any functionality similar to Criteria API in MyBatis, or any wrapper like QueryDSL to provide that functionality over it?

In JPA/Hibernate, we can write type-safe queries and accumulate our query predicates one step at a time. I believe that there is no equivalent of that in MyBatis, but is there any abstraction framework (like QueryDSL) that provides a layer above MyBatis, that can enable us to write criteria-like queries. My basic reason for wanting the criteria API is that I need to construct a query, each of whose predicates come from a separate logic.
MyBatis Generator seems pretty unmaintained to me. Also need to generate classes from existing DB during build is quiet cumbersome.
Isn't MyBatis SQL Builder Class a better solution?
You can use MBG (MyBatis Generator) with example classes.
Though I doubt that the example classes are as powerful as Hibernate's Criteria Queries, they should suit well your task of constructing queries.

Using Hibernate or JDBC when I need one row from a large table

1>Table with millions row and 100 columns I want to run a query which will return one row (and I need 3-4 column) from the table. Which of JDBC or Hibernate is a better option for this use case.
2>Also is there any risk of getting Out Of Memory if we use hibernate in this case. I do not have any idea about caching issues in hibernate and heard people get OOM.
3>Which of hibernate/JDBC will give faster result. As the time matters in my case.
You can do this easily with Hibernate, just use a "view object". Performance will be the same as with native JDBC.
No, Hibernate will only process what's returned in the Resultset. If that only contains one row, there won't be any problem.
Hibernate will be slow in two cases: it generates sub-optimal queries (you can tune this with .hbm config file and/or annotations) or slow to process the results (this happens when the returned Resultset is huge).
By the way, see my blog entry on using Hibernate for OLAP style queries.
If this is a project which already is using hibernate then there is no reason not to use hibernate. See Istvan Devai's answer.
If this is a new project and this is all you do with the db I do not think there is much benefit in using hibernate (or any other JPA implementation) and you are better of using plain JDBC.

Django database scalability

We have a new django powered project which have a potential heavy-traffic characteristic(means a heavy db interaction). So we need to consider the database scalability in advance. With some researches, the following questions are still not clear to us:
coarse-grained: how to specify one db table(a django model) to a specific db(maybe in another server)?
fine-grained: how to specify a group of table rows to a specific db(so-called sharding, also can in another db server)?
how to specify write and read to different db?(which will be helpful for future mysql master/slave replication)
We are finding the solution with:
be transparent to application program(means we don't need to have additional codes in views.py)
should be in ORM level(means only needs to specify in models.py)
compatible with the current(or future) django release(to keep a minimal change for future's upgrading of django)
I'm still doing the research. And will share in this thread later if I've got some fruits.
Hope anyone with the experience can answer. Thanks.
Don't forget about caching either. Using memcached to relieve your DB of load is key to building a high performance site.
As alex said, django-core doesn't support your specific requests for those features, though they are definitely on the todo list.
If you don't do this in the application layer, you're basically asking for performance trouble. There aren't any really good open source automation layers for this sort of task, since it tends to break SQL axioms. If you're really concerned about it, you should be coding the entire application for it, not simply hoping that your ORM will take care of it.
There is the GSoC project by Alex Gaynor that in future will allow to use multiple databases in one Django project. But now there is no cross-RDBMS working solution.
There is no solution right now too.
And again - there is no cross-RDBMS solution. But if you are using MySQL you can try excellent third-party Django application called - mysql_replicated. It allows to setup master-slave replication scenario easily.
here for some reason we r using django with sqlalchemy. maybe combination of django and sqlalchemy also works for your needs.

Resources