Sha256: 33aa9f06280311388dc7da655b676439a80c1c2073ed33e11807c0d63770b399

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

module RTM
  module TMQL
    class TMQL4JEngine < Engine
      attr_reader :topic_map, :runtime, :runtime_setting
      @@version = nil

      def initialize(topic_map, params={})
        raise("topic_map must be a RTM::TopicMap") unless topic_map.is_a?(RTM::TopicMap)
        super(params) #@params is set
        @topic_map = topic_map
        @runtime_setting = set_runtime
      end
    
      def properties
        runtime.properties
      end

      def enable_materialize_meta_model(materialize)
        properties.enableMaterializeMetaModel(materialize)
      end

      def enable_updates(enabled)
        properties.enableLanguageExtensionTmqlUl(enabled)
      end

      def execute(query)
        q = runtime.run(query)
        q.results
      end

      # Returns the version of the underlying TMQL4J version
      # It's a bit of a hack.
      def self.version
        unless @@version
          javalibs_directory = File.join(File.dirname(__FILE__), 'javalibs')
          if File.directory?(javalibs_directory)
            tmql_files = Dir[File.join(javalibs_directory + '/tmql4j-*.jar')]
            tmql_files = tmql_files.reject{|file| file.include?("tmml")}
            if tmql_files.size == 1
              file = tmql_files.first
              @@version = File.basename(file, ".jar").gsub("tmql4j-", "")
            end
          end
        end
        return @@version
      end

      private
      def set_runtime
        if environment_map = @params[:environment_map]
          @runtime = Java::DeTopicmapslabTmql4jCommonCoreRuntime::TMQLRuntimeFactory.newFactory.newRuntime(@topic_map)
          @runtime.setEnvironmentMap(environment_map)
          return :environment_map
        else
          unless tms = @params[:tms]
            tms = @topic_map.engine.tmsf.newTopicMapSystem
          end
          @runtime = Java::DeTopicmapslabTmql4jCommonCoreRuntime::TMQLRuntimeFactory.newFactory.newRuntime(tms, @topic_map)
          return :tms
        end
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rtm-tmql-0.3.1-java lib/rtm/tmql/tmql4j.rb