Tom Pierce's Blog : Let the geek times roll.
Updated: 6/20/04; 3:21:18 PM.

 

Subscribe to "Tom Pierce's Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.

 
 

Friday, January 9, 2004

When you retrieve an object with Toplink, no matter if it's through the ClientSession or a UnitOfWork, Toplink returns an object that it is tracking in its cache. If you change the object in one place, ask for it again in the other, you will get the changed object. In some cases this is great because you can quickly and easily reflect the latest information with incredible performance. However I find myself being confused by this behavior for most of my applications.

My idea is that each of the classes you store with Toplink implements Cloneable. Then, in your DAO layer (you are using a DAO layer, right?) , before you return an object to the caller you call its clone() method. This will ensure that you have a shallow copy of the object that is not associated with Toplink's cache. Then, you can count on 2 retrievals of the same object only reflecting any updates that have actually been committed to the cache/database.

If you have a complex object graph that you are persisting with Toplink and you want the same functionality, you can implement a method to do a deep clone. This would make sure that the entire graph reflects the data at that point in time rather than any changes that are happening in other places.


3:47:30 PM    comment []

I have done something stupid this week.  I did not heed the letter from my ISP that my static IP at home would be changing.  Right now, no one in the world knows how to hit my domain.  Argh.  But, hopefully I'm on the right track to fixing it thanks to this FAQ item.  You have to set the TTL on your zone file to something smaller and smaller as the cut over approaches and then start taking it back up again.



2:51:57 PM    comment []

Within the last six months, I've started using DBVisualizer (http://www.minq.se/products/dbvis/) for accessing databases while I'm coding.  It's a great front end for any relational database that has a JDBC driver.  I highly recommend it.

One of the many cool features is that result sets in the product are displayed in a grid (JTable).  You can select values in the grid and copy them to the clipboard to paste in other applications.  I frequently paste the data into Emacs for use in Java unit tests.

The problem is that the columns of text are not in an array format.  So, I wrote the following Emacs functions to "fix the data up".  After you paste the data into Emacs you can immediately run one of the interactive fix-up functions.  (One of the thousands of beautiful things about Emacs is that it automatically sets the region around the pasted text.)  This will remove the column header and produce a comma delimited list of terms suitable for use in an array.

(defun fixup-dbviz-array (start end replace-string)
"Formats the region for use as an array and replaces the regexp match
with the specified replacement string."

  (unwind-protect
      (progn
        (narrow-to-region start end)
        (goto-char (point-min))
        (kill-line 't)

        (while (re-search-forward "\\(.*?\\)\n" nil t)
          (replace-match replace-string))          
        

        (if (re-search-backward "," nil t)
            (delete-char 1)))
                
    (widen)))

(defun fixup-dbviz-string-array (start end)
"Formats a column of values that are copy and pasted from DB
Visualizer and formats them for use as a String array"
  (interactive "r")
 
  (fixup-dbviz-array start end "\"\1", "))

(defun fixup-dbviz-int-array (start end)
"Formats a column of values that are copy and pasted from DB
Visualizer and formats them for use as a int array"
  (interactive "r")

  (fixup-dbviz-array start end "\\1, "))



12:38:09 PM    comment []

Dong Resin makes me laugh.[lemonodor]

This made me laugh... hard.  He's also got some other humorous stuff on his site.

11:08:29 AM    comment []

Here's a little something that you may or may not find in the documentation about the Toplink Session Console.  If you want to use the console to play with your mappings and run queries with them, you have to add your project's build directory to the classpath.  If it can't find the objects the mappings point to, you get and ConversionException when you try to load your project into the console.

The way I worked around this was to create a copy of the batch file that loads the Session Console and add my project's build directory to the classpath.  Bingo!  Everything works.



8:30:13 AM    comment []

© Copyright 2004 Tom Pierce.



Click here to visit the Radio UserLand website.

 


January 2004
Sun Mon Tue Wed Thu Fri Sat
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Dec   Feb

Search

[sgl dagger]
How this works

Emacs Sources
 tsql-indent.el
 user-add-sql-folding-marks
 remove-line-boundary-in-region
 convert-camel-to-underscore

My Subscriptions
 Funny
 KM