first commit
This commit is contained in:
commit
c91477550f
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project-shared-configuration>
|
||||||
|
<!--
|
||||||
|
This file contains additional configuration written by modules in the NetBeans IDE.
|
||||||
|
The configuration is intended to be shared among all the users of project and
|
||||||
|
therefore it is assumed to be part of version control checkout.
|
||||||
|
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
|
||||||
|
-->
|
||||||
|
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
|
||||||
|
<!--
|
||||||
|
Properties that influence various parts of the IDE, especially code formatting and the like.
|
||||||
|
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
|
||||||
|
That way multiple projects can share the same settings (useful for formatting rules for example).
|
||||||
|
Any value defined here will override the pom.xml file value but is only applicable to the current project.
|
||||||
|
-->
|
||||||
|
<netbeans.hint.jdkPlatform>JDK_21</netbeans.hint.jdkPlatform>
|
||||||
|
</properties>
|
||||||
|
</project-shared-configuration>
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.qsoft.generador.entidades</groupId>
|
||||||
|
<artifactId>generador-entidades</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>17</maven.compiler.source>
|
||||||
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
|
<exec.mainClass>com.qsoft.generador.entidades.GeneradorEntidades</exec.mainClass>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-j</artifactId>
|
||||||
|
<version>8.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>3.14.0</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
|
@ -0,0 +1,271 @@
|
||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Project/Maven2/JavaApp/src/main/java/${packagePath}/${mainClassName}.java to edit this template
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.qsoft.generador.entidades;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import com.qsoft.generador.entidades.coneccion.Conexion;
|
||||||
|
import com.qsoft.generador.entidades.constantes.GenedorConstantes;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author developer2
|
||||||
|
*/
|
||||||
|
public class GeneradorEntidades {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //Ya tenemos el "lector"
|
||||||
|
String mostrarTablas = "SHOW FULL TABLES FROM %s";
|
||||||
|
String driver = "com.mysql.cj.jdbc.Driver";
|
||||||
|
String database = "prueba";
|
||||||
|
String host = "localhost";
|
||||||
|
String port = "3306";
|
||||||
|
String url = "";
|
||||||
|
String user = "christian";
|
||||||
|
String pass = "12345678";
|
||||||
|
String linea = null;
|
||||||
|
String claveCompuesta = null;
|
||||||
|
try {
|
||||||
|
System.out.println(String.format(">>>>>>>>>>>> PENSADO EN SPRING<<<<<<<<<", driver));
|
||||||
|
System.out.println(String.format("Driver [%s]:", driver));
|
||||||
|
linea =br.readLine();
|
||||||
|
driver = linea == null || linea.trim().equals("") ? driver : linea ;
|
||||||
|
|
||||||
|
System.out.println(String.format("Database [%s]:", database));
|
||||||
|
linea = br.readLine();
|
||||||
|
database = linea == null || linea.trim().equals("") ? database : linea ;
|
||||||
|
|
||||||
|
System.out.println(String.format("Host [%s]:", host));
|
||||||
|
linea = br.readLine();
|
||||||
|
host = linea == null || linea.trim().equals("") ? host : linea ;
|
||||||
|
|
||||||
|
System.out.println(String.format("Port [%s]:", port));
|
||||||
|
linea = br.readLine();
|
||||||
|
port = linea == null || linea.trim().equals("") ? port : linea;
|
||||||
|
|
||||||
|
url = String.format("jdbc:mysql://%s:%s/%s?useSSL=false", host,port,database);
|
||||||
|
System.out.println("URL: "+url);
|
||||||
|
|
||||||
|
System.out.println(String.format("user [%s]:", user));
|
||||||
|
linea = br.readLine();
|
||||||
|
user = linea == null || linea.trim().equals("") ? user : linea;
|
||||||
|
|
||||||
|
System.out.println(String.format("pass [%s]:", pass));
|
||||||
|
linea = br.readLine();
|
||||||
|
pass = linea == null || linea.trim().equals("") ? pass : linea;
|
||||||
|
|
||||||
|
Conexion con = new Conexion(driver, database, host, port, url, user, pass);
|
||||||
|
|
||||||
|
Connection conection = con.crearConexionMysql();
|
||||||
|
System.out.println("Conexion>>"+conection);
|
||||||
|
|
||||||
|
ResultSet rs = con.crearResult(conection,String.format(mostrarTablas, database));
|
||||||
|
String nombreTabla;
|
||||||
|
ResultSet tb;
|
||||||
|
ResultSet tbnoPk;
|
||||||
|
String clase;
|
||||||
|
String tipoDato;
|
||||||
|
String paquete = "com.qsoft.ejemplo.rs.model";
|
||||||
|
|
||||||
|
String columna = null;
|
||||||
|
System.out.println(String.format("Paquete [%s]:", paquete));
|
||||||
|
linea = br.readLine();
|
||||||
|
paquete = linea == null || linea.trim().equals("") ? paquete : linea;
|
||||||
|
boolean auto_inc= Boolean.FALSE;
|
||||||
|
while (rs.next()) { /** recorre tablas*/
|
||||||
|
StringBuilder paquetes = new StringBuilder("package ");
|
||||||
|
nombreTabla = rs.getString(1);
|
||||||
|
StringBuilder codigoClase = new StringBuilder(String.format("@Entity\n@Table(name = \"%s\")\n", nombreTabla));
|
||||||
|
StringBuilder gettersSetters = new StringBuilder(String.format("@Entity\n@Table(name = \"%s\")\n", nombreTabla));
|
||||||
|
codigoClase.append("public class ").append(StringUtils.capitalize(toCamelCase(nombreTabla))).append(" implements Serializable {\n\n");
|
||||||
|
codigoClase.append("private static final long serialVersionUID = 1L;\n\n");
|
||||||
|
tb = con.crearResult(conection, String.format(GenedorConstantes.SQL_CAMPOS_RELACIONES.concat(" and tc.CONSTRAINT_TYPE = 'PRIMARY KEY';"), database, nombreTabla));
|
||||||
|
System.out.println(String.format(">>>>>>>>>>>>>>>>>>>>>>%s<<<<<<<<<<<<<<<<<<", nombreTabla));
|
||||||
|
|
||||||
|
paquetes.append(paquete).append(";\n");
|
||||||
|
paquetes.append("import jakarta.persistence.*;\n");
|
||||||
|
// primary key
|
||||||
|
int numeroFilas = 0;
|
||||||
|
List<String> pks = new ArrayList<>();
|
||||||
|
|
||||||
|
while (tb.next()) {
|
||||||
|
try {
|
||||||
|
Integer.parseInt(tb.getObject(15).toString());
|
||||||
|
auto_inc = Boolean.TRUE;
|
||||||
|
} catch (Exception e) {
|
||||||
|
auto_inc = Boolean.FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
numeroFilas++;
|
||||||
|
columna = tb.getString(3);
|
||||||
|
pks.add(String.format(GenedorConstantes.TAB.concat("private %s %s;\n\n"), tipoValor(tb.getString(5), tb.getInt(7), tb.getInt(8)),toCamelCase(columna)));
|
||||||
|
}
|
||||||
|
if(numeroFilas == 1){
|
||||||
|
codigoClase.append(String.format(auto_inc? GenedorConstantes.FORMATO_ANOTACIONES_AUTO_INCREMENT_PK : GenedorConstantes.FORMATO_ANOTACIONES_PK, columna));
|
||||||
|
codigoClase.append(pks.get(0));
|
||||||
|
|
||||||
|
}
|
||||||
|
if(numeroFilas> 1){
|
||||||
|
claveCompuesta = procesarClavePrimaria(pks, paquete, nombreTabla,auto_inc);
|
||||||
|
codigoClase.append("\n@EmbeddedId\n");
|
||||||
|
codigoClase.append(String.format("private %s %s;\n\n",StringUtils.capitalize(toCamelCase(nombreTabla)).concat("PK"), toCamelCase(nombreTabla).concat("PK")));
|
||||||
|
}
|
||||||
|
|
||||||
|
tbnoPk = con.crearResult(conection, String.format(GenedorConstantes.SQL_CAMPOS_RELACIONES.concat(" and tc.CONSTRAINT_TYPE <> 'PRIMARY KEY';"), database, nombreTabla));
|
||||||
|
while (tbnoPk.next()) {
|
||||||
|
if(tb.getString(11).equals("FOREIGN KEY")){
|
||||||
|
columna = tb.getString(3);
|
||||||
|
tipoDato = StringUtils.capitalize(tb.getString(13));
|
||||||
|
}
|
||||||
|
numeroFilas++;
|
||||||
|
columna = tb.getString(3);
|
||||||
|
pks.add(String.format(GenedorConstantes.TAB.concat("private %s %s;\n\n"), tipoValor(tb.getString(5), tb.getInt(7), tb.getInt(8)),columna));
|
||||||
|
|
||||||
|
}
|
||||||
|
System.out.println("CLAVE>>\n"+codigoClase.toString());
|
||||||
|
System.out.println("CLAVE>>\n"+claveCompuesta);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException|SQLException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* el
|
||||||
|
*/
|
||||||
|
public static String toCamelCase(String texto){
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String []textoSeparado = null;
|
||||||
|
if(texto.contains(" ")){
|
||||||
|
textoSeparado = texto.trim().split(" ");
|
||||||
|
}
|
||||||
|
if(texto.contains("-")){
|
||||||
|
textoSeparado = texto.trim().split("-");
|
||||||
|
}
|
||||||
|
if(texto.contains("_")){
|
||||||
|
textoSeparado = texto.trim().split("_");
|
||||||
|
}
|
||||||
|
if(textoSeparado == null){
|
||||||
|
textoSeparado = new String[]{texto};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0; i < textoSeparado.length; i++) {
|
||||||
|
if(i == 0){
|
||||||
|
sb.append(textoSeparado[i].toLowerCase());
|
||||||
|
}else{
|
||||||
|
sb.append(StringUtils.capitalize(texto.toLowerCase()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String procesarClavePrimaria(List<String> pks, String paquete, String nombreTabla,boolean auto_inc) {
|
||||||
|
StringBuilder sb ;
|
||||||
|
StringBuilder packetes ;
|
||||||
|
StringBuilder constructores;
|
||||||
|
StringBuilder gettersSetters;
|
||||||
|
String[] variableSplit;
|
||||||
|
String nombreDato = null;
|
||||||
|
StringBuilder valorPk;
|
||||||
|
|
||||||
|
sb = new StringBuilder(GenedorConstantes.COMENTARIO_DESARROLLADOR);
|
||||||
|
packetes = new StringBuilder("package ").append(paquete).append(";\n");
|
||||||
|
packetes.append("import jakarta.persistence.*;\nimport java.io.Serializable;\n");
|
||||||
|
constructores = new StringBuilder(String.format(GenedorConstantes.FORMATO_CONSTRUCTOR, StringUtils.capitalize(nombreTabla).concat("PK"),""));
|
||||||
|
constructores.append(GenedorConstantes.TAB).append("public ").append(StringUtils.capitalize(nombreTabla)).append("PK(");
|
||||||
|
|
||||||
|
gettersSetters = new StringBuilder();
|
||||||
|
sb.append("@Embeddable\npublic class ");
|
||||||
|
sb.append(StringUtils.capitalize(nombreTabla)).append("PK");
|
||||||
|
sb.append(" implements Serializable {\n");
|
||||||
|
int i = 0;
|
||||||
|
for (String pk : pks) {
|
||||||
|
variableSplit = pk.trim().split(" ");
|
||||||
|
|
||||||
|
nombreDato = variableSplit[2].split(";")[0];
|
||||||
|
|
||||||
|
gettersSetters.append(String.format(GenedorConstantes.FORMATO_GET, variableSplit[1],StringUtils.capitalize(nombreDato),nombreDato));
|
||||||
|
gettersSetters.append(String.format(GenedorConstantes.FORMATO_SET, StringUtils.capitalize(nombreDato),variableSplit[1],nombreDato,nombreDato,nombreDato));
|
||||||
|
if(pk.contains("Date")){
|
||||||
|
packetes.append("import java.util.Date;\n");
|
||||||
|
}
|
||||||
|
if(pk.contains("BigDecimal")){
|
||||||
|
packetes.append("import java.math.BigDecimal;\n");
|
||||||
|
}
|
||||||
|
if(pk.contains("BigInteger")){
|
||||||
|
packetes.append("import java.math.BigInteger;\n");
|
||||||
|
}
|
||||||
|
constructores.append(variableSplit[1]).append(" ").append(nombreDato);
|
||||||
|
if(i != (pks.size()-1)){
|
||||||
|
constructores.append(", ");
|
||||||
|
}
|
||||||
|
sb.append(GenedorConstantes.TAB).append("@Basic(optional = false)\n");
|
||||||
|
if(i == 0 && auto_inc){
|
||||||
|
sb.append(GenedorConstantes.TAB).append("@GeneratedValue(strategy = GenerationType.IDENTITY)\n");
|
||||||
|
}
|
||||||
|
sb.append(GenedorConstantes.TAB).append(String.format("@Column(name = \"%s\")\n", nombreDato));
|
||||||
|
sb.append(pk);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
constructores.append("){\n }\n\n");
|
||||||
|
valorPk = new StringBuilder(packetes).append(sb.append(constructores.append(gettersSetters.append("\n}"))));
|
||||||
|
|
||||||
|
return valorPk.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String tipoValor(String tipo, int presicion, int escala){
|
||||||
|
String tipoJava = "String";
|
||||||
|
|
||||||
|
switch (tipo.toLowerCase()) {
|
||||||
|
case "int":
|
||||||
|
tipoJava = "Integer";
|
||||||
|
if(escala == 0 ){
|
||||||
|
if(presicion > 5){
|
||||||
|
tipoJava = "Long";
|
||||||
|
}
|
||||||
|
if(presicion == 1){
|
||||||
|
tipoJava = "Short";
|
||||||
|
}
|
||||||
|
|
||||||
|
}else{
|
||||||
|
tipoJava = "Double";
|
||||||
|
|
||||||
|
if(presicion > 7 && escala>2){
|
||||||
|
tipoJava = "BigDecimal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "varchar":
|
||||||
|
tipoJava = "String";
|
||||||
|
break;
|
||||||
|
case "number":
|
||||||
|
tipoJava = "Integer";
|
||||||
|
break;
|
||||||
|
case "date":
|
||||||
|
tipoJava = "Date";
|
||||||
|
break;
|
||||||
|
case "datetime":
|
||||||
|
tipoJava = "Date";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
return tipoJava;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,139 @@
|
||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.qsoft.generador.entidades.coneccion;
|
||||||
|
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.DriverManager;
|
||||||
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author developer2
|
||||||
|
*/
|
||||||
|
public class Conexion {
|
||||||
|
private String driver;
|
||||||
|
private String database;
|
||||||
|
private String host;
|
||||||
|
private String port;
|
||||||
|
private String url;
|
||||||
|
private String user;
|
||||||
|
private String pass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Crear conexion a mysql
|
||||||
|
*/
|
||||||
|
public Connection crearConexionMysql(){
|
||||||
|
Connection con = null;
|
||||||
|
try {
|
||||||
|
Class.forName(driver);
|
||||||
|
con = DriverManager.getConnection(url, user, pass);
|
||||||
|
} catch (ClassNotFoundException | SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return con;
|
||||||
|
}
|
||||||
|
public void cerrar(Connection con) throws SQLException {
|
||||||
|
if (con != null) {
|
||||||
|
con.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public ResultSet crearResult(Connection con, String consulta) throws SQLException{
|
||||||
|
ResultSet rs = null;
|
||||||
|
PreparedStatement stmt = con.prepareStatement(consulta) ;
|
||||||
|
rs = stmt.executeQuery();
|
||||||
|
|
||||||
|
return rs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setBasics(){
|
||||||
|
driver = "com.mysql.cj.jdbc.Driver";
|
||||||
|
port = "3306";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Conexion() {
|
||||||
|
setBasics();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public Conexion(String driver, String database, String host, String port, String url, String user, String pass) {
|
||||||
|
this.driver = driver;
|
||||||
|
this.database = database;
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.url = url;
|
||||||
|
this.user = user;
|
||||||
|
this.pass = pass;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* GETERS Y SETTERS
|
||||||
|
*/
|
||||||
|
public String getDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriver(String driver) {
|
||||||
|
this.driver = driver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDatabase(String database) {
|
||||||
|
this.database = database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost() {
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host) {
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPort() {
|
||||||
|
return port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(String port) {
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPass() {
|
||||||
|
return pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPass(String pass) {
|
||||||
|
this.pass = pass;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,72 @@
|
||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package com.qsoft.generador.entidades.constantes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author developer2
|
||||||
|
*/
|
||||||
|
public class GenedorConstantes {
|
||||||
|
public static final String TAB = " ";
|
||||||
|
public static final String COMENTARIO_DESARROLLADOR = "/**\n *\n * @author Christian Ruales\n */\n";
|
||||||
|
public static final String ESQUEMA_CLASE = "package %s;\n" +
|
||||||
|
"import jakarta.persistence.*;\n" +
|
||||||
|
"\n" +
|
||||||
|
"@Entity\n" +
|
||||||
|
"@Table(name = \"%s\")\n" +
|
||||||
|
"public class %s {\n" +
|
||||||
|
"\n" +
|
||||||
|
" public %s() {\n" +
|
||||||
|
" }\n" +
|
||||||
|
"\n" +
|
||||||
|
"\n" +
|
||||||
|
" public %s(%s %s) {\n" +
|
||||||
|
" this.%s = %s;\n" +
|
||||||
|
" }\n" +
|
||||||
|
"\n" +
|
||||||
|
"%s" +
|
||||||
|
"\n" +
|
||||||
|
"}";
|
||||||
|
public static final String FORMATO_PK = " @Id\n" +
|
||||||
|
" @GeneratedValue(strategy = GenerationType.IDENTITY)\n" +
|
||||||
|
" @Column(name = \"%s\")\n" +
|
||||||
|
" private %s %s;\n" +";";
|
||||||
|
public static final String FORMATO_ANOTACIONES_AUTO_INCREMENT_PK = " @Id\n" +
|
||||||
|
" @GeneratedValue(strategy = GenerationType.IDENTITY)\n" +
|
||||||
|
" @Column(name = \"%s\")\n" ;
|
||||||
|
public static final String FORMATO_ANOTACIONES_PK = " @Id\n" +
|
||||||
|
" @Basic(optional = false)\n" +
|
||||||
|
" @Column(name = \"%s\")\n";
|
||||||
|
public static final String FORMATO_CAMPO_NORMAL= " @Column(name = \"%s\")\n" +
|
||||||
|
" private %s %s;\n" ;
|
||||||
|
public static final String FORMATO_CAMPO_RELACION = " @JoinColumn(name = \"%s\", insertable = false, updatable = false)\n" +
|
||||||
|
" @ManyToOne\n" +
|
||||||
|
" private %s %s;\n";
|
||||||
|
|
||||||
|
public static final String FORMATO_CONSTRUCTOR = " public %s(%s) {\n" +
|
||||||
|
" }\n\n";
|
||||||
|
|
||||||
|
public static final String FORMATO_GET=" public %s get%s() {\n" +
|
||||||
|
" return %s;\n" +
|
||||||
|
" }\n" +
|
||||||
|
"\n";
|
||||||
|
public static final String FORMATO_SET=" public void set%s(%s %s) {\n" +
|
||||||
|
" this.%s = %s;\n" +
|
||||||
|
" }\n\n";
|
||||||
|
|
||||||
|
public static final String SQL_CAMPOS_RELACIONES = "SELECT c.TABLE_SCHEMA,c.TABLE_NAME,c.COLUMN_NAME,c.ORDINAL_POSITION,c.DATA_TYPE,\n" +
|
||||||
|
"c.CHARACTER_MAXIMUM_LENGTH,c.NUMERIC_PRECISION,c.NUMERIC_SCALE,c.COLUMN_KEY,\n" +
|
||||||
|
"t.CONSTRAINT_NAME, tc.CONSTRAINT_TYPE,t.COLUMN_NAME, t.REFERENCED_TABLE_NAME, t.REFERENCED_COLUMN_NAME,tab.`AUTO_INCREMENT` \n" +
|
||||||
|
"FROM information_schema.`COLUMNS` c\n" +
|
||||||
|
" LEFT join information_schema.KEY_COLUMN_USAGE t on\n" +
|
||||||
|
" t.TABLE_SCHEMA = c.TABLE_SCHEMA and c.TABLE_NAME = t.TABLE_NAME \n" +
|
||||||
|
" AND c.COLUMN_NAME = t.COLUMN_NAME \n" +
|
||||||
|
" left join information_schema.TABLE_CONSTRAINTS tc on\n" +
|
||||||
|
" t.TABLE_SCHEMA = tc.TABLE_SCHEMA and t.TABLE_NAME = tc.TABLE_NAME \n" +
|
||||||
|
" and t.CONSTRAINT_NAME = tc.CONSTRAINT_NAME \n" +
|
||||||
|
"left join information_schema.TABLES tab on\n" +
|
||||||
|
" t.TABLE_SCHEMA = tab.TABLE_SCHEMA and t.TABLE_NAME = tab.TABLE_NAME \n"+
|
||||||
|
"where c.TABLE_SCHEMA = '%s' and c.TABLE_NAME = '%s'" ;
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,3 @@
|
||||||
|
/home/developer2/NetBeansProjects/generador-entidades/src/main/java/com/qsoft/generador/entidades/constantes/GenedorConstantes.java
|
||||||
|
/home/developer2/NetBeansProjects/generador-entidades/src/main/java/com/qsoft/generador/entidades/coneccion/Conexion.java
|
||||||
|
/home/developer2/NetBeansProjects/generador-entidades/src/main/java/com/qsoft/generador/entidades/GeneradorEntidades.java
|
||||||
Loading…
Reference in New Issue