SlideShare a Scribd company logo
1 of 20
Play Swing and JDBC
     with Rubeus
    Takeshi AKIMA @akm2000
     Ruby Business Commons
Who am I?
I'm one of the authors, "Ruby Tettei
Nyumon(Ruby              )"




                       http://www.amazon.co.jp/JRuby-       -
                                                /dp/4881666452


I wrote all of the code in the last chapter.
Very famous book in the world
Look at this!




http://rubybizcommons.jp/ja/articles/2010/07/28/2010727-rubydays-2010/
GJ, Tom!
http://rubybizcommons.jp


I'm a member of the staff.
In Fukuoka since 2007.
We hold hands-on workshops
about once a month recently.
Rubeus
                    http://code.google.com/p/rubeus/


"Rubeus provides you an easy access to
Java objects from Ruby scripts on JRuby."


We made a gem "Rubeus" in 2008.
It provides a DSL for Java Swing and JDBC
Swing with Rubeus
If you want to write a code of window like
this ...
in Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JavaSwingExample01 {

        public static void main(String[] args) {
            JFrame frame = new JFrame("Rubeus Swing Example 01");
            frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));
            JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
            frame.add(splitPane);
            JPanel panel = new JPanel();
            splitPane.setTopComponent(panel);
            panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
            final JTextField textField = new JTextField();
            panel.add(textField);
            final JTextPane textPane = new JTextPane();
            textField.addKeyListener(new KeyAdapter() {
                    public void keyPressed(KeyEvent event) {
                        if (event.getKeyCode() == 10) {
                            textPane.setText(textPane.getText() + textField.getText() + "n");
                            textField.setText("");
                        }
                    }
                });
            JButton button = new JButton("append");
            panel.add(button);
            button.addActionListener(new ActionListener(){
                    public void actionPerformed(ActionEvent event) {
                        textPane.setText(textPane.getText() + textField.getText() + "n");
                        textField.setText("");
                    }
                });
            JScrollPane scrollPane = new JScrollPane(textPane);
            splitPane.setBottomComponent(scrollPane);
            scrollPane.setPreferredSize(new Dimension(400, 250));
            frame.setSize(400, 300);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
        }
}
in JRuby with Rubeus
require 'rubygems'
require "rubeus"

Rubeus::Swing.irb

JFrame.new("Rubeus Swing Example 01") do |frame|
  frame.layout = BoxLayout.new(:Y_AXIS)
  JSplitPane.new(JSplitPane::VERTICAL_SPLIT) do
    JPanel.new do |panel|
      panel.layout = BoxLayout.new(:X_AXIS)
      @text_field = JTextField.new do |event|
        if event.key_code == 10 # RETURN
          @textpane.text += @text_field.text + "n"
          @text_field.text = ''
        end
      end
      JButton.new("append") do
        @textpane.text += @text_field.text
        @text_field.text = ''
      end
    end
    JScrollPane.new(:preferred_size => [400, 250]) do |pane|
      @textpane = JTextPane.new
    end
  end
  frame.visible = true
end
JDBC with Rubeus
require 'rubygems'
require 'rubeus'
Rubeus::Jdbc.irb
DriverManager.connect("jdbc:derby:test_db") do |conn|
   conn.query("SELECT * FROM TEST ORDER BY ID") do |rs|
     rs.each do |row|
         puts row.to_a.join(",")
     end
   end
end
JDBC Metadata
conn = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db")
#=> #<Java::OrgApacheDerbyImplJdbc::EmbedConnection40:0x478dabf1>

table = conn.meta_data.tables[:FLIGHTS]
#=> #<Rubeus::Jdbc::Table FLIGHTS
     (FLIGHT_ID,SEGMENT_NUMBER,ORIG_AIRPORT,DEPART_TIME,
     DEST_AIRPORT,ARRIVE_TIME,MEAL)>

table.columns
#=> [#<Rubeus::Jdbc::Column FLIGHT_ID CHAR(6) NOT NULL>,
      #<Rubeus::Jdbc::Column SEGMENT_NUMBER INTEGER(10) NOT
      NULL>, #<Rubeus::Jdbc::Column ORIG_AIRPORT CHAR(3) NULL>,
      #<Rubeus::Jdbc::Column DEPART_TIME TIME(8) NULL>....]
