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 = "PgSqlDatabases")
@DiscriminatorValue("pgsql")
@EntityInfo(name = "PostgreSQL Datenbank")
@SearchFilter("obj.instance = 'pgsql' AND (" 
		+ "	obj.pac = :loginUserPac OR "
		+ "	obj.pac.customer.memberCode = :loginUserName )")
public class PgSqlDatabase extends Database implements Serializable {
	
	private static final long serialVersionUID = 6688358817554938015L;

	public PgSqlDatabase() {
		setInstance("pgsql");
		setEncoding("UTF-8");
	}

	public PgSqlDatabase(Pac pac, String name, String owner, String encoding) {
		super("pgsql", pac, name, owner, encoding);
	}

	@Override
	public Class<? extends DatabaseUser> getSqlUserClass() {
		return PgSqlUser.class;
	}

	public String getSystemEncoding() {
		return getEncoding();
	}

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

}

