Class: Spider::OracleSetupWizard

Inherits:
Wizard show all
Defined in:
lib/spiderfw/setup/spider_setup_wizard.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Wizard

#add_key, #ask, #ask!, #ask?, #do_ask, #get_value, #implementation, #initialize, #set_value, #values, #wizard_instance

Constructor Details

This class inherits a constructor from Spider::Wizard

Class Method Details

.parse_db_name(db_name) ⇒ Object



457
458
459
460
461
462
463
464
465
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 457

def self.parse_db_name(db_name)
    if (db_name =~ /(?:(.+):(.+))\/(?:(.+))/)
        @host =$1
        @port = $2
        @tns = $3
    else
        @tns = db_name
    end
end

Instance Method Details

#get_urlObject



467
468
469
470
471
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 467

def get_url
    return "db:oracle://#{@user}:#{@pass}@#{@host}:#{@port}/#{@tns}" if @user && @pass && @host && @port && @tns
    return "db:oracle://#{@user}:#{@pass}@#{@tns}" if @user && @pass && @tns
    return nil
end

#parse_url(url) ⇒ Object



473
474
475
476
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 473

def parse_url(url)
    @user, @pass, @db_name, @role = Spider::Model::Storage::Db::Oracle.parse_url(url)
    self.class.parse_db_name(@db_name)
end

#runObject



376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/spiderfw/setup/spider_setup_wizard.rb', line 376

def run
    
    require 'rubygems'
    require 'rubygems/command.rb'
    require 'rubygems/dependency_installer.rb'
    unless Spider.gem_available?('ruby-oci8')
        if ask? _("Oracle gem is not available. Install?")
            ok = false
            while !ok
                inst = Gem::DependencyInstaller.new
                begin
                    inst.install 'ruby-oci8'
                rescue
                    error _("Installation of oracle gem failed.")
                    puts _(
                    "The oracle gem failed to compile, so the pure-ruby version was installed.
                    You should install the compiled version manually for better performance.")
                end
            end
        else
            error _("Can't configure oracle without the ruby-oci8 gem.")
            return
        end
    end
    require 'oci8'
    
    ok = false
    while !ok
        if (ask _("Do you want to connect via tns or direct connection?"), 
            :choices => ['tns', 'direct']) == 'tns'
            ask! _("Tns:"), :tns, :default => 'ORCL'
            ask _("Username"), :user
            ask _("Password"), :pass
            begin
                m = ::OCI8.new(@user, @pass, @tns)
                m.ping
                m.logoff
                connect_ok = true
                ok = true
                notify_partial("Ok.", true)
            rescue => myerr
                if myerr.exception.code == 1017
                    notify_partial("Connection failed.", true)
                    error _("Username or Password invalid.")
                elsif myerr.exception.code == 12154
                    notify_partial("Connection failed.", true)
                    error _("Tns seems not responding.")
                else
                    notify_partial("", true)
                    error _("Connection failed.")
                end
                ok = ask_error
            end
        else
            ask _("Host:"), :host, :default => 'localhost'
            ask _("Port:"), :port, :default => 1521
            ask _("Tns:"), :tns, :default => 'ORCL'
            ask _("Username"), :user
            ask _("Password"), :pass
            @db_name = "//#{@host}:#{@port}/#{@tns}"
            begin
                m = ::OCI8.new(@user, @pass, @db_name)
                ok = true
                m.logoff
            rescue => myerr
                if myerr.exception.code == 1017
                    notify_partial("Connection failed.", true)
                    error _("Username or Password invalid.")
                elsif myerr.exception.code == 12154
                    notify_partial("Connection failed.", true)
                    error _("Server seems not responding.")
                else
                    notify_partial("", true)
                    error _("Connection failed.")
                end
                ok = ask_error
            end
        end
    end
end