From: Christoph S. <ch...@sc...> - 2002-10-12 14:48:54
|
Hi All! I'd like to implement a new feature in Hibernate, but I dont know how to start best. I would like to be able to map classes that dont really exist as javaclass, but use a dynabean instead http://www.apache.org/~jvanzyl/jakarta-commons/beanutils/apidocs/org/apache/commons/beanutils/DynaBean.html (or a map). All seems to be quite easy, refactor all stuff that loads and initializes a bean to a pluggable factory, and there if the loading of the class fails just create or initialize a Dynabean or Map (or maybe a HibernateGenericValueHolder) instead. The only problem is: The Hibernate API :) Session.load, Session.update, etc all get a java.lang.Class Argument. Do you think it would be possible to add functions that get a classname as String instead? Maybe the functions that take a string as argument should always use Holders instead of beans. I realize that this would be big changes, but if you think that this would be a good idea, I would just go ahead and try to implement it. The inspiration to this comes from the ofbiz entity engine, which always uses generic holders instead of Beans, which i dont really like, but its really nice for some usecases, e.g. letting your user add colums to a table at runtime without restarting the server. I recognize that i could dynamically generate a bean with bcel, but once that bean is loaded i cant add properties to it, so I'd really prefer a map. regards chris |
From: Gavin K. <ga...@ap...> - 2002-10-13 15:44:57
|
Christoph, someone else once asked for this, so it might well be worth the effort. However, I wouldn't like to change the API if we can possibly help it. Now, it might turn out that we don't need to change the API. (1) How do you plan to persist these DynaBeans? A table that contains property name/value pairs seems most reasonable if you need users to be able to specify new properties at runtime ... or did you intend to export tables dynamically at runtime? (2) Would it be possible to load an instance like this: session.load( DynaBean.class, new DynaBeanKey("dynamic.class.name", identifier) ); (3) Not sure of the best way to write a ClassPersister for DynaBeans. Should there be a single persister for each class, or one for all classes? If the latter, you might need to change the ClassPersister interface to accommodate this new notion of a ClassPersister that persists multiple "classes". If the former, does that mean we need to be able to add new DynaBeanPersisters at runtime? Gavin ----- Original Message ----- From: "Christoph Sturm" <ch...@sc...> To: <hib...@li...> Sent: Sunday, October 13, 2002 12:47 AM Subject: [Hibernate] support for dynabeans > Hi All! > > I'd like to implement a new feature in Hibernate, but I dont know how to > start best. I would like to be able to map classes that dont really > exist as javaclass, but use a dynabean instead > http://www.apache.org/~jvanzyl/jakarta-commons/beanutils/apidocs/org/apache/ commons/beanutils/DynaBean.html > (or a map). All seems to be quite easy, refactor all stuff that loads > and initializes a bean to a pluggable factory, and there if the loading > of the class fails just create or initialize a Dynabean or Map (or maybe > a HibernateGenericValueHolder) instead. > > The only problem is: > The Hibernate API :) > Session.load, Session.update, etc all get a java.lang.Class Argument. Do > you think it would be possible to add functions that get a classname as > String instead? Maybe the functions that take a string as argument > should always use Holders instead of beans. > I realize that this would be big changes, but if you think that this > would be a good idea, I would just go ahead and try to implement it. > > > > The inspiration to this comes from the ofbiz entity engine, which always > uses generic holders instead of Beans, which i dont really like, but its > really nice for some usecases, e.g. letting your user add colums to a > table at runtime without restarting the server. I recognize that i could > dynamically generate a bean with bcel, but once that bean is loaded i > cant add properties to it, so I'd really prefer a map. > > regards > chris > > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > hibernate-devel mailing list > hib...@li... > https://lists.sourceforge.net/lists/listinfo/hibernate-devel |
From: Christoph S. <ch...@sc...> - 2002-10-13 15:58:26
|
Gavin King wrote: >Christoph, someone else once asked for this, so it might well be worth the >effort. > I hope it wasnt me :) > However, I wouldn't like to change the API if we can possibly help >it. Now, it might turn out that we don't need to change the API. > >(1) How do you plan to persist these DynaBeans? A table that contains >property name/value pairs seems most reasonable if you need users to be able >to specify new properties at runtime ... or did you intend to export tables >dynamically at runtime? > I want to create a new table for each dynabean. Then I'd also implement the dynamic schema update that I was mentioning long time ago :) >(2) Would it be possible to load an instance like this: > >session.load( DynaBean.class, new DynaBeanKey("dynamic.class.name", >identifier) ); > cool, that would be a good way, since we wouldnt need to change the api. > >(3) Not sure of the best way to write a ClassPersister for DynaBeans. Should >there be a single persister for each class, or one for all classes? If the >latter, you might need to change the ClassPersister interface to accommodate >this new notion of a ClassPersister that persists multiple "classes". If the >former, does that mean we need to be able to add new DynaBeanPersisters at >runtime? > I think we should take the former option, one persister per class. Then we should be able to add new Persisters at runtime. (And change the field definitions of existing persisters) hmm, do we need a new kind of class persister? I dont thimk so. IMHO the best solution would be to factor out the bean access of the existing ClassPersisters, and make that pluggable. > >Gavin > >----- Original Message ----- >From: "Christoph Sturm" <ch...@sc...> >To: <hib...@li...> >Sent: Sunday, October 13, 2002 12:47 AM >Subject: [Hibernate] support for dynabeans > > > > >>Hi All! >> >>I'd like to implement a new feature in Hibernate, but I dont know how to >>start best. I would like to be able to map classes that dont really >>exist as javaclass, but use a dynabean instead >> >> >> >http://www.apache.org/~jvanzyl/jakarta-commons/beanutils/apidocs/org/apache/ >commons/beanutils/DynaBean.html > > >>(or a map). All seems to be quite easy, refactor all stuff that loads >>and initializes a bean to a pluggable factory, and there if the loading >>of the class fails just create or initialize a Dynabean or Map (or maybe >>a HibernateGenericValueHolder) instead. >> >>The only problem is: >>The Hibernate API :) >>Session.load, Session.update, etc all get a java.lang.Class Argument. Do >>you think it would be possible to add functions that get a classname as >>String instead? Maybe the functions that take a string as argument >>should always use Holders instead of beans. >>I realize that this would be big changes, but if you think that this >>would be a good idea, I would just go ahead and try to implement it. >> >> >> >>The inspiration to this comes from the ofbiz entity engine, which always >>uses generic holders instead of Beans, which i dont really like, but its >>really nice for some usecases, e.g. letting your user add colums to a >>table at runtime without restarting the server. I recognize that i could >>dynamically generate a bean with bcel, but once that bean is loaded i >>cant add properties to it, so I'd really prefer a map. >> >>regards >> chris >> >> >> >> >>------------------------------------------------------- >>This sf.net email is sponsored by:ThinkGeek >>Welcome to geek heaven. >>http://thinkgeek.com/sf >>_______________________________________________ >>hibernate-devel mailing list >>hib...@li... >>https://lists.sourceforge.net/lists/listinfo/hibernate-devel >> >> > > > > > |
From: Gavin K. <ga...@ap...> - 2002-10-13 16:13:35
|
> I think we should take the former option, one persister per class. Then > we should be able to add new Persisters at runtime. (And change the > field definitions of existing persisters) Okay, cool, but how are you going to do that without requiring a synchronized method each time we look up a ClassPersister (which happens very often)? I think you will need to think very carefully about the whole add/lookup dynamic ClassPersister issue. It seems to be a major departure from the current model that there is an immutable collection of immutable ClassPersisters. |
From: Christoph S. <ch...@sc...> - 2002-10-13 16:41:39
|
Hey Gavin! Gavin King wrote: >>I think we should take the former option, one persister per class. Then >>we should be able to add new Persisters at runtime. (And change the >>field definitions of existing persisters) >> >> > >Okay, cool, but how are you going to do that without requiring a >synchronized method each time we look up a ClassPersister (which happens >very often)? > >I think you will need to think very carefully about the whole add/lookup >dynamic ClassPersister issue. It seems to be a major departure from the >current model that there is an immutable collection of immutable >ClassPersisters. > > Hadnt thought of that, thanks, Would it be possible to add my definitions to the DataStore, and then recreate or reinitialize the SessionFactoryImpl? Then I could build a guy where the user can define his new tables, and modify just the DataStore, and when he clicks on "apply", i update the db and recreate the SessionFactoryImpl. Would that work? chris |
From: Gavin K. <ga...@ap...> - 2002-10-13 16:50:33
|
> Hadnt thought of that, thanks, > > Would it be possible to add my definitions to the DataStore, and then > recreate or reinitialize the SessionFactoryImpl? > > Then I could build a guy where the user can define his new tables, and > modify just the DataStore, and when he clicks on "apply", i update the > db and recreate the SessionFactoryImpl. > > Would that work? Can't think why not. Should be fine. The Datastore is designed to allow multiple calls to buildSessionFactory (but you should watch out for bugs in that because its not covered in the test suite!) |
From: Christoph S. <ch...@sc...> - 2002-10-13 18:49:38
|
Gavin King wrote: >>Hadnt thought of that, thanks, >> >>Would it be possible to add my definitions to the DataStore, and then >>recreate or reinitialize the SessionFactoryImpl? >> >>Then I could build a guy where the user can define his new tables, and >>modify just the DataStore, and when he clicks on "apply", i update the >>db and recreate the SessionFactoryImpl. >> >>Would that work? >> >> > >Can't think why not. Should be fine. The Datastore is designed to allow >multiple calls to buildSessionFactory (but you should watch out for bugs in >that because its not covered in the test suite!) > > Cool. Then I will start with dynamic schema update. -chris > > >------------------------------------------------------- >This sf.net email is sponsored by:ThinkGeek >Welcome to geek heaven. >http://thinkgeek.com/sf >_______________________________________________ >hibernate-devel mailing list >hib...@li... >https://lists.sourceforge.net/lists/listinfo/hibernate-devel > > > > |
From: Gavin K. <ga...@ap...> - 2002-10-13 16:19:48
|
> >Christoph, someone else once asked for this, so it might well be worth the > >effort. > > > I hope it wasnt me :) Nope: http://sourceforge.net/forum/message.php?msg_id=1634640 :) |