cancel
Showing results for 
Search instead for 
Did you mean: 

Proper connection method for Java web application

Former Member
0 Kudos

I am using the MDM 7.1 Java API within a web application. However, I think I am missing something regarding connection pooling or caching. Every time the application is accessed, it appears a new connection is being created, and this takes a couple of seconds each time. It seems obvious to me that we need some sort of cache or connection pool option, but it's not clear to me what the right approach is here.

Further complicating matters is that we have many images and PDFs we want to place in disk cache. We have the ObjectCache class to do this, however it also doesn't appear to be working as efficiently as it should. I suspect this is related to our confusion over the proper connection model.

Here is the code that appears at the beginning of the portlet. Originally, I had the last line of code call .destroySession, which left hundreds of orphaned sessions on the server console. They appear to be repository sessions, since they survive even when unloading and reloading the repository, but I don't know where a repository session is being created or if I even need one. Changing this to .destroySessions fixed this problem, but it doesn't seem like the right way to do it. Any help would be appreciated!


sessionContext = new UserSessionContext(	
	MDM_SERVER_NAME,
	MDM_REPOSITORY,
	MDM_REPOSITORY_USER );

SessionManager.getInstance().createSession(
	sessionContext, 
	SessionTypes.USER_SESSION_TYPE, 
	MDM_REPOSITORY_USER_PASSWORD);

RepositoryIdentifier repositoryIdentifier = 
	new RepositoryIdentifier(MDM_REPOSITORY, MDM_DBMS, DBMSType.MS_SQL);

RepositorySchema repository = 
MetadataManager.getInstance().getRepositorySchema(sessionContext);

MetadataManager.getInstance().registerRepositoryNotifications(
sessionContext, MDM_REPOSITORY_USER, MDM_REPOSITORY_USER_PASSWORD );
MetadataManager.getInstance().registerDataNotifications(
sessionContext, MDM_REPOSITORY_USER_PASSWORD );

ObjectCache objectCache = 
new ObjectCache(ConnectionManager.getConnectionAccessor(sessionContext));
objectCache.setReposIdentifier( repositoryIdentifier );
// Other objectCache setup commands go here
objectCache.initialize();

// API commands go here

SessionManager.getInstance().destroySessions(sessionContext);

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Shawn,

Try using sessionContext.setConnectionType(ConnectionTypes.LOCAL_POOL_CONNECTION);

Call this method after creating sessionContext object and before calling SessionManager.getInstance().getSession(...)

Regards,

-- Shailesh Surve.

Edited by: Shailesh Surve on Oct 20, 2009 10:51 AM

Former Member
0 Kudos

Hi Shailesh,

Thank you for responding to my post. I tried this, but it seems that the connections still aren't pooling on the server. When I open the console, I see several new connections created each time I refresh my web page.

I have been reading about the MDM Connector, this appears to be the way that SAP wants you to connect when using a J2EE environment. Unfortunately, the documentation doesn't really address how to use this in a standalone Java environment (we are running Liferay portal over a Tomcat application server).

Do you have any experience using the MDM Connector and if so is this a better way to connect?

Thanks in advance,

Shawn

Former Member
0 Kudos

Hi Shawn

AFAIK its better to use ConnectionPoolFactory for creating connections to MDM using Java API. Additionally you can set the timeout in MDSS.ini for the connections to get destroyed after a specific amount of time. This way, you can avoid unnecessary resource usage.

Hope this helps!!

Cheers,

Arafat

Former Member
0 Kudos

One more thing that you need to put stress is the destroying the Sessions. Always destroy sessions once the tas is done since automatic destruction of session is not guaranteed.

Cheers,

Arafat