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

📄 catalogdaohbm.java~1~

📁 用JBuilder+Jboos+mysql实现的EJB项目
💻 JAVA~1~
字号:
package com.jdon.estore.catalog.dao;

import java.util.*;
import javax.sql.*;
import java.sql.*;

import com.jdon.servicelocator.ejb.ServiceLocator;
import com.jdon.servicelocator.ServiceLocatorException;

import com.jdon.estore.model.*;
import com.jdon.controller.model.PageIterator;
import com.jdon.estore.catalog.JNDINames;

import net.sf.hibernate.Session;
import net.sf.hibernate.Query;
import com.jdon.util.HibernateUtil;

public class CatalogDAOHBM implements CatalogDAO {

  private final static String GET_CATEGORIES = "select * from category";

  protected static DataSource getDataSource() throws Exception {
    try {
      ServiceLocator sl = new ServiceLocator();
      return (DataSource) sl.getDataSource(JNDINames.CATALOG_DATASOURCE);
    } catch (ServiceLocatorException slx) {
      throw new Exception(slx);
    }
  }

  public Category getCategory(String catId) throws Exception {
    Session session = HibernateUtil.openSession();
    Category category = null;
    try {
      category = (Category)session.load(Category.class, catId);
    } catch (Exception he) {
      throw new Exception(he);
    } finally {
      HibernateUtil.closeSession(session);
    }
    return category;
  }

  public PageIterator getCategories(int start, int count) throws Exception {
    Connection c = null;
   PreparedStatement ps = null;
   ResultSet rs = null;
   PageIterator  pageIterator  = null;

   try {
     c = getDataSource().getConnection();
     ps = c.prepareStatement(GET_CATEGORIES_STATEMENT,
                             ResultSet.TYPE_SCROLL_INSENSITIVE,
                             ResultSet.CONCUR_READ_ONLY);
     ps.setString(1, l.toString());
     rs = ps.executeQuery();
     if (start >= 0 && rs.absolute(start+1)) {
       boolean hasNext = false;
       List items = new ArrayList();
       do {
         items.add(new Category(rs.getString(1).trim(),
                                rs.getString(2),
                                rs.getString(3)));
       } while ((hasNext = rs.next()) && (--count > 0));
       ret = new Page(items, start, hasNext);
     } else {
       ret = Page.EMPTY_PAGE;
     }

     rs.close();
     ps.close();
     c.close();
     return ret;
   } catch (SQLException se) {
     se.printStackTrace(System.err);
     throw new CatalogDAOSysException("SQLException: " + se.getMessage());
   }

    Session session = HibernateUtil.openSession();
    try {
      Query query = session.createQuery(GET_CATEGORIES);
      query.setFirstResult(start);
      query.setMaxResults(count);
      List list = query.list();
      return new PageIterator((Category[])list.toArray(new Category[0]));

    } catch (Exception he) {
      throw new Exception(he);
    } finally {
      HibernateUtil.closeSession(session);
    }
  }

  public Product getProduct(String productId) throws Exception {
    /**@todo Implement this com.jdon.estore.catalog.dao.CatalogDAO method*/
    throw new java.lang.UnsupportedOperationException("Method getProduct() not yet implemented.");
  }
  public PageIterator getProducts(String catId, int start, int count) throws Exception {
    /**@todo Implement this com.jdon.estore.catalog.dao.CatalogDAO method*/
    throw new java.lang.UnsupportedOperationException("Method getProducts() not yet implemented.");
  }
  public Item getItem(String itemId) throws Exception {
    /**@todo Implement this com.jdon.estore.catalog.dao.CatalogDAO method*/
    throw new java.lang.UnsupportedOperationException("Method getItem() not yet implemented.");
  }
  public PageIterator getItems(String productId, int start, int size) throws Exception {
    /**@todo Implement this com.jdon.estore.catalog.dao.CatalogDAO method*/
    throw new java.lang.UnsupportedOperationException("Method getItems() not yet implemented.");
  }
  public PageIterator searchItems(String query, int start, int size) throws Exception {
    /**@todo Implement this com.jdon.estore.catalog.dao.CatalogDAO method*/
    throw new java.lang.UnsupportedOperationException("Method searchItems() not yet implemented.");
  }

}

⌨️ 快捷键说明

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