/** * Checks whether this context is attached to Cayenne runtime stack and if * not, attempts to attach itself to the runtime using Injector returned * from the call to {@link CayenneRuntime#getThreadInjector()}. If thread * Injector is not available and the context is not attached, throws * CayenneRuntimeException. * <p> * This method is called internally by the context before access to * transient variables to allow the context to attach to the stack lazily * following deserialization. * * @return true if the context successfully attached to the thread runtime, * false - if it was already attached. * @since 3.1 */ protected boolean attachToRuntimeIfNeeded() { if (channel != null) { return false; } Injector injector = CayenneRuntime.getThreadInjector(); if (injector == null) { throw new CayenneRuntimeException("Can't attach to Cayenne runtime. " + "Null injector returned from CayenneRuntime.getThreadInjector()"); } attachToRuntime(injector); return true; }