Fasel/fasel-jfx/src/main/java/de/vanitasvitae/fasel/db/dao/impl/AvatarDaoImpl.java

40 lines
1.2 KiB
Java

package de.vanitasvitae.fasel.db.dao.impl;
import java.sql.SQLException;
import java.util.List;
import com.j256.ormlite.dao.BaseDaoImpl;
import com.j256.ormlite.support.ConnectionSource;
import de.vanitasvitae.fasel.db.dao.AvatarDao;
import de.vanitasvitae.fasel.db.entity.Avatar;
import de.vanitasvitae.fasel.db.entity.XmppEntity;
public class AvatarDaoImpl extends BaseDaoImpl<Avatar, Long> implements AvatarDao {
public AvatarDaoImpl(ConnectionSource connectionSource)
throws SQLException {
super(connectionSource, Avatar.class);
}
/**
* TODO: Test
* @param entity
* @return
* @throws SQLException
*/
public Avatar getAvatarForEntity(XmppEntity entity) throws SQLException {
if (entity == null) {
throw new IllegalArgumentException("XmppEntity cannot be null!");
}
List<Avatar> avatars = queryForEq("entity", entity.getEntityID());
if (avatars.isEmpty()) {
return null;
} else if (avatars.size() == 1) {
return avatars.get(0);
} else {
throw new SQLException("There are more than one Avatar for entity " + entity.toString());
}
}
}