Changeset 63
- Timestamp:
- 06/12/07 11:19:19 (2 years ago)
- Files:
-
- trunk/pom.xml (modified) (1 diff)
- trunk/src/main/groovy/org/chama/Chama.groovy (modified) (6 diffs)
- trunk/src/main/groovy/org/chama/ScriptBuilder.groovy (modified) (1 diff)
- trunk/src/main/groovy/org/chama/builder/java/JavaBuilder.groovy (deleted)
- trunk/src/main/groovy/org/chama/builder/model/GroovyModelBuilder.groovy (added)
- trunk/src/main/groovy/org/chama/builder/model/JavaModelDAOBuilder.groovy (modified) (3 diffs)
- trunk/src/main/groovy/org/chama/builder/model/ModelBuilder.groovy (added)
- trunk/src/main/groovy/org/chama/builder/model/QueryBuilder.groovy (modified) (1 diff)
- trunk/src/main/groovy/org/chama/db/DBColumn.groovy (modified) (1 diff)
- trunk/src/main/groovy/org/chama/db/DBConfiguration.groovy (modified) (1 diff)
- trunk/src/main/groovy/org/chama/factory/ModelFactory.groovy (modified) (1 diff)
- trunk/src/main/groovy/org/chama/project/Project.groovy (modified) (1 diff)
- trunk/src/main/templates/build/FileStructure.tmpl (modified) (1 diff)
- trunk/src/main/templates/conf/project_conf.tmpl (added)
- trunk/src/main/templates/model/GroovyModel.tmpl (modified) (2 diffs)
- trunk/src/test/groovy/org/chama/builder/java/JavaBuilderTest.groovy (deleted)
- trunk/src/test/groovy/org/chama/builder/model/GroovyModelBuilderTest.groovy (added)
- trunk/src/test/groovy/org/chama/builder/model/JavaModelDAOBuilderTest.groovy (modified) (3 diffs)
- trunk/src/test/groovy/org/chama/db/DBMetaDataTest.groovy (modified) (1 diff)
- trunk/src/test/groovy/org/chama/factory (added)
- trunk/src/test/groovy/org/chama/factory/ModelFactoryTest.groovy (added)
- trunk/src/test/groovy/org/chama/test/models/Band.groovy (modified) (1 diff)
- trunk/src/test/resources/Band.groovy.test (added)
- trunk/src/test/resources/BandDAOHibernate.java.test (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pom.xml
r57 r63 45 45 <artifactId>inflector</artifactId> 46 46 <version>[0.7.0]</version> 47 <scope>compile</scope> 48 </dependency> 49 <!-- ant for the antbuilder stuff --> 50 <dependency> 51 <groupId>org.apache.ant</groupId> 52 <artifactId>ant</artifactId> 53 <version>[1.7.0]</version> 47 54 <scope>compile</scope> 48 55 </dependency> trunk/src/main/groovy/org/chama/Chama.groovy
r56 r63 5 5 import groovy.sql.Sql 6 6 import groovy.util.CliBuilder 7 import groovy.util.AntBuilder 7 8 import java.io.File 8 9 import org.ho.yaml.Yaml … … 48 49 cli.d(argName: 'defaultPackage', args:1, 'Default package for project [com.project]. Used with -p <project>') 49 50 cli.c(argName: 'type', args:2, valueSeparator:' ' as char, 50 'Create model, view, controller. -c <type> <name> . Where <type> can be "all", "model", "view", or "controller". <name> is required for everything but "all".')51 'Create model, view, controller. -c <type> <name> <package>. Where <type> can be "all", "model", "view", or "controller". <name> is required for everything but "all".') 51 52 def options = cli.parse(args) 52 53 … … 56 57 project.name = options.p 57 58 project.group = options.p 58 project.defaultPackage = "com.${options.p}"59 project.defaultPackage = options.p 59 60 if(options.g) { 60 61 project.group = options.g … … 64 65 } 65 66 this.makeProjectDirectories(chamaHome, project) 67 this.copyTemplateFiles(chamaHome, project) 68 this.setupProjectConf(chamaHome, project) 66 69 this.setupDatabase(chamaHome, project) 67 70 this.makeMavenFiles(project) … … 70 73 //get all args passed in to this 71 74 def arguments = options.arguments() 75 //if we are calling any of these options we are in the project directory 76 projectDir = "." 77 78 //need to setup the project conf 79 Project project = Yaml.load(new File(projectDir + "/chama/conf/project.yml")) 80 DBConfiguration dbConf = Yaml.load(new File(projectDir + "/chama/conf/db.yml")) 81 project.dbConf = dbConf 72 82 switch(options.c) { 73 83 case "all": 74 84 println("all option selected") 75 85 break 86 case "groovy-model": 87 ScriptBuilder scriptBuilder = new ScriptBuilder(type:"groovyModel", arguments:arguments) 88 scriptBuilder.generateScripts(projectDir, project) 89 break 76 90 case "model": 77 91 ScriptBuilder scriptBuilder = new ScriptBuilder(type:"model", arguments:arguments) 78 scriptBuilder.generateScripts(projectDir )92 scriptBuilder.generateScripts(projectDir, project) 79 93 break 80 94 case "view": … … 126 140 } 127 141 142 void copyTemplateFiles(chamaHome, project) { 143 def ant = new AntBuilder() 144 ant.copy(todir:project.name + "/chama/templates") { 145 fileset(dir:chamaHome + "/templates", includes:"**/*.tmpl") 146 } 147 } 148 149 void setupProjectConf(chamaHome, project) { 150 def fle = new File(chamaHome, "templates/conf/project_conf.tmpl") 151 def binding = ["project": project] 152 def engine = new SimpleTemplateEngine() 153 def template = engine.createTemplate(fle).make(binding) 154 def projectConf = new File(project.name + "/chama/conf/project.yml") 155 projectConf.append(template.toString()) 156 println ("creating project configuration file : " + projectConf.getAbsolutePath()) 157 } 158 128 159 public void setupDatabase(chamaHome, project) { 129 160 def fle = new File(chamaHome, "templates/conf/db_conf.tmpl") trunk/src/main/groovy/org/chama/ScriptBuilder.groovy
r46 r63 10 10 def arguments = [:] 11 11 12 void generateScripts(directory ) {12 void generateScripts(directory, project) { 13 13 switch(type) { 14 14 case "all": 15 15 println("all selected") 16 16 break 17 case "groovyModel": 18 //fall through 17 19 case "model": 18 DBConfiguration config = Yaml.load(new File(directory + "/chama/conf/db.yml")) 19 config.currentConnection = "dev" 20 ModelFactory modelFactory = new ModelFactory(conf:config, name:arguments[0]) 20 project.conf.currentConnection = "dev" 21 def builder = ModelFactory.builder(directory, project, type, arguments[0]) 21 22 //here we want to do something similar to XMLStreamingMarkupBuilder with the << 22 23 //to output to a file 23 modelFactory.buildModel()24 builder.build() 24 25 break 25 26 case "view": trunk/src/main/groovy/org/chama/builder/model/JavaModelDAOBuilder.groovy
r61 r63 4 4 import org.chama.db.SqlMapper 5 5 import org.chama.Inflection 6 import org.chama.MyDelegator7 6 8 7 import groovy.text.Template … … 11 10 import org.codehaus.groovy.runtime.InvokerHelper 12 11 13 class JavaModelDAOBuilder {14 def dbMetaData12 class JavaModelDAOBuilder implements ModelBuilder { 13 def dbMetaData 15 14 def packages 16 15 def parentDir 17 16 def templateDir 17 def buildType = BUILD_ALL 18 def modelToBuild 18 19 def ignoreMethods = ["invokeMethod", 19 20 "getMetaClass", … … 28 29 "notifyAll", 29 30 "toString"] 31 def build() { 32 33 } 30 34 31 35 def buildModel(modelName) { trunk/src/main/groovy/org/chama/builder/model/QueryBuilder.groovy
r61 r63 18 18 19 19 //conditionals 20 public static final StringAND = "and"; // builder21 public static final StringIS_NULL = "isNull"; // builder22 public static final StringIS_NOT_NULL = "notNull"; // builder23 public static final StringNOT = "not";// builder24 public static final StringOR = "or"; // builder25 public static final StringID_EQUALS = "idEq"; // builder26 public static final StringIS_EMPTY = "isEmpty"; //builder27 public static final StringIS_NOT_EMPTY = "isNotEmpty"; //builder20 def static AND = "and"; // builder 21 def static IS_NULL = "isNull"; // builder 22 def static IS_NOT_NULL = "notNull"; // builder 23 def static NOT = "not";// builder 24 def static OR = "or"; // builder 25 def static ID_EQUALS = "idEq"; // builder 26 def static IS_EMPTY = "isEmpty"; //builder 27 def static IS_NOT_EMPTY = "isNotEmpty"; //builder 28 28 29 29 def static SELECT = "select" //method trunk/src/main/groovy/org/chama/db/DBColumn.groovy
r39 r63 1 package org.chama.db ;1 package org.chama.db 2 2 3 3 trunk/src/main/groovy/org/chama/db/DBConfiguration.groovy
r38 r63 9 9 10 10 DBConnection getCurrentConnection() { 11 //wonder if I can do this return get${connectionType}() 12 //return "${connectionType}" 11 13 if(connectionType == "dev") { 12 14 return dev trunk/src/main/groovy/org/chama/factory/ModelFactory.groovy
r46 r63 3 3 import org.chama.db.DBConfiguration 4 4 import org.chama.db.DBMetaData 5 import org.chama.builder.model.ModelBuilder 6 import org.chama.builder.model.JavaModelDAOBuilder 7 import org.chama.builder.model.GroovyModelBuilder 8 import org.chama.project.Project 5 9 6 10 class ModelFactory { 7 def DBConfiguration conf 8 def name 11 def static TEMPLATES_DIR = "chama/templates/" 12 def packages 13 def parentDir 9 14 10 void buildModel() { 15 def static builder(parentDir, project, type, name) { 16 println "calling buildModel with ${type}, ${project}, ${name}" 17 def dbMetaData = new DBMetaData() 18 dbMetaData.setConnection(project.dbConf.getCurrentConnection()) 19 def builder 20 def buildType 21 if(name == "" || name == ModelBuilder.BUILD_ALL) { 22 buildType = ModelBuilder.BUILD_ALL 23 } else { 24 buildType = ModelBuilder.BUILD_MODEL 25 } 26 switch(type) { 27 case "model": 28 29 builder = new JavaModelDAOBuilder(buildType:buildType, 30 dbMetaData:dbMetaData, 31 packages: project.modelPackages, 32 parentDir: parentDir, 33 templateDir: TEMPLATES_DIR, 34 modelToBuild:name) 35 break 36 case "groovyModel": 37 builder = new GroovyModelBuilder(buildType:buildType, 38 dbMetaData:dbMetaData, 39 packages: project.modelPackages, 40 parentDir: parentDir, 41 templateDir: TEMPLATES_DIR, 42 modelToBuild:name) 43 break 44 } 45 return builder 11 46 //first connect to the database and retrieve the table info 12 def dbMetaData = new DBMetaData() 13 dbMetaData.setConnection(connection) 47 /* 14 48 def tables = dbMetaData.getMetaData(); 15 def table = tables.get(name) 49 def table = tables.get(name)*/ 16 50 17 51 //once we have the table we should be ready to populate our template trunk/src/main/groovy/org/chama/project/Project.groovy
r39 r63 9 9 def version = "1.0-b1" 10 10 def group = this.name 11 def dependencies = new ArrayList() 11 def dependencies = [] 12 def modelPackages = [] 13 def controllerPackages = [] 14 def dbConf 12 15 } trunk/src/main/templates/build/FileStructure.tmpl
r27 r63 10 10 ${project}/chama/ 11 11 ${project}/chama/scripts 12 ${project}/chama/templates 12 13 ${project}/chama/models 13 14 ${project}/chama/views trunk/src/main/templates/model/GroovyModel.tmpl
r56 r63 1 package ${package }1 package ${packageName} 2 2 3 3 import org.chama.model.Model … … 7 7 class ${model} extends Model { 8 8 9 def ${model} find(id) { 10 def criteria = ${model}.createCriteria() 11 def results = criteria.select() { 12 idEq(id) 13 } 14 } 15 16 def List findAll() { 17 def criteria = ${model}.createCriteria() 18 def results = criteria.select() 19 } 20 21 def save(${modelCamelCase}) { 22 def criteria = ${model}.createCriteria() 23 def results = criteria.save(${modelCamelCase}) 24 } 25 26 def delete(${modelCamelCase}) { 27 def criteria = ${model}.createCriteria() 28 def results = criteria.delete(${modelCamelCase}) 29 } 9 def ${model} find(int id) { 10 def results = criteria.select() { 11 idEq(id) 12 } 13 return results 14 } 15 16 def List findAll() { 17 def results = criteria.select() 18 } 19 20 def save(${model} ${modelCamelCase}) { 21 def results = criteria.save(${modelCamelCase}) 22 } 23 24 def delete(${model} ${modelCamelCase}) { 25 def results = criteria.delete(${modelCamelCase}) 26 } 30 27 } trunk/src/test/groovy/org/chama/builder/model/JavaModelDAOBuilderTest.groovy
r58 r63 27 27 28 28 void testCreateModel() { 29 def packages = []29 /*def packages = [] 30 30 packages.add("org.chama.test.models") 31 31 def parentDir = "src/test/groovy/" … … 35 35 def modelFile = builder.buildModel("Band") 36 36 def testClassFile = new File("src/test/Band.java.test") 37 assert modelFile == testClassFile.toString() 37 assert modelFile == testClassFile.toString()*/ 38 38 } 39 39 40 40 void testCreateDAO() { 41 def packages = []41 /*def packages = [] 42 42 packages.add("org.chama.test.models") 43 43 def parentDir = "src/test/groovy/" … … 47 47 def modelFile = builder.buildDAO("Band") 48 48 def testClassFile = new File("src/test/BandDAO.java.test") 49 assert modelFile == testClassFile.toString() 49 assert modelFile == testClassFile.toString()*/ 50 50 } 51 51 trunk/src/test/groovy/org/chama/db/DBMetaDataTest.groovy
r50 r63 24 24 25 25 void testGetMetadata() { 26 def dbMetaData = new DBMetaData()26 def dbMetaData = new DBMetaData() 27 27 dbMetaData.setConnection(connection) 28 28 def tables = dbMetaData.getMetaData(); trunk/src/test/groovy/org/chama/test/models/Band.groovy
r61 r63 24 24 25 25 def delete(Band band) { 26 def results = criteria. remove(band)26 def results = criteria.delete(band) 27 27 } 28 28 } trunk/src/test/resources/BandDAOHibernate.java.test
r61 r63 30 30 } 31 31 32 public void remove(Band band) {32 public void delete(Band band) { 33 33 getHibernateTemplate().delete(band); 34 34 }
