1 package org.apache.fulcrum.security.impl.db.entity; 2 3 56 57 import java.util.List ; 58 import org.apache.torque.TorqueException; 59 import org.apache.torque.util.BasePeer; 60 import org.apache.torque.util.Criteria; 61 import org.apache.fulcrum.security.TurbineSecurity; 62 import org.apache.fulcrum.security.entity.User; 63 import org.apache.fulcrum.security.util.DataBackendException; 64 65 75 public class TurbineUserPeer 76 extends org.apache.fulcrum.security.impl.db.entity.BaseTurbineUserPeer 77 implements org.apache.fulcrum.security.impl.db.entity.UserPeer 78 { 79 80 public static final String USERNAME = LOGIN_NAME; 82 public static Class userClass = null; 83 84 92 public static Class getOMClass() 93 throws TorqueException 94 { 95 if ( userClass == null ) 96 { 97 String className = TurbineSecurity.getService() 98 .getConfiguration().getString("user.class", 99 "org.apache.fulcrum.security.impl.db.entity.TurbineUser"); 100 101 try 102 { 103 userClass = Class.forName(className); 104 } 105 catch (Exception e) 106 { 107 throw new TorqueException(e); 108 } 109 } 110 111 return userClass; 112 } 113 114 119 public static String getColumnName(String name) 120 { 121 StringBuffer sb = new StringBuffer (); 122 sb.append(TABLE_NAME); 123 sb.append("."); 124 sb.append(name); 125 return sb.toString(); 126 } 127 128 134 public String getFullColumnName(String name) 135 { 136 return getColumnName(name); 137 } 138 139 144 public static String getTableName() 145 { 146 return TABLE_NAME; 147 } 148 149 159 public static boolean checkExists( User user ) 160 throws DataBackendException, Exception 161 { 162 Criteria criteria = new Criteria(); 163 criteria.addSelectColumn(USER_ID); 164 criteria.add(TurbineUserPeer.USERNAME, user.getUserName()); 165 List results = BasePeer.doSelect(criteria); 166 if (results.size() > 1) 167 { 168 throw new DataBackendException("Multiple users named '" + 169 user.getUserName() + "' exist!"); 170 } 171 return (results.size() == 1); 172 } 173 174 180 public static List selectAllUsers() 181 throws Exception 182 { 183 Criteria criteria = new Criteria(); 184 criteria.addAscendingOrderByColumn(TurbineUserPeer.LAST_NAME); 185 criteria.addAscendingOrderByColumn(TurbineUserPeer.FIRST_NAME); 186 criteria.setIgnoreCase(true); 187 return TurbineUserPeer.doSelect(criteria); 188 } 189 190 196 public static List selectAllConfirmedUsers() 197 throws Exception 198 { 199 Criteria criteria = new Criteria(); 200 criteria.add ( User.CONFIRM_VALUE, User.CONFIRM_DATA ); 201 criteria.addAscendingOrderByColumn(TurbineUserPeer.LAST_NAME); 202 criteria.addAscendingOrderByColumn(TurbineUserPeer.FIRST_NAME); 203 criteria.setIgnoreCase(true); 204 return TurbineUserPeer.doSelect(criteria); 205 } 206 } 207 | Popular Tags |