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 = "MySqlUsers")
@DiscriminatorValue("mysql")
@EntityInfo(name = "MySQL Konto")
@SearchFilter("obj.instance = 'mysql' AND ("
		+ "	obj.pac = :loginUserPac OR "
		+ "	obj.pac.customer.memberCode = :loginUserName )")
public class MySqlUser extends DatabaseUser implements Serializable {
	
	private static final long serialVersionUID = 6218494776881999478L;

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

	public MySqlUser() {
		setInstance("mysql");
	}

	public MySqlUser(Pac pac, String name, String password) {
		super("mysql", pac, name, password);
	}

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

}
