How to use mysql get_lock when using JPA? - locking

I want to leverage get_lock() function of mysql as a global lock, but it looks like impossible as I also use JPA as my database layer. Because get_lock() is connection based that means you have to lock/unlock using the same connection, however, there is no native way to retrieve a JDBC connection from JPA. Does that mean get_lock()/release_lock() is totally impossible in JPA?
I don't like unwrap to underlying JPA implementation as it's not portable.

I finally solved this issue by using a JDBC datasource as well as JPA

Related

OData with a plain SQL (odbc) data source

I have an oracle data source that i would like to expose using odata.
The reason i need to use odata is that there are many parameters and it is hard to write a query for each combination.
How can i connect my oracle database to odata to achieve this given that the database is version 10.2g which as i have read does not support Entity framework.
Thanks
One of the solutions is using NHibernate, and here is a sample: http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/OData/v4/NHibernateQueryableSample/.

custom ADO.NET data provider with NHibernate

I am writing an application that connect to ESRI's File Geodatabase, which is a proprietary database.
I found a custom ADO.NET data provider for this File Geodatabase.
I like to access this database with NHibernate.
Can I use this ADO.NET data provider with NHibernate without writing any customization code for NHibernate?
is there a driver that deal with generic ado.net provider?
so far what I found, they told me to implement IDriver, and IDialect in order to acheive that.
And in case I have to write my own implementation, is there any document that describe how to do that?
There is a GenericDialect (not quite full-featured, as few things are less standard than SQL), but you need to implement a driver so NH can connect to the db.
You can take any of the simpler drivers in https://github.com/nhibernate/nhibernate-core/tree/master/src/NHibernate/Driver as a starting point.

Adding Plain SQL Tables to Grails App instead of using ORM?

In Grails, how can plain SQL/DDL be used to create / drop tables in the same manner they would be if one were using GORM / ORM?
For example, when using GORM / ORM, the tables used for persistence are regularly created/dropped, and inserted into, during the runtime of Integration Tests, and execution of the application.
I know there is a way to do this using just Groovy as shown in the example named "Advanced Usage" here, but I'm looking for something more along the lines of being built into the framework already, something where I can specify an SQL file with DDL to be loaded.
I'm looking for something more along the lines of being built into the framework already, something where I can specify an SQL file with DDL to be loaded.
As far as I know, there is no such support built-into Grails, so you'll have to write it yourself. Luckily it shouldn't be too difficult. Here's an implementation plan:
Store your DDL file in the conf directory
In Bootstrap.groovy, dependency-inject the DataSource Spring bean
In the init closure of Bootstrap.groovy use the DataSource to get a Connection to the DB
Using the Connection, create the database and execute the SQL statements in the DDL file against it
In the destroy closure of Bootstrap.groovy, drop the database

Multiple database with NHibernate 3.x

I found a couple of articles how to use NHibernate with multiple database, for example this one
http://codebetter.com/karlseguin/2009/03/30/using-nhibernate-with-multiple-databases/
But all articles are very old, and may be there is some new approach with NH 3.x? I looked in documentation but did not found anything, but maybe i missed somthing?
Does anybody knows some better way (native NH3.x way) to use NH 3.x with multiple database than described in this article?
http://codebetter.com/karlseguin/2009/03/30/using-nhibernate-with-multiple-databases/
Thanks,
Alexander.
AFAIK, there is nothing new in NH 3. But there are still more options to use several databases than in the blog post you linked.
You can open your own connection and pass it to NH when opening a session.
You can open a session and switch to another database on the same server (eg. by executing a use database statement on sql server).
You can provide a schema (database) name on each table you map in the mapping file. It is not useful to have it hard coded, but you can still replace it after loading the mapping files or use mapping by code.
The articles you linked are still the way to go. Each SessionFactory is responsible for a single connection (connectionstring) and schema.
There is one special case where ou split the database into multiple with the same schema to load balance. This is called sharding and there is the contrib NHibernate.Shards to deal with it.

How to use SQL Cache Dependency Wtih EF DbContext?

I found this article on using Sql Cache Dependency with Linq2SQL.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=263
is it possible to do this same thing in Entity Framework with DbContext?
I have a multi-database app so each DbContext Instance Connection is different depending on the user.
But I feel like utilizing this technology would be the best way to invalidate the cache.
any help is appreciated.
Chase
Take a look at this, will give you a starting point: http://blogs.msdn.com/b/jkowalski/archive/2009/06/11/tracing-and-caching-in-entity-framework-available-on-msdn-code-gallery.aspx, I tried it and it works fine but I have chosen to use a more custom and light weight approach.
Basically I retrieve the TraceString which is nothing but the raw SQL from my IQueriable<T> and create a standard SqlCacheDependency cache entry.
Your DbContext should live only for single unit of work. In your case for single request processing so there is no reason to involve any database dependency in EF.