<?xml version="1.0" encoding="UTF-8" ?><rdf:RDF 
  xmlns="http://purl.org/rss/1.0/"
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xml:lang="ja">
  <channel rdf:about="http://www4.atwiki.jp/gsh/">
    <title>GSH@Wiki</title>
    <link>http://www4.atwiki.jp/gsh/</link>
    <description>GSH@Wiki</description>

    <dc:language>ja</dc:language>
    <dc:date>2007-04-26T23:43:48+09:00</dc:date>

    <items>
      <rdf:Seq>
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/28.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/38.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/2.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/37.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/36.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/34.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/33.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/27.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/35.html" />
                <rdf:li rdf:resource="http://www4.atwiki.jp/gsh/pages/30.html" />
              </rdf:Seq>
    </items>
	
		
    
  </channel>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/28.html">
    <title>Derby</title>
    <link>http://www4.atwiki.jp/gsh/pages/28.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;Apache Derby Database Engine&lt;/h1&gt;)
:Derby|Apacheで開発されているPure Java Databaseのひとつ。(元IBMのCloudscape)&amp;br()Java SE6からは標準バンドル。&amp;br()パフォーマンス的にはまだまだ改良の余地あり？→H2のサイト参照&amp;br()http://db.apache.org/derby/

#contents
----
**データベースへの接続
-組み込みモード
 // Server起動
 Class.forName(&quot;org.apache.derby.jdbc.EmbeddedDriver&quot;).newInstance();
 // JDBC接続
 Connection conn = DriverManager.getConnection(&quot;jdbc:derby:sample&quot;);

-サーバモード
 // Server起動
 NetworkServerControl server = new NetworkServerControl();
 server.start();
 // クライアントから接続（JDBC接続）
 String nsURL = &quot;jdbc:derby://localhost:1527/sample&quot;;
 Class.forName(&quot;org.apache.derby.jdbc.ClientDriver&quot;);
 Connection conn = DriverManager.getConnection(nsURL, &quot;app&quot;, &quot;app&quot;);
 // Server停止
 server.shutdown();

**コマンドラインからの起動
-サーバの起動
 set DERBY_HOME=&lt;&lt;DERBY_INSTALL_HOME&gt;&gt;
 set CLASSPATH=%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\lib\derbynet.jar
 java org.apache.derby.drda.NetworkServerControl start

-サーバの停止
 java org.apache.derby.drda.NetworkServerControl shutdown

**ij
-コンソールツールの起動
 set DERBY_HOME=&lt;&lt;DERBY_INSTALL_HOME&gt;&gt;
 set IJ_HOST=localhost
 set IJ_PORT=1527
 set IJ_USER=APP
 set IJ_PASSWORD=APP
 
 java -cp &quot;%DERBY_HOME%\lib\derbyclient.jar;%DERBY_HOME%\lib\derbytools.jar;%CLASSPATH%&quot; -Dij.driver=org.apache.derby.jdbc.ClientDriver -Dij.protocol=jdbc:derby://%IJ_HOST%:%IJ_PORT%/ -Dij.user=%IJ_USER% -Dij.password=%IJ_PASSWORD%  org.apache.derby.tools.ij

-データベースへの接続
 ij&gt; connect &#039;jdbc:derby://localhost:1527/&lt;&lt;databasename&gt;&gt;[;OPTION]&#039;;

-データベースの切断
 ij&gt; disconnect;

-SQLスクリプトの実行
 ij&gt; run &#039;&lt;&lt;scriptname&gt;&gt;&#039;;

**Tips
-データベース作成箇所
デフォルトではカレントディレクトリ。
設定するにはシステムプロパティ「derby.system.home」にパスを指定する。
 java -Dderby.system.home=C:/databases org.apache.derby.drda.NetworkServerControl start

-ネットワークサーバの設定
derby.property または システムプロパティ で設定する。
（derby.propertyの設置場所はderby.system.homeで指定したパス）
|項目|内容|
|derby.drda.startNetworkServer|ネットワークサーバで起動するかどうか (true false)|
|derby.drda.host|localネットワークサーバのホスト名|
|derby.drda.portNumber|接続受付ポート番号 (default:1527)|

-接続URL Attribute
 jdbc:derby:[subprotcol:][databaseName][;attribute=value]
|Attribute|説明|
|create=true|データベースが作成されていない場合には作成する|
|databaseName=nameofDatabase|接続するデータベース名|
|shutdown=true|組み込みアプリケーションにおいて、アプリ終了時にDerbyも終了する|

-ドキュメント
derbydev.pdf &gt; Working with the database connection URL attributes 参照

