📄 companydaoimpljdbc.java
字号:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/jdbc/CompanyDAOImplJDBC.java,v 1.29 2006/04/14 17:05:26 minhnn Exp $
* $Author: minhnn $
* $Revision: 1.29 $
* $Date: 2006/04/14 17:05:26 $
*
* ====================================================================
*
* Copyright (C) 2002-2006 by MyVietnam.net
*
* All copyright notices regarding mvnForum MUST remain
* intact in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in
* the footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* 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
* 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
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info at MyVietnam net
*
* @author: Tran Van Giang
*/
package com.mvnforum.db.jdbc;
import java.sql.*;
import java.util.*;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.db.DBUtils;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.util.DateUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class CompanyDAOImplJDBC implements CompanyDAO {
private static Log log = LogFactory.getLog(CompanyDAOImplJDBC.class);
// this variable will support caching if cache for this class is needed
private static boolean m_dirty = true;
public CompanyDAOImplJDBC() {
}
protected static boolean isDirty() {
return m_dirty;
}
protected static void setDirty(boolean dirty) {
m_dirty = dirty;
}
public void findByPrimaryKey(int companyID)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT CompanyID");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE CompanyID = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, companyID);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the primary key (" + companyID + ") in table 'Company'.");
}
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByPrimaryKey.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public void findByAlternateKey_GroupID(int groupID)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT GroupID");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE GroupID = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, groupID);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the alternate key [GroupID] (" + groupID + ") in table 'Company'.");
}
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_GroupID.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public void findByAlternateKey_CompanyName(String companyName)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT CompanyName");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE CompanyName = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setString(1, companyName);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the alternate key [CompanyName] (" + companyName + ") in table 'Company'.");
}
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanyName.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public void findByAlternateKey_CompanyEmail(String companyEmail)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT CompanyEmail");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE CompanyEmail = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setString(1, companyEmail);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the alternate key [CompanyEmail] (" + companyEmail + ") in table 'Company'.");
}
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanyEmail.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public void findByAlternateKey_CompanySpaceName(String companySpaceName)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT CompanySpaceName");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE CompanySpaceName = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setString(1, companySpaceName);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the alternate key [CompanySpaceName] (" + companySpaceName + ") in table 'Company'.");
}
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in CompanyDAOImplJDBC.findByAlternateKey_CompanySpaceName.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: GroupID, CompanyName, CompanyAddress, CompanyCity, CompanyCAP,
* CompanyProvince, CompanyRegion, CompanyPhone, CompanyFax, CompanyWebsite,
* CompanyEmail, CompanySpaceName, CompanySpaceHeader, CompanySpaceFooter, CompanyVATNumber,
* CompanyLogo, CompanyCss, CompanyCreationDate, CompanyModifiedDate
* Excluded columns: CompanyID
*/
public void create(int groupID, String companyName, String companyAddress,
String companyCity, String companyCAP, String companyProvince,
String companyRegion, String companyPhone, String companyFax,
String companyWebsite, String companyEmail, String companySpaceName,
String companySpaceHeader, String companySpaceFooter, String companyVATNumber,
String companyLogo, String companyCss, Timestamp companyCreationDate,
Timestamp companyModifiedDate)
throws CreateException, DatabaseException, DuplicateKeyException, ForeignKeyNotFoundException {
// @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
try {
//Check if alternate key already exists
findByAlternateKey_GroupID(groupID);
//If so, then we have to throw an exception
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [GroupID] (" + groupID + ").");
} catch(ObjectNotFoundException e) {
//Otherwise we can go ahead
}
// @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
try {
//Check if alternate key already exists
findByAlternateKey_CompanyName(companyName);
//If so, then we have to throw an exception
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [CompanyName] (" + companyName + ").");
} catch(ObjectNotFoundException e) {
//Otherwise we can go ahead
}
// @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
try {
//Check if alternate key already exists
findByAlternateKey_CompanyEmail(companyEmail);
//If so, then we have to throw an exception
throw new DuplicateKeyException("Alternate key already exists. Cannot create new Company with the same [CompanyEmail] (" + companyEmail + ").");
} catch(ObjectNotFoundException e) {
//Otherwise we can go ahead
}
// @todo: Comment this try-catch block if the needed columns dont have attribute 'include'
// If this is the case, then it is highly recommended that you regenerate this method with the attribute 'include' turned on
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -