I have a grails application. I'd like to load data into the underlying database with something external to grails, perl, specifically. I know I have to update the hibernate sequence after external data loading, otherwise on the next create object in grails, hibernate throws an exception; but is there anything else I need to update? Do I have to clear the hibernate cache, for instance? This would seem to be a very common issue, but there's no discussion of it in the grails docs. Thanks.
Found this
http://grails.1312388.n4.nabble.com/Accessing-the-2nd-level-cache-to-allow-it-to-be-cleared-via-a-controller-or-service-td1390985.html
Hibernate has APIs for this. You can get the query cache via sessionFactory.getQueryCache() and clear it using
sessionFactory.queryCache.clear()
You can access a cache for a domain classes using its full class name, e.g.
def cache = sessionFactory.getSecondLevelCacheRegion('com.foo.bar.Book')
and clear it via
sessionFactory.getSecondLevelCacheRegion('com.foo.bar.Book').clear()
You can also call evict() on the sessionFactory for an entire class
sessionFactory.evict(com.foo.bar.Book)
or for an individual instance
sessionFactory.evict(com.foo.bar.Book, 42)
Related
In OSB Layer when the endpoint uri is changed, I need to alert the core group that the endpoint has changed and to review it. I tried SLA Alert rules but it does not have options for it. My question is, the endpoint uri should be saved somewhere in the underlying database. If so what is the schema and the table name to query it.
URI or in fact any other part of OSB artifact is not stored in relational database but rather kept in memory in it's original XML structure. It can be only accessed thru dedicated session management API. Interfaces you will need to use are part o com.bea.wli.sb.management.configuration and com.bea.wli.sb.management.query packages. Unfortunately it is not as straightforward as it sounds, in short, to extract URI information you will need to:
Create session instance(SessionManagementMBean)
Obtain ALSBConfigurationMBean instance that operates on SessionManagementMBean
Create Query object instance(BusinessServiceQuery) an run it on ALSBConfigurationMBean to get ref object to osb artifact of your interest
Invoke getServiceDefinition on your ref object to get XML service
definition
Extract URI from XML service definition with XPath
Downside of this approach is that you are basically pooling configuration each time you want to check if anything has changed.
More information including JAVA/WLST examples can be found in Oracle Fusion Middleware Java API Reference for Oracle Service Bus
There is also a good blog post describing OSB customization with WLST ALSB/OSB customization using WLST
The information about services and all its properties can be obtained via Java API. The API documentation contains sample code, so you can get it up and running quite quickly, see the Querying resources paragraph when following the given link.
We use the API to read the service (both proxy and business) configuration and for simple management.
As long as you only read the properties you do not need to handle management sessions. Once you change the values, you need to start a session and activate it once you are done -- a very similar approach to Service bus console.
Using GAE, I am using javax's entity manager (javax.persistence.EntityManagerFactory) to generate an instance of the entity manager:
private static final EntityManagerFactory emfInstance = Persistence.createEntityManagerFactory("transactions-optional");
I retrieve from the datastore using the following code:
event = mgr.find(Event.class, id);
The problem I have is that if I retrieve the data for the first time, everything goes fine. However, if I go through the "Datastore Viewer" in the GAE dashboard to edit the values manually. The next time I call the data, using the "find" method, the values returned are the old value. I have to manually upload backend again in order to get the new values.
Any idea what is causing this? I would like mgr.find to always call the latest value. Thanks.
The entity is being cached. When you change it through the Datastore Viewer, the entity cached by your backend is not affected.
After you make a change in the Datastore viewer, click on the "Flush Memcache" button.
If this does not help, you may need to change configuration for your caching:
Level2 Caching is enabled by default. To get the previous default
behavior, set the persistence property datanucleus.cache.level2.type
to none. (Alternatively include the datanucleus-cache plugin in the
classpath, and set the persistence property
datanucleus.cache.level2.type to javax.cache to use Memcache for L2
caching.
Try flushing memcache and then try your query again.Most times the last persisted entity data is what's retrieved until you do this.
Although I know there is already a Blob service for Appengine, I want to experiment on storing big blobs within the datastore.
Basically I am trying to persist this object using Objectify:
BigBlob.java
BigBlobFragments.java
However, appengine is complaining that: "BigBlobFragment is not a supported property type"
For the BigBlob type I created a DAO class with CRUD operation and registed the type like this:
static {
ObjectifyService.register(BigBlob.class);
//ObjectifyService.register(BigBlobFragment.class);
}
protected BigblobDaoImpl() {
super(BigBlob.class);
}
I actually also have tried registering BigBlobFragment.
Hopefully someone can share some ideas on how to actually persist Big blobs and fragments using Objectify.
I have not used Blobs myself but I noticed you have #PersistenceCapable above your entities... that should be #Entity.
import com.googlecode.objectify.annotation.Entity;
Then you should be able to register your entity with Objectify.
ObjectifyService.register(BigBlob.class);
You need to register both the BigBlob and the BigBlobFragment and replace all of your JDO annotations with Objectify annotations (assuming you are using ofy4. You might also want to consider embedding the BigBlobFragment object inside of the BigBlob for performance using #Embed.
I want to make database queries in my Jersey REST webapp. The ideal situation would be to find a way where the database connection is initialised once at the first app run. Afterwards I only get the instance of DAOFactory object in my REST class and make the queries in the methods. I am using mysql connector. Is there a way to find a way to do it in Jersey? In JSF it was possible - I just used an application-scoped bean when I run the code. Moreover it would be good if I could access the ServletContext object inside this method cause I would like to use it's getResourceAsStream() method to read the database connection parameters from WEB-INF/dao.properties file. But the 'only once per app initialisation' is the crucial part here.
We need to get certain information from PortletRequest in our Portal application. We do that using a utility method inside our Portlet Application. In this Utility method we access FacesContext.getCurrentInstance().getRequest() to get the PortletRequest. We access this Utility method in our DAO layer. We do not have access to request parameter here.
It works sometimes, but at times it gives me NullPointerException. I found a similar thread which explains about this. They have mentioned, if it is part of the same request, then you should get the Context. For me, it is part of the same request, but I'm not getting the context. Can you please help me.
If you are getting a null FaceContext from FacesContext.getCurrentInstance() then no FacesContext has been constructed for this Thread/Request.
Are the failing requests coming through a non-faces entry point? Such as an Event or Resource portlet request? If so there will be no FacesContext created.
Rather than relying on static methods and thread local storage to access data in you DAO you should consider extracting what you need from the PortletRequest, and passing it down your stack. It is bad practice to mix presentation layer artefacts such as the FaceContext or a PortletRequest with your DAO layer.
If your application is deployed in separate WAR/JAR files, it is likely that different classloaders are used. I had a similar problem, when I tried to access the FacesContext inside an hibernate HAR archive on JBOSS5. I came up with a successfull solution using reflection API. Take a look at this.
If you bundle your whole application into one EAR, you might be able to force the use of one classloader for the whole ear, but AFAIK that is application server specific.
Regards