📄 daofactory.java
字号:
/* CRMS, customer relationship management system Copyright (C) 2003 Service To Youth Council This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For further information contact the SYC ICT department on GPL@syc.net.au 98 Kermode Street North Adelaide South Australia SA 5006 +61 (0)8 8367 0755 *//* * DAOFactory.java * * Created on 24 March 2003, 04:48 */package crms.dao;import java.sql.*;import org.postgresql.jdbc3.*;import org.apache.log4j.Logger;/** * * @author dmurphy */public class DAOFactory { static Logger logger = Logger.getLogger(DAOFactory.class); private static DAOFactory _instance = null; private Connection con = null; private boolean registered = false; private Jdbc3PoolingDataSource source = null; /** Creates a new instance of DAOFactory */ private DAOFactory() { } public void registerDatabase( String server, String db, String user, String pass, String initialConnections, String maxConnections ) { logger.debug("Initialising Connection Pool..."); source = new Jdbc3PoolingDataSource(); source.setDataSourceName("CRMS-Postgres"); source.setServerName(server); source.setDatabaseName(db); source.setUser(user); source.setPassword(pass); try { source.setInitialConnections(Integer.parseInt(initialConnections)); source.setMaxConnections(Integer.parseInt(maxConnections)); } catch (NumberFormatException ex) { throw new RuntimeException(ex); } registered = true; logger.debug("Initialised."); } public boolean isRegistered() { return registered; } public static DAOFactory getInstance() { if (_instance == null) { _instance = new DAOFactory(); } return _instance; } /** * getConnection - Obtains a database connection. * <p>This uses the JDBC3 postgres support for connection pooling * via the Jdbc3PoolingDataSource.</p> * * return Connection Database connection object. */ public Connection getConnection() throws SQLException { Connection con = null; try { con = source.getConnection(); con.setAutoCommit(true); } catch (SQLException ex) { ex.printStackTrace(); throw new RuntimeException(ex); } return con; } public void cleanup() { // Perform connection pool cleanup. source.close(); } public CallDAO getCallDAO() { CallDAO dao = new CallDAO(); dao.setFactory(this); return dao; } public CompanyDAO getCompanyDAO() { CompanyDAO dao = new CompanyDAO(); dao.setFactory(this); return dao; } public ContactDAO getContactDAO() { ContactDAO dao = new ContactDAO(); dao.setFactory(this); return dao; } public ReminderDAO getReminderDAO() { ReminderDAO dao = new ReminderDAO(); dao.setFactory(this); return dao; } public NotesDAO getNotesDAO() { NotesDAO dao = new NotesDAO(); dao.setFactory(this); return dao; } public LastContactDAO getLastContactDAO() { LastContactDAO dao = new LastContactDAO(); dao.setFactory(this); return dao; } public FileAttachmentDAO getFileAttachmentDAO() { FileAttachmentDAO dao = new FileAttachmentDAO(); dao.setFactory(this); return dao; } public PermissionDAO getPermissionDAO() { PermissionDAO dao = new PermissionDAO(); dao.setFactory(this); return dao; } public ReportDAO getReportDAO() { ReportDAO dao = new ReportDAO(); dao.setFactory(this); return dao; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -