• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Different Database Connection per session for the same model
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Different Database Connection per session for the same model


  • Subject: Re: Different Database Connection per session for the same model
  • From: Lon Varscsak <email@hidden>
  • Date: Mon, 18 Jun 2012 19:04:43 -0700

Here's how I implemented it (it's actually quite simple): 


In Session.java:



public ERXObjectStoreCoordinator defaultObjectStoreCoordinator() {

return defaultObjectStoreCoordinator;

}

public void setDefaultObjectStoreCoordinator(ERXObjectStoreCoordinator defaultObjectStoreCoordinator) {

if (this.defaultObjectStoreCoordinator != null && this.defaultObjectStoreCoordinator != defaultObjectStoreCoordinator) {

this.defaultObjectStoreCoordinator.dispose();

this.defaultObjectStoreCoordinator = null;

System.gc();

}

this.defaultObjectStoreCoordinator = defaultObjectStoreCoordinator;

}

    public static class OneConnectionPerSessionFactory extends ERXEC.DefaultFactory {

        public OneConnectionPerSessionFactory() {

            super();

        }

        

        @Override

public EOEditingContext _newEditingContext() {

            return _newEditingContext(true);

        }

        

        @Override

public EOEditingContext _newEditingContext(boolean validationEnabled) {

            EOObjectStore os = ((Session)ERXSession.session()).defaultObjectStoreCoordinator();

            EOEditingContext ec = _newEditingContext(os, validationEnabled);


            return ec;

        }

    }


    @Override

public void terminate() {

    setDefaultObjectStoreCoordinator(null); //this will cause a logout from the database

    

    super.terminate();

    }


In Application.java:


public Application() {

ERXApplication.log.info("Welcome to " + name() + " !");


          ERXEC.setFactory(new Session.OneConnectionPerSessionFactory());

}


Basically, every where ERXEC.newEditingContext() is used it should use your new factory. I can't remember where I got this from…probably Mike…because I am not smart enough to figure this out (although I do get lucky every now and then :D).  You should be able to use defaultEditingContext without worry too…although I rarely use it.


-Lon


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Different Database Connection per session for the same model (From: Paul Dunkler <email@hidden>)

  • Prev by Date: Re: Question about "To Many" relationships hooks in ERRest
  • Next by Date: @count
  • Previous by thread: Re: Different Database Connection per session for the same model
  • Next by thread: @count
  • Index(es):
    • Date
    • Thread