⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jdoresourcemanager.java

📁 STRUTS数据库项目开发宝典
💻 JAVA
字号:
package org.helpsoft.helplog.resource;

import javax.jdo.PersistenceManagerFactory;
import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.sql.*;

/**
 * Relationinfo uses this source file as a template when generating code for JDO. You can modify
 * this template to suit your own needs so long as you preserve the method signatures that exist.
 *
 * @author  Caoguangxin
 */
public class JdoResourceManager
{
	/**
	 * Obtain a PersistenceManager based on the default properties.
	 *
	 * @return
	 */
	public static PersistenceManager getPersistenceManager()
	{
		Properties prop = getDefaultProperties();
		PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( prop );
		PersistenceManager pm = pmf.getPersistenceManager();
		return pm;
	}

	/**
	 * Obtain a PersistenceManager based on the supplied properties.
	 *
	 * @param prop
	 * @return
	 */
	public static PersistenceManager getPersistenceManager(Properties prop)
	{
		PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( prop );
		PersistenceManager pm = pmf.getPersistenceManager();
		return pm;
	}

	/**
	 * Obtain a PersistenceManager based on the supplied properties file.
	 *
	 * @param propertiesFile
	 * @return
	 */
	public static PersistenceManager getPersistenceManager(File propertiesFile)
		throws FileNotFoundException, IOException
	{
		Properties prop = new Properties();
		FileInputStream is = new FileInputStream( propertiesFile );
		prop.load( is );
		PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( prop );
		PersistenceManager pm = pmf.getPersistenceManager();
		return pm;
	}

	/**
	 * Default JDO properties.
	 *
	 * @return
	 */
	public static Properties getDefaultProperties()
	{
		Properties prop = new Properties();
		prop.put( "javax.jdo.PersistenceManagerFactoryClass", "com.sun.jdori.fostore.FOStorePMF" );
		prop.put( "javax.jdo.option.ConnectionURL", "" );
		prop.put( "javax.jdo.option.ConnectionUserName", "" );
		prop.put( "javax.jdo.option.ConnectionPassword", "" );
		prop.put( "javax.jdo.option.Optimistic", "false" );
		return prop;
	}

	public static void close(Connection conn)
	{
		try {
			if (conn != null) conn.close();
		}
		catch (SQLException sqle)
		{
			sqle.printStackTrace();
		}
	}

	public static void close(PreparedStatement stmt)
	{
		try {
			if (stmt != null) stmt.close();
		}
		catch (SQLException sqle)
		{
			sqle.printStackTrace();
		}
	}

	public static void close(ResultSet rs)
	{
		try {
			if (rs != null) rs.close();
		}
		catch (SQLException sqle)
		{
			sqle.printStackTrace();
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -