// Path: generator/src/main/java/io/github/huherto/springyRecords/generator/SchemaCrawlerGenerator.java
// public class SchemaCrawlerGenerator extends AbstractGenerator {
// 
//     protected static final Log logger = LogFactory.getLog(SchemaCrawlerGenerator.class);
// 
//     private final DataSource ds;
// 
//     public SchemaCrawlerGenerator(DataSource ds, String packageName, String databaseClassName) {
//         super(packageName, databaseClassName);
//         this.ds = ds;
//     }
// 
//     protected TableToolImpl createTableTool(String packageName) {
//         return new TableToolImpl(packageName);
//     }
// 
//     private Database crawl(Connection dbconn, SchemaCrawlerOptions options) {
//         try {
//             SchemaCrawler crawler = new SchemaCrawler(dbconn);
//             return crawler.crawl(options);
//         } catch (SchemaCrawlerException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     private Database crawl(Connection con, String schemaName, String tableName) {
// 
//         SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//         options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaName));
//         options.setTableNamePattern("%" + tableName + "%");
//         SchemaInfoLevel infoLevel = SchemaInfoLevel.standard();
//         options.setSchemaInfoLevel(infoLevel);
//         infoLevel.setRetrieveRoutines(false);
// 
//         return crawl(con, options);
//     }
// 
//     public void printInformationSchema(String schemaInclusionRule) {
// 
//         try (Connection con = ds.getConnection()) {
//             SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//             options.setSchemaInfoLevel(SchemaInfoLevel.minimum());
//             if (schemaInclusionRule != null) {
//                 options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaInclusionRule));
//             }
//             Database database = crawl(con, options);
// 
//             for(Table table : database.getTables()) {
//               logger.info(format("schema:%s, table:%s", table.getSchema(), table.getName()));
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
//     public void processAllTables(String... schemaNameList) {
// 
//         DatabaseTool dbTool = new DatabaseTool(getPackageName(), getDatabaseClassName() );
//         try (Connection con = ds.getConnection()) {
//             for(String schemaName : schemaNameList) {
//                 SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//                 options.setSchemaInfoLevel(SchemaInfoLevel.minimum());
//                 options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaName));
//                 Database database = crawl(con, options);
// 
//                 List<String> tableNames = new ArrayList<>();
// 
//                 for(Table table : database.getTables(database.getSchema(schemaName))) {
//                   tableNames.add(table.getName());
//                 }
//                 logger.info("Schema:"+schemaName+" found "+tableNames.size()+" tables");
// 
//                 prepareTableList(schemaName, tableNames, dbTool);
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//         writeAllClasses(dbTool);
//     }
// 
//     public void processTableList(String schemaName, List<String> tableNames) {
// 
//         DatabaseTool dbTool = new DatabaseTool(getPackageName(), getDatabaseClassName() );
// 
//         prepareTableList(schemaName, tableNames, dbTool);
// 
//         writeAllClasses(dbTool);
//     }
// 
//     private void prepareTableList(String schemaName, List<String> tableNames,
//             DatabaseTool dbTool) {
//         try(Connection con = ds.getConnection()) {
//             for(String tableName : tableNames) {
// 
//                 Database database = crawl(con, schemaName, tableName);
//                 Table table = database.getTable(database.getSchema(schemaName), tableName);
//                 if (table != null) {
//                     TableToolImpl tableTool = createTableTool(getPackageName());
//                     tableTool.initialize(table);
//                     dbTool.add(tableTool);
//                     logger.info(format("Will process schema:[%s] table:[%s]", schemaName, tableName));
//                 }
//                 else {
//                     logger.warn(format("schema:[%s] table:[%s] Not found", schemaName, tableName));
//                 }
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
// 
// }


import static java.util.Arrays.asList;
import java.nio.file.Paths;
import javax.sql.DataSource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import io.github.huherto.springyRecords.generator.SchemaCrawlerGenerator;
package com.example.generator;







/*
 * Modify this file to suit your needs.
 * 
 * 
 */
@SpringBootApplication
public class Application implements CommandLineRunner {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
    
	@Override
	public void run(String... args) {	
	    generateExample();
	}

