Detecting changes in an object

I have a relatively simple 3 tier application. Swing client, business logic with JDBC calls to fetch and save data on the server side. My data layer is simply comprised of JDBC calls which I use to populate JavaBeans, which are then returned to the client.
I want an easy way to be able to tell if the object has been changed, regardless of where it is at (client, business logic, etc). If I have a Person object, I want to be able to call person.hasDataChanged(), or something like that.
At first, I simply kept a dirty flag on the object. I then set this dirty flag to TRUE whenever one of the SET methods is called with data which differs from the current value. This works, and is fairly simple. By only setting the flag for set calls that use different data, I can map data to and from window objects without flipping the flag when I don't want to. The only problem with this is that it's possible to change the data from A to B, then set it back to A. At this point my object hasn't really chagned, but the dirty flag says otherwise.
So I thought of storing a copy of the old object within the object itself, but that seems like I'm passing around more data than I need to. Every object is twice as big as it needs to be.
I then tried to create a hash value when the object is retrieved from the database based upon the combined attributes of the object. The hasDataChanged() method creates a new hash value based upon the current data, compares with the old hash value, and returns the results. This doesn't work though, as there is no guarantee that hash values will be unique. It's possible to have data change and not have it be picked up.
So I now have a long string which I create when the object is first created. It is simply a concatonation of each object attributed. The hasDataChanged() method creates a new value string, compares to the old value string, and returns to the result.
Am I missing an obvious solution? Should I stick with the original approach of flipping a flag on the setter, even though it may be incorrect in instances where data is changed multiple times?
Thanks.

In my, opinion, you may be overcomplicating the issue
a little. If an attribute changes and is then changed
back, does it really matter if the object is no longer
differnt from the original. A simple 'dirty' flag is
usually goos enough for most systems.I suppose the worst that could happen is that I update a record in the database with the exact same data. Not the end of the wolrd I suppose. Still, if there was an easy wa to get it right, I would like to do so.
Having said that, If you absolutely must know
if it is different from the persistent version of the
object, you could place your persited data into a
contained object, something like a memento. Then ,
when a change is made, a comparison is made between
the current state and the stored memento. This would
have a higher memory and processing overhead, though.Yeah, I figured that was likely going to be the case. The downside is that the object is heavier; although it may be that it really doesn't matter.
Actually, all of these would require me to figure out when to take the snapshot of the object. They are JavaBeans, so I create them with an empty constructor, and then call setter methods to set the values on the object from a database result set. So I need a way to tel the object, "Ok, any data change after this means you've been altered". I hadn't thought that through all the way.
-Dave

