DAO and Domain Object

hi,
Normally when i want to persist a domain object like Customer object to a database, my statements will be below,
// code from my facade
Customer cust = new Customer();
cust.setFirstName("myname");
cust.setLastName("mylastname");
// set another attributes
cust.create();
with this code i have a CustomerPersistence object to handler for create this customer record to a database. Now j2ee have a DAO pattern. So my question is,
1.where is a domain object within DAO pattern? --> because of we can reused domain object.
2.DTO is Domain Object, isn't it?
3.when i look at some articles about DAO, many of it will present in this way
facade -->create DTO --> call DAO (plus something about factory pattern)
i never see something like this
facade --> domain object --> dao
any suggestion?
anurakth
sorry for my english!!

Hi,
I am a bit confused about implementation of the domain model and I wondered if you could help. My main concern is that I am introducing too many layers and data holders into the mix. Here is what I am thinking.
DTO - used to carry data between the presentation and the services layer
Service Class - coordinates the calling of domain objects
Domain Object - models a domain entity, service layer logic specific to this object is to be implemented here.
Data Object - an exact representation of a database table. many to many relationship between domain object and data object.
Hibernate DAO Class - has no properties, just methods used for read and writing the object to the database. It is passed in the Data Object for persistence. Is it wrong that the DAO contains no properties?
Perhaps the domain object will contain each data object it is comprised of. I was originally going to keep calls to DAOs in the Services class (as recommended in http://jroller.com/page/egervari/20050109#how_to_change_services_logic ) but I am thinking that each domain object could expose a save method, and that method would co-ordinate persisting itself to the various tables it is derived from.
Does this sound resonable? I have trouble finding a pattern on the net that clealy defines the Domain Model. I was tempted to map Domain Objects directly to database tables, and simply persist the Domain Object, but this 1-1 relationship may not always hold true.
Thanks.

Similar Messages

  • Choicebox with Domain-Objects

    Hi,
    I'm struggeling to find out how to deal with ChoiceBox and domain objects whose toString-method is not appropriate for the label. For ListView I'm able to set a cell factory where I was able to customize the domain to string translation but I'm unable to find something similar for ChoiceBox.
    Tom

    Guess what I've done [1] ;-)
    [1]https://github.com/tomsontom/emfdatabinding-tutorial/blob/master/org.eclipse.ufacekit.ui.jfx.databinding/src/org/eclipse/ufacekit/ui/jfx/databinding/controls/ChoiceBoxViewer.java

  • Domain Object and Service oriented pattern

    We have J2EE based application with following components, we are facing some issues with existing system.
    Current System : We have J2EE based application. The following is the flow.
    Client Layer [including JSP, Struts ] action classes  Delegates  Session fa�ade [Session bean]  DAO EJBDAO  EJB. We use CMP, xDoclets , JBOSS.
    1.     Our Domain objects are heavy. I know they are suppose to be coarse objects but they take more time in loading. Also, we noticed one thing that lot of methods are called during Domain Object creation process and it takes lot of time in loading. Actually, we dont really know what is happening as we are using CMPs.
    Question :
    -     Any input on what can be done to avoid Domain object excessive loading time.
    -     Anyone can share there experiences with Domain objects. Are you facing issues related with performance.
    -     We dont use DTO, we pass domain objects between. Do you see any problem in doing that.
    2.     Currently, our system was used by one single front end or lets say we have only one client but soon we will have more clients using it.
    Question :
    -     What should be our design approach. How can we make our system more like service oriented. If the two clients demand different business logic then how it will be handled. Business logic common to all the clients will be handled by which layer and business logic specific to client will be handles by which layer.
    -     Please suggest based on our existing infrastructure. We don�t want to use SOAP or cannot make drastic changes to our flow.
    We have domain and services in the same package and we are doing the refactoring of code, your inputs will be valuable.
    Thanks
    Sandipan

    What type of logger do you use and what is the loger-level during production?
    If it is log4j set the logger to level INFO or WARN.
    This might sound trivia but can make a difference between 20seconds and 500 ms.

  • Adding domain objects

    Hello,
    I'm working with an application where we have many, many, many domain objects that could be added to a "header". In my business/service interface I don't like to write 50+ of addX(...), addY(...), addZ(...) etc. methods.
    Every domain object extends a domain object base class. In my business/service interface I've added one single method for adding domain objects to make the interface somewhat smaller:
    public void add(DomainObject[] someDomainObjects);
        ...The elements of the domain object array are of different kind, but all extends the domain object base class. I'd like to implement class and method that have a strategy for determining what kind of domain object the current one is in the given array and invoke the correct add(...) method for that particular domain object.
    The most simple way of doing it is to have a very big if-else using instanceof to determine what kind of domain object it is, but it doesn't feel like a very nice design.
    Example:
    public class MyBusinessObject {
        public void add(DomainObject[] someDomainObjects) {
            // Iterate over all domain objects in the array
            for (DomainObject domainObject : someDomainObjects) {
                // Determine what kind of domain object it is and create the correct DAO
                if (domainObject instanceof X) {
                    DomainObjectXDao xDao = new DomainObjectXDao();
                    // Save the current domain object
                    xDao.save((X) domainObject);
                } else if (domainObject instanceof Y) {
                    DomainObjectYDao yDao = new DomainObjectYDao();
                    // Save the current domain object
                    yDao.save((Y) domainObject);
                } else if (domainObject instanceof Z) {
                    DomainObjectZDao zDao = new DomainObjectZDao();
                    // Save the current domain object
                    zDao.save((Z) domainObject);
                } else if (...) {
    }Is there any design pattern for making this a more nice design?
    If anyone could contribute with their good knowledge I'd be very glad!
    Regards, Andreas Eriksson

    Map the DomainObject types to their respective DAOs and look them up as you loop through them in the add method, e.g.:
    public class MyBusinessObject {
      private Map daos = new HashMap();
        daos.put(X.class, new XDomainTypeDAO());
        daos.put(Y.class, new YDomainTypeDAO());
        daos.put(Z.class, new ZDomainTypeDAO());
      public void add(DomainObject[] objs) {
        for (DomainObject obj : objs) {
          Class type = obj.getClass();
          DAO dao = (DAO) daos.get(type);
          if (dao == null) {
            throw new IllegalArgumentException(
              "No DAO configured for DomainObject type " + type);
          dao.save((DomainObject) obj);
    }You'd have to create a DAO interface (or abstract base class) which defines a save method with the signature public void save(DomainObject obj). Then each DAO would have to implement this method and cast the passed domain object to the expected type.
    To take things further, you could introduce a DAOProvider interface to hide where the MyBusinessObject obtains the DAOs from (rather than have it maintain the map), e.g.:
    public interface DAOProvider {
      DAO daoFor(Class domainType);
    // A really simple implementation - assmes that DAOs are thread-safe
    public class SimpleDAOProvider implements DAOProvider {
      private Map daos = new HashMap();
        daos.put(X.class, new XDomainTypeDAO());
        daos.put(Y.class, new YDomainTypeDAO());
        daos.put(Z.class, new ZDomainTypeDAO());
      public DAO daoFor(Class domainType) {
         DAO dao = (DAO) daos.get(type);
         if (dao == null) {
           throw new IllegalArgumentException(
             "No DAO configured for DomainObject type " + domainType);
        return dao;
    }The advantage of this is you can alter the strategy for handing out DAOs, e.g. pass the same instance back each time, or dynamically instantiate a new instance, etc. Of course, you need a way for the MyBusinessObject to get hold of a DAOProvider instance (inject it? Have it use a factory?)

  • Differece b/w dataelement and domain

    hi every body
    when creating table after giving the column name we can mention the direct type or specify the data element. in data element we mention data types and other properties, similarlay in dataelemens we can also specify the domain.
    my question is that what the relationship or diff. b/w data element and domain. plz clear my concepts.
    Rai.

    Domain is the central object for describing the technical characteristics of an attribute of an business objects. It describes the value range of the field. Data Element: It is used to describe the semantic definition of the table fields like description the field. Data element describes how a field can be displayed to end-user.
    A domain defines the properties of a data element within ABAP. The properties include the data element type, it's length if required and any restrictions on the values that may be entered into that variable. By defining a domain you can automate and greatly reduce the amount of work required when handling amongst other things user input parameters. Domains also standardise your programs. By using a domain rather than individually defining the variables within your program, any changes to the domains characteristics are automatically passed on to any programs that use that domain
    A dataelement is the one which has the information about the field's representation on the screen in the form of FIELD TEXTS, COLUMN CAPTIONS in list outputs of the table contents and the format of the output via PARAMETER IDS and Online field documentation.
    Cheers
    Nishanth

  • Using domain object instead of generated ones?

    I'm using NetBeans, and I'm curious if there's a way that we can use our domain objects with the web service calls rather than the empty stubs generated by wsgen?
    wsgen creates the skeletal client classes, as well as an ObjectFactory that returns instances of those classes. I imagine I could modify ObjectFactory to return our domain objects instead, but then we'd be breaking with wsgen.
    Is there a better solution to this?
    Thanx!

    You can associate a Virtual Host to the loopback IP address 127.0.0.1 read about Virtual Hosts here: http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
    But with the above configuration alone you can access your app via http://somedomainname.com only on your local machine, no one else on the internet will see it.

  • Require cert and domain credentials to authenticate?

    Is there a way to require a machine certificate AND domain credentials to authenticate to a wireless network (Cisco LWAPP, ACS, AD)? 
    My objectives are:
    Permit access from corporate hardware ONLY, i.e., prevent users from logging from a personal laptop or PDA using their domain credentials.
    Validate that an employee is logging on to the network. 
    My current PEAP implementation only satisfies the second condition and from everything I have read EAP-TLS will only satisfy the first.  Is there a solution?
    thanks

    PEAP or EAP-TLS with machine auth will do  the first one then the user can log in as normal with their user credentials.

  • How to combine Session Facade and Transfer object?

    Hello All!
    I'm working on an enterprise application. Presentation layer is a stand alone client, business logic is build on the Glassfish v2.1 and MySQL is used as a database. The client is connection to the GlassFishj server remotely using EJBs.
    I have problems with business logic architecture.
    Here is the brief description of backend application architecture design:
    1. Session Facade pattern is used to simplify the client and application server interface and to provide application layers between backend (http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html).
    2.Transfer Object pattern to define update transfer objects strategy in order to decrease network overhead during client and application server interactions and to provide version control for objects. Transfer objects are designed as simple java business serializable objects. (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html)
    3. Originally the backend application consisted of three modules: users, storage and orders, but at the end I have decided to divide my application into the following parts - assortments, map, menu, orders, transactions, users.
    4. All MySQL database transactions are via JDBC using procedures. No use of entity beans.
    Questions:
    1. I have some doubts about using Session Facade and Transfer object patterns at the same time. At first I'd mike to cite the definitions of the patters from the SUN official web site.
    * Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.
    * Use a Transfer Object to encapsulate the business data. A single method call is used to send and retrieve the Transfer Object. When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with its attribute values, and pass it by value to the client.
    * So, if I use Transfer Object along with Session Facade, it makes some difficulties with object version control, because I 2 or
    3 transfer objects controls with the 1 bean class. The best option for Transfer object Pattern is that each transfer object should have its own bean class to provide ability of object's version control. In the case it can bring the network overhead because of frequent remote calls caused by the large number of the bean classes.
    * So, should I use the both patterns? If yes, how to manage the interaction the patterns. If no, which one to use.
    2. E.g. I have a huge list of the Order objects and each Order object consists of other complicated objects. So, would I have trouble to transfer that list over network? If yes, how to manage it.
    Thank you!
    Astghik

    Astghik wrote:
    Hello All!
    I'm working on an enterprise application. Presentation layer is a stand alone client, business logic is build on the Glassfish v2.1 and MySQL is used as a database. The client is connection to the GlassFishj server remotely using EJBs.
    I have problems with business logic architecture.
    Here is the brief description of backend application architecture design:
    1. Session Facade pattern is used to simplify the client and application server interface and to provide application layers between backend (http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html).
    I would simply recommend establishing a service tier. Your services should be stateless. You can go the extra mile and have a session facade, but in the majority of cases, coding to an interface for your service accomplishes the same goals.
    2.Transfer Object pattern to define update transfer objects strategy in order to decrease network overhead during client and application server interactions and to provide version control for objects. Transfer objects are designed as simple java business serializable objects. (http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html)
    The idea of the transfer object is very similar to the Command pattern. I think if you investigate that pattern, it will be more obvious. The transfer object reduces network latency by consolidating all the parameters into an object, ideally, this also consolidates multiple method calls. If you combine a transfer object (or command object) with a service tier, you get the best of both worlds. The service can delegate calls to helper objects (or other services or components) using the data in the transfer / command object.
    3. Originally the backend application consisted of three modules: users, storage and orders, but at the end I have decided to divide my application into the following parts - assortments, map, menu, orders, transactions, users.
    The is your domain. It will vary from application to application. The principles above are more general (e.g., patterns and architectural tiers) and should apply to most domains. However, your actual use case may require something different.
    4. All MySQL database transactions are via JDBC using procedures. No use of entity beans.
    Consider using something like iBatis or Spring's JDBC templating to make your life easier with JDBC.
    Questions:
    1. I have some doubts about using Session Facade and Transfer object patterns at the same time. At first I'd mike to cite the definitions of the patters from the SUN official web site.
    * Use a session bean as a facade to encapsulate the complexity of interactions between the business objects participating in a workflow. The Session Facade manages the business objects, and provides a uniform coarse-grained service access layer to clients.
    * Use a Transfer Object to encapsulate the business data. A single method call is used to send and retrieve the Transfer Object. When the client requests the enterprise bean for the business data, the enterprise bean can construct the Transfer Object, populate it with its attribute values, and pass it by value to the client.
    * So, if I use Transfer Object along with Session Facade, it makes some difficulties with object version control, because I 2 or
    3 transfer objects controls with the 1 bean class. The best option for Transfer object Pattern is that each transfer object should have its own bean class to provide ability of object's version control. In the case it can bring the network overhead because of frequent remote calls caused by the large number of the bean classes.
    * So, should I use the both patterns? If yes, how to manage the interaction the patterns. If no, which one to use.
    Versioning is a separate issue. Generally, the more coarsely grained your transfer / command object is, the more changes are likely to impact dependent objects.
    Your command or transfer object does not have to be a vanilla JavaBean, where you are basically creating a bean that has data from other objects. You can simply use your command / transfer object to encapsulate already existing domain objects. I see no need to map to a JavaBean with what you have described.
    Generally, a method signature should be understandable. This means that many times it is better to pass the method, say, two coarsely grained objects than a signature with a dozen primitives. There are no hard and fast rules here. If you find a method signature getting large, consider a transfer / command object. If you want one service to delegate calls to a number of other services, you can also create a transfer / command object to furnish the controlling service with the data it needs to invoke the dependent services.
    2. E.g. I have a huge list of the Order objects and each Order object consists of other complicated objects. So, would I have trouble to transfer that list over network? If yes, how to manage it.
    This is a large, open-ended question. If you are going to display it to a user on a screen, I do not see how you avoid a network transfer with the data. The general answer is to not pass the data itself but rather a token (such as a primary key, or a primary key and a start and stop range such as you see on a Google search result). You do want to limit the data over the network, but this comes at a cost. Usually, the database will receive additional load. Once that becomes unacceptable, you might start putting things into session. Then you worry about memory concerns, etc. There is no silver bullet to the problem. It depends on what issues you are trying to address and what trade-offs are acceptable in your environment.
    Thank you!
    AstghikBest of luck.
    - Saish

  • What is different between conflict object and lingering object in AD

    Hi
    I found lots of conflict object in my Forest on AD 2k8R2 with FFL & DFL 2k3 with dsquery filter "(name=*\0ACNF:*).
    But Only I can see 4 to 5 AD object in ADUC.
    How can I found others.
    Also these conflict object are replicated with AD replication? and due to these conflict object, can be any issue in AD replication like slow replication or delay replication?
    If I delete them then how can I delete and which command or tool like LDP?
    Also Is conflict AD Object and lingering objects means are same?
    Please suggest and guide..
    See below link of my conflict object ..
    http://sdrv.ms/19DUTbi

    IT means... If I don't find duplicate or conflict object in ADUC then I no need to worry about it as after AD tombstone lifetime period, these conflict object would be delete automatically ...?
    Conflict objects can be duplicate or lingering objects both & you need to worry. Consider an example, if you have a system named abc & you try to join another system with the same name from other site DC where connection b/w other DC's are down &
    ABC information is not present in that local DC, it will allow you to join system in the domain with the same name, then the object joined later vl have CNF added.
    Another case, two new systems are joined together from two different AD site with the same name, it will allow you to join & once replication occurs, you will find duplicate name with CNF.
    Same problem happens, when you connect old DC which has crossed TSL. WHat happens here is you have most recent DC with the deleted objects, when you connect old DC which has not received replication & crossed TSL, again during replication, you will see
    objects with CNF which will be lingering objects.
    So, CNF objects can be duplicate & lingering objects both & in both the case, i'll worry. Lingering objects are not visible directly, you can find out using repadmin tool. It is really complex to clean them if they exists in the ready only partition
    of the GC.
    http://technet.microsoft.com/en-us/library/cc738018%28v=ws.10%29.aspx
    Awinish Vishwakarma - MVP
    My Blog: awinish.wordpress.com
    Disclaimer This posting is provided AS-IS with no warranties/guarantees and confers no rights.

  • DAO and DTO

    In the following piece of code:-
    package com.informit.myejb.dao;
    public interface SampleDAO
    public SampleModel create( long id, String name, String data ) throws
    SampleDAOException;
    public void delete( long id ) throws SampleDAOException;
    public void update( long id, SampleModel model ) throws
    SampleDAOException;
    public SampleModel[] findByName( String name ) throws
    SampleDAOException;
    public SampleModel findById( long id ) throws SampleDAOException;
    }we are creating a DTO named sampleModel. Now considering that I just need one value out of the whole table. Wouldn't creating the whole DTO object be a waste of time effort and memory, specially if each time we hae to access the DTO we have to create a new one. specially if the keys being passed to the method are used only once.
    I understand the concept of separation of concerns but I am concerned over here about the amount of effort required to create these DAOs and DTOs specially in cases where only one or two fields are required.
    To me it seems like an over kill.
    Any comments.

    well Martin Fowlwer does propose IdentityMap pattern in such a case where he says that thes objects should be stored in a Map with the primary key being the key for the map. So next time you need an object you check with the map if it exists or not and if it doesnot you try to grab it again.
    But IMHO if the hit ratio(no. of times the same data is used again) is less these Maps might pose a nightmare in terms of memory and garbage collection.
    So should one use IdentityMap or avoid it?
    What do you think.

  • Bean vs Domain Object Responsibility

    Any thoughts out there regarding the decision point on when to put functionality into a domain object (Customer, Order, Address, etc.) versus when to put it into an EJB that you plan to use? You usually start defining your object model and as you create sequence diagrams or collab. diagrams, you begin assigning methods to the classes. But at what point do you decide that functionality does NOT belong in the domain object and instead belongs outside of that object? EJBs have the ability to perform a lot of the work in an N-Tier system, so how do you draw the line on where the functionality goes? Any articles on the subject?
    Thnx.
    Dave

    Any thoughts out there regarding the decision point on
    when to put functionality into a domain object
    (Customer, Order, Address, etc.) versus when to put it
    into an EJB that you plan to use? When you need to access system resources, like connecting to the database, you may place the functionality in EJB. When you need to perform task of processing the domain object related information like the net purchase of the customer then you place the functionality in the domain object.
    You usually start
    defining your object model and as you create sequence
    diagrams or collab. diagrams, you begin assigning
    methods to the classes. But at what point do you
    decide that functionality does NOT belong in the
    domain object and instead belongs outside of that
    object? EJBs have the ability to perform a lot of the
    work in an N-Tier system, so how do you draw the line
    on where the functionality goes? Any articles on the
    subject?
    Thnx.
    DaveThats my opinion.
    Best Regards,
    Amitabh Choudhury.

  • What is a Domain Object?

    I checked dozens of internet pages but didn't find an answer on that question.

    Domain is everything meaningful in the scope of
    current task, thus domain object is an abstraction of
    the real or imaginable entity from the scope of
    current task.Can you please give me an example?
    I will now explain a little bit why I am asking. But please don't forget to give me an example.
    We use the root object as a domain object. "Article" is a domain object in our company. An Article has a 1:m relationship with a "PackageUnit". The PackageUnit is no domain object. Furthermore the PackageUnit has a 1:m relationship with SalesHistoryWeek (which is no domain object too) and so on.
    Only the domain object (Article) can create new instances of the objects which are linked to it (PackageUnit and so on). A PackageUnit cannot create a new instance of SalesHistoryWeek, only Article can do this, the domain object.
    Furthermore only the domain object has getter and setter methods for the linked non domain objects. So the domain object "jumps" over many knots to get or set an object.
    I think this is a strange design and so I am asking here for the meaning of domain objects. Besides this, the coupling of objects is very large in my example and it doesn't respect the Law of Demeter.
    What do you think?

  • Domain object

    Hello!
    I use Spring back-end layer, when I communicate domain
    objects(Flex - Java), on the server I have zero in int, double
    fields, on the client this fields are declared as int and Number.
    Only String type transfer correctly!!!
    How I can resolve this problem?
    //Flex d-o
    [Bindable]
    [RemoteClass(alias="com.home.flex.bean.GoodsBN")]
    public class Goods
    public var idGoods:int;
    public var code:int;
    public var name:String;
    public var weight:int;
    public var type:String;
    public var category:String;
    public var incomeDate:Date;
    public var description:String;
    public var price:Number;
    public function Goods()
    //Java d-o
    public class GoodsBN //implements Serializable
    private int idGoods;
    private int code;
    private String name;
    private int weight;
    private String type;
    private String category;
    private Date incomeDate;
    private String description;
    private double price;
    public GoodsBN()
    ///getter and setter.....

    "vscmaster" <[email protected]> wrote in
    message
    news:gii9eo$4dl$[email protected]..
    > Hello!
    > I use Spring back-end layer, when I communicate domain
    objects(Flex -
    > Java),
    > on the server I have zero in int, double fields, on the
    client this fields
    > are
    > declared as int and Number.
    >
    > Only String type transfer correctly!!!
    >
    > How I can resolve this problem?
    I think Number _is_ the AS3 equivalent of Double

  • Shoul I have my backing beans extend my domain objects?

    Hi,
    In our JSF application, most of our backing beans have the same properties that a corresponding domain object.
    In order to have a clear separation between layers, we have a set of view objects and a separate set of domain objects. Once we populate the backing bean, we copy the value of properties to the domain object.
    Since all the properties of my domain object are duplicated in my backing beans, we were wondering if it is a good (or bad) idea to extend (inherit) my backing beans from my domain objects, and pass the backing beans to my persistence and business layers. This will save us some work.
    Thanks a lot for the advice.
    Mauricio L.

    I think I've solved my own issue though I'm not sure if it is the correct way to accomplish the task at hand.
    When the button for login is clicked and the logginButton_action() method is called inside of my login_jsp_backing class I do the following:
    User user = new User();
    FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("User", user);
    return user.doLogin(this.getInputUsername().getValue().toString(), this.getInputPassword().getValue().toString());
    (The String return of this method in User is a navigation rule I've setup in my faces-config)
    So my new question is that "Is this best practice?" or should I be doing it differently?
    Message was edited by:
    Steve Carlson

  • How to bind Hibernate domain objects to the UI layer

    Dear All,
    I am trying to bind FX UI controls to properties of a Hibernate Domain object. Is there any good example to refer to for this purpose?
    Thanks & Regards,
    Nitin Gupta

    Assuming you do not formulate your hibernate objects as pojos with javafx properties directly, if the hibernate object is a pojo with or without PCL, you can convert the properties of the pojo to observable values (or properties) directly. These are used in a bind statement.
    Check out what jgoodies does with BeanAdapter or PresentationModel. You need the same concept. I've attached a class that does this for a pojo already (its an incomplete port of jgoodies PresentationModel). It will work for any pojo. It does not have setter support as it was just a demonstration. Its efficient for a pojo with a large number of properties. You could also write a very short property connector to produce one observable value per property. The value of the class below is to be able to swap out the bean being observed without having to change or reset the property observable values each time. Bind once and then just reset the bean (think master detail).
    package scenegraphdemo;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.lang.reflect.Method;
    import java.util.HashMap;
    import java.util.Map;
    import javafx.beans.property.ObjectProperty;
    import javafx.beans.property.ObjectPropertyBase;
    import javafx.beans.property.Property;
    import javafx.beans.property.StringProperty;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.beans.value.WritableValue;
    * An object binding object that creates object bindings based on property names
    * specified as strings. This is a convenience class to avoid having observable
    * values directly dependent on the underlying bean. The actual bean the
    * properties connect can be changed dynamically using the channel or
    * <code>setBean</code>. This allows you to setup binding when you don't have
    * the bean to bind to or the bean to bind to will change as in the detail part
    * of a master-detail screen. Generally, the return values from
    * <code>getProperty()</code> should be used for binding not the factory itself.
    * The object should be a domain object bean with bean methods to get or set the
    * value using java bean naming conventions OR it should use javafx property
    * definition conventions. The factory will automatically listen for standard
    * java bean changes using <code>PropertyChangeListener</code> approaches unless
    * you indicate to not to.
    * <p>
    * When the bean itself changes, the properties fire to indicate that their
    * values may have changed and the observing object should update itself. This
    * object allows you to integrate your javafx/POJOs into the binding
    * infrastructure without being dependent on the actual underlying bean. If you
    * are familiar with jgoodies <code>BindingAdapter</code> this is a similar
    * class.
    * <p>
    * This only handles reading bean properties. Need to add set() logic.
    * <p>
    * TODO: Make this work better. Many corner cases to cover.
    * <p>
    * TODO: Instead of just method calls on POJOs, also check for PCL. Note that
    * javafx properties won't work easily they are always tied to the underlying
    * object so I would have to write another CaptiveObjectProperty object that is
    * essentially a delegator.
    public class BeanPropertyFactory<T> extends ObjectProperty<T> {
         ObservableValue<T> channel;
         Map<String, CaptiveObjectProperty> properties = new HashMap<String, CaptiveObjectProperty>();
         boolean listenForBeanPCLEvents = true;
         public boolean isListenForBeanPCLEvents() {
              return listenForBeanPCLEvents;
         public void setListenForBeanPCLEvents(boolean listenForBeanPCLEvents) {
              this.listenForBeanPCLEvents = listenForBeanPCLEvents;
              if (getBean() != null)
                   removeBeanPCLListener(getBean());
          * The bean channel where the bean is obtained.
          * @return
         public ObservableValue<T> getChannel() {
              return channel;
         public BeanPropertyFactory() {
              setChannel(new ObjectProperty());
         public BeanPropertyFactory(ObservableValue<T> channel) {
              if (channel == null)
                   setChannel(new ObjectProperty());
              else
                   setChannel(channel);
         protected void setChannel(ObservableValue<T> channel) {
              if (this.channel != null) {
                   removeBeanChangeListener(this.channel);
              this.channel = channel;
              if (this.channel != null) {
                   addBeanChangeListener(this.channel);
                   updateStringProperty(getBean());
              invalidateProperties();
              fireValueChangedEvent();
         protected StringProperty stringProperty = new StringProperty();
          * The string property is an observable toString property. It cannot be set.
          * @return
         public StringProperty beanStringProperty() {
              return stringProperty;
         public String getBeanString() {
              return beanStringProperty().getValue();
          * A listener that listens to changes in the bean channel. This only fires
          * when the bean changes not when the properties on the bean change. The
          * default actions updates the "string" property representation of this
          * object as well as attaches property change listeners.
          * @author Mr. Java
         protected class BeanChangeListener implements ChangeListener {
              @Override
              public void changed(ObservableValue arg0, Object arg1, Object arg2) {
                   if (arg1 != null) {
                        BeanPropertyFactory.this.removeBeanPCLListener(arg1);
                   if (arg2 != null) {
                        BeanPropertyFactory.this.addBeanPCLListener(arg2);
                   updateStringProperty(arg2);
         protected void updateStringProperty(Object obj) {
              if (obj != null)
                   beanStringProperty().setValue(obj.toString());
              else
                   beanStringProperty().setValue("null");
         protected void removeBeanChangeListener(ObservableValue<T> obj) {
              if (beanChangeListener == null)
                   beanChangeListener = createBeanChangeListener();
              if (obj != null) {
                   obj.addListener(beanChangeListener);
         protected void addBeanChangeListener(ObservableValue<T> obj) {
              if (beanChangeListener == null)
                   beanChangeListener = createBeanChangeListener();
              if (obj != null)
                   obj.removeListener(beanChangeListener);
          * The instance of a change listener for detecting when the bean in the bean
          * channel changes.
         ChangeListener beanChangeListener = new BeanChangeListener();
          * Subclass can override to create their bean change listener.
          * @return
         protected ChangeListener createBeanChangeListener() {
              return new BeanChangeListener();
         public BeanPropertyFactory(T bean) {
              setChannel(new ObjectProperty(bean));
         public Property getProperty(String property) {
              if (property == null || property.isEmpty())
                   throw new IllegalArgumentException("Property cannot be null");
              if (properties.containsKey(property))
                   return properties.get(property);
              CaptiveObjectProperty p = new CaptiveObjectProperty(this, property);
              properties.put(property, p);
              return p;
         @Override
         public T getValue() {
              return getBean();
          * A listener that listens for property change events on the bean. When the
          * bean changes, the listener must be removed then attached to the new bean
          * but can use the same instance of this class. The action is to inform any
          * existing property objects that the property has changed. The detection of
          * property changes is centralized in the factory class for efficiency.
         protected class BeanPropertyListener implements PropertyChangeListener {
              @Override
              public void propertyChange(PropertyChangeEvent evt) {
                   if (properties.containsKey(evt.getPropertyName())) {
                        CaptiveObjectProperty p = properties.get(evt.getPropertyName());
                        p.propertyChanged();
                   updateStringProperty(getBean());
          * The cached listener instance to listen to the bean (in the bean channel)
          * property change events if it supports PCL.
         PropertyChangeListener beanPropertyListener;
          * Subclasses can override to implement their own behavior. Its best to
          * extend from <code>BeanPropertyListiner</code> to include the default
          * behavior.
          * @return
         protected PropertyChangeListener createBeanPropertyListener() {
              return new BeanPropertyListener();
          * Add a listener only if the PCL methods exist. This listens for property
          * changes on the bean's property not changes in the actually bean held by
          * the bean channel.
         protected void addBeanPCLListener(Object obj) {
              if (!isListenForBeanPCLEvents())
                   return;
              if (obj != null) {
                   if (BeanPropertyUtils.hasPCL(obj.getClass())) {
                        if (beanPropertyListener == null)
                             beanPropertyListener = createBeanPropertyListener();
                        BeanPropertyUtils.addPCL(obj, beanPropertyListener, null);
          * Remove a listener only if the PCL methods exist.
          * @see #attachBeanPCLListener
         protected void removeBeanPCLListener(Object obj) {
              if (obj != null) {
                   if (BeanPropertyUtils.hasPCL(obj.getClass())) {
                        if (beanPropertyListener == null)
                             beanPropertyListener = createBeanPropertyListener();
                        BeanPropertyUtils.removePCL(obj, beanPropertyListener, null);
          * Invalidate the properties in the property cache. Then changed the bean in
          * the bean channel. Then fire a value changed event.
          * @param bean
         public void setBean(T bean) {
              invalidateProperties();
              if (getChannel() instanceof WritableValue) {
                   ((WritableValue) getChannel()).setValue(bean);
              } else {
                   throw new IllegalArgumentException(
                             "Could not set bean value into a non-writable bean channel");
              fireValueChangedEvent();
          * Called to indicate that the underlying bean changed.
         protected void invalidateProperties() {
              for (CaptiveObjectProperty p : properties.values()) {
                   p.invalidate();
         public T getBean() {
              return getChannel().getValue();
          * Lazily get the method representing the property prior to getting or
          * setting. Because this is a property, it can also be bound to.
          * @author Mr. Java
          * @param <T>
         protected static class CaptiveObjectProperty<T> extends
                   ObjectPropertyBase<T> {
               * The string name of the property.
              String readPropertyName, writePropertyName;
               * If the property is really a javafx property, it is stored here.
              Property<T> enhancedProperty;
               * Used if the property is not an enhanced property.
              Method readMethod, writeMethod;
               * The factory that holds the bean we obtain values against.
              BeanPropertyFactory factory;
              public CaptiveObjectProperty(BeanPropertyFactory factory,
                        String property) {
                   this.readPropertyName = property;
                   this.factory = factory;
              public CaptiveObjectProperty(BeanPropertyFactory factory,
                        String property, String writePropertyName) {
                   this.readPropertyName = property;
                   this.writePropertyName = writePropertyName;
                   this.factory = factory;
              @Override
              public Object getBean() {
                   if (factory == null || factory.getBean() == null)
                        return null;
                   return factory.getBean();
              @Override
              public void store(T value) {
                   if (writeMethod == null && enhancedProperty == null) {
                        getWriteMethod(value.getClass());
                   if (writeMethod == null && enhancedProperty == null) {
                        return;
                   try {
                        if (enhancedProperty != null) {
                             enhancedProperty.setValue(value);
                             return;
                        if (getBean() == null)
                             return;
                        writeMethod.invoke(getBean(), value);
                        return;
                   } catch (Exception e) {
                        e.printStackTrace();
              @Override
              public T getValue() {
                   if (readMethod == null && enhancedProperty == null) {
                        getReadMethod();
                   if (readMethod == null && enhancedProperty == null)
                        return null;
                   try {
                        if (enhancedProperty != null)
                             return enhancedProperty.getValue();
                        if (factory.getBean() == null)
                             return null;
                        Object rval = readMethod.invoke(getBean());
                        return (T) rval;
                   } catch (Exception e) {
                        e.printStackTrace();
                   return null;
              @Override
              public String getName() {
                   return readPropertyName;
               * Invalidate the method. Perhaps the bean changed to another object and
               * we should find the method on the new object. This is called prior to
               * the <code>getBean()</code> being changed.
              public void invalidate() {
                   readMethod = null;
                   fireValueChangedEvent();
               * This is used to externally signal that the property has changed. It
               * is quite possible that this object does not detect those changes and
               * hence, an external object (in all cases the BeanPropertyFactory) will
               * signal when a change occurs. Property change detection is centralized
               * in the factory for efficiency reasons.
              public void propertyChanged() {
                   fireValueChangedEvent();
              protected Property getJavaFXReadProperty(String propertyName) {
                   if (factory.getBean() == null)
                        return null;
                   String methodName = getName() + "Property";
                   try {
                        Method mtmp = factory.getBean().getClass()
                                  .getMethod(methodName, new Class<?>[0]);
                        enhancedProperty = (Property) mtmp.invoke(factory.getBean(),
                                  new Object[0]);
                        return enhancedProperty;
                   } catch (Exception e) {
                        // e.printStackTrace();
                        // silently fail here
                   return null;
              protected void getWriteMethod(Class<?> argType) {
                   if (factory == null || factory.getBean() == null)
                        return;
                   if (enhancedProperty == null)
                        enhancedProperty = getJavaFXReadProperty(getName());
                   if (enhancedProperty != null)
                        return;
                   writeMethod = getPojoWriteMethod(getName(), argType);
               * Sets the method, either an enhanced property or the POJO method via
               * reflection.
               * @return
              protected void getReadMethod() {
                   if (factory == null || factory.getBean() == null)
                        return;
                   enhancedProperty = getJavaFXReadProperty(getName());
                   if (enhancedProperty != null)
                        return;
                   // Look for standard pojo method.
                   readMethod = getPOJOReadMethod(getName());
               * Return a get method using reflection.
               * @param propertyName
               * @return
              protected Method getPOJOReadMethod(String propertyName) {
                   if (factory.getBean() == null)
                        return null;
                   // Look for standard pojo method.
                   String methodName = getGetMethodName();
                   try {
                        Method mtmp = factory.getBean().getClass()
                                  .getMethod(methodName, new Class<?>[0]);
                        return mtmp;
                   } catch (Exception e) {
                        // silently fail here
                        // e.printStackTrace();
                   return null;
              protected String getGetMethodName() {
                   String methodName = "get"
                             + Character.toUpperCase(getName().charAt(0));
                   if (getName().length() > 1)
                        methodName += getName().substring(1);
                   return methodName;
               * Return a set method using reflection.
               * @param propertyName
               * @param argType
               * @return
              protected Method getPojoWriteMethod(String propertyName,
                        Class<?> argType) {
                   if (factory.getBean() == null)
                        return null;
                   String methodName = getSetMethodName();
                   try {
                        Method mtmp = factory.getBean().getClass()
                                  .getMethod(methodName, argType);
                        return mtmp;
                   } catch (Exception e) {
                        // silently fail here
                        // e.printStackTrace();
                   return null;
              protected String getSetMethodName() {
                   String methodName = "set"
                             + Character.toUpperCase(getName().charAt(0));
                   if (getName().length() > 1)
                        methodName += getName().substring(1);
                   return methodName;
          * Obtain a property using the binding path. The binding path should be
          * simple property names separated by a dot. The bean has to specified
          * because the return value is a property that can be used directly for
          * binding. The first property specified in the binding path should be a
          * property on the bean.
          * <p>
          * The difference between this and <code>Bindings.select()</code> is not
          * much other that it uses the bean factory machinery and the path can be
          * specified as a string. Of course, the bean can be a plain pojo.
          * @param bindingPath
          * @return
         public static Property propertyFromBindingPath(Object bean,
                   String bindingPath) {
              if (bindingPath == null || bindingPath.isEmpty())
                   return null;
              BeanPropertyFactory lastFactory = null;
              Property lastProperty = null;
              String[] parts = bindingPath.split("\\.");
              if (parts.length > 0) {
                   for (int i = 0; i < parts.length; i++) {
                        if (parts.length() <= 0 || parts[i].isEmpty()) {
                             throw new IllegalArgumentException("Binding path part " + i
                                       + " has no length");
                        BeanPropertyFactory newFactory;
                        if (i == 0)
                             newFactory = new BeanPropertyFactory(bean);
                        else
                             newFactory = new BeanPropertyFactory(
                                       (WritableValue) lastProperty);
                        lastProperty = newFactory.getProperty(parts[i].trim());
                        lastFactory = newFactory;
              return lastProperty;
         * Alot like <code>Bindings.select</code> but also handles pojos.
         * @param bean
         * @param path
         * @return
         public static Property propertyFromBindingPath(Object bean, String... path) {
              String tmp = "";
              for (int i = 0; i < path.length; i++) {
                   tmp += path[i];
                   if (i <= path.length - 1)
                        tmp += ".";
              return propertyFromBindingPath(bean, tmp);
    and a supporting classpackage scenegraphdemo;
    import java.beans.PropertyChangeListener;
    * Static methods for manipulating PCL for standard java beans.
    * @author Mr. Java
    public class BeanPropertyUtils {
         protected final static Class<?>[] NO_ARGS = new Class<?>[] { PropertyChangeListener.class };
         protected final static Class<?>[] ARGS = new Class<?>[] { String.class,
                   PropertyChangeListener.class };
         protected final static String pclAddMethodName = "addPropertyChangeListener";
         protected final static String pclRemoveMethodName = "removePropertyChangeListener";
         * Return true if the class has PCL methods. Does not check for remove.
         * <p>
         * addPropertyChangeListener(PropertyChangeListener)
         * <p>
         * addPropertyChangeListener(String, PropertyChangeListener)
         * @param bean
         * @return
         public static boolean hasPCL(Class<?> clazz) {
              try {
                   if (clazz.getMethod(pclAddMethodName, NO_ARGS) != null) {
                        return true;
              } catch (Exception e) {
                   // silently fail
              try {
                   if (clazz.getMethod(pclAddMethodName, ARGS) != null) {
                        return true;
              } catch (Exception e) {
                   // silently fail
              return false;
         * Add a listener.
         * @param bean
         * @param listener
         * @param propertyName
         public static void addPCL(Object bean, PropertyChangeListener listener,
                   String propertyName) {
              try {
                   if (propertyName == null) {
                        bean.getClass().getMethod(pclAddMethodName, NO_ARGS)
                                  .invoke(bean, new Object[] { listener });
                   } else {
                        bean.getClass()
                                  .getMethod(pclAddMethodName, ARGS)
                                  .invoke(bean,
                                            new Object[] { propertyName, listener });
              } catch (Exception e) {
                   e.printStackTrace();
         * Remove a listener.
         * @param bean
         * @param listener
         * @param propertyName
         public static void removePCL(Object bean, PropertyChangeListener listener,
                   String propertyName) {
              try {
                   if (propertyName == null) {
                        bean.getClass().getMethod(pclRemoveMethodName, NO_ARGS)
                                  .invoke(bean, new Object[] { listener });
                   } else {
                        bean.getClass()
                                  .getMethod(pclRemoveMethodName, ARGS)
                                  .invoke(bean,
                                            new Object[] { propertyName, listener });
              } catch (Exception e) {
                   e.printStackTrace();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              

Maybe you are looking for

  • Lookup creation and using this lookup in SQL query

    I Have two tables one table called T_KEY_VALUES (KEY_ID , VALUE) and other is my transition table T_TRANSACTIONS (VERSION_ID , COL_VENDOR , COL_PREFIX, COL_RECIPTID , COL_STATE , COL_COUNTRY ..) The data looks like below: T_KEY_VALUES: KEY_ID , VALUE

  • Preparedstatement with two tables

    I try to use "preparedstatement" to insert two tables. Is there any posibility to control the constraint of the two tables? Assume that the two tables are master detail. Commit them both or rollback them both... An example would be very helpful.

  • My SAP SRM Application Monitors Purchase order / local errors

    I am seeing local errors in the monitor under Purchase order. The message is incorrect status in pricing, but when i click on the message i get no further information. How can I track there errors

  • How do I switch to phone speaker N78

    Hello yesterday I bought Nokia N78 but problem is following. I put headphones in Nokia N78 and now I don't know how to switch back to phone speaker. Some1 help! I can't find the answer anywhere.  I'm having headphones picture all the time in right up

  • How to call Functional Modules..

    Hi,    Kindly let me know, (other than BAPI) whether I can bring any other Functional Modules from R3 system into Webdynpro. If so, How can I?? Regards, Kalai