HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2011-08-12 f86c4952e13578865f5426b41f7fe99121eb5684
etwas zurueck...
5 files modified
75 ■■■■■ changed files
hsarback/src/de/hsadmin/core/model/AbstractEntity.java 34 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/AbstractModuleImpl.java 20 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/Database.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/db/DatabaseUser.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/email/EMailAlias.java 7 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/core/model/AbstractEntity.java
@@ -1,10 +1,5 @@
package de.hsadmin.core.model;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.persistence.EntityManager;
import de.hsadmin.mods.user.UnixUser;
@@ -93,8 +88,7 @@
        try {
            method = entityClass.getDeclaredMethod("restriction");
        } catch (SecurityException e) {
            throw new RuntimeException(
                    "unexpected SecurityException in restriction()");
            throw new RuntimeException("unexpected SecurityException in restriction()");
        } catch (NoSuchMethodException e) {
            // don't grant any access
            return "FALSE";
@@ -105,8 +99,7 @@
        try {
            restriction = (String) method.invoke(null);
        } catch (Exception e) {
            throw new RuntimeException(
                    "unexpected Exception in Entity-restriction() implementation");
            throw new RuntimeException("unexpected Exception in Entity-restriction() implementation");
        }
        return restriction;
    }
@@ -222,28 +215,5 @@
     * @return
     */
    public abstract UnixUser owningUser(EntityManager em);
    /**
     * Clonable::clone did result in javasisst errors (duplicate method) since
     * JBoss 5.1.
     * This is just for testing, it does not use the proper class loader!
     */
    public <T extends AbstractEntity> T replicate() {
        try {
            ByteArrayOutputStream baOut = new ByteArrayOutputStream();
            ObjectOutputStream oOut = new ObjectOutputStream(baOut);
            oOut.writeObject(this);
            byte[] buffer = baOut.toByteArray();
            ByteArrayInputStream baIn = new ByteArrayInputStream(buffer);
            ObjectInputStream oIn = new ObjectInputStream(baIn);
            @SuppressWarnings("unchecked")
            T clone = (T) oIn.readObject();
            return clone;
        } catch (Exception exc) {
            throw new RuntimeException(exc);
        }
    }
}
hsarback/src/de/hsadmin/core/model/AbstractModuleImpl.java
@@ -108,9 +108,9 @@
        EntityManager entityManager = transaction.getEntityManager();
        entityManager.clear();
        Query query = entityManager.createQuery(queryString);
        query.setParameter("loginUser", loginUser);
        query.setParameter("loginUserName", loginUser.getName());
        query.setParameter("loginUserPac", loginUser.getPac());
        setQueryParameter(query, queryString, "loginUser", loginUser);
        setQueryParameter(query, queryString, "loginUserName", loginUser.getName());
        setQueryParameter(query, queryString, "loginUserPac", loginUser.getPac());
        try {
            List<?> res = query.getResultList();
            List<AbstractEntity> ret = new LinkedList<AbstractEntity>();
@@ -209,4 +209,18 @@
            condition = restriction;
        return condition;
    }
    public static void setQueryParameter(Query query, String queryString,
            String argName, Object argValue) {
        int argLen = argName.length();
        int iMax = queryString.length();
        int i = 0;
        while ((i = queryString.indexOf(argName, i)) >= 0) {
            if ((i + argLen) >= iMax || queryString.charAt(i + argLen) < 'A') {
                query.setParameter(argName, argValue);
                break;
            }
            ++i;
        }
    }
}
hsarback/src/de/hsadmin/mods/db/Database.java
@@ -22,6 +22,7 @@
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.FieldValidation;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;
@@ -91,9 +92,9 @@
                String queryString = "SELECT obj FROM " + entityAnnot.name() + " obj WHERE "
                        + Pac.createQueryFromStringKey(pacName);
                Query query = em.createQuery(queryString);
                query.setParameter("loginUser", loginUser);
                query.setParameter("loginUserName", loginUser.getName());
                query.setParameter("loginUserPac", loginUser.getPac());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUser", loginUser);
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserName", loginUser.getName());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserPac", loginUser.getPac());
                pac = (Pac) query.getSingleResult();
            } catch (NoResultException exc) {
                throw new SecurityException("packet '" + pacName + "' not found or access denied");
hsarback/src/de/hsadmin/mods/db/DatabaseUser.java
@@ -23,6 +23,7 @@
import javax.persistence.Transient;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.FieldValidation;
import de.hsadmin.mods.pac.Pac;
import de.hsadmin.mods.user.UnixUser;
@@ -86,9 +87,9 @@
                // set parameters
                Query query = em.createQuery(queryString);
                query.setParameter("loginUser", loginUser);
                query.setParameter("loginUserName", loginUser.getName());
                query.setParameter("loginUserPac", loginUser.getPac());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUser", loginUser);
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserName", loginUser.getName());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserPac", loginUser.getPac());
                pac = (Pac) query.getSingleResult();
            } catch (NoResultException exc) {
                throw new SecurityException("packet '" + pacName
hsarback/src/de/hsadmin/mods/email/EMailAlias.java
@@ -17,6 +17,7 @@
import javax.persistence.Table;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.EntityInfo;
import de.hsadmin.core.model.FieldValidation;
import de.hsadmin.core.model.ModuleImpl;
@@ -79,9 +80,9 @@
                Entity entityAnnot = Pac.class.getAnnotation(Entity.class);
                String queryString = "SELECT obj FROM " + entityAnnot.name() + " obj WHERE " + Pac.createQueryFromStringKey(pacName);
                Query query = em.createQuery(queryString);
                query.setParameter("loginUser", loginUser);
                query.setParameter("loginUserName", loginUser.getName());
                query.setParameter("loginUserPac", loginUser.getPac());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUser", loginUser);
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserName", loginUser.getName());
                AbstractModuleImpl.setQueryParameter(query, queryString, "loginUserPac", loginUser.getPac());
                pac = (Pac) query.getSingleResult();
            } catch (NoResultException exc) {
                throw new SecurityException("packet '" + pacName + "' not found or access denied");