
2005年7月26日
最近在弄swing,需要由JComponent生成BufferedImage,在CSDN上發(fā)現(xiàn)一個好例子。下面是范例:
Rectangle?rect?=?comp.getBounds();
?BufferedImage?bufImage?=?new?BufferedImage(rect.width,
???????????rect.height,
???????????BufferedImage.TYPE_INT_RGB);
?Graphics?g?=?bufImage.getGraphics();
?g.translate(-rect.x,?-rect.y);
?comp.paint(g);這樣,JComponent中的圖像就保存到BufferedImage中了。
原文的鏈接:
http://dev.csdn.net/article/13/13531.shtm
posted @
2006-04-14 23:41 小米 閱讀(1383) |
評論 (1) |
編輯 收藏
??????? 好久沒有寫blog了,距離上次寫幾乎已經(jīng)是半年前的事情了。

?這半年發(fā)生了不少事情。首先換了家公司,進了家金融企業(yè),每天要西裝革履的,一開始還真是不習(xí)慣。

?這里開發(fā)是用的spring框架,以后要多研究研究spring的東西了。
??????? 第二件事就是和戀愛了三年的女友結(jié)婚了,從此兩人長相廝守,不知道時間久了會不會審美疲勞。呵呵。

??????? 第三件事就是在深圳買了自己的小房子,雖然是小小的兩房,不過我們已經(jīng)很知足了。

?而且剛好是趕在房價大漲前買的,還算走了點運氣。換到現(xiàn)在,都不知道去哪里買好了。
??????? 在這里要向一些留言和發(fā)郵件給我的網(wǎng)友道歉,前段時間實在是太忙,沒有空回復(fù)你們的信息和郵件。請原諒!
posted @
2006-03-29 19:43 小米 閱讀(788) |
評論 (0) |
編輯 收藏
最近真是多事情忙,而且可能要忙到9月底。好久沒有上來更新我的博客了,暫且發(fā)發(fā)牢騷。
posted @
2005-08-10 17:32 小米 閱讀(1184) |
評論 (1) |
編輯 收藏
這一節(jié)是非常實用的一節(jié),我在閱讀此書的時候,一直在迷惑,究竟應(yīng)該怎樣管理Session呢?因為Session的管理是如此重要,類似于以前寫程序?qū)DBC Connection的管理??赐甏斯?jié)后,終于找到了方法。
在各種Session管理方案中,ThreadLocal模式得到了大量使用。ThreadLocal是Java中一種較為特殊的線程綁定機制。通過ThreadLocal存取的數(shù)據(jù),總是與當(dāng)前線程相關(guān),也就是說,JVM為每個運行的線程,綁定了私有的本定實例存取空間,從而為多線程環(huán)境經(jīng)常出現(xiàn)的并發(fā)訪問問題提供了一種隔離機制。
下面是Hibernate官方提供的一個ThreadLocal工具:
import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;
import org.apache.log4j.Logger;


/**//**
* <p>Title: </p>
*
* <p>Description: Session的管理類</p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author George Hill
* @version 1.0
*/


public class HibernateUtil
{

private static final Logger log = Logger.getLogger(HibernateUtil.class);

private static final SessionFactory sessionFactory;


/**//**
* 初始化Hibernate配置
*/

static
{

try
{
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();

} catch (Throwable ex)
{
log.error("Initial SessionFactory creation failed.", ex);
throw new ExceptionInInitializerError(ex);
}
}

public static final ThreadLocal session = new ThreadLocal();


/**//**
* 根據(jù)當(dāng)前線程獲取相應(yīng)的Session
* @return Session
* @throws HibernateException
*/

public static Session currentSession() throws HibernateException
{
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet

if (s == null)
{
s = sessionFactory.openSession();
session.set(s);
}
return s;
}


/**//**
* 返回Session給相應(yīng)的線程
* @throws HibernateException
*/

public static void closeSession() throws HibernateException
{
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}

}

針對WEB程序,還可以利用Servlet2.3的Filter機制,輕松實現(xiàn)線程生命周期內(nèi)的Session管理。下面是一個通過Filter進行Session管理的典型案例:

public class PersistenceFilter implements Filter
{
protected static ThreadLocal hibernateHolder = new ThreadLocal();


public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
hibernateHolder.set(getSession());

try
{


chain.doFilter(request, response);



} finally
{
Session session = (Session) hibernateHolder.get();

if (session != null)
{
hibernateHolder.set(null);

try
{
session.close();

} catch (HibernateException ex)
{
throw new ServletException(ex);
}
}
}
}


}
posted @
2005-07-29 19:43 小米 閱讀(3938) |
評論 (1) |
編輯 收藏
數(shù)據(jù)分頁顯示,是很多B/S系統(tǒng)會遇到的問題?,F(xiàn)在大多數(shù)主流數(shù)據(jù)庫都提供了數(shù)據(jù)部分讀取機制,而對于某些沒有提供相應(yīng)機制的數(shù)據(jù)而言,Hibernate也通過其它途徑實現(xiàn)了分頁,如通過Scrollable ResultSet,如果JDBC不支持Scrollable ResultSet,Hibernate也會自動通過ResultSet的next方法進行記錄定位。Hibernate的Criteria、Query等接口提供了一致的方法設(shè)定分頁范圍。下面是書中的例子:
Criteria criteria = session.createCriteria(TUser.class);
Criteria.add(Expression.eq("age", "20"));
//從檢索結(jié)果中獲取第100條記錄開始的20條記錄
criteria.setFirstResult(100);
criteria.setFetchSize(20); 不過,我在測試的時候總是不能夠正常工作,把setFetchSize方法換成setMaxResults方法才行。換成最新的mysql-connector-java-3.1.10-bin-g.jar驅(qū)動也是一樣。
posted @
2005-07-26 18:12 小米 閱讀(5554) |
評論 (4) |
編輯 收藏
小米,生活在深圳,專注于Java,主要從事數(shù)據(jù)庫和網(wǎng)頁編程。現(xiàn)在在學(xué)習(xí)著Hibernate和Spring。喜歡游戲、音樂和臺球。聯(lián)系方式:georgehill@21cn.com
|
|
26 | 27 | 28 | 29 | 30 | 1 | 2 |
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 | 1 | 2 | 3 | 4 | 5 | 6 |
常用鏈接
留言簿(27)
隨筆分類
隨筆檔案
文章分類
文章檔案
我的朋友們
我的鏈接
搜索
積分與排名
最新評論

閱讀排行榜
評論排行榜