Here we provide some sample code, specific to JBlooming framework. The web.xml file should poit to two configuration files, comma separated.
ThreadLocalPersistenceContextCarrier.java
package org.jblooming.persistence;
...
public class ThreadLocalPersistenceContextCarrier {
private Operator operator;
public PersistenceContext currentPC;
public Map
...
PersistenceContext.java
package org.jblooming.persistence.hibernate;
...
public class PersistenceContext {
public Session session;
public PersistenceConfiguration persistenceConfiguration;
public static ThreadLocal
protected ThreadLocalPersistenceContextCarrier initialValue() {
return null;
}
};
________________________________________
public PersistenceContext() {
this((Connection) null);
}
________________________________________
public PersistenceContext(Connection c) {
this(null, c);
}
________________________________________
/**
* this is not managed by the filter
*/
public PersistenceContext(String persistenceConfigurationName, Connection c) {
if (JSP.ex(persistenceConfigurationName))
persistenceConfiguration = PersistenceConfiguration.persistenceConfigurations.get(persistenceConfigurationName);
else
persistenceConfiguration = PersistenceConfiguration.getFirstPersistenceConfiguration();
Sniffer interceptor = null;
if (Fields.TRUE.equals(ApplicationState.getApplicationSetting(SystemConstants.AUDIT)))
interceptor = new Sniffer();
Throwable t = null;
try {
if (c != null && interceptor != null)
session = persistenceConfiguration.getSessionFactory().openSession(c, interceptor);
else if (c != null)
session = persistenceConfiguration.getSessionFactory().openSession(c);
else if (interceptor != null)
session = persistenceConfiguration.getSessionFactory().openSession(interceptor);
else
session = persistenceConfiguration.getSessionFactory().openSession();
session.beginTransaction();
} catch (Throwable e) {
t = e;
}
//by thowing the exception only if there is an exp AND session is null, in all other cases the external finally can close the session correctly
if (t != null && session == null)
throw new PlatformRuntimeException(t);
}
________________________________________
public PersistenceContext(Session session) {
this.session = session;
}
________________________________________
public static Connection getNewConnection() throws ClassNotFoundException, SQLException {
PersistenceConfiguration pcf = PersistenceConfiguration.getDefaultPersistenceConfiguration();
Class.forName(pcf.driver_class);
return DriverManager.getConnection(pcf.driver_url, pcf.db_user_name, pcf.db_user_psw);
}
________________________________________
private void close(boolean thereHasBeenAnException) throws PersistenceException {
boolean exceptionInCommit = true;
if (!thereHasBeenAnException) {
try {
if (session.getTransaction() != null) {
session.getTransaction().commit();
exceptionInCommit = false;
}
} catch (Throwable throwable) {
Tracer.platformLogger.error(throwable);
}
}
if (thereHasBeenAnException || exceptionInCommit) {
try {
if (session.getTransaction() != null) {
session.getTransaction().rollback();
}
} catch (Throwable throwable) {
Tracer.platformLogger.error(throwable);
}
}
try {
//as we are NOT using Hibernate managed context, in contrast with FrontControllerFilter, there is need after commit/rollbacdk to close session
session.close();
} catch (Throwable throwable) {
throw new PersistenceException(throwable);
}
}
________________________________________
public void checkPoint() {
if (session.isOpen()) {
Transaction currentTransaction = session.getTransaction();
if (session.isOpen() && currentTransaction != null && !currentTransaction.wasRolledBack()) {
session.flush();
currentTransaction.commit();
session.beginTransaction();
}
}
}
________________________________________
public void commitAndClose() throws PersistenceException {
close(false);
}
________________________________________
public void rollbackAndClose() {
try {
close(true);
} catch (PersistenceException e) {
}
}
________________________________________
public static PersistenceContext getDefaultPersistenceContext() {
return switchTo((String) null);
}
________________________________________
public static PersistenceContext switchToFirst() {
return switchTo(PersistenceConfiguration.getFirstPersistenceConfiguration().name);
}
________________________________________
public static PersistenceContext switchTo(Class persistentClass) {
PersistenceContext persistenceContext = get(persistentClass);
threadLocalPersistenceContextCarrier.get().currentPC = persistenceContext;
return persistenceContext;
}
________________________________________
public static PersistenceContext switchTo(String persistenceConfigurationName) {
// set last used as current
PersistenceContext pc = getByConfigurationName(persistenceConfigurationName);
threadLocalPersistenceContextCarrier.get().currentPC = pc;
return pc;
}
________________________________________
public static PersistenceContext get(Class persistentClass) {
String conf = null;
for (String confName : PersistenceConfiguration.persistenceConfigurations.keySet()) {
PersistenceConfiguration pcf = PersistenceConfiguration.persistenceConfigurations.get(confName);
if (pcf.getHibernateConfiguration().getClassMapping(persistentClass.getName()) != null) {
conf = confName;
break;
}
}
return getByConfigurationName(conf);
}
________________________________________
public static PersistenceContext get(IdentifiableSupport persistentObj) {
String className=PersistenceHome.deProxy(persistentObj.getClass().getName());
String conf = null;
for (String confName : PersistenceConfiguration.persistenceConfigurations.keySet()) {
PersistenceConfiguration pcf = PersistenceConfiguration.persistenceConfigurations.get(confName);
if (pcf.getHibernateConfiguration().getClassMapping(className) != null) {
conf = confName;
break;
}
}
return getByConfigurationName(conf);
}
________________________________________
public static PersistenceContext get(String className) {
PersistenceContext pc;
try {
pc = PersistenceContext.get((Class) Class.forName(className));
} catch (ClassNotFoundException e) {
throw new PlatformRuntimeException(e);
}
return pc;
}
________________________________________
private static PersistenceContext getByConfigurationName(String persistenceConfigurationName) {
//there could be already a closed session on it
ThreadLocalPersistenceContextCarrier localPersistenceContextCarrier = null;
// exists ThreadLocal?
if (threadLocalPersistenceContextCarrier.get() == null) {
localPersistenceContextCarrier = new ThreadLocalPersistenceContextCarrier();
threadLocalPersistenceContextCarrier.set(localPersistenceContextCarrier);
}
localPersistenceContextCarrier = threadLocalPersistenceContextCarrier.get();
// guess the right persistenceConfiguration Name
PersistenceConfiguration persistenceConfiguration;
if (JSP.ex(persistenceConfigurationName))
persistenceConfiguration = PersistenceConfiguration.persistenceConfigurations.get(persistenceConfigurationName);
else {
// if there is a current in use sedimented on threadlocal, give that
if (localPersistenceContextCarrier.currentPC != null)
persistenceConfiguration = localPersistenceContextCarrier.currentPC.persistenceConfiguration;
//no current sedimented on threadlocal, use the first, "main" one
else
persistenceConfiguration = PersistenceConfiguration.getFirstPersistenceConfiguration();
}
// exist a PersistentContext for this conf ?
PersistenceContext persistenceContext = localPersistenceContextCarrier.getPersistenceContext(persistenceConfiguration.name);
if (persistenceContext == null) {
persistenceContext = new PersistenceContext(persistenceConfigurationName, null);
localPersistenceContextCarrier.putPersistenceContext(persistenceContext);
System.out.println("Creating new pc thlocid:"+localPersistenceContextCarrier.hashCode());
} else {
// check if sessions are still good
if (persistenceContext.session != null && !(persistenceContext.session.isOpen())) {
persistenceContext = new PersistenceContext(persistenceConfigurationName, null);
localPersistenceContextCarrier.putPersistenceContext(persistenceContext);
System.out.println("Creating currupted new pc thlocid:"+localPersistenceContextCarrier.hashCode());
}
}
return persistenceContext;
}
}
26 comments:
Newdatabases.com hosts free msaccess databases look-alikes for windows. Might offer something helpful.
WoW shares many wow gold of its features with previously launched games. Essentially, you battle with wow gold cheap monsters and traverse the countryside, by yourself or as a buy cheap wow gold team, find challenging tasks, and go on to higher aoc gold levels as you gain skill and experience. In the course of your journey, you will be gaining new powers that are increased as your skill rating goes up. All the same, in terms of its features and quality, that is a ture stroy for this.WoW is far ahead of all other games of the genre the wow power leveling game undoubtedly is in a league of its own and cheapest wow gold playing it is another experience altogether.
Even though WoW is a Cheap Wow Gold rather complicated game, the controls and interface are done in warhammer gold such a way that you don't feel the complexity. A good feature of the game is that it buy wow items does not put off people with lengthy manuals. The instructions bygamer cannot be simpler and the pop up tips can help you start playing the game World Of Warcraft Gold immediately. If on the other hand, you need a detailed manual, the instructions are there for you to access. Buy wow gold in this site,good for you, BUY WOW GOLD.
I think 2moons dil changes my life. Because of 2moons gold, I meet a lot of friends. Besides, my friends usually give me some 2moon dil. I usually buy 2moons dil through Internet and advice from my friends, so I gain a lot of cheap 2moons gold and harvest in life.
9Dragons is a very good game. Through buying 9Dragons gold, I find fun in it. I am so glad that I can earn a lot of 9 Dragons gold. 9Dragons cater to the taste of young people. With cheap 9Dragons gold, you can get everything you want in this game. So I like to buy 9 Dragons gold. For me 9Dragons money is not just a simple thing.
Weekends to peopleig2tmean that they can have a two-day wowgold4europe good rest. For example, people gameusdcan go out to enjoy themselves or get meinwowgoldtogether with relatives and friends to talk with each storeingameother or watch interesting video tapes with the speebiewhole family.
Everyone spends agamegoldweekends in his ownmmoflyway. Within two days,some people can relax themselves by listening to music, reading novels,or watchingogeworld films. Others perhaps are more active by playing basketball,wimming ormmorpgvipdancing. Different people have different gamesavorrelaxations.
I often spend weekends withoggsalemy family or my friends. Sometimes my parents take me on a visit to their old friends. Sometimesgamersell I go to the library to study or borrow some books tommovirtexgain much knowledge. I also go to see various exhibition to broadenrpg tradermy vision. An excursion to seashore or mountain resorts is my favorite way of spending weekends. Weekends are always enjoyable for me.
Do you know cabal online alz? I like it. My brother often goes to the internet bar to buy cabal alz and play it. After school, He likes playing games using these cabal gold with his friend. I think that it not only costs much money but also spend much time. One day, he give me many cabal money and play the game with me. I came to the bar following him and found buy cabal alz was so cheap.
Do you know cabal online alz? I like it. My brother often go to the internet bar to buy cabal alz and play it. After school, He likes playing games using these cabal gold with his friend. I think that it not only costs much money but also spend much time. One day, he give me many cabal money and play the game with me. I came to the bar following him and found buy cabal alz was so cheap. After that, I also go to play game with him.
Do you know fiesta Gold? I like it. My brother often go to the internet bar to buy fiesta money and play it. After school, He likes playing games using these fiesta online gold with his friend. I think that it not only costs much money but also spend much time. One day, he give me many buy fiesta Gold and play the game with me. I came to the bar following him and found fiesta online money was so cheap.
they are like me and tell me anything about them wakfu kamas, I know wakfu gold. one of my friend likes to go to play buy wakfu kamas, I can not stand praising the land and the nature wakfu money , It makes us to be wakfu kama.
It is a very nice game silkroad gold, I like sro gold. You can play it silkroad online gold, you can buy the cheap silk road gold. You smart and buy cheap silkroad gold.
Do you know latale online gold? I like it. My brother often go to the internet bar to buy latale gold and play it. After school, He likes playing games using these latale money with his friends. I do not like to play it. Because I think that it not only costs much money but also spend much time. One day, he give me many buy latale online gold and play the game with me. I came to the bar following him and found cheap latale gold was so cheap. After that, I also go to play game with him.
Have you heared about 9Dragons which you need use aion kina to play, and you can also borrow aion online kina from other players? But you can buy aion kina, or you will lose the choice if you do not have aion gold. If you get cheap aion kina, you can continue this game.
Have you heared about 9Dragons which you need use 9Dragons gold to play, and you can also borrow 9 Dragons gold from other players? But you can buy 9 Dragons gold, or you will lose the choice if you do not have cheap 9Dragons gold. If you get 9Dragons money, you can continue this game.
Have you heared about a game which you need use Anarchy credits to play, and you can also borrow Anarchy Online credits from other players? But you can buy AO credits, or you will lose the choice if you do not have Anarchy online gold. If you get Anarchy gold, you can continue this game.
Without hesitate, I bought second life linden , in the game I can find myself. I feel lonely, but I do not want to talk with anyone, so I buy lindens . At present, think the happy day I spend in knight, I am eager to enter it, and cheap linden . Own linden dollars , it means that you own the life of happiness. So I will not leave secondlife money . It is the origin of the happiness.
On account of I have rohan crone , I am not afraid of the lonely. At that time I do not know the meaning of it. Later I buy rohan gold . And every time, I have no rohan online crone , I will feel very anxious. Why I buy rohan online gold , please it gives me such a warm place. At the moment, I have rohan money .
rf gold which in RF Online Game is very popular for many players. Play this online game the premise that we have more enough rf online gold first. They are able to combine creative tools and weapons with some rf money and the Light form of universal magic. Under such sustained attacks they fell from power, yet they have bided their rf cp and time. Due to make cheap rf gold the intense gravity on their home planet, the Bellato are the smallest people.
It is the LOTRO Gold which make me very happy these days, my brother says Lord Of The Rings Gold is his favorite games gold he likes, he usually buy some buy LOTRO Gold to start his game and most of the time he will win the cheap Lord Of The Rings Gold</a back
I always heard something from my neighbor that he sometimes goes to the internet bar to play the game which will use him some Solstice Kron, he usually can win a lot of Solstice Online Kron, then he let his friends all have some Solstice Gold, his friends thank him very much for introducing them the Solstice Online Gold, they usually buy Solstice Kron together. And then share their cheap Solstice Kron to each other. At last they all get some Solstice Online money than before.
I am so happy to get some maple mesos and the mesos is given by my close friend who tells me that the cheap mesos is the basis to enter into the game. Therefore, I should maplestory mesos with the spare money and I gain some maple story mesos from other players.
Do you want to know the magic of online games, and here you can get more angels gold. Do you want to have a try? Come on and angels online gold can make you happy. You can change a lot buy angels gold for play games. And you can use the cheap angels online gold do what you want to do in the online game.
Do you want to know the magic of online games, and here you can get more Sho Online Mun. Do you want to have a try? Come on and Sho Mun can make you happy.You can change a lot Sho Online gold for play games. Playing online games can make much Sho gold. And you can buy Sho Online gold do what you want to do in the online game.
Do you know that the wow gold? The players often forget to eat meal when they play the online games. In the game many players need the World of Warcraft Gold to up their levels. so they often search where can warcraft gold, I think our website maybe is your best choice. Many friends told me that in here can get buy wow gold, and here you can also relax yourself. so i hope more and more players come here to buy the cheap wow gold.
dessicant air dryerpediatric asthmaasthma specialistasthma children specialistcarpet cleaning dallas txcarpet cleaners dallascarpet cleaning dallas
vero beach vacationvero beach vacationsbeach vacation homes veroms beach vacationsms beach vacationms beach condosmaui beach vacationmaui beach vacationsmaui beach clubbeach vacationsyour beach vacationscheap beach vacations
bob hairstylebob haircutsbob layeredpob hairstylebobbedclassic bobCare for Curly HairTips for Curly Haircurly hair12r 22.5 best pricetires truck bustires 12r 22.5
washington new housenew house houstonnew house san antonionew house ventura
new houston house houston house txstains removal dyestains removal clothesstains removalteeth whiteningteeth whiteningbright teeth
jennifer grey nosejennifer nose jobscalebrities nose jobsWomen with Big NosesWomen hairstylesBig Nose Women, hairstyles
black mold exposureblack mold symptoms of exposurewrought iron garden gatesiron garden gates find them herefine thin hair hairstylessearch hair styles for fine thin hairnight vision binocularsbuy night vision binocularslipitor reactionslipitor allergic reactionsluxury beach resort in the philippines
afordable beach resorts in the philippineshomeopathy for eczema.baby eczema.save big with great mineral makeup bargainsmineral makeup wholesalersprodam iphone Apple prodam iphone prahacect iphone manualmanual for P 168 iphonefero 52 binocularsnight vision Fero 52 binocularsThe best night vision binoculars here
night vision binoculars bargainsfree photo albums computer programsfree software to make photo albumsfree tax formsprintable tax forms for free craftmatic air bedcraftmatic air bed adjustable info hereboyd air bedboyd night air bed lowest price
find air beds in wisconsinbest air beds in wisconsincloud air beds
best cloud inflatable air bedssealy air beds portableportables air bedsrv luggage racksaluminum made rv luggage racksair bed raisedbest form raised air bedsbed air informercialsbest informercials bed airmattress sized air beds
bestair bed mattress antique doorknobsantique doorknob identification tipsdvd player troubleshootingtroubleshooting with the dvd playerflat panel television lcd vs plasmaflat panel lcd television versus plasma pic the bestadjustable bed air foam The best bed air foam
hoof prints antique equestrian printsantique hoof prints equestrian printsBuy air bedadjustablebuy the best adjustable air bedsair beds canadian storesCanadian stores for air beds
migraine causemigraine treatments floridaflorida headache clinicdrying dessicantair drying dessicant
Post a Comment