サイトリニューアル
iD for WebLifeは面白いソフトだった。
これは、実用的なソフトだと思う。
新しい STBBS.NET オフィシャルサイトへ
ITやガジェットのこと
ラベル: Rails
date = new Date(
dateChooser.selectedDate.time
- dateChooser.selectedDate.timezoneOffset * 60 * 1000
);

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Label x="10" y="10" text="Webサービス(SOAP)呼び出し君"/>
<mx:Label x="10" y="36" text="お名前"/>
<mx:TextInput id="yourName" x="53" y="34"/>
<mx:Button x="221" y="34" label="送信"
click="helloService.SayHello.send()"/>
<mx:Text x="10" y="62" width="257" height="33"
text="{helloService.SayHello.lastResult}"/>
<mx:WebService id="helloService"
wsdl="http://my-rails-host:3000/hello/service.wsdl">
<mx:operation name="SayHello">
<mx:request>
<name>{yourName.text}</name>
</mx:request>
</mx:operation>
</mx:WebService>
</mx:Application>
# Helloという Webサービスのインターフェイスを表現するクラス
class HelloAPI < ActionWebService::API::Base
# nameという文字列引数を取り、文字列を返す say_hello メソッドの定義
# Railsのお節介により、外からは SayHelloという名前で呼び出されるようになる。
# (お節介を抑制するには inflect_names false とする)
api_method :say_hello, :expects=>[{:name=>:string}], :returns=>[:string]
end
# Helloという Webサービスを実装するコントローラクラス
class HelloController < ApplicationController
# メソッドsay_helloの実装。
def say_hello(name)
# 名前を聞いて、こんにちは、○○さん。って言うだけ。
"Hello, " + name
end
end
ラベル: Rails
def list
xml = Builder::XmlMarkup.new(:indent=>2)
render :xml => xml.results {
xml.item do
xml.id(1)
xml.name("Konata Izumi")
end
xml.item do
xml.id(2)
xml.name("Kagami Hiiragi")
end
}
end
<results>
<item>
<id>1</id>
<name>Konata Izumi</name>
</item>
<item>
<id>2</id>
<name>Kagami Hiiragi</name>
</item>
</results>
ラベル: Rails
require 'yaml'
require 'dbi'
module WithDBI
@@dbconfig =
YAML::load(File.open("#{RAILS_ROOT}/config/database.yml"))[RAILS_ENV]
@@drivernames = {
"postgresql"=>"Pg",
"mysql"=>"Mysql",
"oci"=>"OCI8"
} # ActiveRecordのadapterと DBIのドライバ名を対応づけるマップ
def with_dbi
dbname = @@dbconfig["database"]
username = @@dbconfig["username"]
password = @@dbconfig["password"]
host = @@dbconfig["host"]
adapter = @@dbconfig["adapter"]
# encodingを処理する方法不明...多分DBIでは吸収されずDBMS依存
connstr = "DBI:" + @@drivernames[adapter] + ":" + dbname
if host != nil then
connstr += ":" + host
end
DBI.connect(connstr, username, password) {|dbh|
dbh['AutoCommit'] = false
dbh.transaction {|dbh|
yield dbh
}
}
end
end
def list
with_dbi { |dbh| # DBI::DatabaseHandle
@results = dbh.select_all("select id,name from people")
# @resultsには DBI::Rowの Arrayが入る
}
end
ラベル: Rails
ラベル: Rails
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
ラベル: Rails
ラベル: Xen
ラベル: OpenJPA
create table people (
id number(10) primary key,
name varchar(255)
);
create sequence people_seq;
class Person < ActiveRecord::Base
end
development:
adapter: oci
username: scott
password: tiger
host: mydbhost/XE


<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter"/>
</property>
</bean>
<?xml version="1.0"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="適当な名前" transaction-type="RESOURCE_LOCAL"/>
</persistence>
EntityManager em = entityManagerFactory.createEntityManager();MyEntityはDBのテーブルに対応づけられるべくアノテーション漬けにされた永続クラス。
// 主キー指定でDBから行をフェッチし、MyEntityのインスタンスとして得る
MyEntity e = em.find(MyEntity.class, 123);
// ...など、いろいろ処理
em.close(); // 使い終わったら片付ける