Re: Need Help !
Sylvain Juge wrote: It seems that when I load OJB, it doesn't automatically load the repository_database.xml file that is in the build/resources folder on runtime. I've seen that OJB is able to work like that, but I don't want to do it on runtime, just use static xml config files. Since i'm an absolute newbie, and I use Eclipse with defaults settings, is there anything special that I need to configure in order to make my program use the repository files ?? When you use the ojb-blank project with default settings of Eclipse, then any Debug/Run configuration will be started in the project's top level folder. However the ojb-blank project is configured in such a way that the main class(es) are run from the build/resources subdirectory. So you should change your Debug/Run configuration' Working directory accordingly. Also, you need to call 'ant build' at least once before running the app, and everytime you've changed something in a non-Java source file, e.g. one of the repository xml files. Tom - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: RE: Need Help !
Hi, It seems that when I load OJB, it doesn't automatically load the repository_database.xml file that is in the build/resources folder on runtime. I've seen that OJB is able to work like that, but I don't want to do it on runtime, just use static xml config files. Since i'm an absolute newbie, and I use Eclipse with defaults settings, is there anything special that I need to configure in order to make my program use the repository files ?? Any help will be appreciated, Thanks in advance. Sylvain. I always create the broker in this way: broker = PersistenceBrokerFactoryFactory.instance().defaultPersistenceBroker(); and I don't have problem, but I'm not an expert. -Mensaje original- De: Rajadurai K [mailto:[EMAIL PROTECTED] Enviado el: miércoles, 06 de octubre de 2004 11:58 Para: 'OJB Users List' Asunto: RE: Need Help ! hi, I think U have to increase the maxActive in Ojb.properties. can u do that and verify. Basically that error says that it can't able to get the connection from pool. Rajadurai -Original Message- From: Sylvain Juge [mailto:[EMAIL PROTECTED] Sent: Wednesday, October 06, 2004 1:18 PM To: ojb-user Subject: Need Help ! I'm trying to use OJB API, and especially Object Persistance, but it doesn't work. I can build without any errors, the database schema is properly generated and executed on the RDBMS (MySQL). I've tried with default configuration files provided in ojb-blank, thus using embedded database, and I get exactly the same results. When I try to use PersistanceBroker, I've got two problems : -- I get an error because there's no default PBKey when I try to get the default Broker : broker = PersistenceBrokerFactory.defaultPersistenceBroker() results in : Exception in thread main org.apache.ojb.broker.PBFactoryException: There was no default-PBKey specified at org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersi sten ceBroker(PersistenceBrokerFactoryBaseImpl.java:157) at org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker( Pers istenceBrokerFactory.java:65) at PBSample.storeProduct(PBSample.java:19) at Application.run(Application.java:37) at Application.main(Application.java:28) -- When I try to use a specific PBKey created by hand : initially PersistenceBrokerFactory.getDefaultKey() returns null PBKey pbk = new PBKey(localmysql,root,); broker = PersistenceBrokerFactory.createPersistenceBroker(pbk); results in : Exception in thread main org.apache.ojb.broker.PBFactoryException: Borrow broker from pool failed, using PBKey org.apache.ojb.broker.PBKey: jcdAlias=localmysql, user=root, password=* at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPer sist enceBroker(PersistenceBrokerFactoryDefaultImpl.java:119) at org.apache.ojb.broker.PersistenceBrokerFactory.createPersistenceBroker(P ersi stenceBrokerFactory.java:86) at PBSample.storeProduct(PBSample.java:25) at Application.run(Application.java:37) at Application.main(Application.java:28) Caused by: org.apache.ojb.broker.PBFactoryException: Given PBKey org.apache.ojb.broker.PBKey: jcdAlias=default, user=root, password=* does not match in metadata configuration at org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.createNewBro kerI nstance(PersistenceBrokerFactoryBaseImpl.java:87) at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl$PBKeyedPo olab leObjectFactory.makeObject(PersistenceBrokerFactoryDefaultImpl.java:238) at org.apache.commons.pool.impl.GenericKeyedObjectPool.borrowObject(Generic Keye dObjectPool.java:792) at org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPer sist enceBroker(PersistenceBrokerFactoryDefaultImpl.java:100) ... 4 more However, the repository_database.xml file (in build/ressources), seems to be well configurated, here is the file : jdbc-connection-descriptor jcd-alias=localmysql default-connection=true platform=MySQL jdbc-level=3.0 driver=com.mysql.jdbc.Driver protocol=jdbc subprotocol=mysql dbalias=//localhost/proj1 username=root password= batch-mode=false useAutoCommit=1 ignoreAutoCommitExceptions=false object-cache class=org.apache.ojb.broker.cache.ObjectCacheDefaultImpl attribute attribute-name=timeout attribute-value=900/ attribute attribute-name=autoSync attribute-value=true/ attribute attribute-name=cachingKeyType attribute-value=0/ /object-cache connection-pool maxActive=21 validationQuery=@VALIDATION_QUERY@ testOnBorrow=@TEST_ON_BORROW@ testOnReturn=@TEST_ON_RETURN@ / sequence-manager className=org.apache.ojb.broker.util.sequence.SequenceManagerHighLowImp l
Re: Need help to auto-retrieve some individuals
Unless your Father has a very large number of children (as can occur in a Construction and the elements of construction in a price building system), you will find easier to get all childrens and implements two business methods in your Father bean: getFemaleChildrens() and getMaleChildrens(). So, you will have three ways to get the data you want, withou need to execute more than two selects on database. If you use JavaBeans based programming, when OJB call setChild, you can separate males and females, and kee each in theyr own list... Just my 2c, Edson Richter [EMAIL PROTECTED] wrote: Hi all, Lets say we have an object name Father, who has a Child class collection (aggregate association). With the right repository settings (autoretrieve= true etc.) every time we load a father from the database, the children will be instantiated (they may be proxies or materialized). Heres our ignorance: when we retrieve a father we need the retrieved children collection, to be just a subset of the all fathers children collection. The children are those with a any given attribute set to a any given value (let say just those children with gender attribute set to female). This is just like having a filter or criteria setting at the owned collection level. Please pay attention to the fact we do not want to filter the fathers based in some children attributes. We need retrieve all fathers, just filtering some children. We are aware we could retrieve the father an then iterate the collection discarding the children we do not need, but we need this to become a common feature for our classes, not just a business logic for a single app, therefore we would like to know how to handle this in general. Thanks in advance, Gustavo Faerman. Buenos Aires, Argentina - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need help to auto-retrieve some individuals
Thanks Edson for your quick answer. We ve already seen your approach. The problem we see with it,is in our real world, the fact that attributes values are more than two in some cases (male and female is just a set of two for this example), and as you say, in some cases there is a large numbre of childre. We envision our requirement (retrieving a subset of child objects) more as a behaviour pattern than a business method. Lets say attribute is something like the object state, and values could be active, inactive, suspended, deprecated, preferred etc. and let say as you suggest, there is a very large number of children. There are so many combinations to hard code business methods for each persistent class. OJB capabilities to retrieve collections are great. I would like to see them enhaced to be able to retrieve collection sub sets just passing some criteria. Arguments might be class collection name, attribute, value and connector (equal, not equal, less than etc.). In the mean time we are thinking about delegating this to a helper class or some storage controller thing in order to avoid coding class by class. We suspect this will not be that efficient in terms of database reads etc. compared to a pure OJB native solution. Thanks! Gustavo. Edson Carlos Ericksson Richter [EMAIL PROTECTED] wrote on 27/04/2004 09:55:28 a.m.: Unless your Father has a very large number of children (as can occur in a Construction and the elements of construction in a price building system), you will find easier to get all childrens and implements two business methods in your Father bean: getFemaleChildrens() and getMaleChildrens(). So, you will have three ways to get the data you want, withou need to execute more than two selects on database. If you use JavaBeans based programming, when OJB call setChild, you can separate males and females, and kee each in theyr own list... Just my 2c, Edson Richter [EMAIL PROTECTED] wrote: Hi all, Lets say we have an object name Father, who has a Child class collection (aggregate association). With the right repository settings (autoretrieve= true etc.) every time we load a father from the database, the children will be instantiated (they may be proxies or materialized). Heres our ignorance: when we retrieve a father we need the retrieved children collection, to be just a subset of the all fathers children collection. The children are those with a any given attribute set to a any given value (let say just those children with gender attribute set to female). This is just like having a filter or criteria setting at the owned collection level. Please pay attention to the fact we do not want to filter the fathers based in some children attributes. We need retrieve all fathers, just filtering some children. We are aware we could retrieve the father an then iterate the collection discarding the children we do not need, but we need this to become a common feature for our classes, not just a business logic for a single app, therefore we would like to know how to handle this in general. Thanks in advance, Gustavo Faerman. Buenos Aires, Argentina - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Need help to auto-retrieve some individuals
Hi Gustavo, did you see the query customizer stuff? http://db.apache.org/ojb/tutorial3.html#Customizing%20collection%20queries regards, Armin [EMAIL PROTECTED] wrote: Thanks Edson for your quick answer. We ve already seen your approach. The problem we see with it,is in our real world, the fact that attributes values are more than two in some cases (male and female is just a set of two for this example), and as you say, in some cases there is a large numbre of childre. We envision our requirement (retrieving a subset of child objects) more as a behaviour pattern than a business method. Lets say attribute is something like the object state, and values could be active, inactive, suspended, deprecated, preferred etc. and let say as you suggest, there is a very large number of children. There are so many combinations to hard code business methods for each persistent class. OJB capabilities to retrieve collections are great. I would like to see them enhaced to be able to retrieve collection sub sets just passing some criteria. Arguments might be class collection name, attribute, value and connector (equal, not equal, less than etc.). In the mean time we are thinking about delegating this to a helper class or some storage controller thing in order to avoid coding class by class. We suspect this will not be that efficient in terms of database reads etc. compared to a pure OJB native solution. Thanks! Gustavo. Edson Carlos Ericksson Richter [EMAIL PROTECTED] wrote on 27/04/2004 09:55:28 a.m.: Unless your Father has a very large number of children (as can occur in a Construction and the elements of construction in a price building system), you will find easier to get all childrens and implements two business methods in your Father bean: getFemaleChildrens() and getMaleChildrens(). So, you will have three ways to get the data you want, withou need to execute more than two selects on database. If you use JavaBeans based programming, when OJB call setChild, you can separate males and females, and kee each in theyr own list... Just my 2c, Edson Richter [EMAIL PROTECTED] wrote: Hi all, Lets say we have an object name Father, who has a Child class collection (aggregate association). With the right repository settings (autoretrieve= true etc.) every time we load a father from the database, the children will be instantiated (they may be proxies or materialized). Heres our ignorance: when we retrieve a father we need the retrieved children collection, to be just a subset of the all fathers children collection. The children are those with a any given attribute set to a any given value (let say just those children with gender attribute set to female). This is just like having a filter or criteria setting at the owned collection level. Please pay attention to the fact we do not want to filter the fathers based in some children attributes. We need retrieve all fathers, just filtering some children. We are aware we could retrieve the father an then iterate the collection discarding the children we do not need, but we need this to become a common feature for our classes, not just a business logic for a single app, therefore we would like to know how to handle this in general. Thanks in advance, Gustavo Faerman. Buenos Aires, Argentina - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help to auto-retrieve some individuals
Gustavo, You are proposing that your business object be partially loaded. This presents a problem because the collection represents all relations for a parent object (required for saving, updating, and deleting dependent objects). OJB has no way to know that a object is partially loaded, so a save will update all attributes and relations to the current state of the object. This could mean data loss or corruption. The solution I think you are looking for is to create a layer on top of OJB that returns value objects (NOT business objects) and loads the child collections manually using whatever criteria you want. You will have to deal with how to merge these value objects back into the business layer if you allow changes on the value objects. Hope this gives you a start. Wally -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 27, 2004 8:47 AM To: OJB Users List Subject: Re: Need help to auto-retrieve some individuals Thanks Edson for your quick answer. We ´ve already seen your approach. The problem we see with it,is in our real world, the fact that attributes values are more than two in some cases (male and female is just a set of two for this example), and as you say, in some cases there is a large numbre of childre. We envision our requirement (retrieving a subset of child objects) more as a behaviour pattern than a business method. Let´s say attribute is something like the object state, and values could be active, inactive, suspended, deprecated, preferred etc. and let say as you suggest, there is a very large number of children. There are so many combinations to hard code business methods for each persistent class. OJB capabilities to retrieve collections are great. I would like to see them enhaced to be able to retrieve collection sub sets just passing some criteria. Arguments might be class collection name, attribute, value and connector (equal, not equal, less than etc.). In the mean time we are thinking about delegating this to a helper class or some storage controller thing in order to avoid coding class by class. We suspect this will not be that efficient in terms of database reads etc. compared to a pure OJB native solution. Thanks! . Edson Carlos Ericksson Richter [EMAIL PROTECTED] wrote on 27/04/2004 09:55:28 a.m.: Unless your Father has a very large number of children (as can occur in a Construction and the elements of construction in a price building system), you will find easier to get all childrens and implements two business methods in your Father bean: getFemaleChildrens() and getMaleChildrens(). So, you will have three ways to get the data you want, withou need to execute more than two selects on database. If you use JavaBeans based programming, when OJB call setChild, you can separate males and females, and kee each in theyr own list... Just my 2c, Edson Richter [EMAIL PROTECTED] wrote: Hi all, Let's say we have an object name Father, who has a Child class collection (aggregate association). With the right repository settings (autoretrieve= true etc.) every time we load a father from the database, the children will be instantiated (they may be proxies or materialized). Here's our ignorance: when we retrieve a father we need the retrieved children collection, to be just a subset of the all father's children collection. The children are those with a any given attribute set to a any given value (let say just those children with gender attribute set to female). This is just like having a filter or criteria setting at the owned collection level. Please pay attention to the fact we do not want to filter the fathers based in some children attributes. We need retrieve all fathers, just filtering some children. We are aware we could retrieve the father an then iterate the collection discarding the children we do not need, but we need this to become a common feature for our classes, not just a business logic for a single app, therefore we would like to know how to handle this in general. Thanks in advance, Gustavo Faerman. Buenos Aires, Argentina - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Need help to auto-retrieve some individuals
The pattern I typically use for this is to provide accessors for the collection that take a filter: public interface Filter { public boolean accept(Object o); } public class CollectionUtil { public static List filter(List l, Filter f) { ArrayList result = new ArrayList(); for (int i = 0; i l.size(); i++) { Object item = l.get(i); if (f.accept(item)) result.add(item); } return result; } } public class Father { private List children; public List getChildren() { return children; } public List getChildren(filter f) { return CollectionUtil.filter(children, f); } } public class Child { private String gender; private int age; public String getGender() { return gender; } public int getAge() { return age; } // I typically then define common filters that I expect to be useful on the class of the object // being filtered but the client can define their own for other criteria public static final Filter MALES = new Filter() { public boolean accept(Object o) { return ((Child) o).getGender().equals(male); } }; public static final Filter FEMALES = new Filter() { public boolean accept(Object o) { return ((Child) o).getGender().equals(female); } }; public static final Filter MINORS = new Filter() { public boolean accept(Object o) { return ((Child) o).getAge() 18; } }; public static final Filter ADULTS = new Filter() { public boolean accept(Object o) { return ((Child) o).getAge() = 18; } }; } So the client code is just something along the lines of: List femaleChildren = father.getChildren(Children.FEMALES); It leaves itself open to defining composite filters and negating filters as well to combine conditions, i.e.: List femaleAdultChildren = father.getChildren(new CompositeFilter(Children.FEMALES, Children.ADULTS)); In this example the assumption is that all of the children are loaded into memory. As has been pointed out this works great if the collection of child objects is reasonable but you probably wouldn't want to take this approach if the children were in the 10's of thousands and the filter is fairly selective (male/female isn't very selective, you expect whichever query you do to return roughly half the collection). In a couple of situations like that I've used the same pattern but had the filter be a little more introspectable and implemented the equivalent of getChildren(filter) by introspecting on the filter and constructing a query object and doing a query to get the results. As Armin said there are query customizers as well. The problem I think you'll have there though is if the membership in the collection overlaps as in my male/female - adult/minor example above. The collections are really modeled to represent relationships not arbitrary queries. In this case each child is going to belong to two distinct collections, it's unclear to me what happens when you remove a child from the 'females' collection but I'm guessing there will be inconsistency with other collections you have currently loaded that contain that same child. -Original Message- From: Armin Waibel [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 27, 2004 8:52 AM To: OJB Users List Subject: Re: Need help to auto-retrieve some individuals Hi Gustavo, did you see the query customizer stuff? http://db.apache.org/ojb/tutorial3.html#Customizing%20collection%20queries regards, Armin [EMAIL PROTECTED] wrote: Thanks Edson for your quick answer. We ve already seen your approach. The problem we see with it,is in our real world, the fact that attributes values are more than two in some cases (male and female is just a set of two for this example), and as you say, in some cases there is a large numbre of childre. We envision our requirement (retrieving a subset of child objects) more as a behaviour pattern than a business method. Lets say attribute is something like the object state, and values could be active, inactive, suspended, deprecated, preferred etc. and let say as you suggest, there is a very large number of children. There are so many combinations to hard code business methods for each persistent class. OJB capabilities to retrieve collections are great. I would like to see them enhaced to be able to retrieve collection sub sets just passing some criteria. Arguments might be class collection name, attribute, value and connector (equal, not equal, less than etc.). In the mean time we are thinking about delegating this to a helper class or some storage controller thing in order to avoid coding