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.Role; 024import org.apache.fulcrum.security.torque.TorqueAbstractRoleManager; 025import org.apache.fulcrum.security.torque.om.TorqueDynamicRole; 026import org.apache.fulcrum.security.torque.om.TorqueDynamicRolePeer; 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 TorqueDynamicRoleManagerImpl extends TorqueAbstractRoleManager 038{ 039 /** 040 * Serial 041 */ 042 private static final long serialVersionUID = 907083674412091946L; 043 044 /* (non-Javadoc) 045 * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectAllRoles(java.sql.Connection) 046 */ 047 @SuppressWarnings("unchecked") 048 protected <T extends Role> List<T> doSelectAllRoles(Connection con) throws TorqueException 049 { 050 Criteria criteria = new Criteria(TorqueDynamicRolePeer.DATABASE_NAME); 051 052 return (List<T>)TorqueDynamicRolePeer.doSelect(criteria, con); 053 } 054 055 /* (non-Javadoc) 056 * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectById(java.lang.Integer, java.sql.Connection) 057 */ 058 @SuppressWarnings("unchecked") 059 protected <T extends Role> T doSelectById(Integer id, Connection con) throws NoRowsException, TooManyRowsException, TorqueException 060 { 061 return (T) TorqueDynamicRolePeer.retrieveByPK(id, con); 062 } 063 064 /* (non-Javadoc) 065 * @see org.apache.fulcrum.security.torque.TorqueAbstractRoleManager#doSelectByName(java.lang.String, java.sql.Connection) 066 */ 067 @SuppressWarnings("unchecked") 068 protected <T extends Role> T doSelectByName(String name, Connection con) throws NoRowsException, TooManyRowsException, TorqueException 069 { 070 Criteria criteria = new Criteria(TorqueDynamicRolePeer.DATABASE_NAME); 071 criteria.where(TorqueDynamicRolePeer.ROLE_NAME, name); 072 criteria.setIgnoreCase(true); 073 criteria.setSingleRecord(true); 074 075 List<TorqueDynamicRole> roles = TorqueDynamicRolePeer.doSelect(criteria, con); 076 077 if (roles.isEmpty()) 078 { 079 throw new NoRowsException(name); 080 } 081 082 return (T) roles.get(0); 083 } 084}