|
1 | 1 | package dev.sassine.api.structure; |
2 | 2 |
|
3 | 3 | import static dev.sassine.api.structure.export.DatabaseConverter.convert; |
4 | | -import static dev.sassine.api.structure.export.builder.BuilderEntity.build; |
5 | | -import static dev.sassine.api.structure.type.TypeConverter.convertTypeFromSQLToEntityStore; |
| 4 | +import static dev.sassine.api.structure.type.TypeConverter.convertTypeFromSQLDataBaseToEntityStore; |
6 | 5 | import static dev.sassine.api.structure.util.Util.read; |
7 | 6 | import static dev.sassine.api.structure.validation.DatabaseValidator.validate; |
| 7 | +import static org.apache.logging.log4j.LogManager.getLogger; |
8 | 8 |
|
9 | 9 | import java.io.FileInputStream; |
10 | 10 | import java.io.InputStream; |
11 | 11 | import java.util.List; |
12 | 12 |
|
| 13 | +import org.apache.logging.log4j.Logger; |
| 14 | + |
| 15 | +import dev.sassine.api.structure.export.builder.ClassSourceBuilder; |
13 | 16 | import dev.sassine.api.structure.model.java.EntityModel; |
14 | 17 | import dev.sassine.api.structure.model.sql.Database; |
15 | 18 | import dev.sassine.api.structure.parser.SqlImport; |
16 | | -import lombok.extern.slf4j.Slf4j; |
17 | 19 |
|
18 | | -@Slf4j |
19 | 20 | public class Sqlschema2Java { |
20 | 21 |
|
21 | | - public void compile(String inputFile,boolean isPostgress,boolean isAutoGenerated) { |
22 | | - inputFile = "C:\\poc\\poc.sql"; |
| 22 | + private static final Logger log = getLogger(); |
| 23 | + |
| 24 | + public static void generate(String inputFile, boolean isPostgress, boolean isAutoGenerated, String packageName) { |
23 | 25 | log.debug("preparing to read SQL file('{}') ", inputFile); |
24 | 26 | try (InputStream in = new FileInputStream(inputFile)) { |
25 | | - log.debug("file read successfully"); |
26 | | - process(read(in),isPostgress,isAutoGenerated); |
| 27 | + log.debug("file read successfull"); |
| 28 | + log.debug("Parameters ::: isPostgress: {} | isAutoGenerated: {} | packageName: {}", isPostgress, isAutoGenerated, packageName); |
| 29 | + process(read(in), isPostgress, isAutoGenerated, packageName); |
| 30 | + log.info("Congratulations build successful [√]"); |
27 | 31 | } catch (final Exception e) { |
28 | 32 | log.error(e.getMessage(), e); |
29 | 33 | } |
30 | 34 | } |
31 | | - |
32 | | - private void process(final String sqlContent, boolean isPostgress, boolean isAutoGenerated) { |
33 | | - Database database = new SqlImport().getDatabase(sqlContent); |
34 | | - convertTypeFromSQLToEntityStore(database,isPostgress); |
| 35 | + |
| 36 | + private static void process(final String sqlContent, boolean isPostgress, boolean isAutoGenerated, String packageName) { |
| 37 | + final Database database = SqlImport.init().getDatabase(sqlContent); |
| 38 | + convertTypeFromSQLDataBaseToEntityStore(database, isPostgress); |
35 | 39 | validate(database); |
36 | 40 | List<EntityModel> entityModel = convert(database); |
37 | | - build(entityModel,isAutoGenerated); |
| 41 | + ClassSourceBuilder.init().build(entityModel, isAutoGenerated, packageName); |
38 | 42 | } |
39 | 43 |
|
40 | 44 | } |
0 commit comments