Changeset 6986
- Timestamp:
- 03/20/07 20:09:48
- Files:
-
- trunk/lib/jerbil/hibernate_task.rb (modified) (3 diffs)
- trunk/lib/jerbil/java_helper.rb (modified) (1 diff)
- trunk/test/test_java_helper.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/jerbil/hibernate_task.rb
r6772 r6986 51 51 52 52 # 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 54 60 55 61 def initialize(name=:export_schema) … … 64 70 @dialect = "org.hibernate.dialect.MySQL5Dialect" 65 71 @sql_reserved = nil 72 @system_property_name = nil 73 @system_property_value = nil 74 66 75 67 76 yield self if block_given? … … 71 80 def define # :nodoc: 72 81 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 102 112 end 103 113 file schemafile => name 104 114 task name => entities_yml 105 115 end 106 116 107 117 # Filters all entities. Useful to only export schema for a subset of classes. 108 118 # ====Example trunk/lib/jerbil/java_helper.rb
r6737 r6986 66 66 byteoos.toByteArray 67 67 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 69 88 # Loads the java virtual machine. This method should only be invoked once, typically 70 89 # before task definitions in a Rakefile. If the environment variable +JAVA_OPTS+ is trunk/test/test_java_helper.rb
r6774 r6986 63 63 64 64 #puts flist.outofdate 65 end 65 end 66 66 67 end 67 68 end
