Java tutorial
/* * WebimModel.java * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 webim.dao.ibatis; import java.util.ArrayList; import java.util.List; import java.util.Map; import org.apache.ibatis.session.SqlSession; import webim.model.WebimVisitor; /** * Webim? * * @author Feng Lee <feng.lee at nextalk.im> * */ //@Repository("webimVisitorDao") public class WebimVisitorDao extends WebimDaoSupport { public WebimVisitor find(String vid) { SqlSession session = sessionFactory.openSession(); try { return (WebimVisitor) session.selectOne("VisitorMapper.findVisitor", vid); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return null; } public WebimVisitor insert(Map<String, String> data) { String vid = data.get("name"); WebimVisitor v = new WebimVisitor(data.get("name"), "v" + vid); v.setIpaddr(data.get("ipaddr")); v.setReferer(data.get("referer")); v.setGroup("visitor"); v.setAvatar("static/images/male.png"); SqlSession session = sessionFactory.openSession(); try { session.insert("VisitorMapper.insertVisitor", v); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return v; } public List<WebimVisitor> findAll(String[] vids) { List<WebimVisitor> visitors = new ArrayList<WebimVisitor>(); SqlSession session = sessionFactory.openSession(); try { visitors = session.selectList("VisitorMapper.findVisitors", vids); } catch (Exception e) { e.printStackTrace(); } finally { session.close(); } return visitors; } }