	private void generateExample() {	    
	    
	    String packageName = "com.example";  // Modify this.
	    String databaseClassName = "Example"; // Modify this.
// Path: generator/src/main/java/io/github/huherto/springyRecords/generator/SchemaCrawlerGenerator.java
// public class SchemaCrawlerGenerator extends AbstractGenerator {
// 
//     protected static final Log logger = LogFactory.getLog(SchemaCrawlerGenerator.class);
// 
//     private final DataSource ds;
// 
//     public SchemaCrawlerGenerator(DataSource ds, String packageName, String databaseClassName) {
//         super(packageName, databaseClassName);
//         this.ds = ds;
//     }
// 
//     protected TableToolImpl createTableTool(String packageName) {
//         return new TableToolImpl(packageName);
//     }
// 
//     private Database crawl(Connection dbconn, SchemaCrawlerOptions options) {
//         try {
//             SchemaCrawler crawler = new SchemaCrawler(dbconn);
//             return crawler.crawl(options);
//         } catch (SchemaCrawlerException e) {
//             throw new RuntimeException(e);
//         }
//     }
// 
//     private Database crawl(Connection con, String schemaName, String tableName) {
// 
//         SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//         options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaName));
//         options.setTableNamePattern("%" + tableName + "%");
//         SchemaInfoLevel infoLevel = SchemaInfoLevel.standard();
//         options.setSchemaInfoLevel(infoLevel);
//         infoLevel.setRetrieveRoutines(false);
// 
//         return crawl(con, options);
//     }
// 
//     public void printInformationSchema(String schemaInclusionRule) {
// 
//         try (Connection con = ds.getConnection()) {
//             SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//             options.setSchemaInfoLevel(SchemaInfoLevel.minimum());
//             if (schemaInclusionRule != null) {
//                 options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaInclusionRule));
//             }
//             Database database = crawl(con, options);
// 
//             for(Table table : database.getTables()) {
//               logger.info(format("schema:%s, table:%s", table.getSchema(), table.getName()));
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
//     public void processAllTables(String... schemaNameList) {
// 
//         DatabaseTool dbTool = new DatabaseTool(getPackageName(), getDatabaseClassName() );
//         try (Connection con = ds.getConnection()) {
//             for(String schemaName : schemaNameList) {
//                 SchemaCrawlerOptions options = new SchemaCrawlerOptions();
//                 options.setSchemaInfoLevel(SchemaInfoLevel.minimum());
//                 options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaName));
//                 Database database = crawl(con, options);
// 
//                 List<String> tableNames = new ArrayList<>();
// 
//                 for(Table table : database.getTables(database.getSchema(schemaName))) {
//                   tableNames.add(table.getName());
//                 }
//                 logger.info("Schema:"+schemaName+" found "+tableNames.size()+" tables");
// 
//                 prepareTableList(schemaName, tableNames, dbTool);
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//         writeAllClasses(dbTool);
//     }
// 
//     public void processTableList(String schemaName, List<String> tableNames) {
// 
//         DatabaseTool dbTool = new DatabaseTool(getPackageName(), getDatabaseClassName() );
// 
//         prepareTableList(schemaName, tableNames, dbTool);
// 
//         writeAllClasses(dbTool);
//     }
// 
//     private void prepareTableList(String schemaName, List<String> tableNames,
//             DatabaseTool dbTool) {
//         try(Connection con = ds.getConnection()) {
//             for(String tableName : tableNames) {
// 
//                 Database database = crawl(con, schemaName, tableName);
//                 Table table = database.getTable(database.getSchema(schemaName), tableName);
//                 if (table != null) {
//                     TableToolImpl tableTool = createTableTool(getPackageName());
//                     tableTool.initialize(table);
//                     dbTool.add(tableTool);
//                     logger.info(format("Will process schema:[%s] table:[%s]", schemaName, tableName));
//                 }
//                 else {
//                     logger.warn(format("schema:[%s] table:[%s] Not found", schemaName, tableName));
//                 }
//             }
//         }
//         catch(SQLException ex) {
//             throw new RuntimeException(ex);
//         }
//     }
// 
// 
// }


// Path: example-generator/src/main/java/com/example/generator/Application.java
import static java.util.Arrays.asList;
import java.nio.file.Paths;
import javax.sql.DataSource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import io.github.huherto.springyRecords.generator.SchemaCrawlerGenerator;

package com.example.generator;







/*
 * Modify this file to suit your needs.
 * 
 * 
 */
@SpringBootApplication
public class Application implements CommandLineRunner {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
    
	@Override
	public void run(String... args) {	
	    generateExample();
	}

	private void generateExample() {	    
	    
	    String packageName = "com.example";  // Modify this.
	    String databaseClassName = "Example"; // Modify this.
	    SchemaCrawlerGenerator dbGenerator = new SchemaCrawlerGenerator(dataSource(), packageName, databaseClassName);