001package org.apache.fulcrum.security.torque.dynamic; 002/* 003 * Licensed to the Apache Software Foundation (ASF) under one 004 * or more contributor license agreements. See the NOTICE file 005 * distributed with this work for additional information 006 * regarding copyright ownership. The ASF licenses this file 007 * to you under the Apache License, Version 2.0 (the 008 * "License"); you may not use this file except in compliance 009 * with the License. You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, 014 * software distributed under the License is distributed on an 015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 016 * KIND, either express or implied. See the License for the 017 * specific language governing permissions and limitations 018 * under the License. 019 */ 020import java.sql.Connection; 021import java.util.List; 022 023import org.apache.fulcrum.security.entity.User; 024import org.apache.fulcrum.security.torque.TorqueAbstractUserManager; 025import org.apache.fulcrum.security.torque.om.TorqueDynamicUser; 026import org.apache.fulcrum.security.torque.om.TorqueDynamicUserPeer; 027import org.apache.torque.NoRowsException; 028import org.apache.torque.TooManyRowsException; 029import org.apache.torque.TorqueException; 030import org.apache.torque.criteria.Criteria; 031/** 032 * This implementation persists to a database via Torque. 033 * 034 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a> 035 * @version $Id:$ 036 */ 037public class TorqueDynamicUserManagerImpl extends TorqueAbstractUserManager 038{ 039 /** 040 * 041 */ 042 private static final long serialVersionUID = 1L; 043 044 /* (non-Javadoc) 045 * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectAllUsers(java.sql.Connection) 046 */ 047 @SuppressWarnings("unchecked") 048 protected <T extends User> List<T> doSelectAllUsers(Connection con) throws TorqueException 049 { 050 Criteria criteria = new Criteria(TorqueDynamicUserPeer.DATABASE_NAME); 051 052 return (List<T>)TorqueDynamicUserPeer.doSelect(criteria, con); 053 } 054 055 /* (non-Javadoc) 056 * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectById(java.lang.Integer, java.sql.Connection) 057 */ 058 @SuppressWarnings("unchecked") 059 protected <T extends User> T doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException 060 { 061 return (T) TorqueDynamicUserPeer.retrieveByPK(id, con); 062 } 063 064 /* (non-Javadoc) 065 * @see org.apache.fulcrum.security.torque.TorqueAbstractUserManager#doSelectByName(java.lang.String, java.sql.Connection) 066 */ 067 @SuppressWarnings("unchecked") 068 protected <T extends User> T doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException 069 { 070 Criteria criteria = new Criteria(TorqueDynamicUserPeer.DATABASE_NAME); 071 criteria.where(TorqueDynamicUserPeer.LOGIN_NAME, name); 072 criteria.setIgnoreCase(true); 073 criteria.setSingleRecord(true); 074 075 List<TorqueDynamicUser> users = TorqueDynamicUserPeer.doSelect(criteria, con); 076 077 if (users.isEmpty()) 078 { 079 throw new NoRowsException(name); 080 } 081 082 return (T) users.get(0); 083 } 084}