Similar Messages

  • Agentry Delta Mechanism - Detecting changes in nested objects?

    Hi all,
    I have some experience with the Agentry Delta mechanism directly on a SQL backend (Update / Exchange Tables, Triggers, etc.). Now I am trying to find the right documentation, examples and stuff for that mechanism in the "Work Manager for SAP 6.0".
    Maybe, someone could outline a solution to the following "gap" in the Standard Work Managers exchange mechanism?
    A notifications in the "Work Manager" is updated, when the description of the notification has been changed in SAP.
    However, a notification is not updated, when the description of the functional locations of the notification has been changed in SAP. Now, the question is, how to extend the exchange mechanism to listen to the functional locations description?
    Thanks in advance for any hints you might have.
    Regards, Daniel

    Note: I reposted this question in its own discussion. Please do reply there if you can contribute to this topic. Thank you!
    Hi,
    its me again. I did some reading and I found something called "Exchange Object Linkage Settings" that sounds like it should be used for the use case above. The problem is, that it does not seem to work as I would expect.
    Here is some description from the smp_agentry_sap_framework.pdf, page 78:
    Exchange Object - Linkage Settings The Linkage Settings tab allows the exchange objects that are linked together to communicate with each other. The communication is one-directional, with the exchange object sending information to the object(s) listed in the Linked Exchange Objects List. When there is a value change to the exchange object, that value change information is passed on to the linked exchange objects. The linked exchange objects then go through additional processes related to the value change.
    In the Config Panel, one can see that in the Standard Work Manager, there is a linkage between Functional Location and Workorder:
    (Note that I started this discussion with an example on Notifications and Functional Locations. This is still where I want to go, but I wanted to stay within the Standard Workmanager Setup to make the - hopefully - ongoing discussion easier to follow.)
    According to the above description, I would expect that, when changing the Functional Locations description, that information is passed to all Workorders with that Functional Location.
    BUT HOW? It is not entirely clear to me how and what information is passed where. I would expect, that in the end, all related entries in the workorder exchange table will be updated with a new time stamp. (How else could the client get the information that the workorder is to be updated?)
    This is not what I can see! When changing the Functional Locations description in SAP, I see that the Functional Locations exchange table entry is updated, but the corresponding Work Orders exchange table entry is not changed.
    Does anybody have an idea how this feature is supposed to work? Maybe, there are some configuration steps necessary? Any input on the would be highly appreciated.
    Regards, Daniel

  • Detect changes in an instance

    Hello,
    how can I detect changes in an instantiated object? I could serialize the object and write it into a file. After some minutes I could write it a second time into a file. Now I could compare the two files. But I thing this is not the best way for doing this, isnt't it.
    Any suggestions?
    Thanks

    it can be of any help, here's how I implement object changes:
    /** Interface for object instances comparison */
    interface ContentComparable {
       /** Returns a string describing the object instance for comparison */
       public String getCompareString();
    /** Custom class sample */
    public class CustomClass implements ContentComparable {
       private String    customField1;
       private int       customField2;
       /** Constructor */
       private CustomClass(String field1, int field2) {
          this.customField1 = field1;
          this.customField2 = field2;
       //------------------------------------------------------------ ContentComparable ---
       /** Returns a string describing the object instance for comparison */
       public String getCompareString() {
          String content = this.getClass().getName() + "["
                           + "customField1='" + this.customField1 + "', "
                           + "customField2=" + this.customField2 + "]";
           return content;          
       /** Returns TRUE if the object is equal to an other object
        * @param   otherobj  the other object
        * @return  TRUE or FALSE
        * @see #getCompareString()
       public boolean equals(Object otherobj) {
          if (otherobj instanceof CustomClass) {
             CustomClass classobj = (CustomClass)otherobj;
             return this.getCompareString().equals(classobj.getCompareString());
          return false;
    }With that, you just have to keep a copy of the getCompareString() of the object before any changes are made.
    When you want to test changes, call this method:
       // private member to hold copy of unchanged object string
       private String oldObjectValue;
       // Returns TRUE if object has changed
       private boolean testDataChanged() {
          if (oldObjectValue == null) oldObjectValue = object.getCompareString();
          String newObjectValue = object.getCompareString();
          return !oldObjectValue.equals(newObjectValue);  
       //...Hope this helped,
    Regards.

  • Error while changing the Resource Object Status

    Hi,
    I am trying to change the resource object status from Waiting to Provisioned for a self service task. Before approval I see the Resource Object Status as " Ticket Sent To REMEDY" on the administrator's web console and at the Requestor's web console I get the following error message-
    ???en_US.global.viewProfileForm.Lookup.Ticket-Sent-to-REMEDY???
    But after approval, based on the completion the task, the process on both the consoles is set to provisioned. That is what I want to display but the problem comes when the requestors sees the error status message on its console before approval.
    Can any body tell me the reason of the above error and how to resolve it?
    Thanks in advance

    do you have any custom written event handlers getting triggered off after request submission or during approval?
    It might also be due to either a browser issue or you might have missed any entry in the xladmin properties file for a custom label/error message etc.

  • Do you know how to change the Text Object for Billing Document?

    Hi,
    If you execute Transaction VOTX or VOTXn it will take you to Text Determination. The Billing Doc & Sales Document both has the VBBK as Text Object for me and is it like that for all.
    I need to change the Text Object to VBRK for Billing Doc, which is the ideal because I am using the Function Module READ_TEXT to retrieve text. This work perfectly for Sales Document which has VBBK as Text Object, but does not work for Billing Doc where it through as error message saying “Text 0020000021 ID 0002 language EN not found”.
    Thank You
    Kishan

    Hi kishan,
    For updating these text you can use FM 'SAVE_TEXT'.
    As for your problem, to get the parameter you need, go to the billing document, go to the text, and display it in plain page mode.
    Then you do 'GO TO' -> 'HEADER', and a pop-up window open with the parameters you need Obect type, ID, Name, ...
    Regards,
    Erwan.

  • Data not updated in business entity after change in architectural object

    Hi,
    A business entity was created from Architectural Object.
    When we modify the address in the architectural object, the data is not updated in the business entity.
    Is there any solution that make an automatic update for the address in business entity after a change in architectural object ?
    Thx for your help.
    Regards
    Saad

    Hi,
    I have created new infopackage and ran. Now the following message I have got on the monitor.
    "Data not received in PSA Table
    Diagnosis
    Data has not been updated in PSA Table . The request is probably still running or there was a short dump.
    Procedure
    In the short dump overview in BW, look for the short dump that belongs to your data request. Make sure the correct date and time are specified in the selection screen.
    You can use the wizard to get to the short dump list, or follow the menu path "Environment -> Short dump -> In Data Warehouse".
    Removing errors
    Follow the instructions in the short dump."
    Any more thoughts?
    Thanks,
    Rao.

  • System setting does not allow changes to be object CLAS /1SEM/CL_FACTORY_30

    hi,
    Recently we upgraded our BW system from BW 3.0B to BW 3.5.In BW 3.5,we created a planning area to which we
    assigned a transactional cube.Now when we are going for creating variables or planning levels for the planning area it
    gives the following error:
    System setting does not allow changes to be object CLAS /1SEM/CL_FACTORY_300ZPLAN
    Our support packages are as following:
    SAP_BASIS       640                   0009
    SAP_ABA         640                   0009
    ST-PI           2005_1_640            0000
    PI_BASIS        2004_1_640            0006
    SAP_BW          350                   0009
    BI_CONT         353                   0000
    Could you please suggest or help us in resolving the issue ?
    thanks and regards,
    Yogesh

    Hello,
    the above mentioned note is too old. Please check note 781371.
    Please also check in transaction SM30 view V_TRNSPACE
    the record for /1SEM/:
    Namespace:     /1SEM/
    Namespace role C
    Repair License
    SSCR Popup     X
    SAP Standard   X
    Gen Objs Only  X
    Regards,
    Gregor

  • XY-Graph / Plot legend: How to detect changes in 2nd/3rd/4th ... legend position

    Hello,
    I have an XY-Graph with 4 plots. How can I detect, for example, the color change of the second plot in the legend. The active plot, using a property node, is always plot 0. So I am not able to detect changes in the 2nd/3rd ... plot.
    Any ideas?
    Thanks a lot.
    Best regards,
    Michael
    Solved!
    Go to Solution.

    You can do it with an event sturcture.
    Attachments:
    Plot detect.vi ‏25 KB

  • Event Structure's value change, not detecting changes when tabbing thru array of clusters

    Hi!  I have an array of clusters (int, int, string, int) control, and want to detecting changes made to the it.  I used the Event Structure's value change case on the array, it works excellent except that it'll only detect the changes when you click out of the element or press the enter key (the one by the numbers, not carriage return).  I want it to detect the changes when I tab thru the cluster or array too, but I can't figure it out... Does anyone have any ideas?
    Thanks!

    mfitzsimons wrote:
    altenbach
    Tried Value Change with my example done in 7.1 and it doesn't trgger an event.  That is why I suggested Mouse Down.
    Curious. I did a few minor edits in 8.0 before saving as 7.1, but the simple value change event got triggered just fine when the value vas terminated with a tab in 7.1. Every time.  Strange....
    Are you on 7.1 or 7.1.1? Maybe there's a difference (I am using 7.1.1).
    LabVIEW Champion . Do more with less code and in less time .

  • Why can't I change colors of objects?

    why can't I change colors of objects?

    Thanks KT.  I did mean the Fill color, but my real issue is that changing the fill color in the inspector doesn't change the color of the selected object.  In tis case, I was trying to chnage the fill color from pale blue to the more ingense blue:

  • Track changes of a object in Jswing Application

    Hi Folks,
    I have a jswing application which loads a object(*xml decoder*) when it gets opened.
    I may make changes to this object(*xml decoder*).
    Finally when terminating the application i need to check if any changes made to object(*xml decoder*)
    if there are any changes i need to write object(*xml decoder*) to xml encoder.
    Just like microsoftword/powerpoint.
    How do i compare old object with the recent object.
    Any suggestions

    Thanks for your response friend,
    1)yes it is a swing application
    2)yes it is a bean.xmlencoder
    3)yes am changing object returned by xml decoder
    i have java bean classes to be written to Xml encoder.
    public class TestContainer implements  Cloneable {
         @Override
        public TestContainer clone() {
         try {
           final TestContainer testcontainer = (TestContainer) super.clone();
            testcontainer.mTests = new ArrayList(mTests.size());
           for (Test tests : mTests) {
              testcontainer.mTests.add(tests.clone());
            testcontainer.mTopics=new ArrayList(mTopics.size());
            for (Topic topics : mTopics) {
              testcontainer.mTopics.add(topics.clone());
           return  testcontainer;
         } catch (CloneNotSupportedException cnse) {
           throw new Error(cnse);
        private List<Topic> mTopics;
        private List<Test> mTests;
        public List<Topic> getTopics() {
            return mTopics;
        public List<String> getTopicNames() {
            List<String> lTopicNamesList = new ArrayList<String>();
            for (Topic lTopic : mTopics) {
                lTopicNamesList.add(lTopic.getTopicName());
            return lTopicNamesList;
          public List<String> getTestNames() {
            List<String> lTestNamesList = new ArrayList<String>();
            for (Test lTest : mTests) {
                lTestNamesList .add(lTest.getTestName());
            return lTestNamesList;
        public void setTopics(List<Topic> pTopics) {
            this.mTopics = pTopics;
        public List<Test> getTests() {
            return mTests;
        public void setTests(List<Test> pTests) {
            this.mTests = pTests;
       // public static void main(String args[]) {
          //  TestContainer sampleTestFile = new TestContainer();
            // Set Topics
          /// List<Topic> lTopics = new ArrayList<Topic>();
          //  sampleTestFile.setTopics(lTopics);
            //Set Tests
           // List<Test> lTests = new ArrayList<Test>();
            //sampleTestFile.setTests(lTests);
           // try {
              //  XMLEncoder e = new XMLEncoder(
                     //   new BufferedOutputStream(
                     //   new FileOutputStream("Empty.xml")));
                //e.writeObject(sampleTestFile);
               // e.close();
           // } catch (Exception lEx) {
       so finally i need to write this testconatiner object to java.bean.XmlEncoder in front end application(AdminTool.java) if there are any changes.
    How and where should i override equals method

  • BAPI for "Change Base Planning Object"

    Hi
    Is there any BAPI for "Change Base Planning Object" ( TC KKE2).
    I need to change the Price of a Resource in the Cost Items for a Base Planning Object.
    So if any one know the BAPI for this topic please let me know, and if possible send me your code also it will be really help full.
    Regards

    I didn't find a BAPI to do this. I had to do it by a Batch Input.

  • Folder in Change view of object Type

    Hi Guys,
    Can anyone tell me if there is any folder involved in the change view of object type.
    Any input is appreciated.
    Thanks,
    Shilpa

    Hi Shilpy!
    What do you mean with folder?
    Thanks,
    Zsolt

  • How to change attributes of Objects of all windows in a MDI application

    Hi,
    I have a MDI application to draw Object. In these MDI windows I can modify attributes of Object like color, size... Now I want to create an option, when the user change or modifies attribute of Objects in a window, so it allow to change attributes of objects in all windows. I don't know how I can do it, please help me. Thanks

    Allow your objects to alias mutable attribute objects.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    import java.util.List;
    public class Example extends JPanel {
        private List bangles = new ArrayList();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            for(Iterator j=bangles.iterator(); j.hasNext(); )
                ((Bangle)j.next()).paint(g2);
        public void addBangle(Bangle bangle) {
            bangles.add(bangle);
            repaint();
        public static void main(String[] args) {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            Example app = new Example();
            JFrame f = new JFrame("Example");
            Container cp = f.getContentPane();
            cp.add(app, BorderLayout.CENTER);
            cp.add(Controller.create(app), BorderLayout.NORTH);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(800,600);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    class Controller {
        private Shade shade1 = new Shade(Color.GREEN), shade2 = new Shade(Color.RED), currentShade=shade1;
        private Example modelView;
        public static JComponent create(Example modelView) {
            return new Controller(modelView).createUI();
        private Controller(final Example modelView) {
            this.modelView = modelView;
            modelView.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent evt) {
                    Rectangle shape = new Rectangle(evt.getX(), evt.getY(), 20, 20);
                    modelView.addBangle(new Bangle(shape, currentShade));
        private JComponent createUI() {
            ButtonGroup bg = new ButtonGroup();
            final JToolBar tb = new JToolBar();
            final JRadioButton rb1 = createRadio("Shade 1", true,  shade1, bg, tb);
            final JRadioButton rb2 = createRadio("Shade 2", false, shade2, bg, tb);
            JButton btn = new JButton("Change color of selected shade");
            btn.setContentAreaFilled(false);
            btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    Color newColor = JColorChooser.showDialog(tb, "Choose new color", currentShade.getColor());
                    if (newColor != null) {
                        currentShade.setColor(newColor);
                        if (currentShade == shade1)
                            rb1.setForeground(newColor);
                        else
                            rb2.setForeground(newColor);
            tb.add(btn);
            return tb;
        private JRadioButton createRadio(String text, boolean selected, final Shade shade, ButtonGroup bg, JToolBar tb) {
            JRadioButton rb = new JRadioButton(text, selected);
            rb.setContentAreaFilled(false);
            rb.setForeground(shade.getColor());
            rb.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    currentShade = shade;
            tb.add(rb);
            return rb;
    class Bangle {
        private Shape shape;
        private Shade shade;
        public Bangle(Shape shape, Shade shade) {
            this.shape = shape;
            this.shade = shade;
        public void paint(Graphics2D g2) {
            g2.setColor(shade.getColor());
            g2.draw(shape);
    class Shade {
        private Color color;
        public Shade(Color color) {
            this.color = color;
        public Color getColor() {
            return color;
        public void setColor(Color color) {
            this.color = color;
    }

  • BPM-  Change Standard Monitoring Object

    Hi,
    I have few queries in BPM:
    1). How to change a standard Montior?
         For example, if I want to change Monitoring Object Sales Document (KPSD0001) and add New Keyfigure or add a new
         selection parameter (eg. Plant) for a keyfigure. How do I do this??
    2) In which database table/Transaction can I see all the Standard Monitoring Objects available.
    3) How can I copy a standard Monitoring Object  into a Z Monitor and make the required Changes.
    Regards,
    Shalini Chauhan

    Hi Shalini
    1)As Ragu mentioned, it is not possible to change standard monitoring
      object. Code is already fixed to the selection parameter.
    2)It is stored in special way in satellite system. (Cluster table).
      So it is not easy to check it like via SE16.
      You can get list of available monitoring object and key figure from
      the list that is available in service market place.
      (You need authorization to access service market place).
      http://www.service.sap.com/bpm
      =>media library =>Customer Information
      =>Business Process & Interface Monitoring - Part 2
    3)As Ragu mentioned, I also recommend you to check customer exit
      development guide.
        http://www.service.sap.com/bpm
        =>media library =>Technical Information
        =>Technical Information
        =>Guide - Customer Exit
    Best Regards
    Keiji  Mishima

Maybe you are looking for

  • Problem in installing a HP network printer

    I have a P2055dn laserjet.  It is connected directly to the router on my network.  I have a computer that uses it regularly and I can install it on another one.  It goes thru the installation, finds the printer itself and when it's close to completio

  • Acrobat Pro 8 and Reader X - Enable Extended Features for Form

    Using Acrobat Pro 8.3.0, I "Enabled Usage Rights for Adobe Reader" for a fillable form created in LiveCycle Designer 8.0.  The following error message occurs when opening this form in Reader X: "This document enabled extended features in Adobe Reader

  • Using StyledEditorKit text actions

    Hi I'm trying to build a text editor using a JTextPane. I want to be able to provide a toolbar for things like font size, bold, underline, etc. Bold and Underline are no problem. There exist classes StyledEditorKit.BoldStyleAction Which I can create

  • Can't open zipped files

    I can't open zipped files that have been sent to me. I have found the files I saved in Archive Utility and when I try to open them a dialogue box says the default app is BOMArchive Helper. If I click that something I cant read flashes on the screen b

  • Color mode & settings for grayscale illustration to monochrome laser printer

    Is there a best setting for the mode, color settings, and color profiles when printing a grayscale vector illustration to a monochrome laser printer? I am making vector maps, and right now they are mostly black line and black text with only the K val