示例#1
0
 public DbContext(String defaultPackageName, String authority, String databaseName, File outDir) {
   this.defaultPackageName = defaultPackageName;
   this.authority = authority;
   this.databaseName = databaseName;
   this.versions = new ArrayList<Version>();
   this.outDir = outDir;
   newVersion(Version.VersionType.DIFF);
 }
示例#2
0
  public static DbContext newContext(
      JSONObject model, File outputDir, String defaultPackage, String authority)
      throws IOException {
    EntityModelRegistry.clear();
    DbContext ctx =
        new DbContext(
            model.getString("defaultPackage"),
            authority == null ? model.getString("authority") : authority,
            model.getString("databaseName"),
            outputDir);

    JSONArray versions = model.getJSONArray("versions");
    for (int i = 0; i < versions.length(); i++) {
      JSONObject version = versions.getJSONObject(i);
      JSONArray entities = version.getJSONArray("entities");

      for (int e = 0; e < entities.length(); e++) {
        JSONObject entity = entities.getJSONObject(e);
        processEntity(entity, ctx, ctx.currentVersion());
      }

      if (i + 1 < versions.length()) {
        version = versions.getJSONObject(i + 1);
        ctx.newVersion(
            version.has("type")
                ? Version.VersionType.valueOf(version.getString("type"))
                : Version.VersionType.DIFF);
      }
    }

    for (int i = 0; i < versions.length(); i++) {
      JSONObject version = versions.getJSONObject(i);
      JSONObject defaultQueries = version.has("queries") ? version.getJSONObject("queries") : null;
      JSONArray entities = version.getJSONArray("entities");

      for (int e = 0; e < entities.length(); e++) {
        JSONObject entity = entities.getJSONObject(e);
        EntityModel entityModel = ctx.getModel(entity.getString("name"));
        processQueries(defaultQueries, entityModel, ctx.currentVersion());
      }
    }

    return ctx;
  }