hs.hsadmin/hsarback/src/de/hsadmin/remote/MysqlUserRemote.java
Peter Hormanns 041111d845 introduce annotated class property on AbstractRemote
pac is readonly property
2015-09-11 17:26:42 +02:00

57 lines
1.4 KiB
Java

package de.hsadmin.remote;
import java.util.Map;
import de.hsadmin.core.model.AbstractEntity;
import de.hsadmin.core.model.Transaction;
import de.hsadmin.mods.db.DatabaseUser;
import de.hsadmin.mods.db.MySqlUser;
public class MysqlUserRemote extends AbstractRemote {
@Override
protected void entity2map(Transaction tx, AbstractEntity entity, Map<String, Object> map) {
MySqlUser user = (MySqlUser) entity;
String id = Long.toString(user.getId());
String name = user.getName();
String instance = user.getInstance();
String pac = user.getPac().getName();
String hive = user.getHiveName();
map.put("id", id);
map.put("name", name);
map.put("pac", pac);
map.put("hive", hive);
map.put("instance", instance);
}
@Override
protected Class<? extends AbstractEntity> getAnnotatedEntityClass() {
return DatabaseUser.class;
}
@Override
protected Class<? extends AbstractEntity> getEntityClass() {
return MySqlUser.class;
}
@Override
protected void map2entity(Transaction tx, Map<String, Object> map, AbstractEntity entity) {
MySqlUser user = (MySqlUser) entity;
user.setInstance("mysql");
String name = (String) map.get("name");
String password = (String) map.get("password");
if (assertNotNull(name)) {
user.setName(name);
}
if (assertNotNull(password)) {
user.setPassword(password);
}
}
@Override
protected void regularizeKeys(Map<String, String> whereParams) {
replaceKey(whereParams, "pac", "pac.name");
}
}