This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 293354 - Generating session names from connection properties and SE deployment changes
Summary: Generating session names from connection properties and SE deployment changes
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 271066 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-10-26 14:45 EDT by Andrei Ilitchev CLA
Modified: 2022-06-09 10:18 EDT (History)
0 users

See Also:


Attachments
Suggested patch. (86.45 KB, patch)
2009-10-26 14:57 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Correction for standalone SE case (globalInstrumentation != null) (7.18 KB, patch)
2009-10-27 14:56 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Correction 2 for standalone SE case (globalInstrumentation != null) (781 bytes, patch)
2009-10-29 13:45 EDT, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2009-10-26 14:45:30 EDT
To connect the same persistence unit with two different connection parameters (in two different EMFs) the session name should be specified, like:
props1.put(PersistenceUnitProperties.SESSION_NAME, "session1");
props1.put(PersistenceUnitProperties.JDBC_USER, "user1");
EMF emf1 = createEMF("default", props1);
props2.put(PersistenceUnitProperties.SESSION_NAME, "session2");
props2.put(PersistenceUnitProperties.JDBC_USER, "user2");
EMF emf2 = createEMF("default", props2);
// emf1 uses session "session1"; emf2 = "session2".

This change enables automatic creation of a new session based on connection properties passed to createEMF. The generated session name is a concatination of unique persistence unit name and connenction properties' names and values:
props1.put(PersistenceUnitProperties.JDBC_USER, "user1");
EMF emf1 = createEMF("default", props1);
props2.put(PersistenceUnitProperties.JDBC_USER, "user2");
EMF emf2 = createEMF("default", props2);
// emf1 uses session "default_user=user1"; emf2 - "default_user=user2".

Connection properties used for session name generation are listed in updated EntityManagerSetupImpl:
    public static String[] connectionPropertyNames = {
        PersistenceUnitProperties.TRANSACTION_TYPE,
        PersistenceUnitProperties.JTA_DATASOURCE,
        PersistenceUnitProperties.NON_JTA_DATASOURCE,
        PersistenceUnitProperties.JDBC_URL,
        PersistenceUnitProperties.JDBC_USER,
    };

There are some changes made to deployment (mostly application managed case - creatEMF):
emSetupImpls keyed on session names;
puName requires url for uniquiness in the only case of JavaSECMPInitializer  without agent (potential app. server case) - for all other cases puName uniquely defines the persistence unit;
JPAInitializer.initialize now happens only for JavaSECMPInitializer - only once and only in case agent is used.
It (as always) creates and predeploys all the pu it can find, those are now cached in initialEmSetupImpls map; also initialPuInfos map caches their puInfos - forever.
The first factory for the persistence unit gets the cached initialEmSetupImpl;
       all others get the cached initialPuInfo.
    Added clean up for temp class loaders, globalInstrumentation, not adding transformers after initialization - should eat less memory.
    JPAInitializer is no longer a singleton.
 In all other cases there is no initialization - each pu is initialized individually when the factory for it is created; puInfos never shared between emSetupImpls.
    Instead of initialize the key method now is findPersistenceUnitInfo.
 After undeployed emSetupImpl is discarded from the emSetupImpls map;
 Altered a bit states of EntityManagerSetupImpl - now there is no way to get anywhere from UNDEPLOYED state.
 Also EntityManagerSetupImpl  no longer caches properties passed to predeploy - that resolves bug 271066.
Comment 1 Andrei Ilitchev CLA 2009-10-26 14:57:43 EDT
Created attachment 150543 [details]
Suggested patch.
Comment 2 Andrei Ilitchev CLA 2009-10-26 15:14:00 EDT
Checked the patch into trunk.
Comment 3 Andrei Ilitchev CLA 2009-10-26 15:20:45 EDT
*** Bug 271066 has been marked as a duplicate of this bug. ***
Comment 4 Andrei Ilitchev CLA 2009-10-27 14:56:32 EDT
Created attachment 150667 [details]
Correction for standalone SE case (globalInstrumentation != null)

This is a small correction affecting only standalone SE case (globalInstrumentation != null).
In the original patch initialSetupImpls and initialPuInfos are (stupidly)initialized in JavaSECMPInitializer.initPersistenceUnits method - that means every new resource removes initialSetupImpls and initialPuInfos cached by the previous one - this patch moves initialization of the maps before persistence units loop.
Note that the code still worked - just inefficiently didn't reuse initialSetupImpls and initialPuInfos for the bulk of persistence units.

Unrelated addition to the same code is verification of uniqueness of persistence unit name: because in standalone SE (globalInstrumentation!=null) case all the persistence units are loaded from the same classloader the puName should uniqueky identify persistence unit (there is no way to distinguish between several persistence units with the same name, loaded on the same classloaader).
The new exception specifies puName and two URLs that both use it - that allows user to quickly fix the problem.
Comment 5 Andrei Ilitchev CLA 2009-10-27 15:07:27 EDT
Checked in Correction for standalone SE case patch.
Comment 6 Andrei Ilitchev CLA 2009-10-29 13:45:31 EDT
Created attachment 150856 [details]
Correction 2 for standalone SE case (globalInstrumentation != null)

Initialization never happened if postponed until main 
(-javaagent:eclipselink.jar=main)
Comment 7 Andrei Ilitchev CLA 2009-10-29 13:49:11 EDT
Checked into trunk.
Comment 8 Eclipse Webmaster CLA 2022-06-09 10:17:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:18:48 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink