Changeset 6298

Show
Ignore:
Timestamp:
01/04/07 19:11:04
Author:
mccraig
Message:

added the ability to set hibernate configuration properties to the
hibernate_task.rb

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/jerbil/hibernate_task.rb

    r6192 r6298  
    2929      # serialized as a list of strings (YAML format). 
    3030      attr_accessor :entities_yml 
     31 
     32      # a file containing a map of properties, property names are keys in the map, and 
     33      # property values are values in the map 
     34      attr_accessor :properties_yml 
    3135                         
    3236      # Classname implementing the db dialect, defaults to 
     
    5256        @schemafile = "schema.sql" 
    5357        @entities_yml = "entities.yml" 
     58        @properties_yml = nil 
    5459        @dialect = "org.hibernate.dialect.MySQL5Dialect" 
    5560                 
     
    6873          entities = entities.dup.select { |e| @classfilter.call(e) } if @classfilter          
    6974          entity_classes = entities.map {|klass| Rjb::import(klass)} 
    70            
    71           cfg = get_config(entity_classes, package) 
     75 
     76          properties = (YAML.load_file(@properties_yml) if @properties_yml) || {} 
     77 
     78          cfg = get_config(entity_classes, properties, package) 
    7279          sql = cfg.generateSchemaCreationScript(Rjb::import(dialect).new) 
    7380           
     
    100107         
    101108      protected 
    102       def get_config(classes, package=nil) 
     109      def get_config(classes, properties, package=nil) 
    103110        anncfg = Rjb::import('org.hibernate.cfg.AnnotationConfiguration') 
    104111        acfg = anncfg.new 
     
    114121        packages.each { |pkg| acfg.addPackage(pkg) } 
    115122                 
     123        properties.each do |key,value| 
     124          acfg.setProperty(key, value) 
     125        end 
     126         
    116127        acfg 
    117128      end