📄 accountserviceimp.java
字号:
/*
* Copyright 2003-2005 the original author or authors.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.jdon.jivejdon.service.imp;
import com.jdon.container.visitor.data.SessionContext;
import com.jdon.container.visitor.data.SessionContextAcceptable;
import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.PageIterator;
import com.jdon.controller.service.Stateful;
import com.jdon.jivejdon.Constants;
import com.jdon.jivejdon.dao.AccountDao;
import com.jdon.jivejdon.dao.SequenceDao;
import com.jdon.jivejdon.model.Account;
import com.jdon.jivejdon.model.auth.Role;
import com.jdon.jivejdon.service.AccountService;
import com.jdon.jivejdon.service.util.SessionContextUtil;
import com.jdon.util.Debug;
/**
* @author <a href="mailto:banqiao@jdon.com">banq</a>
*
*/
public class AccountServiceImp implements AccountService, Stateful, SessionContextAcceptable {
private final static String module = AccountServiceImp.class.getName();
private AccountDao accountDao;
private SequenceDao sequenceDao;
protected SessionContext sessionContext;
protected SessionContextUtil sessionContextUtil;
private Account account;
public AccountServiceImp(AccountDao accountDao, SequenceDao sequenceDao, SessionContextUtil sessionContextUtil) {
this.accountDao = accountDao;
this.sequenceDao = sequenceDao;
this.sessionContextUtil = sessionContextUtil;
}
public Account getloginAccount(){
if (account == null)
account = sessionContextUtil.getLoginAccount(sessionContext);
return account;
}
/**
* init the account
*/
public Account initAccount(EventModel em) {
return new Account();
}
/* (non-Javadoc)
* @see com.jdon.framework.samples.jpetstore.service.AccountService#insertAccount(com.jdon.framework.samples.jpetstore.domain.Account)
*/
public void createAccount(EventModel em) {
Account account = (Account) em.getModelIF();
Debug.logVerbose("createAccount username=" + account.getUsername(), module);
try {
if (accountDao.getAccountByEmail(account.getEmail()) != null) {
em.setErrors(Constants.EMAIL_EXISTED);
return;
}
if (accountDao.getAccountByName(account.getUsername()) != null) {
em.setErrors(Constants.USERNAME_EXISTED);
return;
}
Long userIDInt = sequenceDao.getNextId(Constants.USER);
Debug.logVerbose("new userIDInt =" + userIDInt, module);
account.setUserId(userIDInt.toString().trim());
//setup the role is User
account.setRoleName(Role.USER);
accountDao.createAccount(account);
} catch (Exception e) {
Debug.logError(" createAccount error : " + e, module);
em.setErrors(Constants.ERRORS);
}
}
/* (non-Javadoc)
* @see com.jdon.framework.samples.jpetstore.service.AccountService#updateAccount(com.jdon.framework.samples.jpetstore.domain.Account)
*/
public void updateAccount(EventModel em) {
Account accountInput = (Account) em.getModelIF();
try {
Account account = getloginAccount();
if (account == null) {
Debug.logError("this user not login", module);
return;
}
if (account.getUsername().equalsIgnoreCase(accountInput.getUsername())) {
accountDao.updateAccount(accountInput);
}
} catch (Exception daoe) {
Debug.logError(" updateAccount error : " + daoe, module);
em.setErrors(Constants.ERRORS);
}
}
public void deleteAccount(EventModel em) {
Account account = (Account) em.getModelIF();
accountDao.deleteAccount(account);
}
/* (non-Javadoc)
* @see com.jdon.jivejdon.service.AccountService#getAccounts(int, int)
*/
public PageIterator getAccounts(int start, int count) {
return accountDao.getAccounts(start, count);
}
/**
* @return Returns the sessionContext.
*/
public SessionContext getSessionContext() {
return sessionContext;
}
/**
* @param sessionContext The sessionContext to set.
*/
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -