Package dk.brics.jwig.persistence

Examples of dk.brics.jwig.persistence.Persistable


public class CacheInterceptor extends EmptyInterceptor {

    @Override
  public void postFlush(Iterator iterator) {
        while (iterator.hasNext()) {
        Persistable persistable = (Persistable) iterator.next();
        ThreadContext.getDependencyMap().objectUpdated(persistable);
    }
    }
View Full Code Here


    /**
     * If p is a persistable object, a proxy object is returned. Else the object itself is simply returned.
     */
    private Object getObject(Object p) {
        if (p instanceof Persistable) {
            Persistable persistable = (Persistable) p;
            if (persistable.getId() == null) {
                log.warn("Tried to set up a dependency with a non-persistent persistable", new Exception());
                return null;
            }
            return new ProxyObject(ThreadContext.getWebSite().getQuerier(), (Persistable) p);
        } else {
View Full Code Here

     * the same ID they will always have the same hash value.
     */
    private void hash(Object[] dependencies, HashMethod<?> h) {
        for (Object o : dependencies) {
            if (o instanceof Persistable) {
                Persistable persistable = (Persistable) o;
                o = new ProxyObject(getWebSite().getQuerier(),persistable);
            } else if (o instanceof Enum) {
                Enum<?> anEnum = (Enum<?>) o;
                o = anEnum.getClass().getName().hashCode() * anEnum.ordinal();
            }
View Full Code Here

     */
    public static String makeURLArg(Object arg) { // TODO: Move method?
        Map<Object, String> map = ThreadContext.get().getCachedPropertyValues();
        String s = "";
        if (arg instanceof Persistable) {
            Persistable persistable = (Persistable) arg;
            if (map.containsKey(persistable)) {
                s = map.get(persistable);
            } else {
                Class<? extends Persistable> persistableClass = ThreadContext
                        .getWebSite().getQuerier().getBaseType(persistable);
                Method method = findQueryMethod(persistableClass);
                if (method != null) {
                    String name = method.getName();
                    try {
                        // Prefer calling the getter method to use cache if
                        // possible
                        name = name.substring(3);
                        String getterName = "get" + name;
                        Method getterMethod = persistableClass
                                .getMethod(getterName);
                        s = getterMethod.invoke(persistable).toString();
                    } catch (Exception e) {
                        name = name.substring(3, 4).toLowerCase()
                                + name.substring(4);
                        s = ThreadContext
                                .getWebSite()
                                .getQuerier()
                                .getPropertyFromId(persistableClass, name,
                                        persistable.getId());
                    }
                    map.put(persistable, s);
                } else {
                    s = persistable.getId().toString();
                }
            }
        } else if (arg != null) {
            s = arg.toString();
        } else {
View Full Code Here

TOP

Related Classes of dk.brics.jwig.persistence.Persistable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.