Re: OSUser and Hibernate: couple of questions

Konstantin Priblouda <[email protected]>
Newsgroups gmane.comp.java.open-symphony.devel
Message-ID <[email protected]>
--- Ilja <[email protected]> wrote:
> Sorry, but I really don't understand anything from
> your code, can you
> give me a more concrete and simple example?

PropertySet properties = entity.getPropertySet();

where entity is either user or group. 
Now you can set/get properties through it. 

> First of all: do I need to change hibernate mapping
> files if I want to
> add new properties?
No. 
> Second: when I retrieve a user through the
> UserManager will it
> automatically retreive this custom properties as
> well?

Yes. Though not actually eagerly require, but 
they are accessible through property set.


> Third: how do I set these properties in a simple
> manner, ie:
> user.setSex("M"), user.setLocation("Netherlands")
> etc... and the opposite
> for retreiving

PropertySet properties = user.getPropertySet();
String sex = properties.get("user_sex");

properties.setString("user_sex","daily");

> How do I let osuser know which properties are
> required on top of the
> default ones?

It does not care about it. It's up on your
application.

> Sorry for asking, but osuser really lacks any
> documentation for this,

You are damn right... Though carefull reading of code
sheds some light :) I'm even able to patch
and improve  hibernate providers now :) 

> Ilja
> 
> ps: are osaccess and osuser being worked on or is
> this project standing
> still?

Dunno. I never used OSaccess....  You'll have to look
for CVS logs to determine activeness of each of
projects. 


Any my code sample demonstrates how to populate java
bean from property set, and also to save it. 

regards,

> > Of course I have first to create  my user/group, 
> > and then save properties there.
> > 
> > 
> > 
> > That's my 2 methods allowing
> > marshalling/unmarschalling of generic java bean
> into
> > user / group properties
> > ( Entity happens to be base interface for bothz
> user &
> > group ). You owe me a beer :) 
> > ---%<------------------
> >    /**
> >      * populate bean with properties from entity
> >      *
> >      * @param entity                        
> > Description of Parameter
> >      * @param bean                          
> > Description of Parameter
> >      * @exception IllegalAccessException    
> > Description of Exception
> >      * @exception InvocationTargetException 
> > Description of Exception
> >      */
> >     public static void populateBean(Entity entity,
> > Object bean) throws IllegalAccessException,
> > InvocationTargetException {
> >         PropertySet properties =
> > entity.getPropertySet();
> >         BeanIntrospectorPropertySet beanSet = new
> > BeanIntrospectorPropertySet();
> >         beanSet.setBean(bean);
> > 
> >         _log.debug("looking for properties
> starting
> > with: " + bean.getClass().getName());
> >         Collection keys =
> > properties.getKeys(bean.getClass().getName());
> >         int offset =
> > bean.getClass().getName().length() + 1;
> > 
> >         String key;
> >         for (Iterator iter = keys.iterator();
> > iter.hasNext(); ) {
> >             key = (String) iter.next();
> >             if (_log.isDebugEnabled()) {
> >                 _log.debug("setting property : " +
> > key.substring(offset));
> >             }
> >            
> > beanSet.setAsActualType(key.substring(offset),
> > properties.getAsActualType(key));
> >         }
> > 
> >     }
> > 
> > 
> >     /**
> >      * save properties for this entity
> >      *
> >      * @param entity                        
> entity to
> > associate data with
> >      * @param bean                           bean
> > holding those properties
> >      * @exception IllegalAccessException    
> > Description of Exception
> >      * @exception InvocationTargetException 
> > Description of Exception
> >      * @exception NoSuchMethodException     
> > Description of Exception
> >      */
> >     public static void saveBean(Entity entity,
> Object
> > bean) throws IllegalAccessException,
> >         InvocationTargetException,
> > NoSuchMethodException {
> >         PropertySet property =
> > entity.getPropertySet();
> >         BeanIntrospectorPropertySet beanSet = new
> > BeanIntrospectorPropertySet();
> >         beanSet.setBean(bean);
> > 
> >         String prefix = bean.getClass().getName()
> +
> > ".";
> > 
> >         for (Iterator ii =
> > property.getKeys(prefix).iterator(); ii.hasNext();
> ) {
> >             property.remove((String) ii.next());
> >         }
> >         String key;
> >         String newKey;
> >         for (Iterator iter =
> > beanSet.getKeys().iterator(); iter.hasNext(); ) {
> >             key = (String) iter.next();
> > 
> >             if (!beanSet.isSettable(key)) {
> >                 continue;
> >             }
> >             if (_log.isDebugEnabled()) {
> >                 _log.debug("property " + key + "
> is
> > settable. saving it");
> >             }
> >             newKey = prefix + key;
> > 
> >             Object obj =
> beanSet.getAsActualType(key);
> > 
> >             if (property.exists(newKey)) {
> >                 _log.debug("property exists,
> remove it
> > first");
> >                 property.remove(newKey);
> >             }
> >             if (obj != null) {
> >                 // need saving only if not null
> >                 _log.debug("really saving...");
> >                 property.setAsActualType(newKey,
> obj);
> >             }
> > 
> >         }
> >     }
> > 
> > ---%<----------------
> > 
> > 
> > =====
> > ----[ Konstantin Pribluda ( ko5tik )
> ]----------------
> > Zu Verstärkung meines Teams suche ich ab Sofort
> einen
> > Softwareentwickler[In] für die Festanstellung. 
> > Arbeitsort: Mainz 
> > Skills:  Programieren, Kentnisse in
> OpenSource-Bereich
> > ----[ http://www.pribluda.de
> ]------------------------
> > 
> > __________________________________
> > Do you Yahoo!?
> > The New Yahoo! Shopping - with improved product
> search
> > http://shopping.yahoo.com
> > 
> > 
> >
>
-------------------------------------------------------
> > This sf.net email is sponsored by:ThinkGeek
> > Welcome to geek heaven.
> > http://thinkgeek.com/sf
> > _______________________________________________
> > Opensymphony-developers mailing list
> > [email protected]
> >
>
https://lists.sourceforge.net/lists/listinfo/opensymphony-developers
> > 
> 
> 
>
-------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Opensymphony-developers mailing list
> [email protected]
>
https://lists.sourceforge.net/lists/listinfo/opensymphony-developers


=====
----[ Konstantin Pribluda ( ko5tik ) ]----------------
Zu Verstärkung meines Teams suche ich ab Sofort einen
Softwareentwickler[In] für die Festanstellung. 
Arbeitsort: Mainz 
Skills:  Programieren, Kentnisse in OpenSource-Bereich
----[ http://www.pribluda.de ]------------------------

__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com


-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.