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; }
public EntityModel getModel(String name, String packageName) { return EntityModelRegistry.getModel(name, packageName); }