hs.hsadmin/hsarback/src/de/hsadmin/mods/db/MySqlDatabaseModuleImpl.java

43 lines
1.5 KiB
Java
Raw Normal View History

2011-03-22 23:02:06 +01:00
package de.hsadmin.mods.db;
import java.util.List;
import javax.persistence.EntityManager;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.AbstractModuleImpl;
import de.hsadmin.core.model.AuthorisationException;
import de.hsadmin.core.model.HSAdminException;
import de.hsadmin.mods.user.UnixUser;
public class MySqlDatabaseModuleImpl extends AbstractModuleImpl {
@Override
public List<AbstractEntity> search(Class<? extends AbstractEntity> entityClass,
String condition, String orderBy) throws HSAdminException {
if (orderBy == null || orderBy.length() == 0) {
2011-04-01 18:53:37 +02:00
orderBy = "ORDER BY obj.name ASC";
2011-03-22 23:02:06 +01:00
}
return super.search(entityClass, condition, orderBy);
}
@Override
public AbstractEntity update(AbstractEntity existingEntity) throws HSAdminException {
EntityManager em = getTransaction().getEntityManager();
UnixUser unixUser = getLoginUser();
MySqlDatabase detachtedDB = (MySqlDatabase) existingEntity;
MySqlDatabase attachedDB = em.find(MySqlDatabase.class, detachtedDB.getId());
if (!attachedDB.getName().equals(detachtedDB.getName())) {
throw new AuthorisationException(unixUser, "update", existingEntity, "name");
}
if (!attachedDB.getEncoding().equals(detachtedDB.getEncoding())) {
throw new AuthorisationException(unixUser, "update", existingEntity, "encoding");
}
if (!attachedDB.getInstance().equals(detachtedDB.getInstance())) {
throw new AuthorisationException(unixUser, "update", existingEntity, "instance");
}
return super.update(existingEntity);
}
}