1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.ftp.exec;
22
23 import goldengate.common.database.exception.GoldenGateDatabaseNoConnectionException;
24 import goldengate.common.file.filesystembased.FilesystemBasedFileParameterImpl;
25 import goldengate.common.logging.GgInternalLogger;
26 import goldengate.common.logging.GgInternalLoggerFactory;
27 import goldengate.common.logging.GgSlf4JLoggerFactory;
28 import goldengate.ftp.core.utils.FtpChannelUtils;
29 import goldengate.ftp.exec.config.FileBasedConfiguration;
30 import goldengate.ftp.exec.control.ExecBusinessHandler;
31 import goldengate.ftp.exec.data.FileSystemBasedDataBusinessHandler;
32 import goldengate.ftp.exec.database.DbConstant;
33 import goldengate.ftp.exec.database.model.DbModelFactory;
34
35 import org.jboss.netty.logging.InternalLoggerFactory;
36
37
38
39
40
41
42 public class ServerInitDatabase {
43
44
45
46 static volatile GgInternalLogger logger;
47
48 static String sxml = null;
49 static boolean database = false;
50
51 protected static boolean getParams(String [] args) {
52 if (args.length < 1) {
53 logger.error("Need at least the configuration file as first argument then optionally\n" +
54 " -initdb");
55 return false;
56 }
57 sxml = args[0];
58 for (int i = 1; i < args.length; i++) {
59 if (args[i].equalsIgnoreCase("-initdb")) {
60 database = true;
61 }
62 }
63 return true;
64 }
65
66
67
68
69
70
71 public static void main(String[] args) {
72 InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
73 if (logger == null) {
74 logger = GgInternalLoggerFactory.getLogger(ServerInitDatabase.class);
75 }
76 if (! getParams(args)) {
77 logger.error("Need at least the configuration file as first argument then optionally\n" +
78 " -initdb");
79 if (DbConstant.admin != null && DbConstant.admin.isConnected) {
80 DbConstant.admin.close();
81 }
82 FtpChannelUtils.stopLogger();
83 System.exit(1);
84 }
85 FileBasedConfiguration configuration = new FileBasedConfiguration(
86 ExecGatewayFtpServer.class, ExecBusinessHandler.class,
87 FileSystemBasedDataBusinessHandler.class,
88 new FilesystemBasedFileParameterImpl());
89 try {
90 if (!configuration.setConfigurationServerFromXml(args[0])) {
91 System.err.println("Bad main configuration");
92 if (DbConstant.admin != null){
93 DbConstant.admin.close();
94 }
95 FtpChannelUtils.stopLogger();
96 System.exit(1);
97 return;
98 }
99 if (database) {
100
101 try {
102 initdb();
103 } catch (GoldenGateDatabaseNoConnectionException e) {
104 logger.error("Cannot connect to database");
105 return;
106 }
107 System.out.println("End creation");
108 }
109 System.out.println("Load done");
110 } finally {
111 if (DbConstant.admin != null) {
112 DbConstant.admin.close();
113 }
114 }
115 }
116
117 public static void initdb() throws GoldenGateDatabaseNoConnectionException {
118
119 DbModelFactory.dbModel.createTables(DbConstant.admin.session);
120 }
121
122 }