You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Malcolm Edgar <ma...@gmail.com> on 2006/08/15 02:58:49 UTC

DataContext hasThreadDataContext()

Hi All,

It would be good if the DataContext class had a method:

   public static boolean hasThreadDataContext() {
       return (threadDataContext.get() != null);
   }


I am working with a scenario where a third party library is making
direct calls to Cayenne service methods. If I can test whether the
thread local dataContext is not defined I can then initialize it.

Currently I have hacked the DataContext class as a work around:

    public static DataContext getThreadDataContext() throws
IllegalStateException {
        DataContext dc = (DataContext) threadDataContext.get();
        if (dc == null) {
            dc = createDataContext();
            threadDataContext.set(dc);
        }

        return dc;
    }


regards Malcolm Edgar