Easy to use
Swing and JDBC


table names   result set
require 'rubygems'
require "rubeus"
Rubeus::Swing.irb

@conn = Rubeus::Jdbc::DriverManager.
  connect("jdbc:derby:test_db;create = true")
tables = @conn.meta_data.tables(:schema => "APP")

JFrame.new("Rubeus Swing Example 01") do |frame|
  frame.layout = BoxLayout.new(:X_AXIS)
  JSplitPane.new(JSplitPane::HORIZONTAL_SPLIT) do
    JScrollPane.new(:preferred_size => [150, 250]) do |pane|
      @list = JList.new(tables.map(&:name).to_java) do |event|
       table_name = @list.selected_value.inspect
       @conn.query("select * from #{table_name}") do |rs|
         @table.model = rs.map{|row| row.to_a}
       end
      end
    end
    JScrollPane.new{|pane| @table = JTable.new}
  end
  frame.visible = true
end
JRuby + irb
It's a good Java Object Inspector.
Now I always use irb to inspect
Java classes before using it.
I don't remember using many
names of Java method and their
arguments any more.
listing String methods
> java.lang.String.java_class.declared_class_methods
#=> [#<Java::JavaMethod/indexOf([C,int,int,[C,int,int,int)>,
#<Java::JavaMethod/checkBounds([B,int,int)>,
#<Java::JavaMethod/lastIndexOf([C,int,int,[C,int,int,int)>,
#<Java::JavaMethod/format(java.util.Locale,java.lang.String,
[Ljava.lang.Object;)>, #<Java::JavaMethod/
format(java.lang.String,[Ljava.lang.Object;)>,
#<Java::JavaMethod/valueOf([C)>, #<Java::JavaMethod/
valueOf(double)>, #<Java::JavaMethod/
valueOf(java.lang.Object)>, #<Java::JavaMethod/

                                 It's difficult to read :-(
You can get
method names only
with Rubeus
Step1. get public static
 method names only
require 'rubeus'
> Rubeus::Reflection.irb
#=> Object
> java.lang.String.java_public_class_methods
#=> ["format", "valueOf", "copyValueOf"]
Step2. check the
      method arguments
> java.lang.String.java_class.
?> java_public_class_methods.
?> select{|m| m.name == "copyValueOf"}
#=> [#<Java::JavaMethod/copyValueOf([C,int,int)>,
      #<Java::JavaMethod/copyValueOf([C)>]
Rubeus in JRuby book!?
JRuby guys are writing a book.
Rubeus and other libraries are
introduced in the GUI part.
          GET IT!

       http://pragprog.com/titles/jruby/using-jruby
Thanks



Tom gave us some patches.
We appreciate your kindness.

More Related Content

What's hot

Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Domenic Denicola
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperJon Kruger
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Railsrstankov
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptJon Kruger
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Eyal Vardi
 
djangocon dajaxproject lightning talk
djangocon dajaxproject lightning talkdjangocon dajaxproject lightning talk
djangocon dajaxproject lightning talkJorge Bastida
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for JoomlaLuke Summerfield
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data ObjectsWez Furlong
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design PatternsDerek Brown
 

What's hot (18)

Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
Callbacks, Promises, and Coroutines (oh my!): Asynchronous Programming Patter...
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby DeveloperVenturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
Venturing Into The Wild: A .NET Developer's Experience As A Ruby Developer
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
 
Ruby/Rails
Ruby/RailsRuby/Rails
Ruby/Rails
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Testable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScriptTestable, Object-Oriented JavaScript
Testable, Object-Oriented JavaScript
 
Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0Component lifecycle hooks in Angular 2.0
Component lifecycle hooks in Angular 2.0
 
djangocon dajaxproject lightning talk
djangocon dajaxproject lightning talkdjangocon dajaxproject lightning talk
djangocon dajaxproject lightning talk
 
Javascript Frameworks for Joomla
Javascript Frameworks for JoomlaJavascript Frameworks for Joomla
Javascript Frameworks for Joomla
 
Oojs 1.1
Oojs 1.1Oojs 1.1
Oojs 1.1
 
Javascript - Beyond-jQuery
Javascript - Beyond-jQueryJavascript - Beyond-jQuery
Javascript - Beyond-jQuery
 
PHP Data Objects
PHP Data ObjectsPHP Data Objects
PHP Data Objects
 
JavaScript Design Patterns
JavaScript Design PatternsJavaScript Design Patterns
JavaScript Design Patterns
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 

Viewers also liked

仕事で使ってるプラグイン
仕事で使ってるプラグイン仕事で使ってるプラグイン
仕事で使ってるプラグインTakeshi AKIMA
 
Repetition & Consistency
Repetition & ConsistencyRepetition & Consistency
Repetition & Consistencymattylars5
 
Supply & Demand
Supply & DemandSupply & Demand
Supply & Demandmattylars5
 

Viewers also liked (6)

Alignment
AlignmentAlignment
Alignment
 
Child Labor
Child LaborChild Labor
Child Labor
 
White Space
White SpaceWhite Space
White Space
 
仕事で使ってるプラグイン
仕事で使ってるプラグイン仕事で使ってるプラグイン
仕事で使ってるプラグイン
 
Repetition & Consistency
Repetition & ConsistencyRepetition & Consistency
Repetition & Consistency
 
Supply & Demand
Supply & DemandSupply & Demand
Supply & Demand
 

Similar to jrubykaigi2010-lt-rubeus

Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashBret Little
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2Pat Cavit
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
 
Joose - JavaScript Meta Object System
Joose - JavaScript Meta Object SystemJoose - JavaScript Meta Object System
Joose - JavaScript Meta Object Systemmalteubl
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCpootsbook
 
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2JCD 2012 JavaFX 2
JCD 2012 JavaFX 2益裕 張
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryAlexandre Morgaut
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Foreverstephskardal
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2Haroon Idrees
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleThierry Wasylczenko
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011Nick Sieger
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsphanleson
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commandsleminhvuong
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevMattias Karlsson
 

Similar to jrubykaigi2010-lt-rubeus (20)

Java beans
Java beansJava beans
Java beans
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
How to React Native
How to React NativeHow to React Native
How to React Native
 
JavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and LodashJavaScript Fundamentals with Angular and Lodash
JavaScript Fundamentals with Angular and Lodash
 
The next step, part 2
The next step, part 2The next step, part 2
The next step, part 2
 
JJUG CCC 2011 Spring
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 Spring
 
Joose - JavaScript Meta Object System
Joose - JavaScript Meta Object SystemJoose - JavaScript Meta Object System
Joose - JavaScript Meta Object System
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
JCD 2012 JavaFX 2
JCD 2012 JavaFX 2JCD 2012 JavaFX 2
JCD 2012 JavaFX 2
 
NoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love StoryNoSQL and JavaScript: a Love Story
NoSQL and JavaScript: a Love Story
 
jQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends ForeverjQuery and Rails: Best Friends Forever
jQuery and Rails: Best Friends Forever
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Json generation
Json generationJson generation
Json generation
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
JRuby + Rails = Awesome Java Web Framework at Jfokus 2011
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Executing Sql Commands
Executing Sql CommandsExecuting Sql Commands
Executing Sql Commands
 
Java 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from OredevJava 7 Whats New(), Whats Next() from Oredev
Java 7 Whats New(), Whats Next() from Oredev
 

More from Takeshi AKIMA

LT at JavaOne2012 JVM language BoF #jt12_b101
LT at JavaOne2012  JVM language BoF #jt12_b101LT at JavaOne2012  JVM language BoF #jt12_b101
LT at JavaOne2012 JVM language BoF #jt12_b101Takeshi AKIMA
 
DSL by JRuby at JavaOne2012 JVM language BoF #jt12_b101
DSL by JRuby at JavaOne2012  JVM language BoF #jt12_b101DSL by JRuby at JavaOne2012  JVM language BoF #jt12_b101
DSL by JRuby at JavaOne2012 JVM language BoF #jt12_b101Takeshi AKIMA
 
20120324 git training
20120324 git training20120324 git training
20120324 git trainingTakeshi AKIMA
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routingTakeshi AKIMA
 
Oktopartial Introduction
Oktopartial IntroductionOktopartial Introduction
Oktopartial IntroductionTakeshi AKIMA
 

More from Takeshi AKIMA (7)

20120831 mongoid
20120831 mongoid20120831 mongoid
20120831 mongoid
 
LT at JavaOne2012 JVM language BoF #jt12_b101
LT at JavaOne2012  JVM language BoF #jt12_b101LT at JavaOne2012  JVM language BoF #jt12_b101
LT at JavaOne2012 JVM language BoF #jt12_b101
 
DSL by JRuby at JavaOne2012 JVM language BoF #jt12_b101
DSL by JRuby at JavaOne2012  JVM language BoF #jt12_b101DSL by JRuby at JavaOne2012  JVM language BoF #jt12_b101
DSL by JRuby at JavaOne2012 JVM language BoF #jt12_b101
 
20120324 git training
20120324 git training20120324 git training
20120324 git training
 
20120121 rbc rails_routing
20120121 rbc rails_routing20120121 rbc rails_routing
20120121 rbc rails_routing
 
Llonsen object ruby
Llonsen object rubyLlonsen object ruby
Llonsen object ruby
 
Oktopartial Introduction
Oktopartial IntroductionOktopartial Introduction
Oktopartial Introduction
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

jrubykaigi2010-lt-rubeus

  • 1. Play Swing and JDBC with Rubeus Takeshi AKIMA @akm2000 Ruby Business Commons
  • 2. Who am I? I'm one of the authors, "Ruby Tettei Nyumon(Ruby )" http://www.amazon.co.jp/JRuby- - /dp/4881666452 I wrote all of the code in the last chapter. Very famous book in the world
  • 5. http://rubybizcommons.jp I'm a member of the staff. In Fukuoka since 2007. We hold hands-on workshops about once a month recently.
  • 6. Rubeus http://code.google.com/p/rubeus/ "Rubeus provides you an easy access to Java objects from Ruby scripts on JRuby." We made a gem "Rubeus" in 2008. It provides a DSL for Java Swing and JDBC
  • 7. Swing with Rubeus If you want to write a code of window like this ...
  • 8. in Java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JavaSwingExample01 {     public static void main(String[] args) {         JFrame frame = new JFrame("Rubeus Swing Example 01");         frame.setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.Y_AXIS));         JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);         frame.add(splitPane);         JPanel panel = new JPanel();         splitPane.setTopComponent(panel);         panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));         final JTextField textField = new JTextField();         panel.add(textField);         final JTextPane textPane = new JTextPane();         textField.addKeyListener(new KeyAdapter() {                 public void keyPressed(KeyEvent event) {                     if (event.getKeyCode() == 10) {                         textPane.setText(textPane.getText() + textField.getText() + "n");                         textField.setText("");                     }                 }             });         JButton button = new JButton("append");         panel.add(button);         button.addActionListener(new ActionListener(){                 public void actionPerformed(ActionEvent event) {                     textPane.setText(textPane.getText() + textField.getText() + "n");                     textField.setText("");                 }             });         JScrollPane scrollPane = new JScrollPane(textPane);         splitPane.setBottomComponent(scrollPane);         scrollPane.setPreferredSize(new Dimension(400, 250));         frame.setSize(400, 300);         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         frame.setVisible(true);     } }
  • 9. in JRuby with Rubeus require 'rubygems' require "rubeus" Rubeus::Swing.irb JFrame.new("Rubeus Swing Example 01") do |frame|   frame.layout = BoxLayout.new(:Y_AXIS)   JSplitPane.new(JSplitPane::VERTICAL_SPLIT) do     JPanel.new do |panel|       panel.layout = BoxLayout.new(:X_AXIS)       @text_field = JTextField.new do |event|         if event.key_code == 10 # RETURN           @textpane.text += @text_field.text + "n"           @text_field.text = ''         end       end       JButton.new("append") do         @textpane.text += @text_field.text         @text_field.text = ''       end     end     JScrollPane.new(:preferred_size => [400, 250]) do |pane|       @textpane = JTextPane.new     end   end   frame.visible = true end
  • 10. JDBC with Rubeus require 'rubygems' require 'rubeus' Rubeus::Jdbc.irb DriverManager.connect("jdbc:derby:test_db") do |conn| conn.query("SELECT * FROM TEST ORDER BY ID") do |rs| rs.each do |row| puts row.to_a.join(",") end end end
  • 11. JDBC Metadata conn = Rubeus::Jdbc::DriverManager.connect("jdbc:derby:test_db") #=> #<Java::OrgApacheDerbyImplJdbc::EmbedConnection40:0x478dabf1> table = conn.meta_data.tables[:FLIGHTS] #=> #<Rubeus::Jdbc::Table FLIGHTS (FLIGHT_ID,SEGMENT_NUMBER,ORIG_AIRPORT,DEPART_TIME, DEST_AIRPORT,ARRIVE_TIME,MEAL)> table.columns #=> [#<Rubeus::Jdbc::Column FLIGHT_ID CHAR(6) NOT NULL>, #<Rubeus::Jdbc::Column SEGMENT_NUMBER INTEGER(10) NOT NULL>, #<Rubeus::Jdbc::Column ORIG_AIRPORT CHAR(3) NULL>, #<Rubeus::Jdbc::Column DEPART_TIME TIME(8) NULL>....]
  • 12. Easy to use Swing and JDBC table names result set
  • 13. require 'rubygems' require "rubeus" Rubeus::Swing.irb @conn = Rubeus::Jdbc::DriverManager. connect("jdbc:derby:test_db;create = true") tables = @conn.meta_data.tables(:schema => "APP") JFrame.new("Rubeus Swing Example 01") do |frame| frame.layout = BoxLayout.new(:X_AXIS) JSplitPane.new(JSplitPane::HORIZONTAL_SPLIT) do JScrollPane.new(:preferred_size => [150, 250]) do |pane| @list = JList.new(tables.map(&:name).to_java) do |event| table_name = @list.selected_value.inspect @conn.query("select * from #{table_name}") do |rs| @table.model = rs.map{|row| row.to_a} end end end JScrollPane.new{|pane| @table = JTable.new} end frame.visible = true end
  • 14. JRuby + irb It's a good Java Object Inspector. Now I always use irb to inspect Java classes before using it. I don't remember using many names of Java method and their arguments any more.
  • 15. listing String methods > java.lang.String.java_class.declared_class_methods #=> [#<Java::JavaMethod/indexOf([C,int,int,[C,int,int,int)>, #<Java::JavaMethod/checkBounds([B,int,int)>, #<Java::JavaMethod/lastIndexOf([C,int,int,[C,int,int,int)>, #<Java::JavaMethod/format(java.util.Locale,java.lang.String, [Ljava.lang.Object;)>, #<Java::JavaMethod/ format(java.lang.String,[Ljava.lang.Object;)>, #<Java::JavaMethod/valueOf([C)>, #<Java::JavaMethod/ valueOf(double)>, #<Java::JavaMethod/ valueOf(java.lang.Object)>, #<Java::JavaMethod/ It's difficult to read :-(
  • 16. You can get method names only with Rubeus
  • 17. Step1. get public static method names only require 'rubeus' > Rubeus::Reflection.irb #=> Object > java.lang.String.java_public_class_methods #=> ["format", "valueOf", "copyValueOf"]
  • 18. Step2. check the method arguments > java.lang.String.java_class. ?> java_public_class_methods. ?> select{|m| m.name == "copyValueOf"} #=> [#<Java::JavaMethod/copyValueOf([C,int,int)>, #<Java::JavaMethod/copyValueOf([C)>]
  • 19. Rubeus in JRuby book!? JRuby guys are writing a book. Rubeus and other libraries are introduced in the GUI part. GET IT! http://pragprog.com/titles/jruby/using-jruby
  • 20. Thanks Tom gave us some patches. We appreciate your kindness.

Editor's Notes