Package org.byteliberi.easydriver.generator.model

Examples of org.byteliberi.easydriver.generator.model.ClassModel


      final String structureName = Utils.getCamelNameFirstCapital(tableName);
      final String className = structureName + "ObjectModel";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
      Logger.getLogger(ObjectModelGeneration.class.getName()).info("Working on: " + tableName);
       
      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className, false);
      classModel.setPackageName(this.packageName);
     
      // Let's look for the foreign keys and let's add the properties
      final Map<String, String> fks = addExternalClasses(tableInfo, classModel);
         
      // There can be more than one field for just one external table.
      // Let's group by the Class name, saving just the first column name.
      final HashSet<String> usedClasses = new HashSet<String>();
      final Set<Entry<String,String>> fksEntries = fks.entrySet();
      for (Entry<String, String> fksEntry : fksEntries) {
        final String examinedClass = Utils.getCamelNameFirstCapital( fksEntry.getValue() ) + "ObjectModel";
        if (!usedClasses.contains(examinedClass)) {
          usedClasses.add(examinedClass);
          classModel.addProperty(new PropertyModel(Visibility.PRIVATE, examinedClass, fksEntry.getKey()));
        }
      }
     
      // Let's add the properties for the columns
      for (PropertyModel prop : tableInfo.getProperties()) {
        if (!fks.containsKey(prop.getName()))
          classModel.addProperty(prop);
      }
     
      final List<PropertyModel> primaryKeys = new LinkedList<PropertyModel>();
      final List<PropertyModel> presentProps = classModel.getProperties();
      for(PropertyModel primaryKey : tableInfo.getPrimaryKey()) {
        final String key = primaryKey.getName();
        for (PropertyModel presentProp : presentProps) {
           if (presentProp.getName().equals(key)) {
             primaryKeys.add(new PropertyModel(Visibility.PRIVATE, presentProp.getPropertyClass(), key));
           }
        }
      }
     
      classModel.setConstructorGenerator(new PrimaryKeyConstructor(className, primaryKeys));
     
      // Getters
      classModel.createGetters();
      // Setters
      classModel.createSetters();
     
      classModel.write(out);
      out.flush();
      out.close();
    }       
  }   
View Full Code Here


      final String className = objectModelName + "Factory";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
           
      Logger.getLogger(ObjectModelGeneration.class.getName()).info("Working on: " + tableName);

      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className);
      classModel.setPackageName(this.packageName);       
      classModel.addImport("java.sql.ResultSet");
      classModel.addImport("java.sql.SQLException");
      classModel.addImport("org.byteliberi.easydriver.ObjectFactory");
      classModel.setImplementList(MessageFormat.format("ObjectFactory<{0}>", objectModelName));
     
      classModel.addMethod(new MapRS(objectModelName, structureName, findFieldInit(tableInfo)));
     
      classModel.write(out);
      out.flush();
      out.close();
    }
  }
View Full Code Here

      final String structureName = Utils.getCamelNameFirstCapital(tableName);
      final String className = structureName + "Service";
      final PrintStream out = new PrintStream( Utils.getCamelNameFirstCapital(dirPath + className + ".java"), "UTF-8" );
      final String objectModelName = structureName + OBJECT_MODEL;
           
      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  className);
      classModel.setPackageName(this.packageName);
      classModel.addImport("java.sql.Connection");
      classModel.addImport("java.sql.SQLException");
      classModel.addImport("org.byteliberi.easydriver.*");
      classModel.addImport("org.byteliberi.easydriver.fields.*");
      classModel.addImport("org.byteliberi.easydriver.expressions.*");
     
       
      classModel.addMethod(new SelectByPKMethod(tableInfo.getPrimaryKey(), structureName, objectModelName));
      classModel.addMethod(new DeleteMethod(tableInfo.getPrimaryKey(), structureName));
      classModel.addMethod(new InsertMethod(tableInfo.getFields(), structureName, objectModelName, tableInfo));
      classModel.addMethod(new UpdateMethod(tableInfo.getFields(), tableInfo.getPrimaryKey(), structureName, objectModelName, tableInfo));
       
      classModel.write(out);
      out.flush();
      out.close();
   
  }
View Full Code Here

      final String tableName = tableInfo.getTableName();
      final PrintStream out = new PrintStream( dirPath + Utils.getCamelNameFirstCapital(tableName) + ".java", "UTF-8" );
     
      logger.info("Working on: " + tableName);

      final ClassModel classModel = new ClassModel(Visibility.PUBLIC,  tableName, true);
       
      classModel.setEnumList("INSTANCE");
      classModel.setPackageName(this.packageName);
      classModel.addImport("org.byteliberi.easydriver.*")
      classModel.addImport("org.byteliberi.easydriver.fields.*");
     
      classModel.addProperty(new PropertyModel(Visibility.PRIVATE, DBTable.class.getSimpleName(), "table"));

      // Let's look for the fields       
      final List<FieldPropertyAssociation> fieldAssoc = tableInfo.getFields();
      final HashSet<String> usedFields = new HashSet<String>();
     
      for (FieldPropertyAssociation fa : fieldAssoc) {
        final String fieldName = fa.getFieldName();
        if (!usedFields.contains(fieldName)) {
          classModel.addProperty(fa.getProp());
          usedFields.add(fieldName);
        }
      }
       
      // Let's look for the relationships
      final Collection<List<RelationModel>> rels = tableInfo.getRelationships();
      // Now we add the properties for the relationships that we have found         
     
      final HashSet<String> ext = new HashSet<String>();
      if ((rels != null) && (rels.size() > 0)) {
        Iterator<List<RelationModel>> relsIterator = rels.iterator();
        while (relsIterator.hasNext()) {
          final List<RelationModel> relList = relsIterator.next();
          if (relList.size() > 0) {
            final String oneTable = relList.get(0).getOneTable();
            ext.add(oneTable);
          }
        }       
      } 
     
      for (String name : ext) {
        classModel.addProperty(new PropertyModel(Visibility.PRIVATE,
                             ManyToOne.class.getSimpleName(),
                             "fk" + Utils.getCamelNameFirstCapital(name)));
      }
       
      classModel.setConstructorGenerator(new TableStructureConstructor(tableName, fieldAssoc, rels, tableInfo.getPrimaryKey()));

      classModel.createGetters();
      classModel.write(out);
      out.flush();
      out.close();
   
  } 
View Full Code Here

TOP

Related Classes of org.byteliberi.easydriver.generator.model.ClassModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.