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.

Generator.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package com.rthoni.intellij.codefromds.business;
  2. import com.intellij.database.psi.DbDataSource;
  3. import com.rthoni.intellij.codefromds.dbo.GenerateOptions;
  4. import org.json.JSONObject;
  5. import java.io.FileOutputStream;
  6. import java.nio.charset.StandardCharsets;
  7. import java.nio.file.Files;
  8. import java.nio.file.Paths;
  9. import java.util.HashMap;
  10. /**
  11. * Created by robin on 11/15/16.
  12. */
  13. public abstract class Generator {
  14. public static void saveOptions(GenerateOptions options) throws Exception {
  15. HashMap<String, Object> map = options.toMap();
  16. JSONObject obj = new JSONObject(map);
  17. FileOutputStream file = new FileOutputStream(options.getConfigPath());
  18. file.write(obj.toString(4).getBytes());
  19. file.close();
  20. }
  21. public static GenerateOptions loadOptions(String configPath) throws Exception {
  22. String data = Files.readAllLines(Paths.get(configPath), StandardCharsets.UTF_8).stream().reduce("", (s1, s2) -> s1 + s2);
  23. JSONObject obj = new JSONObject(data);
  24. String src = obj.getJSONObject("selection").getString("source");
  25. DbDataSource dataSource = Helper.findDataSource(src);
  26. if (dataSource == null) {
  27. throw new Exception("Data source " + src + " not found");
  28. }
  29. GenerateOptions options = new GenerateOptions(dataSource);
  30. options.setConfigPath(configPath);
  31. options.fromJson(obj);
  32. return options;
  33. }
  34. public static void generate(GenerateOptions options)
  35. {
  36. }
  37. }