// Path: airomem-core/src/main/java/pl/setblack/airomem/core/ContextCommand.java
// @FunctionalInterface
// public interface ContextCommand<T, R> extends Serializable {
// 
//     /**
//      * @param system  reference to mutable system
//      * @param context context info (such as date)
//      */
//     R execute(T system, PrevalanceContext context);
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PrevalanceContext.java
// public class PrevalanceContext {
// 
//     /**
//      * Use this time object whenewer actual time was needed in command.
//      */
//     public final Instant time;
// 
//     public final boolean safe;
// 
//     public PrevalanceContext(final Date date) {
//         this(date.toInstant(), false);
//     }
// 
//     private PrevalanceContext(final Instant time, final boolean safe) {
//         this.time = time;
//         this.safe = safe;
//     }
// 
//     public PrevalanceContext safe() {
//         return new PrevalanceContext(this.time, true);
//     }
// 
//     public PrevalanceContext unsafe() {
//         return new PrevalanceContext(this.time, false);
//     }
// }
// 
// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/OperationType.java
// public enum OperationType {
// 
//     WRITE,
//     READ_FAST,
//     READ_COMMITTED;
// }
// 
// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/PersistenceInterceptor.java
// @Interceptor
// @Persistent
// public class PersistenceInterceptor {
// 
//     private static final ThreadLocal<Boolean> MARKER = new ThreadLocal<>();
// 
//     @Inject
//     private ClassContextRegistry registry;
// 
//     @AroundInvoke
//     public Object preparePersistence(InvocationContext ctx) {
//         try {
//             if (!Boolean.TRUE.equals(MARKER.get())) {
//                 final ClassContext classContext = registry.getContext(ctx.getTarget());
//                 return classContext.performTransaction(ctx);
// 
//             } else {
//                 return Politician.beatAroundTheBush(() -> ctx.proceed());
//             }
//         } finally {
//             MARKER.remove();
//         }
//     }
// 
//     public static void setMarker() {
//         MARKER.set(Boolean.TRUE);
//     }
// }


import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.interceptor.InvocationContext;
import javax.naming.InitialContext;
import org.apache.commons.lang.ClassUtils;
import pl.setblack.airomem.core.ContextCommand;
import pl.setblack.airomem.core.PrevalanceContext;
import pl.setblack.airomem.core.SimpleController;
import pl.setblack.airomem.direct.OperationType;
import pl.setblack.airomem.direct.PersistenceInterceptor;
import pl.setblack.airomem.direct.PersistentObject;
import pl.setblack.badass.Politician;
        for (Field f : fields) {
            final PersistentObject po = f.getAnnotation(PersistentObject.class);
            if (po != null) {
                result.add(new FieldHandler(f));
            }
        }
        if (aClass.getSuperclass() != null) {
            result.addAll(scanFields(aClass.getSuperclass()));
        }
        return result;
    }

    private void prepare(ElemHandler elem) {
        this.elem = elem;

    }

    private Class calcTargetClass(Object obj) {
        return obj.getClass().getSuperclass();
    }

    Object performTransaction(final Object target, Method method, final Object[] args) {

        final SimpleController controller = PrevaylerRegister.getInstance().getController(elem.getTargetType(), elem.getName());

        final WraperTransaction transaction = new WraperTransaction(calcTargetClass(target).getCanonicalName(), method, args);
        return controller.executeAndQuery(transaction);

    }

// Path: airomem-core/src/main/java/pl/setblack/airomem/core/ContextCommand.java
// @FunctionalInterface
// public interface ContextCommand<T, R> extends Serializable {
// 
//     /**
//      * @param system  reference to mutable system
//      * @param context context info (such as date)
//      */
//     R execute(T system, PrevalanceContext context);
// }
// 
// Path: airomem-core/src/main/java/pl/setblack/airomem/core/PrevalanceContext.java
// public class PrevalanceContext {
// 
//     /**
//      * Use this time object whenewer actual time was needed in command.
//      */
//     public final Instant time;
// 
//     public final boolean safe;
// 
//     public PrevalanceContext(final Date date) {
//         this(date.toInstant(), false);
//     }
// 
//     private PrevalanceContext(final Instant time, final boolean safe) {
//         this.time = time;
//         this.safe = safe;
//     }
// 
//     public PrevalanceContext safe() {
//         return new PrevalanceContext(this.time, true);
//     }
// 
//     public PrevalanceContext unsafe() {
//         return new PrevalanceContext(this.time, false);
//     }
// }
// 
// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/OperationType.java
// public enum OperationType {
// 
//     WRITE,
//     READ_FAST,
//     READ_COMMITTED;
// }
// 
// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/PersistenceInterceptor.java
// @Interceptor
// @Persistent
// public class PersistenceInterceptor {
// 
//     private static final ThreadLocal<Boolean> MARKER = new ThreadLocal<>();
// 
//     @Inject
//     private ClassContextRegistry registry;
// 
//     @AroundInvoke
//     public Object preparePersistence(InvocationContext ctx) {
//         try {
//             if (!Boolean.TRUE.equals(MARKER.get())) {
//                 final ClassContext classContext = registry.getContext(ctx.getTarget());
//                 return classContext.performTransaction(ctx);
// 
//             } else {
//                 return Politician.beatAroundTheBush(() -> ctx.proceed());
//             }
//         } finally {
//             MARKER.remove();
//         }
//     }
// 
//     public static void setMarker() {
//         MARKER.set(Boolean.TRUE);
//     }
// }


// Path: airomem-direct/src/main/java/pl/setblack/airomem/direct/impl/ClassContext.java
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.spi.CreationalContext;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
import javax.interceptor.InvocationContext;
import javax.naming.InitialContext;
import org.apache.commons.lang.ClassUtils;
import pl.setblack.airomem.core.ContextCommand;
import pl.setblack.airomem.core.PrevalanceContext;
import pl.setblack.airomem.core.SimpleController;
import pl.setblack.airomem.direct.OperationType;
import pl.setblack.airomem.direct.PersistenceInterceptor;
import pl.setblack.airomem.direct.PersistentObject;
import pl.setblack.badass.Politician;

        for (Field f : fields) {
            final PersistentObject po = f.getAnnotation(PersistentObject.class);
            if (po != null) {
                result.add(new FieldHandler(f));
            }
        }
        if (aClass.getSuperclass() != null) {
            result.addAll(scanFields(aClass.getSuperclass()));
        }
        return result;
    }

    private void prepare(ElemHandler elem) {
        this.elem = elem;

    }

    private Class calcTargetClass(Object obj) {
        return obj.getClass().getSuperclass();
    }

    Object performTransaction(final Object target, Method method, final Object[] args) {

        final SimpleController controller = PrevaylerRegister.getInstance().getController(elem.getTargetType(), elem.getName());

        final WraperTransaction transaction = new WraperTransaction(calcTargetClass(target).getCanonicalName(), method, args);
        return controller.executeAndQuery(transaction);

    }

    private void inject(Object target, Object system) {