Boa tarde amigos,
Estou desenvolvendo um projeto utilizando JPA, Hibernate e JavaFX. Tenho uma classe chamada JPAUtil, segue o código:
public class JpaUtil {
private static EntityManagerFactory factory;
private static String user = "teste";
private static String pass = "teste";
private static String enderecoServidor = "localhost";
private static String portaServidor = "3306";
private static Map proprieties = getProprieties(user, pass);
static {
factory = Persistence.createEntityManagerFactory("linksPU", proprieties);
}
public static EntityManager getEntityManager() {
return factory.createEntityManager();
}
public static void close() {
factory.close();
}
public static Map getProprieties(String user, String pass) {
Map pmap = new HashMap();
pmap.put("javax.persistence.jdbc.url", getUrl());
pmap.put("javax.persistence.jdbc.user", user);
pmap.put("javax.persistence.jdbc.password", pass);
pmap.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
pmap.put("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
pmap.put("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
pmap.put("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
pmap.put("hibernate.show_sql", "true");
pmap.put("hibernate.format_sql", "true");
pmap.put("hibernate.hbm2ddl.auto", "update");
return pmap;
}
public static String getEnderecoServidor() {
return JpaUtil.enderecoServidor;
}
public static String getPortaServidor() {
return JpaUtil.portaServidor;
}
public static String getUrl() {
return "jdbc:mysql://" + JpaUtil.enderecoServidor + ":" + JpaUtil.portaServidor + "/dblinks";
}
}
Eu gostaria de criar uma classe para a criação do Banco e configuração dos privilégios do usuário “teste”, caso ainda não existam na instalação da aplicação em um novo micro. Alguém de dá uma luz? O código SQL seria mais ou menos isso:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'teste';
grant all privileges on *.* to 'root'@'%' identified by 'teste' with grant option;
flush privileges;
CREATE DATABASE IF NOT EXISTS `dblinks`;