Changeset 6986

Show
Ignore:
Timestamp:
03/20/07 20:09:48
Author:
mccraig
Message:

pass a system property through from ExportSchemaTask? to the Rjb vm

Files:

Legend:

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

    r6772 r6986  
    5151       
    5252      # Pretty printing of generated SQL (default: true) 
    53       attr_accessor :prettyprint             
     53      attr_accessor :prettyprint 
     54 
     55      # name of a java system property to set when exporting schema 
     56      attr_accessor :system_property_name 
     57 
     58      # value of java system property to set when exporting schema 
     59      attr_accessor :system_property_value 
    5460       
    5561      def initialize(name=:export_schema) 
     
    6470        @dialect = "org.hibernate.dialect.MySQL5Dialect" 
    6571        @sql_reserved = nil 
     72        @system_property_name = nil 
     73        @system_property_value = nil 
     74 
    6675                 
    6776        yield self if block_given? 
     
    7180      def define # :nodoc: 
    7281        task name => dependencies do |t|        
    73      
    74           entities = File.open(entities_yml) {|f| YAML.load(f)} 
    75      
    76           raise 'no annotated entities found!' if entities.empty? 
    77            
    78           #puts "found #{entities.size} entities"     
    79           entities = entities.dup.select { |e| @classfilter.call(e) } if @classfilter          
    80           entity_classes = entities.map {|klass| Rjb::import(klass)} 
    81  
    82           properties = (YAML.load_file(@properties_yml) if @properties_yml) || {} 
    83  
    84           cfg = get_config(entity_classes, properties, package) 
    85            
    86           validate_config(cfg) unless validate.empty? 
    87           sql = cfg.generateSchemaCreationScript(Rjb::import(dialect).new) 
    88            
    89           schema =  "# -- do not edit ---\n" 
    90           schema << "# generated by Jerbil::Hibernate::ExportSchemaTask at #{Time.new}\n\n" 
    91            
    92           schema << preamble << "\n" if preamble 
    93            
    94           sql.each do |s| 
    95             s = format(s) if prettyprint 
    96             schema << "#{s};" 
    97           end 
    98            
    99           schema << "\n\n#{epilogue}" if epilogue 
    100                               
    101           File.open(schemafile, "w") {|file| file << schema } 
     82            with_system_property( @system_property_name , @system_property_value ) do 
     83                entities = File.open(entities_yml) {|f| YAML.load(f)} 
     84 
     85                raise 'no annotated entities found!' if entities.empty? 
     86 
     87                #puts "found #{entities.size} entities" 
     88                entities = entities.dup.select { |e| @classfilter.call(e) } if @classfilter 
     89                entity_classes = entities.map {|klass| Rjb::import(klass)} 
     90 
     91                properties = (YAML.load_file(@properties_yml) if @properties_yml) || {} 
     92 
     93                cfg = get_config(entity_classes, properties, package) 
     94 
     95                validate_config(cfg) unless validate.empty? 
     96                sql = cfg.generateSchemaCreationScript(Rjb::import(dialect).new) 
     97 
     98                schema =  "# -- do not edit ---\n" 
     99                schema << "# generated by Jerbil::Hibernate::ExportSchemaTask at #{Time.new}\n\n" 
     100 
     101                schema << preamble << "\n" if preamble 
     102 
     103                sql.each do |s| 
     104                  s = format(s) if prettyprint 
     105                  schema << "#{s};" 
     106                end 
     107 
     108                schema << "\n\n#{epilogue}" if epilogue 
     109 
     110                File.open(schemafile, "w") {|file| file << schema } 
     111            end 
    102112        end 
    103113        file schemafile => name 
    104114        task name => entities_yml 
    105115      end 
    106        
     116 
    107117      # Filters all entities. Useful to only export schema for a subset of classes. 
    108118      # ====Example 
  • trunk/lib/jerbil/java_helper.rb

    r6737 r6986  
    6666      byteoos.toByteArray 
    6767    end 
    68      
     68 
     69    # do a block, with a given value of a java system property set... 
     70    # sets up the value of the system property before calling the supplied 
     71    # block, then restores the 
     72    def with_system_property( property_name,  property_value, &a_proc ) 
     73        if property_name 
     74            system_class = Rjb::import( 'java.lang.System' ) 
     75            property_value_save = system_class.getProperty( property_name ) 
     76            begin 
     77                system_class.setProperty( property_name , property_value ) 
     78                a_proc.call 
     79            rescue Exception 
     80                system_class.setProperty( property_name , property_value_save ) 
     81            end 
     82        else 
     83            a_proc.call 
     84        end 
     85    end 
     86 
     87 
    6988    # Loads the java virtual machine. This method should only be invoked once, typically 
    7089    # before task definitions in a Rakefile. If the environment variable +JAVA_OPTS+ is 
  • trunk/test/test_java_helper.rb

    r6774 r6986  
    6363       
    6464      #puts flist.outofdate 
    65     end     
     65    end 
     66 
    6667  end 
    6768end