コード例 #1
0
ファイル: DbContext.java プロジェクト: nuclei-io/box
 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
ファイル: DbContext.java プロジェクト: nuclei-io/box
  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;
  }