実現機能:
①エンティティ定義
②テーブル名定義
③採番テーブル定義
④列定義
Employee.java
自分で作ったり提供したりするものは、まず自分自身で使ってみろろということです。自分じゃ使わないものなら人はいくらでも無責任にも無思考にもなれる。そういう投げやりな「サービス」やら「プロダクツ」なんて、だれだってイヤだ。自分が作り手と同時に利用者の立場になれば、ちゃんと使えるレベルのものを提供しようとします。
2011年12月31日土曜日
My First Hibernate EntityManager
/META-INF/persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="org.hibernate.tutorial.jpa">
<description>
Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide
</description>
<class>com.test.Cat</class>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
<property name="javax.persistence.jdbc.url"
value="jdbc:postgresql://192.168.3.1:5432/testdb" />
<property name="javax.persistence.jdbc.user" value="postgres" />
<property name="javax.persistence.jdbc.password" value="postgres" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="update" />
</properties>
</persistence-unit>
</persistence>
2011年12月28日水曜日
My First crossContextテスト
context.xml
testWeb1
testWeb2
… <Context sessionCookiePath="/" crossContext="true"> …
testWeb1
…
ServletContext servletContext = getServletContext();
servletContext.setAttribute("bobopapa", "hello crossContext!!!");
…
testWeb2
…
ServletContext servletContext = getServletContext();
servletContext = servletContext.getContext("/testWeb1");
out.println("get " + servletContext.getAttribute("bobopapa"));
…
My First FORM認証(JDBC)
server.xml
…
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
<Engine defaultHost="localhost" name="Catalina">
<Realm className="org.apache.catalina.realm.JDBCRealm"
connectionName="postgres"
connectionPassword="postgres"
connectionURL="jdbc:postgresql://127.0.0.1:5432/testdb"
driverName="org.postgresql.Driver"
roleNameCol="enabled"
userCredCol="password"
userNameCol="name"
userRoleTable="users"
userTable="users"
/>
<Host appBase="webapps" autoDeploy="true" name="localhost"
unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve"
directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log."
resolveHosts="false" suffix=".txt" />
<Context docBase="testFormAuth" path="/testFormAuth"
reloadable="true" source="org.eclipse.jst.j2ee.server:testFormAuth" />
</Host>
</Engine>
</Service>
…
2011年12月26日月曜日
My First Spring Listener
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>testWebApp</display-name>
<listener>
<listener-class>com.test.MyFirstListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/testWebApp.xml</param-value>
</context-param>
</web-app>
My First Servelt Filter
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>testWebApp</display-name> <filter> <filter-name>MyFirstFilter</filter-name> <filter-class>com.test.MyFirstFilter</filter-class> <init-param> <param-name>fp1</param-name> <param-value>first value 1</param-value> </init-param> </filter> <filter-mapping> <filter-name>MyFirstFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> </web-app>
2011年12月25日日曜日
HibernateUtil
package com.test;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateUtil {
private static SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure()
.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
}
}
public static Session OpenSession() {
return sessionFactory.getCurrentSession();
}
public static void CloseSession(Session session) {
if (null != session)
session.close();
}
}
My First Ant
<?xml version="1.0" encoding="UTF-8"?>
<project default="package">
<description>This is my first ant.</description>
<property name="p1" value="v1" />
<property name="p2" value="v2" />
<property name="p3" location="c:/temp" />
<target name="init"></target>
<target name="preprocess" depends="init"></target>
<target name="compile" depends="init,preprocess"></target>
<target name="package" depends="compile"></target>
</project>
2011年12月23日金曜日
Hello Freemarker
test.java
...
public void test() throws Exception {
Configuration cfg = new Configuration();
cfg.setDirectoryForTemplateLoading(new File("" + "./src"));
cfg.setObjectWrapper(new DefaultObjectWrapper());
Map<String, Object> root = new HashMap<String, Object>();
root.put("user", "Koma");
Map<String, String> latest = new HashMap<String, String>();
root.put("latestProduct", latest);
latest.put("url", "1.htm");
latest.put("name", "product name");
Template temp = cfg.getTemplate("test.ftl");
Writer out = new OutputStreamWriter(System.out);
temp.process(root, out);
out.flush();
}
2011年12月22日木曜日
簡単なPortlet設定XML
Apache PlutoでリリースするPortelt設定ファイルをメモします。
web.xml
…
<servlet>
<servlet-name>MyFirstPortlet</servlet-name>
<servlet-class>org.apache.pluto.container.driver.PortletServlet</servlet-class>
<init-param>
<param-name>portlet-name</param-name>
<param-value>MyFirstPortlet</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyFirstPortlet</servlet-name>
<url-pattern>/PlutoInvoker/MyFirstPortlet</url-pattern>
</servlet-mapping>
…
2011年12月20日火曜日
Tomcat7設定例
<tomcat-users> <role rolename="admin-gui"/> <role rolename="manager-gui"/> <role rolename="tomcat"/> <role rolename="pluto"/> <role rolename="manager"/> <user name="tomcat" password="tomcat" roles="tomcat,pluto,manager,admin-gui,manager-gui" /> <user name="pluto" password="pluto" roles="pluto,manager,admin-gui,manager-gui" /> <user username="role2" password="role2" roles="manager-gui"/> <user username="role3" password="role3" roles="admin-gui"/> </tomcat-users>
2011年12月12日月曜日
Liferayノーハウ
①値転送
... extends MVCPortlet
request.setAttribute("cvalue1", "koma");
jspページ
<jsp:useBean id="cvalue1" class="java.lang.String" scope="request"></jsp:useBean>
<%=cvalue1%>
②PortletPreferencesで値処理
... extends GenericPortlet
設定:
PortletPreferences prefs = request.getPreferences();
prefs.setValue("name", request.getParameter("username"));
prefs.store();
読込:
PortletPreferences prefs = request.getPreferences();
String username = prefs.getValue("name", "no");
... extends MVCPortlet
request.setAttribute("cvalue1", "koma");
jspページ
<jsp:useBean id="cvalue1" class="java.lang.String" scope="request"></jsp:useBean>
<%=cvalue1%>
②PortletPreferencesで値処理
... extends GenericPortlet
設定:
PortletPreferences prefs = request.getPreferences();
prefs.setValue("name", request.getParameter("username"));
prefs.store();
読込:
PortletPreferences prefs = request.getPreferences();
String username = prefs.getValue("name", "no");
2011年12月8日木曜日
ギリシャ文字
大文字、小文字、呼び方、物理記号の意味 で書きます。
Α α あるふぁオイラー角、+1/2スピン
Β β べーた オイラー角、-1/2スピン
Γ γ がんま オイラー変数、磁気回転比
Δ δ でるた 微分記号、微小変化、δ関数
Ε ε いぷしろん モル吸光係数
Ζ ζ つぇーた 変数
Η η いーた 変数、粘度
Θ θ しぐま 角度
Ι ι いおた
Κ κ かっぱ 伝導度、素粒子
Λ λ らむだ 波長、素粒子
Μ μ みゅう 素粒子、単位(まいくろ)
Ν ν にゅう 周波数
Ξ ξ ぐざい 変数
Ο ο おみくろん
Π π ぱい 円周率、素粒子
Ρ ρ ろー 密度
Σ σ しぐま 数学の和記号、電気抵抗
Τ τ たう 素粒子、時間変数
Υ υ うぷしろん
Φ φ ふぁい 角度、波動関数
Χ χ かい 磁化率、変数
Ψ ψぷさい 波動関数
Ω ω おめが 角速度、角度、角振動数
全部で24個あり、ほとんどが数学や物理でおめにかかります。
Α α あるふぁオイラー角、+1/2スピン
Β β べーた オイラー角、-1/2スピン
Γ γ がんま オイラー変数、磁気回転比
Δ δ でるた 微分記号、微小変化、δ関数
Ε ε いぷしろん モル吸光係数
Ζ ζ つぇーた 変数
Η η いーた 変数、粘度
Θ θ しぐま 角度
Ι ι いおた
Κ κ かっぱ 伝導度、素粒子
Λ λ らむだ 波長、素粒子
Μ μ みゅう 素粒子、単位(まいくろ)
Ν ν にゅう 周波数
Ξ ξ ぐざい 変数
Ο ο おみくろん
Π π ぱい 円周率、素粒子
Ρ ρ ろー 密度
Σ σ しぐま 数学の和記号、電気抵抗
Τ τ たう 素粒子、時間変数
Υ υ うぷしろん
Φ φ ふぁい 角度、波動関数
Χ χ かい 磁化率、変数
Ψ ψぷさい 波動関数
Ω ω おめが 角速度、角度、角振動数
全部で24個あり、ほとんどが数学や物理でおめにかかります。
2011年12月7日水曜日
[Liferay] Hello world サンプル
view.jsp
<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<jsp:useBean id="userName" class="java.lang.String" scope="request"></jsp:useBean>
<portlet:defineObjects />
日本語テスト
<br/>
Hello <%=userName%>.
<%@page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<jsp:useBean id="userName" class="java.lang.String" scope="request"></jsp:useBean>
<portlet:defineObjects />
日本語テスト
<br/>
Hello <%=userName%>.
2011年12月3日土曜日
Liferayインストール
お勧め:メモリ2G以上
unzip liferay-portal-tomcat-6.0.6-20110225.zip
sudo mv liferay-portal-6.0.6/ /var/www
sudo -u postgres createuser -D -A -P liferay
sudo -u postgres createdb -O liferay lportal
#sudo -u postgres dropdb lportal
/var/www/tomcat-6.0.29/webapps/ROOT/WEB-INF/classes/portal-ext.properties
jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://localhost:5432/lportal
jdbc.default.username=liferay
jdbc.default.password=password
unzip liferay-portal-tomcat-6.0.6-20110225.zip
sudo mv liferay-portal-6.0.6/ /var/www
sudo -u postgres createuser -D -A -P liferay
sudo -u postgres createdb -O liferay lportal
#sudo -u postgres dropdb lportal
/var/www/tomcat-6.0.29/webapps/ROOT/WEB-INF/classes/portal-ext.properties
jdbc.default.driverClassName=org.postgresql.Driver
jdbc.default.url=jdbc:postgresql://localhost:5432/lportal
jdbc.default.username=liferay
jdbc.default.password=password
PostgreSQL Ubuntuでインストール
sudo apt-get install postgresql
sudo -u postgres psql postgres
\password postgres
#sudo -u postgres createdb mydb
sudo apt-get install postgresql-contrib
cd /etc/postgresql/8.4/mainll
pg_hba.conf
host all all 192.168.3.0/24 trust
postgresql.conf
listen_addresses = '192.168.3.240,localhost'
sudo -u postgres createuser -D -A -P myuser
sudo -u postgres createdb -O myuser mydb
sudo /etc/init.d/postgresql-8.4 restart
jdbcドライバー:
http://jdbc.postgresql.org/
sudo -u postgres psql postgres
\password postgres
#sudo -u postgres createdb mydb
sudo apt-get install postgresql-contrib
cd /etc/postgresql/8.4/mainll
pg_hba.conf
host all all 192.168.3.0/24 trust
postgresql.conf
listen_addresses = '192.168.3.240,localhost'
sudo -u postgres createuser -D -A -P myuser
sudo -u postgres createdb -O myuser mydb
sudo /etc/init.d/postgresql-8.4 restart
jdbcドライバー:
http://jdbc.postgresql.org/
2011年12月1日木曜日
メール送信テスト用:swaks
wget http://jetmore.org/john/code/swaks/latest/swaks
使い方:
./swaks --from abc@xxx.com --to xyz@xxx.com --auth --auth-user abc@xxx.com --auth-password 12345678 --server mail.xxx.com --port 587 --h-Subject "testmail subject" --body "testmail body" --attach testfile
使い方:
./swaks --from abc@xxx.com --to xyz@xxx.com --auth --auth-user abc@xxx.com --auth-password 12345678 --server mail.xxx.com --port 587 --h-Subject "testmail subject" --body "testmail body" --attach testfile
登録:
コメント (Atom)