defdoVote(name, comment) Nomination.transaction { n = Nomination.find_by_name(name) returnif n == nil if comment != nil && comment != ""then Comment.create(:nomination_id=>n.id, :comment=>comment) end n.votes_obtained += 1 n.save } broker = MessageBroker.getMessageBroker(nil) msg = AsyncMessage.new msg.setDestination("vote") msg.setMessageId(UUIDUtils.createUUID) msg.setBody({:name=>name,:progress=>getProgress}) broker.routeMessageToService(msg, nil) end end
VoteService.new ]]> </lang:inline-script> <lang:property name="jndiName" value="java:/comp/env/jdbc/vote"/> <lang:property name="DDL"> <value> <![CDATA[ drop table if exists nominations; create table if not exists nominations ( id integer IDENTITY primary key, name varchar not null, full_name varchar not null, votes_obtained integer default 0 ); create unique index nominations_idx on nominations(name); drop table if exists comments; create table if not exists comments ( id integer IDENTITY primary key, nomination_id integer not null, comment varchar not null, created_at timestamp not null ); ]]> </value> </lang:property> </lang:jruby>
public Collection<Map> searchMember(String nameOrProperty) { Collection<Map> results = new ArrayList<Map>(); Map p = new HashMap(); p.put("オタク", 5); p.put("胸", 1); p.put("アホ毛", 5); p.put("運動神経", 5); p.put("需要", 4); results.add(createRecord( "konata", "泉 こなた", "05月28日", "埼玉県", "A","極小",142, p ));
p = new HashMap(); p.put("バルサミコ酢", 5); p.put("巫女", 3); p.put("ドジっ娘", 4); p.put("どんだけ〜", 5); p.put("妹属性", 4); results.add(createRecord( "tsukasa", "柊 つかさ", "07月07日", "埼玉県", "B", "小", 158, p ));
p = new HashMap(); p.put("ツインテール", 5); p.put("お姉ちゃん", 3); p.put("ツンデレ", 5); p.put("お菓子好き", 4); p.put("ツリ目", 5); results.add(createRecord( "kagami", "柊 かがみ", "07月07日", "埼玉県", "B", "中", 159, p ));
p = new HashMap(); p.put("天然", 5); p.put("巨乳", 5); p.put("眼鏡っ娘", 5); p.put("委員長", 5); p.put("虫歯", 5); results.add(createRecord( "miyuki", "高良 みゆき", "10月25日", "東京都", "O", "巨", 166, p ));
if (nameOrProperty == null || "".equals(nameOrProperty)) return results;
Collection<Map> searchResults = new ArrayList<Map>(); for (Map m:results) { boolean hit = false; if ( ((String)m.get("name")).indexOf(nameOrProperty) >= 0) { hit = true; } else { for (Object property:((Map)m.get("properties")).keySet()) { if ( ((String)property).indexOf(nameOrProperty) >= 0) { hit = true; break; } } } if (hit) searchResults.add(m);
そしたら今度は org.jruby.exceptions.RaiseException: superclass must be a Class (Module) given というエラー。勘弁してください。 Springのフォーラムで同じ悩みを抱えている人が一人だけいた。 JRuby 1.0以降を使う場合、ドキュメントに書いてある例どおりにRubyクラスにJava側のインターフェイスを継承させるとエラーになってしまうようだ。何も継承していないクラスを記述したところ解決。