Esempio n. 1
0
 void renderMappers(Configuration cfg) throws IOException {
   for (EntityModel model : getAllModels()) {
     Map<String, Object> params = new HashMap<String, Object>();
     params.put("model", model);
     params.put("version", currentVersion());
     for (Query query : model.getSelectQueries()) {
       params.put("query", query);
       writeFile(
           defaultPackageName + ".mapper.cursor",
           model.getName() + query.getName() + "Mapper",
           getTemplate(cfg, "java", "cursorobjectmapper"),
           params);
     }
     params.put("prefix", "insert");
     params.put("suffix", "");
     writeFile(
         defaultPackageName + ".mapper.content.insert",
         model.getName() + "Mapper",
         getTemplate(cfg, "java", "contentvaluesmapper"),
         params);
     for (Query query : model.getUpdateQueries()) {
       params.put("prefix", "update");
       params.put("suffix", query.getName());
       writeFile(
           defaultPackageName + ".mapper.content.update",
           model.getName() + query.getName() + "Mapper",
           getTemplate(cfg, "java", "contentvaluesmapper"),
           params);
     }
   }
 }
Esempio n. 2
0
 void renderPersistence(Configuration cfg) throws IOException {
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("models", getAllModels());
   params.put("package", defaultPackageName);
   writeFile(
       defaultPackageName + ".persistence",
       "PersistenceManager",
       getTemplate(cfg, "java", "persistencemanager"),
       params);
 }
Esempio n. 3
0
 void renderContentProvider(Configuration cfg) throws IOException {
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("models", getAllModels());
   params.put("package", defaultPackageName + ".providers");
   params.put("defaultPackage", defaultPackageName);
   writeFile(
       defaultPackageName + ".providers",
       "NucleiContentProvider",
       getTemplate(cfg, "java", "contentprovider"),
       params);
 }
Esempio n. 4
0
 void renderModels(Configuration cfg) throws IOException {
   List<EntityModel> allModels = getAllModels();
   Map<String, Object> params = new HashMap<String, Object>();
   params.put("models", allModels);
   params.put("packageName", defaultPackageName + ".providers");
   params.put("authority", authority);
   params.put("version", currentVersion());
   writeFile(
       defaultPackageName + ".providers", "Schemas", getTemplate(cfg, "java", "schema"), params);
   for (EntityModel model : allModels) {
     if (!model.isRender()) continue;
     params = new HashMap<String, Object>();
     params.put("model", model);
     params.put("version", currentVersion());
     params.put("properties", model.getAllProperties(null));
     writeFile(
         model.getPackageName() + ".model",
         model.getName(),
         getTemplate(cfg, "java", "model"),
         params);
   }
 }
Esempio n. 5
0
  void renderDbHelper(Configuration cfg) throws IOException {
    Version lastVersion = null;
    for (Version version : versions) {
      if (lastVersion != null) {
        List<String> sql = new ArrayList<String>();
        switch (version.getType()) {
          case DIFF:
            {
              Version.Diff diff = lastVersion.diff(version);
              for (EntityModel removed : diff.removedModels) {
                if (removed instanceof ViewEntityModel) sql.add(renderDropStructure(removed, cfg));
              }
              for (EntityModel removed : diff.removedModels) {
                if (!(removed instanceof ViewEntityModel))
                  sql.add(renderDropStructure(removed, cfg));
              }
              for (EntityIndex removed : diff.removedIndexes) {
                sql.add(renderDropIndex(removed, cfg));
              }
              for (EntityModel added : diff.addedModels) {
                if (!(added instanceof ViewEntityModel))
                  sql.add(renderCreateStructure(added, added.getProperties(version), cfg));
              }
              for (EntityModel added : diff.addedModels) {
                if (added instanceof ViewEntityModel)
                  sql.add(renderCreateStructure(added, added.getProperties(version), cfg));
              }
              for (EntityIndex added : diff.addedIndexes) {
                sql.add(renderCreateIndex(added, cfg));
              }
              diffProperties(sql, lastVersion, version, diff, cfg);
              break;
            }
          case DIFF_PROPERTIES:
            {
              Version.Diff diff = lastVersion.diff(version);
              diffProperties(sql, lastVersion, version, diff, cfg);
              break;
            }
          case ADD_MODELS:
            for (EntityModel model : version.getModels()) {
              sql.add(renderCreateStructure(model, model.getProperties(version), cfg));
              for (EntityIndex index : model.getIndexes(version)) {
                sql.add(renderCreateIndex(index, cfg));
              }
            }
            break;
          case DROP_MODELS:
            for (EntityModel removed : version.getModels()) {
              if (removed instanceof ViewEntityModel) sql.add(renderDropStructure(removed, cfg));
            }
            for (EntityModel removed : version.getModels()) {
              if (!(removed instanceof ViewEntityModel)) sql.add(renderDropStructure(removed, cfg));
            }
            break;
          case ADD_PROPERTIES:
            {
              for (EntityModel model : version.getModels()) {
                for (EntityProperty property : model.getProperties(version)) {
                  sql.add(renderAddProperty(property, cfg));
                }
              }
              break;
            }
          case ADD_INDEXES:
            {
              for (EntityModel model : version.getModels()) {
                for (EntityIndex index : model.getIndexes(version)) {
                  sql.add(renderCreateIndex(index, cfg));
                }
              }
              break;
            }
          case DROP_PROPERTIES:
            {
              for (EntityModel model : version.getModels()) {
                for (EntityProperty property : model.getProperties(version)) {
                  sql.add(renderDropProperty(property, cfg));
                }
              }
              break;
            }
          case DROP_INDEXES:
            {
              for (EntityModel model : version.getModels()) {
                for (EntityIndex index : model.getIndexes(version)) {
                  sql.add(renderDropIndex(index, cfg));
                }
              }
              break;
            }
        }

        version.setSql(sql);
      } else {
        List<String> sql = new ArrayList<String>();
        for (EntityModel model : version.getModels()) {
          sql.add(renderCreateStructure(model, model.getProperties(version), cfg));
          for (EntityIndex index : model.getIndexes(version)) {
            sql.add(renderCreateIndex(index, cfg));
          }
        }
        version.setSql(sql);
      }
      lastVersion = version;
    }

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("baseVersion", baseVersion());
    params.put("versions", versions);
    params.put("versionCount", versions.size());
    params.put("packageName", defaultPackageName + ".providers");
    params.put("defaultPackage", defaultPackageName);
    params.put("databaseName", databaseName);
    writeFile(
        defaultPackageName + ".providers",
        "NucleiDbHelper",
        getTemplate(cfg, "java", "dbhelper"),
        params);
  }