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

📄 accountserviceimp.java

📁 简单的Jdon实现
💻 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.framework.samples.jpetstore.service.bo;

import java.util.ArrayList;
import java.util.List;

import com.jdon.controller.events.EventModel;
import com.jdon.controller.model.PageIterator;
import com.jdon.controller.pool.Poolable;
import com.jdon.framework.samples.jpetstore.domain.Account;
import com.jdon.framework.samples.jpetstore.domain.Product;
import com.jdon.framework.samples.jpetstore.persistence.dao.iface.AccountDao;
import com.jdon.framework.samples.jpetstore.service.AccountService;
import com.jdon.framework.samples.jpetstore.service.ProductManager;
import com.jdon.util.Debug;

/**
 * @author <a href="mailto:banqiao@jdon.com">banq</a>
 *
 */
public class AccountServiceImp implements AccountService, Poolable {
    private final static String module = AccountServiceImp.class.getName();

    private AccountDao accountDao;
    private ProductManager productManager;
    
    public AccountServiceImp(AccountDao accountDao,
                             ProductManager productManager){
        this.accountDao = accountDao;
        this.productManager = productManager;
    }
    
    /**
     * init the account
     * 
     */
    public Account initAccount(){
        Account account = new Account();
        account.setCategories(productManager.getCategoryList());
        return account;
    }
    
    private void initAccount(Account account){      
        PageIterator pageIterator = productManager.getProductIDsListByCategory(account.getFavouriteCategoryId(), 0, 4);
        List myList = new ArrayList();
        while(pageIterator.hasNext()){
            String productId = (String)pageIterator.next();
            Product product = productManager.getProduct(productId);
            myList.add(product);   
        }

    }

    /* (non-Javadoc)
     * @see com.jdon.framework.samples.jpetstore.service.AccountService#getAccount(java.lang.String)
     */
    public Account getAccount(String username) {
        Account account = null;

        try{
      
            account = accountDao.getAccount(username);
            if (account != null) initAccount(account);
            //other business logic
        }catch(Exception daoe){
            	Debug.logError(" Dao error : " + daoe, module);
        }
        return account;
    }

    /* (non-Javadoc)
     * @see com.jdon.framework.samples.jpetstore.service.AccountService#getAccount(java.lang.String, java.lang.String)
     */
    public Account getAccount(String username, String password) {
        Account account = null;
        try{
            Debug.logVerbose(" check: username="+ username + " password:" + password);
            account = accountDao.getAccount(username, password);
            if (account != null) initAccount(account);
            //other business logic
        }catch(Exception daoe){
            	Debug.logError(" Dao error : " + daoe, module);
        }
        return account;
    }

    /* (non-Javadoc)
     * @see com.jdon.framework.samples.jpetstore.service.AccountService#insertAccount(com.jdon.framework.samples.jpetstore.domain.Account)
     */
    public void insertAccount(EventModel em) {
        Account account = (Account)em.getModel();
        try{
            accountDao.insertAccount(account);
            //other business logic
        }catch(Exception daoe){
            Debug.logError(" Dao error : " + daoe, module);
            em.setErrors("errors.general");
        }



    }

    /* (non-Javadoc)
     * @see com.jdon.framework.samples.jpetstore.service.AccountService#updateAccount(com.jdon.framework.samples.jpetstore.domain.Account)
     */
    public void updateAccount(EventModel em) {
        Account account = (Account)em.getModel();
        try{
            accountDao.updateAccount(account);
            //other business logic
        }catch(Exception daoe){
            Debug.logError(" Dao error : " + daoe, module);
            em.setErrors("errors.general");            	
        }


    }

    /* (non-Javadoc)
     * @see com.jdon.framework.samples.jpetstore.service.AccountService#getUsernameList()
     */
    public List getUsernameList() {
        List list = new ArrayList();
        try{
            list = accountDao.getUsernameList();
            //other business logic
        }catch(Exception daoe){
            	Debug.logError(" Dao error : " + daoe, module);
        }
        return list;
    }

}

⌨️ 快捷键说明

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