Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   *  Copyright 2009-2014 Pavel Ponec
   *
   *  Licensed under the Apache License, Version 2.0 (the "License");
   *  you may not use this file except in compliance with the License.
   *  You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
 package org.ujorm.implementation.orm;
 
 import static org.ujorm.extensions.PropertyModifier.*;
 import static org.ujorm.orm.ao.LazyLoading.*;

The special Key pro LazyLoadiing
 
 public class OrmProperty<U extends OrmUjo, VALUE> extends Property<U, VALUE> {

    
Logger
 
     private static final UjoLogger LOGGER = UjoLoggerFactory.getLogger(OrmProperty.class);
 
     // /** Is the Key type of Relation  */
     // private boolean relation;
 
     public OrmProperty(int index) {
         super(index);
     }
 
     public OrmProperty(int indexString name, VALUE defaultValueValidator<VALUE> validator) {
         super(index);
         init(name);
         init(defaultValue);
         init(validator);
     }

    
Lock the Property
 
     @Override
     protected void lock() {
         super.lock();
         // relation = isTypeOf(OrmUjo.class); // TODO ...
     }

    
An alias for the method of(Ujo) with a lazy-loading features.
Note: if no session is available than lazy attributes provides the null value - since the release 1.33.
 
     @SuppressWarnings("unchecked")
     @Override
     public VALUE of(final U ujo) {
         Session mySession = ujo.readSession();  // maybe readSession() is better?
         Object result = ujo.readValue(this);
 
         if (isTypeOf(OrmUjo.class)) {
             if (result instanceof ForeignKey) {
                 if (mySession == null) {
                     return null;
                 }
                 if (.equalsTo(mySession.getLazyLoading())) {
                     throw new IllegalStateException("The lazy loading is disabled in the current Session.");
                 }
                 if (mySession.isClosed()) {
                    IllegalStateException e = null;
                     switch (mySession.getLazyLoading()) {
                         default:
                             throw new IllegalStateException("The lazy loading is disabled in the closed Session.");
                         case :
                             if (.isLoggable(.)) {
                                 e = new IllegalStateException(mySession.getLazyLoading().name());
                             }
                         case :
                             if (.isLoggable(.)) {
                                 .log(."The lazy loading on closed session on the key " + getFullName() + " = " + resulte);
                             }
                         case :
                             // open temporary session if it's closed ;) - because of lazy-loading of detached objects (caches, etc.) */
                             final Session tempSession = mySession.getHandler().createSession();
                             try {
                                 result = tempSession.loadInternal(this, ((ForeignKeyresult).getValue(), true);
                                 if (result != null) {
                                     // Assign the same session due original session arguments (lazyLoading e.g.):
                                     ((OrmUjoresult).writeSession(mySession);
                                 }
                             } finally {
                                 tempSession.close();
                             }
                     }
                 } else {
                    result = mySession.loadInternal(this, ((ForeignKeyresult).getValue(), true);
                }
                ujo.writeSession(null); // Replacing of the foreign key is not a key change
                ujo.writeValue(thisresult);
                ujo.writeSession(mySession); // Restore the Session
            } else if (result != null
                && mySession != null
                && mySession != ((OrmUjoresult).readSession()
                // A sesssion will be written to a result in case missing primary key too - due more relations
            ) {
                // Write the current session to a related object:
                ((OrmUjoresult).writeSession(mySession);
            }
        }
        return result != null
                ? (VALUE) result
                : getDefault();
    }
New to GrepCode? Check out our FAQ X