1 16 17 package org.apache.jetspeed.om.security.turbine; 18 19 import java.util.List ; 20 import java.util.Hashtable ; 21 import java.util.ArrayList ; 22 import com.workingdogs.village.*; 23 24 import org.apache.torque.util.Criteria; 25 import org.apache.torque.TorqueException; 26 import org.apache.torque.om.NumberKey; 27 import org.apache.turbine.util.ObjectUtils; 28 29 import org.apache.jetspeed.om.security.JetspeedUser; 30 import org.apache.jetspeed.om.security.JetspeedUserFactory; 31 32 33 35 44 public class TurbineUserPeer 45 extends org.apache.jetspeed.om.security.turbine.BaseTurbineUserPeer 46 { 47 48 49 private static Schema schema = initTableSchema(TABLE_NAME); 50 51 52 private static com.workingdogs.village.Column[] columns = 53 initTableColumns(schema); 54 55 56 57 public static String [] columnNames = initColumnNames(columns); 58 59 60 68 public static List doSelectUsers( Criteria criteria ) throws TorqueException 69 { 70 return populateUserObjects( doSelectVillageRecords(criteria) ); 71 } 72 73 74 78 public static List populateUserObjects(List records) 79 throws TorqueException 80 { 81 List results = new ArrayList (records.size()); 82 83 for ( int i=0; i<records.size(); i++ ) 85 { 86 Record row = (Record)records.get(i); 87 results.add(TurbineUserPeer.row2UserObject(row, 1, TurbineUserPeer.getOMClass())); 88 } 89 return results; 90 } 91 92 93 99 public static JetspeedUser row2UserObject (Record row, 100 int offset, 101 Class cls ) 102 throws TorqueException 103 { 104 try 105 { 106 JetspeedUser user = JetspeedUserFactory.getInstance(false); 111 populateUserObject(row, offset, user); 112 return user; 113 } 114 catch (Exception e) 115 { 116 throw new TorqueException(e); 117 } 118 } 119 120 protected static final String TURBINE_OBJECTDATA = "OBJECTDATA"; 121 122 131 protected static void populateUserObject(Record row, int offset, JetspeedUser user) 132 throws Exception 133 { 134 int idPosition = 1; 138 int objectDataPosition = columnNames.length; 139 for( int i=0; i<columnNames.length; i++ ) 140 { 141 if (columnNames[i].equals(USER_ID)) 142 idPosition = i+1; 143 144 if (columnNames[i].equals(TURBINE_OBJECTDATA)) 145 objectDataPosition = i+1; 146 } 147 148 byte[] objectData = (byte[])row.getValue(objectDataPosition).asBytes(); 152 Hashtable tempHash = (Hashtable )ObjectUtils.deserialize(objectData); 153 if (tempHash == null) 154 { 155 tempHash = new Hashtable (10); 156 } 157 158 for( int j=0; j<columnNames.length; j++ ) 159 { 160 if (! columnNames[j].equalsIgnoreCase( TURBINE_OBJECTDATA ) ) 161 { 162 Object obj2 = null; 163 Value value = row.getValue(j+1); 164 if (value.isString()) 165 obj2 = value.asString(); 166 else if (value.isBigDecimal()) 167 obj2 = value.asBigDecimal(); 168 else if (value.isBytes()) 169 obj2 = value.asBytes(); 170 else if (value.isDate()) 171 obj2 = value.asDate(); 172 else if (value.isShort()) 173 obj2 = new Short (value.asShort()); 174 else if (value.isInt()) 175 obj2 = new Integer (value.asInt()); 176 else if (value.isLong()) 177 obj2 = new Long (value.asLong()); 178 else if (value.isDouble()) 179 obj2 = new Double (value.asDouble()); 180 else if (value.isFloat()) 181 obj2 = new Float (value.asFloat()); 182 else if (value.isBoolean()) 183 obj2 = new Boolean (value.asBoolean()); 184 else if (value.isTime()) 185 obj2 = value.asTime(); 186 else if (value.isTimestamp()) 187 obj2 = value.asTimestamp(); 188 else if (value.isUtilDate()) 189 obj2 = value.asUtilDate(); 190 else if (value.isByte()) 191 obj2 = new Byte (value.asByte()); 192 193 if ( obj2 != null ) 194 { 195 if (columnNames[j].equalsIgnoreCase( JetspeedUser.USER_ID )) 196 { 197 obj2 = value.toString(); 198 } 199 200 tempHash.put( columnNames[j], obj2 ); 201 } 202 } 203 } 204 user.setPermStorage( tempHash ); 205 } 206 207 208 217 292 293 296 public static Criteria buildCriteria(JetspeedUser user) 297 { 298 Hashtable permData = (Hashtable ) user.getPermStorage().clone(); 299 Criteria criteria = new Criteria(); 300 if ( !user.isNew() ) 301 { 302 criteria.add(USER_ID, new NumberKey(user.getUserId())); 303 } 304 305 for (int i=1; i < columnNames.length; i++ ) 306 { 307 if ( permData.containsKey(columnNames[i]) ) 308 { 309 String key = new StringBuffer (TABLE_NAME) 310 .append('.').append(columnNames[i]).toString(); 311 312 criteria.add( key, 313 permData.remove(TurbineUserPeer.columnNames[i]) ); 314 } 315 } 316 String dataKey = new StringBuffer (TABLE_NAME).append('.').append(TURBINE_OBJECTDATA).toString(); 317 criteria.add( dataKey, permData ); 318 return criteria; 319 } 320 321 } 322 | Popular Tags |