package de.hsadmin.mods.db;

import java.io.Serializable;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;

import de.hsadmin.core.model.EntityInfo;
import de.hsadmin.core.model.SearchFilter;
import de.hsadmin.mods.pac.Pac;

@Entity(name = "PgSqlUsers")
@DiscriminatorValue("pgsql")
@EntityInfo(name = "PostgreSQL Konto")
@SearchFilter("obj.instance = 'pgsql' AND (" + "	obj.pac = :loginUserPac OR "
		+ "	obj.pac.customer.memberCode = :loginUserName )")
public class PgSqlUser extends DatabaseUser implements Serializable {

	private static final long serialVersionUID = -1097602753310286629L;

	public static String createQueryFromStringKey(String humanKey) {
		return "obj.name='" + humanKey + "' AND obj.instance='pgsql'";
	}

	public PgSqlUser() {
		setInstance("pgsql");
	}

	public PgSqlUser(Pac pac, String name, String password) {
		super("pgsql", pac, name, password);
	}

	/**
	 *  query restriction for access control
	 */
	public static String restriction() {
		return "obj.instance='pgsql' AND ( " + DatabaseUser.restriction() + " )";
	}

}
