You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
73 lines
2.2 KiB
package de.superx.bin; |
|
|
|
import java.io.File; |
|
import java.io.FileWriter; |
|
import java.io.IOException; |
|
import java.io.Writer; |
|
import java.util.HashMap; |
|
|
|
import de.memtext.util.DateUtils; |
|
import freemarker.template.Configuration; |
|
import freemarker.template.Template; |
|
import freemarker.template.TemplateException; |
|
|
|
public class DialectCreator { |
|
private static String path, sourceFileName; |
|
|
|
private static String source; |
|
|
|
protected static Configuration cfg = new Configuration(); |
|
|
|
private static Template template; |
|
|
|
public static void main(String[] args) { |
|
checkArgs(args); |
|
try { |
|
cfg.setDirectoryForTemplateLoading(new File(path)); |
|
template = cfg.getTemplate(sourceFileName); |
|
//source=StringUtils.readFile(f); |
|
translate("Informix", "_ids"); |
|
translate("Postgres", "_pg"); |
|
|
|
} catch (Exception e) { |
|
e.printStackTrace(); |
|
} |
|
} |
|
|
|
private static void checkArgs(String[] args) { |
|
if (args.length != 2) { |
|
System.out.println("Error: use: DialectCreator path sourcefilename"); |
|
System.exit(1); |
|
} |
|
path = args[0]; |
|
sourceFileName = args[1]; |
|
File f = new File(path + File.separator + sourceFileName); |
|
if (!f.exists() || !f.canRead()) { |
|
System.out.println("Error: can't read source file " + args[1]); |
|
System.exit(1); |
|
} |
|
} |
|
|
|
private static void translatePostgres() { |
|
HashMap map = new HashMap(); |
|
|
|
map.put("SQLdialect", "Postgres"); |
|
|
|
} |
|
|
|
private static void translate(String dialect, String fileAppendix) throws TemplateException, IOException { |
|
HashMap map = new HashMap(); |
|
map.put("SQLdialect", dialect); |
|
map.put("current", DateUtils.getTodayString() + " um " + DateUtils.getNowString()); |
|
String fname = sourceFileName.substring(0, sourceFileName.length() - 4) + fileAppendix + ".sql"; |
|
|
|
Writer out = new FileWriter(path + File.separator + fname); |
|
|
|
// Merge the data-model and the template |
|
template.process(map, out); |
|
out.close(); |
|
System.out.println(" " + dialect + " variant created:" + fname); |
|
} |
|
} |
|
|
|
//Created on 19.04.2005 at 10:22:09
|
|
|