using the clock in nanning-prevayler

Martin Lilja <[email protected]> Tue, 7 Oct 2003 07:53:46 -0700 (PDT)
Newsgroups gmane.comp.java.nanning.devel
Message-ID <[email protected]>
Hi!
We've been having some trouble with using the clock in
prevayler. The problem is that during transaction
playback, calls to
CurrentPrevayler.getPrevayler().clock().time() fails
because CurrentPrevayler hasn't been setup yet.

Don't know exactly when it happened, but my guess is
that it has something to do with the access of the
clock being moved from the PrevalentSystem to the
Prevayler interface.

Below is a test case that triggers the bug which
should be pasted into PrevaylerTest.java. Is there a
way to solve this?

/Behe

--- snippet o'code ---

    /**
     * @entity
     */
    public static interface TestDatesWithPrevayler {
        /**
         * @transaction
         */
        void touchTime();

        Date getTime();
    }

    public static class TestDatesWithPrevaylerImpl
implements TestDatesWithPrevayler, Serializable {
        private Date time;

        public void touchTime() {
            this.time =
CurrentPrevayler.getPrevayler().clock().time();
        }

        public Date getTime() {
            return time;
        }
    }

    public void testDatesWithPrevayler() throws
Exception {
        newPrevayler();

        final TestDatesWithPrevayler
testDatesWithPrevayler = (TestDatesWithPrevayler)
newInstance(TestDatesWithPrevayler.class);
        withCurrentPrevayler(new PrevaylerAction() {
            public Object run() throws Exception {
               
currentSystem().add(testDatesWithPrevayler);

               
assertNull(testDatesWithPrevayler.getTime());
                testDatesWithPrevayler.touchTime();
               
assertNotNull(testDatesWithPrevayler.getTime());
                return null;
            }
        });

        final long testDatesWithPrevaylerId =
getObjectId(testDatesWithPrevayler);
        newPrevayler();
        withCurrentPrevayler(new PrevaylerAction() {
            public Object run() throws Exception {
                TestDatesWithPrevayler
testDatesWithPrevayler = (TestDatesWithPrevayler)
currentSystem().getIdentifiable(testDatesWithPrevaylerId);
               
assertNotNull(testDatesWithPrevayler.getTime());
                return null;
            }
        });
    }


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com