<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
   <channel>
      <title>Weblogic Portal</title>
      <link>http://blogs.oracle.com/wlp/</link>
      <description></description>
      <language>en</language>
      <copyright>Copyright 2009</copyright>
      <lastBuildDate>Wed, 07 Jan 2009 21:20:09 -0700</lastBuildDate>
      <generator>http://www.sixapart.com/movabletype/</generator>
      <docs>http://blogs.law.harvard.edu/tech/rss</docs> 

            <item>
         <title>Unified User Profile (UUP) in Weblogic Portal</title>
         <description><![CDATA[<p>Attached is everything you need I think.</p>

<p>To Learn the theoretical part please refer following link</p>

<p><a href="http://e-docs.bea.com/wlp/docs100/users/uup.html">http://e-docs.bea.com/wlp/docs100/users/uup.html</a></p>

<p>Let get to practical, Here’s the basic steps to get this running :</p>

<p><strong>1. Add a Data Source to your domain with the JNDI name "dizzyworld.dizzyDataSource"</p>

<p>2. Run Following SQL script on the corresponding DB</p>

<p></strong><br />
CREATE TABLE weblogic.CUSTOMER_PROFILE (USER_NAME VARCHAR(20) NOT NULL,AGE INTEGER,EMAIL VARCHAR(30),STATUS VARCHAR(30),CATEGORY VARCHAR(30));<br />
ALTER TABLE weblogic.CUSTOMER_PROFILE ADD CONSTRAINT DIZZY_PROFILE PRIMARY KEY (USER_NAME);<br />
INSERT INTO weblogic.CUSTOMER_PROFILE (USER_NAME) VALUES('weblogic');<br />
INSERT INTO weblogic.CUSTOMER_PROFILE (USER_NAME) VALUES('portaladmin');</p>

<p><strong>3. Add USR file to your Datasync project<br />
</strong></p>

<p><br />
DizzyCustomer</p>

<p>USER</p>

<p>Age<br />
The customer's age<br />
false<br />
false<br />
Integer</p>

<p><br />
Email<br />
The customer's email address<br />
false<br />
false<br />
Text</p>

<p><br />
Status<br />
The customer's status<br />
false<br />
false<br />
Text</p>

<p><br />
Category<br />
The type of customer<br />
false<br />
false<br />
Text</p>

<p></p>

<p><strong><br />
4. Add a WebLogic EJB Project to your EAR named "DizzyUUP"</p>

<p>5. Add Following EJB source file to the EJB project<br />
</strong><br />
package com.dizzyworld.profile;</p>

<p>import java.rmi.RemoteException;<br />
import java.sql.Connection;<br />
import java.sql.PreparedStatement;<br />
import java.sql.ResultSet;<br />
import java.sql.SQLException;</p>

<p>import javax.ejb.CreateException;<br />
import javax.ejb.SessionBean;<br />
import javax.naming.InitialContext;<br />
import javax.naming.NamingException;<br />
import javax.sql.DataSource;</p>

<p>import com.bea.p13n.cache.Cache;<br />
import com.bea.p13n.cache.CacheFactory;<br />
import com.bea.p13n.property.ConfigurableEntityCreateException;<br />
import com.bea.p13n.property.ConfigurableEntitySystemException;<br />
import com.bea.p13n.property.EntityNotFoundException;<br />
import com.bea.p13n.property.EntityPropertyCache;<br />
import com.bea.p13n.property.PropertyLocator;<br />
import com.bea.p13n.property.PropertyMapKey;<br />
import com.bea.p13n.property.PropertyValidationException;<br />
import com.bea.p13n.property.internal.EntityPropertyCacheImpl;<br />
import com.bea.p13n.property.internal.PropertyMapKeyImpl;</p>

<p>import weblogic.ejb.GenericSessionBean;<br />
import weblogic.ejbgen.Session;<br />
import weblogic.ejbgen.JndiName;<br />
import weblogic.ejbgen.FileGeneration;<br />
import weblogic.ejbgen.Constants;<br />
import weblogic.ejbgen.RemoteMethod;<br />
import weblogic.ejbgen.ResourceRefs;<br />
import weblogic.ejbgen.ResourceRef;</p>

<p>/**<br />
* A UUP is implemented by providing your own EntityPropertyManager EJB<br />
* implementation class. This EJB is registered with the ProfileManager in the<br />
* ProfileManager's EJB deployment descriptor. The ProfileManager is, in turn,<br />
* registered with the UserManager EJB.<br />
*<br />
* This EntityPropertyManager manages user properties found in a custom database<br />
* table. This table is accessed using the dizzyDataSource.<br />
*/<br />
@Session(ejbName = "MyEntityPropertyManager", defaultTransaction = Constants.TransactionAttribute.NOT_SUPPORTED)<br />
@JndiName(remote = "dizzyworld.MyEntityPropertyManager")<br />
@FileGeneration(remoteClass = Constants.Bool.TRUE, remoteHome = Constants.Bool.TRUE, localClass = Constants.Bool.FALSE, localHome = Constants.Bool.FALSE)<br />
@ResourceRefs(value = { @ResourceRef(name = "jdbc/dizzyDataSource", type = "javax.sql.DataSource", auth = ResourceRef.Auth.CONTAINER, jndiName = "dizzyworld.dizzyDataSource") })<br />
public class MyEntityPropertyManager extends GenericSessionBean implements<br />
SessionBean {<br />
private static final long serialVersionUID = 1L;</p>

<p>/**<br />
* Cache name used to obtain the application-wide cache from the<br />
* CacheFactory. Configure and manage this cache through the portal admin<br />
* console.<br />
*/<br />
protected static final String PROPERTY_CACHE_NAME = "DizzyUUPCache";</p>

<p>protected static final boolean USE_CACHE = false;</p>

<p>/**<br />
* Profile propery names Must match the names used in the property set<br />
* definition (.usr)<br />
*/<br />
protected static final String AGE_PROPERTY = "Age";</p>

<p>protected static final String EMAIL_PROPERTY = "Email";</p>

<p>protected static final String STATUS_PROPERTY = "Status";</p>

<p>protected static final String CATEGORY_PROPERTY = "Category";</p>

<p>/**<br />
* The name of the database table containing profile data<br />
*/<br />
protected static final String TABLE_NAME = "weblogic.CUSTOMER_PROFILE";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for retrieving all<br />
* properties for a given user. This schema only supports single valued<br />
* properties.<br />
*/<br />
protected static final String SELECT_PROPERTIES_STATEMENT = "SELECT AGE,EMAIL,STATUS,CATEGORY FROM "<br />
+ TABLE_NAME + " WHERE USER_NAME = ?";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for removing all<br />
* properties for a given user.<br />
*/<br />
protected static final String REMOVE_PROPERTIES_STATEMENT = "UPDATE "<br />
+ TABLE_NAME<br />
+ " SET AGE = NULL, SET EMAIL = NULL, SET STATUS = NULL, SET CATEGORY = NULL WHERE USER_NAME = ?";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for removing a single<br />
* given property for a given user.<br />
*/<br />
protected static final String REMOVE_PROPERTY_STATEMENT_1 = "UPDATE "<br />
+ TABLE_NAME + " SET ";<br />
protected static final String REMOVE_PROPERTY_STATEMENT_2 = " = NULL WHERE USER_NAME = ?";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for removing a given user<br />
* and all of their properties.<br />
*/<br />
protected static final String REMOVE_ENTITY_STATEMENT = "DELETE FROM "<br />
+ TABLE_NAME + " WHERE USER_NAME = ?";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for setting a given<br />
* property for a given user.<br />
*/<br />
protected static final String SET_PROPERTY_STATEMENT_1 = "UPDATE "<br />
+ TABLE_NAME + " SET ";</p>

<p>protected static final String SET_PROPERTY_STATEMENT_2 = " = ? WHERE USER_NAME = ?";</p>

<p>/**<br />
* SQL string used to create the PreparedStatement for creating a new user.<br />
*/<br />
protected static final String CREATE_ENTITY_STATEMENT = "INSERT INTO "<br />
+ TABLE_NAME + " (USER_NAME) VALUES(?)";</p>

<p>/**<br />
* Name for the DataSource specified in the<br />
*/<br />
protected static final String DATA_SOURCE = "jdbc/dizzyDataSource";</p>

<p>/**<br />
* ejbCreate method<br />
*/<br />
public void ejbCreate() throws CreateException {<br />
// do nothing<br />
}</p>

<p>/**<br />
* Returns an EntityPropertyCache containing all properties that are<br />
* persisted for the given user, as identified with a PropertyLocator.<br />
*<br />
* @param locator<br />
* a PropertyLocator that identifies the user entity<br />
* @return a populated EntityPropertyCache<br />
* @exception EntityNotFoundException<br />
* if the user entity identified by the property locator does<br />
* not exist<br />
*/<br />
@RemoteMethod()<br />
public EntityPropertyCache getProperties(PropertyLocator locator)<br />
throws EntityNotFoundException {<br />
Connection connection = null;<br />
PreparedStatement selectStatement = null;<br />
ResultSet resultSet = null;<br />
EntityPropertyCache propertyCache = null;</p>

<p>// Check the cache first.<br />
propertyCache = getItemFromCache(locator);<br />
if (propertyCache != null) {<br />
return propertyCache;<br />
}</p>

<p>/*<br />
* The cache did not contain properties for this user so get the<br />
* properties from the database.<br />
*/<br />
propertyCache = new EntityPropertyCacheImpl();<br />
boolean userExists = false;</p>

<p>try {<br />
// Get a database connection.<br />
connection = getConnection();<br />
// SELECT to find all the properties associated with the user<br />
String userName = locator.getPkString();<br />
selectStatement = connection<br />
.prepareStatement(SELECT_PROPERTIES_STATEMENT);<br />
selectStatement.setString(1, userName);<br />
resultSet = selectStatement.executeQuery();</p>

<p>while (resultSet.next()) {<br />
userExists = true;<br />
Integer age = resultSet.getInt(1);<br />
String email = resultSet.getString(2);<br />
String status = resultSet.getString(3);<br />
String category = resultSet.getString(4);</p>

<p>/*<br />
* Cache the properties. The<br />
* com.bea.p13n.property.PropertyMapKey is a lightweight key for<br />
* the property name and property set name. The<br />
* com.bea.p13n.internal.property.PropertyMapKeyImpl class<br />
* implements the PropertyMapKey interface.<br />
*/<br />
if (age != null) {<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(<br />
null, AGE_PROPERTY);<br />
propertyCache.put(propertyMapKey, age);<br />
}<br />
if (email != null) {<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(<br />
null, EMAIL_PROPERTY);<br />
propertyCache.put(propertyMapKey, email);<br />
}<br />
if (status != null) {<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(<br />
null, STATUS_PROPERTY);<br />
propertyCache.put(propertyMapKey, status);<br />
}<br />
if (category != null) {<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(<br />
null, CATEGORY_PROPERTY);<br />
propertyCache.put(propertyMapKey, category);<br />
}<br />
}<br />
} catch (SQLException sqle) {<br />
throw new ConfigurableEntitySystemException(sqle);<br />
} finally {<br />
try {<br />
resultSet.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
selectStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
connection.close();<br />
} catch (Exception e) {<br />
}<br />
}</p>

<p>if (userExists) {<br />
/*<br />
* Put the whole entity value cache into the application-wide cache.<br />
*/<br />
addItemToCache(locator, propertyCache);</p>

<p>return propertyCache;<br />
} else {<br />
throw new EntityNotFoundException(locator.getPkString()<br />
+ " does not exist");<br />
}<br />
}</p>

<p>/**<br />
* Returns the value of the property defined for the specified property and<br />
* property set.<br />
*</p>

<p><br />
* If the property does not have a value persisted, then null is returned.<br />
*<br />
* @param locator<br />
* a PropertyLocator identifying the user entity to look up<br />
* @param propertySet<br />
* the name of the property set<br />
* @param propertyName<br />
* the name of the property<br />
* @return the property's value, or null if there is none<br />
* @exception EntityNotFoundException<br />
* if the entity identified by the property locator does not<br />
* exist<br />
*/<br />
@RemoteMethod()<br />
public Object getProperty(PropertyLocator locator, String propertySetName,<br />
String propertyName) throws EntityNotFoundException {<br />
/*<br />
* Use getProperties() to check cache, get from database if not in<br />
* cache. The EntityPropertyCache is the container used to keep all user<br />
* properties in the application-wide cache.<br />
*/<br />
EntityPropertyCache epc = getProperties(locator);<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(null,<br />
propertyName);</p>

<p>return epc.get(propertyMapKey);<br />
}</p>

<p>/**<br />
* Removes all property values associated with the user entity specified by<br />
* the property locator. After a property value is removed for a user<br />
* entity, subsequent calls to getProperty() must return null for that user<br />
* entity, notifying the property search algorithm to move on to the<br />
* successors.<br />
*<br />
* @param locator<br />
* a PropertyLocator identifying the user entity to modify<br />
* @exception EntityNotFoundException<br />
* if the user entity identified by the property locator does<br />
* not exist<br />
*/<br />
@RemoteMethod()<br />
public void removeProperties(PropertyLocator locator)<br />
throws EntityNotFoundException {<br />
Connection conn = null;<br />
PreparedStatement removePropertiesStatement = null;</p>

<p>try {<br />
conn = getConnection();</p>

<p>removePropertiesStatement = conn<br />
.prepareStatement(REMOVE_PROPERTIES_STATEMENT);</p>

<p>// The userName is in the PropertyLocator's pkString<br />
removePropertiesStatement.setString(1, locator.getPkString());<br />
int affectedRowCount = removePropertiesStatement.executeUpdate();<br />
if (affectedRowCount == 0) {<br />
throw new EntityNotFoundException(locator.getPkString()<br />
+ " does not exist");<br />
}</p>

<p>// Remove the properties from the cache<br />
removeItemFromCache(locator);<br />
} catch (SQLException sqle) {<br />
throw new ConfigurableEntitySystemException(sqle);<br />
} finally {<br />
try {<br />
removePropertiesStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
conn.close();<br />
} catch (Exception e) {<br />
}<br />
}<br />
}</p>

<p>/**<br />
* Removes a specific property value from the user entity specified by the<br />
* property locator. After a property value is removed for a user entity,<br />
* subsequent calls to getProperty() must return null for that user entity,<br />
* notifying the property search algorithm to move on to the successors.<br />
*<br />
* @param locator<br />
* a PropertyLocator identifying the user entity to modify<br />
* @param propertySet<br />
* the property set containing the property to remove<br />
* @param propertyName<br />
* the name of the property to remove<br />
* @return The old value of the property, if any<br />
* @exception EntityNotFoundException<br />
* if the entity identified by the property locator does not<br />
* exist<br />
*/<br />
@RemoteMethod()<br />
public Object removeProperty(PropertyLocator locator,<br />
String propertySetName, String propertyName)<br />
throws EntityNotFoundException {<br />
// Get the current value<br />
Object oldValue = getProperty(locator, propertySetName, propertyName);</p>

<p>if (oldValue != null) {<br />
Connection conn = null;<br />
PreparedStatement removePropertyStatement = null;<br />
try {<br />
conn = getConnection();<br />
// Set the column name to clear<br />
removePropertyStatement = conn<br />
.prepareStatement(REMOVE_PROPERTY_STATEMENT_1 + propertyName.toUpperCase() + REMOVE_PROPERTY_STATEMENT_2);</p>

<p>// The userName is in the PropertyLocator's pkString<br />
removePropertyStatement.setString(1, locator.getPkString());</p>

<p>int affectedRowCount = removePropertyStatement.executeUpdate();<br />
if (affectedRowCount == 0) {<br />
throw new EntityNotFoundException(locator.getPkString()<br />
+ " does not exist");<br />
}</p>

<p>// Remove it from the cache.<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(null,<br />
propertyName);<br />
removeCachedPropertyValue(locator, propertyMapKey);<br />
} catch (SQLException sqle) {<br />
throw new ConfigurableEntitySystemException(sqle);<br />
} finally {<br />
try {<br />
removePropertyStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
conn.close();<br />
} catch (Exception e) {<br />
}<br />
}<br />
}<br />
return oldValue;<br />
}</p>

<p>/**<br />
* Sets the property identified by the given property set and property name<br />
* to the given value for the user entity specified by the given property<br />
* locator.<br />
*<br />
* @param locator<br />
* a PropertyLocator identifying the user entity to modify<br />
* @param propertySet<br />
* the property set containing the property to modify<br />
* @param propertyName<br />
* the name of the property to modify<br />
* @param value<br />
* the value to persist for the given property and user entity<br />
* @exception PropertyValidationException<br />
* if the value is not valid for the given property<br />
* @exception EntityNotFoundException<br />
* if the entity identified by the property locator does not<br />
* exist<br />
*/<br />
@RemoteMethod()<br />
public void setProperty(PropertyLocator locator, String propertySet,<br />
String propertyName, Object propertyValue)<br />
throws PropertyValidationException, EntityNotFoundException {<br />
Connection conn = null;<br />
PreparedStatement setPropertyStatement = null;<br />
try {</p>

<p>/*<br />
* Perform any validation, such as for data types or restricted<br />
* values<br />
*/<br />
if (propertyValue == null) {<br />
throw new PropertyValidationException();<br />
}<br />
if (propertyName.equals(AGE_PROPERTY)<br />
&& !(propertyValue instanceof Long)) {<br />
throw new PropertyValidationException();<br />
}</p>

<p>conn = getConnection();<br />
// Set the column name to update<br />
setPropertyStatement = conn<br />
.prepareStatement(SET_PROPERTY_STATEMENT_1<br />
+ propertyName.toUpperCase()<br />
+ SET_PROPERTY_STATEMENT_2);<br />
// Set the updated value<br />
if (propertyName.equals(AGE_PROPERTY)) {<br />
setPropertyStatement.setLong(1, (Long) propertyValue);<br />
} else {<br />
setPropertyStatement.setString(1, (String) propertyValue);<br />
}<br />
// The userName is in the PropertyLocator's pkString<br />
setPropertyStatement.setString(2, locator.getPkString());</p>

<p>int affectedRowCount = setPropertyStatement.executeUpdate();<br />
if (affectedRowCount == 0) {<br />
throw new EntityNotFoundException(locator.getPkString()<br />
+ " does not exist");<br />
}</p>

<p>// Update the cache<br />
PropertyMapKey propertyMapKey = new PropertyMapKeyImpl(null,<br />
propertyName);<br />
cachePropertyValue(locator, propertyMapKey, propertyValue);<br />
} catch (SQLException sqle) {<br />
throw new ConfigurableEntitySystemException(sqle);<br />
} finally {<br />
try {<br />
setPropertyStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
conn.close();<br />
} catch (Exception e) {<br />
}<br />
}<br />
}</p>

<p>/**<br />
* Remove all properties, and the entity record, for the user entity<br />
* identified by the given property locator.<br />
*<br />
* @param locator<br />
* the PropertyLocator identifying the entity to remove<br />
* @exception EntityNotFoundException<br />
* if the entity identified by the property locator does not<br />
* exist<br />
*/<br />
@RemoteMethod()<br />
public void removeEntity(PropertyLocator locator)<br />
throws EntityNotFoundException {<br />
Connection conn = null;<br />
PreparedStatement removeEntityStatement = null;<br />
try {<br />
conn = getConnection();<br />
// Remove the entity record<br />
removeEntityStatement = conn<br />
.prepareStatement(REMOVE_ENTITY_STATEMENT);<br />
// The user name is in the PropertyLocator pkString<br />
removeEntityStatement.setString(1, locator.getPkString());</p>

<p>int affectedRowCount = removeEntityStatement.executeUpdate();<br />
if (affectedRowCount == 0) {<br />
throw new EntityNotFoundException(locator.getPkString()<br />
+ " does not exist");<br />
}</p>

<p>// Remove it from the cache<br />
removeItemFromCache(locator);<br />
} catch (SQLException sqle) {<br />
throw new ConfigurableEntitySystemException(sqle);<br />
} finally {<br />
try {<br />
removeEntityStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
conn.close();<br />
} catch (Exception e) {<br />
}<br />
}<br />
}</p>

<p>/**<br />
* Create a record for a new user entity, as identified by the given<br />
* jndiHomeName (User or Group) and pkString. A custom EntityPropertyManager<br />
* is not used as the default EntityPropertyManager for the ProfileManager,<br />
* so you do not have to return a unique id for your user. Only the default<br />
* EntityPropertyManager is required to return a unique number. Simply<br />
* return -1.<br />
*<br />
* @param jndiHomeName<br />
* the entity's home name<br />
* @param pkString<br />
* the entity's identifier string<br />
* @return the newly created unique user entity id<br />
* @exception ConfigurableEntityCreateException<br />
* if there is an error<br />
*/<br />
@RemoteMethod()<br />
public long createUniqueId(String jndiHomeName, String pkString)<br />
throws ConfigurableEntityCreateException {<br />
PreparedStatement createEntityStatement = null;<br />
Connection conn = null;<br />
try {<br />
conn = getConnection();<br />
createEntityStatement = conn<br />
.prepareStatement(CREATE_ENTITY_STATEMENT);<br />
// Create a row in the table for the new user<br />
createEntityStatement.setString(1, pkString);<br />
createEntityStatement.executeUpdate();<br />
} catch (SQLException sqe) {<br />
throw new ConfigurableEntityCreateException(sqe);<br />
} finally {<br />
try {<br />
createEntityStatement.close();<br />
} catch (Exception e) {<br />
}<br />
try {<br />
conn.close();<br />
} catch (Exception e) {<br />
}<br />
}</p>

<p>return -1;<br />
}</p>

<p>/**<br />
* Only the default EntityPropertyManager has to support this method. A<br />
* custom EntityPropertyManager can simply throw<br />
* java.lang.UnsupportedOperationException<br />
*/<br />
@RemoteMethod()<br />
public long getUniqueId(String jndiHomeName, String pkString)<br />
throws EntityNotFoundException {<br />
throw new UnsupportedOperationException();<br />
}</p>

<p>/**<br />
* Only the default EntityPropertyManager has to support this method. A<br />
* custom EntityPropertyManager can simply throw<br />
* java.lang.UnsupportedOperationException<br />
*/<br />
@RemoteMethod()<br />
public String[] getDynamicProperties(PropertyLocator locator,<br />
String propertySet) throws EntityNotFoundException {</p>

<p>throw new UnsupportedOperationException();<br />
}</p>

<p>/**<br />
* Only the default EntityPropertyManager has to support this method. A<br />
* custom EntityPropertyManager can simply throw<br />
* java.lang.UnsupportedOperationException<br />
*/<br />
@RemoteMethod()<br />
public String getHomeName(long anEntityId) throws EntityNotFoundException {<br />
throw new UnsupportedOperationException();<br />
}</p>

<p>/**<br />
* Only the default EntityPropertyManager has to support this method. A<br />
* custom EntityPropertyManager can simply throw<br />
* java.lang.UnsupportedOperationException<br />
*/<br />
@RemoteMethod()<br />
public PropertyLocator getPropertyLocator(long anEntityId)<br />
throws EntityNotFoundException {<br />
throw new UnsupportedOperationException();<br />
}</p>

<p>/**<br />
* Only the default EntityPropertyManager has to support this method. A<br />
* custom EntityPropertyManager can simply throw<br />
* java.lang.UnsupportedOperationException<br />
*/<br />
@RemoteMethod()<br />
public String[] getEntityNames(String jndiName) throws RemoteException {<br />
throw new UnsupportedOperationException();<br />
}</p>

<p>/**<br />
* Cache a property value for a user entity. The application-wide cache<br />
* contains a EntityPropertyCache, which is the container used to hold the<br />
* properties for the user entity. The application-wide cache contains<br />
* object references, so there is no need to update the application-wide<br />
* cache after changing the contents of the EntityPropertyCache container.<br />
*<br />
* @param locator<br />
* the entity's property locator<br />
* @param key<br />
* the property's key<br />
* @param value<br />
* the value to cache<br />
*/<br />
private void cachePropertyValue(PropertyLocator locator,<br />
PropertyMapKey key, Object value) {<br />
if (!USE_CACHE) {<br />
return;<br />
}<br />
// Get any existing EntityPropertyCache container for the locator<br />
// (user).<br />
EntityPropertyCache cacheItem = getItemFromCache(locator);<br />
if (cacheItem != null) {<br />
// Add property to the cache<br />
cacheItem.put(key, value);<br />
} else {<br />
// There was no EntityPropertyCache for this locator, so create one.<br />
cacheItem = new EntityPropertyCacheImpl();<br />
// Add property to the cache<br />
cacheItem.put(key, value);<br />
// Put the new EntityPropertyCache container into the cache<br />
addItemToCache(locator, cacheItem);<br />
}<br />
}</p>

<p>/**<br />
* Remove a cached property value from the application-wide cache. The<br />
* application-wide cache contains a EntityPropertyCache, which is the<br />
* container used to hold the properties for the user entity. The<br />
* application-wide cache contains object references, so there is no need to<br />
* update the application-wide cache after changing the contents of the<br />
* EntityPropertyCache container.<br />
*<br />
* @param locator<br />
* the property locator of the user entity who owns the property<br />
* @param key<br />
* the property's key<br />
*/<br />
private void removeCachedPropertyValue(PropertyLocator locator,<br />
PropertyMapKey key) {<br />
if (!USE_CACHE) {<br />
return;<br />
}<br />
// Get any existing EntityPropertyCache container for the locator<br />
// (user).<br />
EntityPropertyCache cacheItem = getItemFromCache(locator);<br />
if (cacheItem != null) {<br />
// Remove property from cache<br />
cacheItem.remove(key);<br />
}<br />
}</p>

<p>/**<br />
* Cache a set of properties that belong to a user entity. The<br />
* EntityPropertyCache is the container for the properties. The<br />
* EntityPropertyCache container is cached in the application-wide cache<br />
* using the PropertyLocator for the user entity as the key.<br />
*<br />
* @param locator<br />
* the user entity's property locator, to use as the cache key<br />
* @param cacheItem<br />
* the EntityPropertyCache holding that user entity's properties<br />
*/<br />
private void addItemToCache(PropertyLocator locator,<br />
EntityPropertyCache cacheItem) {<br />
if (!USE_CACHE) {<br />
return;<br />
}<br />
Cache cache = CacheFactory.getCache(PROPERTY_CACHE_NAME);<br />
if (cache != null) {<br />
cache.put(locator, cacheItem);<br />
}<br />
}</p>

<p>/**<br />
* Get the EntityPropertyCache holding the properties for a user entity. The<br />
* EntityPropertyCache is the container for the values, it is not the<br />
* application-wide cache. The EntityPropertyCache is what is cached in the<br />
* application-wide cache. The application-wide cache is<br />
* com.bea.p13n.cache.Cache<br />
*<br />
* @param locator<br />
* the entity's property locator<br />
* @return the EntityPropertyCache, or null if it was not found in the cache<br />
*/<br />
private EntityPropertyCache getItemFromCache(PropertyLocator locator) {<br />
if (!USE_CACHE) {<br />
return null;<br />
}<br />
EntityPropertyCache cacheItem = null;<br />
Cache cache = CacheFactory.getCache(PROPERTY_CACHE_NAME);<br />
if (cache != null) {<br />
// Get any existing EntityPropertyCache container for the locator<br />
// (user).<br />
cacheItem = (EntityPropertyCache) cache.get(locator);<br />
}<br />
return cacheItem;<br />
}</p>

<p>/**<br />
* Remove all cached property values associated with a user entity<br />
*<br />
* @param locator<br />
* the entity's property locator<br />
*/<br />
private void removeItemFromCache(PropertyLocator locator) {<br />
if (!USE_CACHE) {<br />
return;<br />
}<br />
Cache cache = CacheFactory.getCache(PROPERTY_CACHE_NAME);<br />
if (cache != null) {<br />
cache.remove(locator);<br />
}<br />
}</p>

<p>/**<br />
* Gets a connection from the DataSource specified in the<br />
* environment entry for the EJB.<br />
*<br />
* @return a java.sql.Connection<br />
*/<br />
protected Connection getConnection() {<br />
try {<br />
DataSource dataSource = getDataSource();<br />
return dataSource.getConnection();<br />
} catch (SQLException ex) {<br />
throw new ConfigurableEntitySystemException(ex);<br />
}<br />
}</p>

<p>/**<br />
* Gets the DataSource specified in the environment entry for<br />
* the EJB.<br />
*/<br />
protected DataSource getDataSource() {<br />
DataSource src = null;<br />
try {<br />
src = (DataSource) getEnvironmentProperty(DATA_SOURCE);<br />
} catch (Exception ex) {<br />
throw new ConfigurableEntitySystemException(ex);<br />
}<br />
return src;<br />
}</p>

<p>/**<br />
* This method returns the value of the specified EJB environment property.<br />
*<br />
* @throws javax.naming.NamingException -<br />
* if a naming exception is encountered<br />
*/<br />
protected final Object getEnvironmentProperty(String propertyName)<br />
throws NamingException {<br />
Object envProperty = null;<br />
InitialContext jndiContext = new InitialContext();<br />
String lookupName = ((new StringBuffer("java:comp/env/"))<br />
.append(propertyName)).toString();<br />
envProperty = jndiContext.lookup(lookupName);</p>

<p>return envProperty;<br />
}<br />
}<strong></p>

<p>6. Add XML file to EAR project’s META-INF (or configure this dynamically using the Portal Console)</strong></p>

<p>Better way is to<br />
<em>a. in merged view copy p13n-profile-config.xml to project<br />
b. Add following lines to it.<br />
</em></p>

<p>DizzyPropertyManager<br />
DizzyPropertyManager<br />
DizzyCustomer<br />
DizzyUUP.jar#MyEntityPropertyManager<br />
true<br />
true<br />
<strong></p>

<p>7. Here is the one trick: Edit generated remote interface under the EJB project’s apt_src folder and change the parent interface from EJBObject to EntityPropertyManager</p>

<p><br />
8. Deploy</strong></p>

<p>Seems to work great for me.<br />
No problems at all, except there is one known WLP bug: remoteEntity is never called and so profiles are only deleted from the DB manually.</p>

<p>Have fun.<br />
Do post your feedback or if you need to make it for your custom usecase.........<br />
</p>]]></description>
         <link>http://blogs.oracle.com/wlp/2009/01/unified_user_profile_uup_in_we_1.html</link>
         <guid>http://blogs.oracle.com/wlp/2009/01/unified_user_profile_uup_in_we_1.html</guid>
                  <category domain="http://www.sixapart.com/ns/types#category">weblogic portal</category>
        
                  <category domain="http://www.sixapart.com/ns/types#tag">uup</category>
                  <category domain="http://www.sixapart.com/ns/types#tag">uupsamples</category>
                  <category domain="http://www.sixapart.com/ns/types#tag">weblogic portal</category>
                  <category domain="http://www.sixapart.com/ns/types#tag">wlp</category>
        
         <pubDate>Wed, 07 Jan 2009 21:20:09 -0700</pubDate>
      </item>
      
   </channel>
</rss>