-Windows Service化
[[JavaService&gt;http://forge.objectweb.org/projects/javaservice]]を利用することで可能。    </description>
    <dc:date>2007-04-26T23:43:48+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/38.html">
    <title>Tomcat5</title>
    <link>http://www4.atwiki.jp/gsh/pages/38.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;Tomcat5&lt;/h1&gt;)
メニュー
#contents
----
**Apacheとの連携
-Apache2.2.4 [[DOWNLOAD&gt;http://httpd.apache.org/download.cgi]]
-Tomcat5.5.23 [[DOWNLOAD&gt;http://tomcat.apache.org/download-55.cgi]]
-jk1.2.22 (mod_jk-apache-2.2.4.so) [[DOWNLOAD&gt;http://tomcat.apache.org/download-connectors.cgi]]
Apacheのバージョンに合ったjk connectorを使うこと。

***Apacheの設定変更
-jk connectorのコピー
mod_jk-apache-2.2.4.so → mod_jk.so にリネームして、&lt;&lt;APACHE_HOME&gt;&gt;/modulesにコピー。

-httpd.confの編集
 [&lt;&lt;APACHE_HOME&gt;&gt;/conf/httpd.conf]
 # http.confの最後に以下を追加
 Include &quot;C:/Java/tomcat5.5.23/conf/mod_jk.conf&quot;

***Tomcatの設定変更
-server.xmlの編集
 [&lt;&lt;TOMCAT_HOME&gt;&gt;/conf/server.xml]
 &lt;Engine name=&quot;Catalina&quot; defaultHost=&quot;localhost&quot;&gt;
   &lt;Listener className=&quot;org.apache.jk.config.ApacheConfig&quot;
     modJk=&quot;C:/Apache2.2.4/modules/mod_jk.so&quot; /&gt;
&lt;Engine&gt;タグの直下に&lt;Listener&gt;タグを追加する。
modjkパラメータには先ほどコピーした mod_jk.so のパスを記述する。

-confディレクトリの配下に「auto」「jk」ディレクトリを作成する。

-Tomcatの起動→停止
設定が正しければ、conf/autoに mod_jk.conf ファイルが作成されている。
 [&lt;&lt;TOMCAT_HOME&gt;&gt;/conf/auto/mod_jk.conf]
 ########## Auto generated on Sun Apr 15 23:32:35 JST 2007##########
 
 &lt;IfModule !mod_jk.c&gt;
   LoadModule jk_module &quot;C:/Apache2.2.4/modules/mod_jk.so&quot;
 &lt;/IfModule&gt;
 
 &lt;VirtualHost localhost&gt;
     ServerName localhost
 
     JkMount /manager ajp13
     JkMount /manager/* ajp13
 
     JkMount /webdav ajp13
     JkMount /webdav/* ajp13
 
     JkMount /servlets-examples ajp13
     JkMount /servlets-examples/* ajp13
 
     JkMount /tomcat-docs ajp13
     JkMount /tomcat-docs/* ajp13
 
     JkMount /host-manager ajp13
     JkMount /host-manager/* ajp13
 
     JkMount /jsp-examples ajp13
     JkMount /jsp-examples/* ajp13
 
     JkMount /balancer ajp13
     JkMount /balancer/* ajp13
 &lt;/VirtualHost&gt;

-mod_jk.confのコピーとworkers.propertiesの作成
mod_jk.confをhttpd.confで記述したパス（&lt;&lt;TOMCAT_HOME&gt;&gt;/conf）へコピーする。
&lt;&lt;TOMCAT_HOME&gt;&gt;/conf/jkにworkers.propertiesを作成する。
 [[&lt;&lt;TOMCAT_HOME&gt;&gt;/conf/jk/workers.properties]]
 worker.list=ajp13

-Tomcat→Apacheの順にサーバを起動する
http://localhost/jsp-examples/ にアクセスできれば成功。

***Tips
-TomcatのListenerを生かしておくのなら、常にApacheからの参照はauto/mod_j.confでもよい
-ロードバランサなどを利用したい場合には、jk/workers.propertiesに設定する。
[[ワーカの手引き&gt;http://www.jajakarta.org/tomcat/tomcat-jk2/ja/docs/jk/workershowto.html]]    </description>
    <dc:date>2007-04-16T00:23:59+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/2.html">
    <title>メニュー</title>
    <link>http://www4.atwiki.jp/gsh/pages/2.html</link>
    <description>
      **JAVA
[[JSF+Spring]]
[[SpringFramework]]
[[JSF]]
[[Facelets]]

[[メモ]]

***EJB3.0
[[GlassFish]]
[[JPA]]
[[Seam]]

***DB
[[H2]]
[[Derby]]
[[HSQLDB]]

**Server
[[Apache2]]
[[Tomcat5]]

**.NET
[[覚え書き]]

**TrashBox
[[旧メニュー]]

**更新履歴
#recent(10)    </description>
    <dc:date>2007-04-15T23:49:03+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/37.html">
    <title>Seam</title>
    <link>http://www4.atwiki.jp/gsh/pages/37.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;JBoss Seam&lt;/h1&gt;)
:JBoss Seam|EJB3+JSFを統合するJavaEE5フレームワーク。&amp;br()JavaEE5でJSFとEJB3はそれぞれ標準とされたが、双方を連携する手段はない。Seamはこれを行う。&amp;br()また、マイクロコンテナを利用することでEJB3をサポートしていないTomcatなどのコンテナ上でもEJB3を動作させることが可能。&amp;br()http://labs.jboss.com/portal/jbossseam

#contents
----
*JBoss Seamを動かす（Tomcat）
-前知識&amp;br()JavaEE5フレームワークなので、EJB3やJPAの知識はほしいところ。&amp;br()ビュー表示にはJSFを利用しているのでFaceletsでも可。&amp;br()また、ページナビゲーションにはjBPMを使用することもできる。

-動作環境&amp;br()JavaSE5以上、JBossAS(EJB3)または、Tomcat5.5.x&amp;br()Seamがアノテーションを利用して設定などを記述するため。

-日本語リファレンス&amp;br()http://www.jbug.jp/cgi-bin/fswiki/wiki.cgi (日本JBossグループ)から入手可能。

**JSF、servletコンテナと結合する
-Seam起動リスナの登録
 [web.xml]
 &lt;listener&gt;
     &lt;listener-class&gt;org.jboss.seam.servlet.SeamListener&lt;/listener-class&gt;
 &lt;/listener&gt;

-(JSF)クライアント側での保存を有効にする
 [web.xml]
 &lt;context-param&gt;
     &lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
     &lt;param-value&gt;client&lt;/param-value&gt;
 &lt;/context-param&gt;

-JSFリクエストサイクルの結合
 [faces-config.xml]
 &lt;lifecycle&gt;
     &lt;phase-listener&gt;org.jboss.seam.jsf.SeamPhaseListener&lt;/phase-listener&gt;
 &lt;/lifecycle&gt;
このリスナクラスはトランザクション区分によって変わる。

**EJBコンテナとSeamの結合
-インタセプターの設定
 [ejb-jar.xml]
 &lt;assembly-descriptor&gt;
    &lt;interceptor-binding&gt;
       &lt;ejb-name&gt;*&lt;/ejb-name&gt;
       &lt;interceptor-class&gt;org.jboss.seam.ejb.SeamInterceptor&lt;/interceptor-class&gt;
    &lt;/interceptor-binding&gt;
 &lt;/assembly-descriptor&gt;
インタセプターを追加することにより、Seamコンポーネント(Session Bean)のハンドリングができるようになる。

-JNDIパターンの登録
 [component.xml]
 &lt;!-- JBossASの場合 --&gt;
 &lt;component name=&quot;org.jboss.seam.core.init&quot;&gt;
     &lt;property name=&quot;jndiPattern&quot;&gt;myEarName/#{ejbName}/local&lt;/property&gt;
 &lt;/component&gt;
 
 &lt;!-- Embedded EJB3の場合 --&gt;
 &lt;component name=&quot;org.jboss.seam.core.init&quot;&gt;
     &lt;property name=&quot;jndiPattern&quot;&gt;#{ejbName}/local&lt;/property&gt;
 &lt;/component&gt;
myEarNameはBeanがデプロイされたEARの名前。

**リダイレクトで対話の伝搬を可能にする
 [web.xml]
 &lt;filter&gt;
     &lt;filter-name&gt;Seam Redirect Filter&lt;/filter-name&gt;
     &lt;filter-class&gt;org.jboss.seam.servlet.SeamRedirectFilter&lt;/filter-class&gt;
 &lt;/filter&gt;
 &lt;filter-mapping&gt;
     &lt;filter-name&gt;Seam Redirect Filter&lt;/filter-name&gt;
     &lt;url-pattern&gt;*.seam&lt;/url-pattern&gt;
 &lt;/filter-mapping&gt;

**組み込み可能EJB3
embedded-ejbコンテナを利用することで、Tomcatなどの非JavaEE5コンテナでもEJB3が利用できるようになる。

***embedded-ejbのインストール
-Seamの解凍先にあるembedded-ejb/conf配下にあるファイルをmc-conf.jarにアーカイブする。
-Seamでembedded-ejbを利用することを宣言する。
 [components.xml]
 &lt;component class=&quot;org.jboss.seam.core.Ejb&quot; installed=&quot;true&quot;/&gt;
Seam起動時に、embedded-ejbコンテナも起動される。

***embedded-ejbコンテナのリソース設定
Seamに添付されているjboss-beans.xmlを利用すると、新しいデータソースを追加することができる。
 [jboss-beans.xml]
 &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
 &lt;deployment xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;urn:jboss:bean-deployer bean-deployer_1_0.xsd&quot;
     xmlns=&quot;urn:jboss:bean-deployer&quot;&gt;
     &lt;bean name=&quot;bookingDatasourceBootstrap&quot;
         class=&quot;org.jboss.resource.adapter.jdbc.local.LocalTxDataSource&quot;&gt;
         &lt;property name=&quot;driverClass&quot;&gt;org.hsqldb.jdbcDriver&lt;/property&gt;
         &lt;property name=&quot;connectionURL&quot;&gt;jdbc:hsqldb:.&lt;/property&gt;
         &lt;property name=&quot;userName&quot;&gt;sa&lt;/property&gt;
         &lt;property name=&quot;jndiName&quot;&gt;java:/bookingDatasource&lt;/property&gt;
         &lt;property name=&quot;minSize&quot;&gt;0&lt;/property&gt;
         &lt;property name=&quot;maxSize&quot;&gt;10&lt;/property&gt;
         &lt;property name=&quot;blockingTimeout&quot;&gt;1000&lt;/property&gt;
         &lt;property name=&quot;idleTimeout&quot;&gt;100000&lt;/property&gt;
         &lt;property name=&quot;transactionManager&quot;&gt;
             &lt;inject bean=&quot;TransactionManager&quot;/&gt;
         &lt;/property&gt;
         &lt;property name=&quot;cachedConnectionManager&quot;&gt;
             &lt;inject bean=&quot;CachedConnectionManager&quot;/&gt;
         &lt;/property&gt;
         &lt;property name=&quot;initialContextProperties&quot;&gt;
             &lt;inject bean=&quot;InitialContextProperties&quot;/&gt;
         &lt;/property&gt;
     &lt;/bean&gt;
     &lt;bean name=&quot;bookingDatasource&quot; class=&quot;java.lang.Object&quot;&gt;
         &lt;constructor factoryMethod=&quot;getDatasource&quot;&gt;
             &lt;factory bean=&quot;bookingDatasourceBootstrap&quot;/&gt;
         &lt;/constructor&gt;
     &lt;/bean&gt;
 &lt;/deployment&gt;

**パッケージング
Tomcat(embedded-ejb)の場合。
（リファレンスの構成では動かなかったので、動作するサンプルを元にしました）
 my-application.war/
     META-INF/
         MANIFEST.MF
     WEB-INF/
         web.xml
         components.xml
         faces-config.xml
     lib/
         jboss-seam.jar
         myfaces-api.jar
         myfaces-impl.jar
         jboss-ejb3-all.jar
         ...
         mc-conf.jar/
             ejb3-interceptors-aop.xml
             embedded-jboss-beans.xml
             default.persistence.properties
             jndi.properties
             jboss-jms-beans.xml
             login-config.xml
             security-beans.xml
             log4j.xml
         my-application.jar/
             seam.properties
             import.sql
             META-INF/
                 MANIFEST.MF
                 persistence.xml
                 jboss-beans.xml
                 ejb-jar.xml
             org/
                 jboss/
                     myapplication/
                         User.class
                         Login.class
                         LoginBean.class
                         Register.class
                         RegisterBean.class
                         ...
     login.jsp
     register.jsp
     ...

*Tips
-動作に必要なJAR&amp;br()%SEAM_HOME%/jboss-seam.jar&amp;br()%SEAM_HOME%/lib配下のJAR(ただし、javax.servlet.jsp.jar, servlet-api.jar, testng-4.5.1-jdk15.jarを除く）&amp;br()Faceletsを使用する場合には%SEAM_HOME%/facelets/libに含まれるJARも追加

-SeamContext情報を表示させるには&amp;br()クラスパスに jboss-seam-debug.jar を追加する。&amp;br()%SEAM_HOME%/SRC/DEBUG/META-INF/debug.xhtmlをWebページに追加する。

-日本語表示するには&amp;br()ソースファイルの文字コードをUTF-8にする。&amp;br()Faceletsと同様、ページエンコード設定をmetaタグを利用して定義する（UTF-8に）。&amp;br()とりあえずUTF-8にしませう。もしくは国際化で対応。

-設定ファイルの記述が大変&amp;br()SeamではEJB3等の設定はアノテーションを利用するので、DDファイルへ記述するのはJSFのページナビゲーションくらいになる。&amp;br()このためひとつ基本的なSeamプロジェクトを作成しておくと、２回目以降は省略できる。

*ブランクプロジェクト
-Seam付属サンプルを参考に作成&amp;br()[[SeamBlank_20061031.zip&gt;http://www4.atwiki.jp/gsh/?cmd=upload&amp;act=open&amp;page=Seam&amp;file=SeamBlank_20061031.zip]]    </description>
    <dc:date>2006-10-31T00:47:41+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/36.html">
    <title>Facelets</title>
    <link>http://www4.atwiki.jp/gsh/pages/36.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;Facelets&lt;/h1&gt;)
:Facelets|従来のJSP+JSFではなく、TapestryのようなテンプレートエンジンでJSFページを構成する。&amp;br()https://facelets.dev.java.net/

#contents
----
*Faceletsを使う
**Faceletsのダウンロード
https://facelets.dev.java.net/ から最新版のバイナリを入手する。
Faceletsで利用するJSFの実装はSunのJSF RIか、Apache MyFaces。
必要に応じて別途DLしておく。（Faceletsに付属）

**Faceletsアプリケーションの基本構成
FaceletsのJAR（jsf-facelets.jar, el-api.jar, el-ri.jar）とJSF実装JARを含める。
 $DEPLOY_DIR
 +- /WEB-INF
    +- /classes
    +- /lib
       +- /jsf-facelets.jar
       +- /el-api.jar
       +- /el-ri.jar
          [jsf implementation dependencies]
       +- /jsf-api.jar
       +- /jsf-impl.jar
       +- /commons-digester.jar
       +- /commons-logging.jar
       +- /commons-collections.jar
       +- /commons-beanutils.jar
    +- /web.xml
    +- /faces-config.xml
 +- /[xhtml documents]

**Faceletsプロジェクト
%facelets_binary%/docs/dev/docbook.html の「1.3. Directory Structure」以降を参照。

***web.xml
 &lt;web-app&gt;
  &lt;context-param&gt;
    &lt;param-name&gt;javax.faces.DEFAULT_SUFFIX&lt;/param-name&gt;
    &lt;param-value&gt;.xhtml&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;context-param&gt;
    &lt;param-name&gt;facelets.DEVELOPMENT&lt;/param-name&gt;
    &lt;param-value&gt;true&lt;/param-value&gt;
  &lt;/context-param&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
 &lt;/web-app&gt;
+javax.faces.DEFAULT_SUFFIX&amp;br()JSFページとして処理を行う（ページの）拡張子を「.xhtml」にする
+facelets.DEVELOPMENT&amp;br()「true」を設定することで例外発生時にFaceletsによる詳細なエラーページが表示されるようになる。
+その他&amp;br()SunやMyFacesそれぞれのオプション設定を記述する。

***faces-config.xml
 &lt;faces-config&gt;
   &lt;application&gt;
     &lt;view-handler&gt;
          com.sun.facelets.FaceletViewHandler&lt;/view-handler&gt;
   &lt;/application&gt;
 &lt;/faces-config&gt;
ビュー表示はJSPではなくXHTML（XML）で記述するテンプレートを利用するため、Faceletsが提供するViewHandlerを設定する。

***Webページ
-テンプレートページ（template.xhtml）
 &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; 
  &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
 &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
       xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
       xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;
 &lt;head&gt;
     &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
     &lt;title&gt;&lt;ui:insert name=&quot;title&quot;&gt;Facelets Sample&lt;/ui:insert&gt;&lt;/title&gt;
     &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;css/screen.css&quot; /&gt;
 &lt;/head&gt;
 &lt;body&gt;
     &lt;ui:insert name=&quot;content&quot;&gt;Default Content&lt;/ui:insert&gt;
 &lt;/body&gt;
 &lt;/html&gt;
-xmlns:[prefix]=[uri]&amp;br()JSPのtaglib定義の変わり。&amp;br()faceletsは「ui」を通例としている。
-&lt;ui:insert name=&quot;title&quot;&gt;&lt;/ui:insert&gt;&amp;br()template.xhtmlを利用するページで&lt;ui:define name=&quot;title&quot;&gt;&lt;/ui:define&gt;を指定することによって挿入される。&amp;br()&lt;ui:define&gt;がない場合には、template.xhtmlにかかれている「Facelets Sample」が表示される。

-コンテンツページ
 &lt;!DOCTYPE composition PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; 
  &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
 &lt;ui:composition xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
     xmlns:ui=&quot;http://java.sun.com/jsf/facelets&quot;
     xmlns:h=&quot;http://java.sun.com/jsf/html&quot;
     xmlns:f=&quot;http://java.sun.com/jsf/core&quot; template=&quot;template.xhtml&quot;&gt;
     &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
     &lt;ui:define name=&quot;title&quot;&gt;
     Facelets ユーザ登録サンプルページ
     &lt;/ui:define&gt;
     &lt;ui:define name=&quot;content&quot;&gt;
         &lt;h1&gt;ユーザ登録サンプル&lt;/h1&gt;
         &lt;form jsfc=&quot;h:form&quot;&gt;
         &lt;table border=&quot;0&quot;&gt;
             &lt;tr&gt;
                 &lt;td&gt;ユーザ名&lt;/td&gt;
                 &lt;td&gt;&lt;input type=&quot;text&quot; jsfc=&quot;h:inputText&quot; size=&quot;30&quot;
                     value=&quot;#{user.username}&quot; /&gt;&lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                 &lt;td&gt;パスワード&lt;/td&gt;
                 &lt;td&gt;&lt;input type=&quot;password&quot; jsfc=&quot;h:inputSecret&quot; size=&quot;30&quot;
                     value=&quot;#{user.password}&quot; /&gt;&lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                 &lt;td colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; jsfc=&quot;h:commandButton&quot;
                     value=&quot;登録&quot; action=&quot;#{register.register}&quot; /&gt;&lt;/td&gt;
             &lt;/tr&gt;
         &lt;/table&gt;
     &lt;/ui:define&gt;
 &lt;/ui:composition&gt;
-jsfc属性&amp;br()&lt;h:inputText&gt;で記述した場合、ページをプレビューできないが、Faceletsでは「jsfc=&quot;h:inputText&quot;」とすることでViewHandler側でJSFタグと解釈されるために、ブラウザでプレビューが可能となる。

**Tips
-XHTMLで日本語を表示するには&amp;br()1,ファイルエンコード（文字コード）をUTF-8にする。&amp;br()2,（EclipseWTPを使用している場合）「&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;」を記述しておく。
-タグの閉じ忘れに注意&amp;br()HTMLタグなどで終了タグが省略可能なものでも、FaceletsではXMLパーサによるエラーになるので必ず終了タグを記述しなければならない。    </description>
    <dc:date>2006-10-22T00:05:00+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/34.html">
    <title>JPA</title>
    <link>http://www4.atwiki.jp/gsh/pages/34.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;Java Persistence API [JPA]&lt;/h1&gt;)
:JPA|以前のEntityBean周りをJavaSEでも利用できるようAPIとして分離したもの。&amp;br()JavaEEではインタフェースを定義してあるのみなので、別途実装環境が必要になる。&amp;br()→GlassFish(TopLink)、JBoss(Hibernate)など

メニュー
#contents

**永続化ユニット(Persistence.xml)
EntityManagerを作成するために使用するデータベースなどの設定を記述したXMLファイル。
作成したファイルはMETA-INF/persistence.xmlとして格納する。
 &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
 &lt;persistence
         xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence
           http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;
         version=&quot;1.0&quot;&gt;
     &lt;persistence-unit name=&quot;sample-pu&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
         &lt;provider&gt;oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider&lt;/provider&gt;
         &lt;class&gt;sample.jpa.entity.Customer&lt;/class&gt;
         &lt;properties&gt;
             &lt;property name=&quot;toplink.ddl-generation&quot; value=&quot;drop-and-create-tables&quot; /&gt;
             &lt;property name=&quot;toplink.logging.level&quot; value=&quot;FINE&quot; /&gt;
             &lt;property name=&quot;toplink.jdbc.driver&quot; value=&quot;org.h2.Driver&quot; /&gt;
             &lt;property name=&quot;toplink.jdbc.url&quot; value=&quot;jdbc:h2://localhost:9092/jpasample&quot; /&gt;
             &lt;property name=&quot;toplink.jdbc.user&quot; value=&quot;sa&quot; /&gt;
             &lt;property name=&quot;toplink.jdbc.password&quot; value=&quot;&quot; /&gt;
             &lt;property name=&quot;toplink.platform.class.name&quot;
                       value=&quot;oracle.toplink.essentials.platform.database.JavaDBPlatform&quot; /&gt;
         &lt;/properties&gt;
     &lt;/persistence-unit&gt;
 &lt;/persistence&gt;
※GlassFish(Toplink)を利用した場合のサンプル。

&lt;persistence-unit&gt;タグのname属性に永続化ユニット名を記述する。
transaction-type属性にはJavaSEで利用する場合には「RESOURCE_LOCAL」、JavaEEの場合は「JTA」を記述する。
また、JTAの場合には&lt;jta-data-source&gt;に使用するDataSourceを指定する必要がある。
&lt;properties&gt;タグの子要素には実装環境によりnameに指定するキーが異なる。
|キー|説明|
|toplink.logging.level|ログ出力レベル。「FINE」が標準。「FINEST」を指定すると詳細なログが出力される。|
|toplink.ddl-generation|DDL作成「drop-and-create-tables」「create-tables」など|
|toplink.platform.class.name|データベース固有の方言クラスを指定。&amp;br()oracle.toplink.essentials.platform.databaseパッケージ配下にあるクラスを指定する。|
|toplink.jdbc.driver|JDBCドライバクラス。|
|toplink.jdbc.url|JDBC接続URL。|
|toplink.jdbc.user|接続ユーザ名。|
|toplink.jdbc.password|接続パスワード。|

**EnityManagerの取得
JPAで永続化を行うにはEntityManagerクラスを利用する。
EntityManagerを取得するときにパーシステンスユニットを指定する。
 [JavaSE]
 EntityManagerFactory emf = Persistence.createEntityManagerFactory(&quot;sample-pu&quot;);
 EntityManager em = emf.createEntityManager();

 [JavaEE]
 @PersistenceContext(&quot;sample-pu&quot;)
 private EntityManager em;
JavaEE環境ではアノテーションを使いパーシステンスユニットを指定することによってEJBコンテナがインジェクションしてくれる。

**JavaSEでJPA
環境：
JDK5.0
GlassFish (toplink-essentials.jar, toplink-essentials-agent.jar)
H2 Database (h2.jar)
サンプル→[[JPASample.zip&gt;http://www4.atwiki.jp/gsh/?cmd=upload&amp;act=open&amp;page=JPA&amp;file=JPASample.zip]]
（上記必要JARをlibディレクトリにコピーするか、build.propertiesを編集してください）

***EntityBeanの作成
「@Entityアノテーション」をクラス宣言につける。
パラメータを省略した場合、クラス名と同名のテーブルとがマッピングされる。
 @Entity
 public class Customer {
    // 略
 }

エンティティの中で主キー（一意）となるメンバに「@Idアノテーション」をつける。
また主キー生成の方法を「@GeneratedValueアノテーション」で指定する。
 @Id
 @GeneratedValue(strategy=&quot;AUTO&quot;)
 private int id;
strategyに指定するのは javax.persistence.GenerationType のenumで定義されている。    </description>
    <dc:date>2006-09-24T23:22:54+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/33.html">
    <title>GlassFish</title>
    <link>http://www4.atwiki.jp/gsh/pages/33.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;GlassFish&lt;/h1&gt;)
:GlassFish|オープンソースとして提供されているアプリケーションサーバ。&amp;br()JavaEE5の実装環境にもなっている。

メニュー
#contents

**GlassFishの導入
GlassFishのサイトから入手可能。
[[https://glassfish.dev.java.net/]]
Downloads &gt; Milestone bibary builds &gt; V1 Milestone 7 &gt; Binary builds

また、JavaEE5ではアノテーションを利用するのでJDKもVersion.5以上が必要。

サンプル実行確認環境
-JavaSE5 update 7
-ant1.6.5
-GlassFish 9.0 b48 (Windows Binary build)

***１）GlassFishのインストール
次のコマンドでJARを起動してインストールを行う。
（カレントディレクトリにアーカイブが展開される）
 java -Xmx256m -jar glassfish-installer-9.0-b48.jar
 ＊-Xmx256m オプションはJVMの使用メモリサイズの割り当て。

展開された場所を GLASSFISH_HOME とする。

***２）GlassFishのセットアップ
展開したglassfishディレクトリに移動して、ANTを実行する。
 cd glassfish
 ant -f setup.xml

***３）環境変数の設定
EJBのコンパイル等でライブラリを参照する必要があるため、環境変数を設定する。
 GLASSFISH_HOME=&lt;GlassFishのインストールディレクトリ&gt;
 PATH=%GLASSFISH_HOME%\bin;%PATH%

***GlassFishの起動と停止
-サーバの起動/停止
 asadmin start-domain
 asadmin stop-domain

-同梱のDarbyの起動/停止
 asadmin start-database
 asadmin stop-database

***管理コンソール
-管理画面
 http://localhost:4848/ （ID：admin PASS：adminadmin）

-GlassFishトップページ
 http://localhost:8080/&lt;context-root&gt;

***おまけ：バッチファイル
 [env.bat]
 @echo off
 @set JAVA_HOME=C:\jdk1.5.0_07
 @set ANT_HOME=D:\Java\ant1.6.5
 @set GLASSFISH_HOME=D:\Java\glassfish
 @set PATH=%GLASSFISH_HOME%\bin;%PATH%
 
 [runGlassFish.bat]
 @echo off
 @call env.bat
 @call asadmin start-database
 @call asadmin start-domain
 
 [stopGlassFish.bat]
 @echo off
 @call env.bat
 @call asadmin stop-domain
 @call asadmin stop-database


**データソースの設定（H2 Database編）
GlassFishにはDarbyがバンドルされているが、別のDBを利用する場合にはデータソースの設定を行う必要がある。

***１）ドメインにJDBCドライバをインストールする
　%GLASSFISH_HOME%/domains/domain1/lib/ext に h2.jar をコピー。

***２）コネクションプールの作成
　管理コンソールの左メニューから Resources &gt; JDBC &gt; Connection Pools を選択。
　「New...」ボタンを押して、以下を入力し「Next」ボタンを押す。
 Name : H2Pool（任意の名前）
 Resource Type : javax.sql.DataSource
 Database Vendor : 未選択
 ＊Vendorを選択すると次の編集画面で選択したVendorの設定値（初期値？）が読み込まれる。
#ref(New_Pool.jpg)


　Edit Connection Pool画面で、以下の設定へ変更、追加する。
 General Settings
  Datasource Classname : org.h2.jdbcx.JdbcDataSource
 
 Properties
  user : TEST
  password : TEST
  url : jdbc:h2:tcp://localhost:9092/sample_ejb
  ＊GlassFishの仕様かもしれないが、
  DB接続設定でパスワードに空文字を設定できないようなのであらかじめ使用するデータベースにユーザを作成しておく。
#ref(Edit_Conn_Pool.jpg)


　編集が終わったら「save」ボタンを押して保存。
　「Ping」ボタンを押すと接続テストができる。

***３）データソースの作成
　管理コンソールの左メニューから Resources &gt; JDBC &gt; JDBC Resources を選択。
　「New...」ボタンを押して以下を入力。
 JNDI Name : jdbc/h2（任意の名前）
 Pool Name : ２－２で作成したConnection Poolを選択。
#ref(New_JDBC.jpg)


これでデータソースへJNDI経由でアクセスできるようになる。
JPAなどで利用可能に。



&amp;html(&lt;b&gt;参考&lt;/b&gt;)
標準 EJB3.0 プログラミング [著：山田和夫]    </description>
    <dc:date>2006-09-24T23:02:30+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/27.html">
    <title>H2</title>
    <link>http://www4.atwiki.jp/gsh/pages/27.html</link>
    <description>
      &amp;html(&lt;h1 class=pageheader&gt;H2 Database Engine&lt;/h1&gt;)
:H2 Database Engine|HSQLDBの後継とかいわれてるPure Java Database。&amp;br()2006.09.10 Version1.0 Release.&amp;br()http://www.h2database.com/

#contents
----
**H2サーバの起動と停止

***起動
-C/Sモード（TCPサーバ）
 [コマンドライン]
 java -cp h2.jar org.h2.tools.Server [options]
 
 [プログラム]
 import org.h2.tools;
 Server.startTcpServer(new String[]{});

-組み込みモード
 [Embedded (local) connection]
 jdbc:h2:[file:][&lt;path&gt;]&lt;databaseName&gt;
 
 [In-Memory]
 jdbc:h2:mem:&lt;databaseName&gt;
※JDBCドライバのロードをしておくこと。
※データベースファイルはH2を起動したカレントディレクトリに作成される。

***停止
 [コマンドライン]
 java -cp h2.jar org.h2.tools.Server -tcpShutdown tcp://localhost:9092
 
 [プログラム]
 import org.h2.tools;
 Server.shutdownTcpServer(
     &quot;tcp://localhost:9092&quot;, // 停止させるサーバ
     &quot;&quot;,                     // パスワード
     true);                  // 強制シャットダウン

**起動オプション
|CENTER:BGCOLOR(#F0F0F0):オプション|CENTER:BGCOLOR(#F0F0F0):説明|
|-tcp|TCPサーバの起動|
|-tcpShutdown {url}|TCPサーバの停止 {url}に停止するサーバのURLを指定|
|-web|Webサーバの起動|
|-browser|Webコンソール（ブラウザ）の起動|
|-odbc|ODBCサーバの起動|
|-baseDir &lt;directory&gt;|データベースファイルの保存先となるディレクトリ&amp;br()（プログラムから起動する場合のみ指定可？）|
その他のオプションについては「org.h2.tools.Server -?」で表示されるヘルプを参照。

**データタイプ
|CENTER:BGCOLOR(#F0F0F0):&amp;html(&lt;b&gt;H2 Data Types&lt;/b&gt;)|CENTER:BGCOLOR(#F0F0F0):&amp;html(&lt;b&gt;Java Mapping&lt;/b&gt;)|
|INT|int|
|BOOLEAN|boolean|
|TINYINT|int|
|SMALLINT|int|
|BIGINT|long|
|IDENTITY|long|
|DECIMAL|BigDecimal|
|DOUBLE|double|
|REAL|float|
|TIME|java.sql.Time (hh:mm:ss)|
|DATE|java.sql.Date (yyyy-MM-dd)|
|TIMESTAMP|java.sql.Timestamp (yyyy-MM-dd hh:mm:ss[.nnnnnn].)|
|BINARY|Blob|
|OTHER|Object (PreparedStatement#getObject)|
|VARCHAR|String|
|VARCHAR_IGNORECASE|String|
|BLOB|Blob (PreparedStatement#getBinaryStream)|
|CLOB|String (PreparedStatement#getCharacterStream)|
-[[H2 Data types&gt;http://www.h2database.com/html/datatypes.html]]参照

**サーブレットコンテナとの連動
-ContextListenerを作成する。（HSQLDB同様[[Amateras&gt;http://amateras.sourceforge.jp/cgi-bin/fswiki/wiki.cgi/free?page=hsqldb]]さんのサイトを参考）
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
 import org.h2.tools.Server;
 
 public class H2ServletContextListener implements ServletContextListener {
   
   /*
    * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
    */
   public void contextInitialized(ServletContextEvent env) {
     try {
       // H2サーバを起動（別スレッド）
       Server.startTcpServer(
           new String[]{
             &quot;-baseDir&quot;, &quot;C:/H2/DB&quot;,
             &quot;-tcpPort&quot;, &quot;9092&quot;
           });
       
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 
   /*
    * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent)
    */
   public void contextDestroyed(ServletContextEvent env) {
     try {
       // 起動中のH2サーバに停止要求をする
       Server.shutdownTcpServer(
           &quot;tcp://localhost:9092&quot;, &quot;&quot;, true);
       
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
 }
&amp;br()*Tomcat5.5.17ではコンテナ終了時、H2シャットダウンでエラーが発生する？    </description>
    <dc:date>2006-09-24T22:54:17+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/35.html">
    <title>覚え書き</title>
    <link>http://www4.atwiki.jp/gsh/pages/35.html</link>
    <description>
      ***コンソールアプリでMessageBox
[プロジェクト]→[参照の追加]→[.NET]
&amp;html(&lt;b&gt;System.Windows.Forms&lt;/b&gt;)を追加。

***ファイル読み込み
 using System.IO;
 
 StreamReader reader = 
     new StreamReader(&quot;./hogehoge.txt&quot;, Encoding.GetEncoding(932));
 // 第一パラメータにファイル名（パス）を指定するとSystem.IO.FileStreamは不要。
 // 第二パラメータに文字コードを指定。

usingキーワードを利用すると、close処理などをフレームワークに任せる事ができる。
 using (StreamReader reader = 
     new StreamReader(&quot;./hogehoge.txt&quot;, Encoding.GetEncoding(932))) {
     // 個別の処理を記述
 }

***ファイル情報
ファイル操作は System.IO.File クラスを利用する。
同様にディレクトリ操作は System.IO.Directory クラス。
また、ドライブ操作？は System.IO.DriveInfo クラス。
上記クラスのインスタンスメソッドを使う。
○○Info クラスは、それ自身をインスタンス化(new)して利用する。

 // File
 string path = &quot;c:\\temp\\test.txt&quot;;
 if (!System.IO.File.Exists(path)) {
   System.IO.File.Create(path);
 }
 
 // Directory
 string dir = &quot;c:\\hogehoge&quot;;
 if (!System.IO.Directory.Exists(dir)) {
   System.IO.Directory.CreateDirectory(dir);
 }
 
 // DriveInfo (.NET2.0以降)
 DriveInfo[] drives = DriveInfo.GetDrives();
 foreach (DriveInfo d in drives) {
   System.Console.WriteLine(&quot;Drive {0}&quot;, d.Name());
 }    </description>
    <dc:date>2006-09-17T22:20:32+09:00</dc:date>
  </item>
    <item rdf:about="http://www4.atwiki.jp/gsh/pages/30.html">
    <title>JSF</title>
    <link>http://www4.atwiki.jp/gsh/pages/30.html</link>
    <description>
      &amp;html(&lt;h1 class=&quot;pageheader&quot;&gt;JavaServer Faces&lt;/h1&gt;)

-DDファイル
[[web.xml&gt;http://www4.atwiki.jp/gsh/?cmd=upload&amp;act=open&amp;page=JSF&amp;file=web.xml]]
[[faces-config.xml&gt;http://www4.atwiki.jp/gsh/?cmd=upload&amp;act=open&amp;page=JSF&amp;file=faces-config.xml]]


以下、編集中。。。    </description>
    <dc:date>2006-09-01T17:11:19+09:00</dc:date>
  </item>
  </rdf:RDF>

