1 40 package com.mvnforum.admin; 41 42 import com.mvnforum.admin.importexport.XMLUtil; 43 import com.mvnforum.db.DAOFactory; 44 import net.myvietnam.mvncore.exception.*; 45 46 53 public class FavoriteThreadXML { 54 55 60 61 private int parentThreadID; 62 64 public int getParentThreadID() { return parentThreadID; } 65 66 private int parentForumID; 67 69 public int getParentForumID() { return parentForumID; } 70 71 public FavoriteThreadXML() { 72 super(); 73 parentThreadID=-1; 75 parentForumID=-1; 76 } 77 78 81 82 public void setParentThread(Object o) 83 throws ForeignKeyNotFoundException { 84 if (o instanceof ThreadXML) { 85 parentThreadID=((ThreadXML)o).getThreadID(); 86 } else { 87 throw new ForeignKeyNotFoundException("Can't find parent thread's ID"); 88 } 89 } 90 91 public void setParentThreadID(int value) { 92 if (value<0) parentThreadID=-1; 93 else parentThreadID=value; 94 } 95 96 public void setParentForum(Object o) 97 throws ForeignKeyNotFoundException { 98 if (o instanceof ThreadXML) { 99 parentForumID=((ThreadXML)o).getParentForumID(); 100 } else { 101 throw new ForeignKeyNotFoundException("Can't find parent forum's ID"); 102 } 103 } 104 105 public void setParentForumID(int value) { 106 if (value<0) parentForumID=-1; 107 else parentForumID=value; 108 } 109 110 128 public void addFavoriteThread(String memberName, 129 String favoriteCreationDate, String favoriteType, 130 String favoriteOption, String favoriteStatus) 131 throws CreateException, DuplicateKeyException, ObjectNotFoundException, 132 DatabaseException, ForeignKeyNotFoundException { 133 if (parentThreadID<0) { 134 throw new CreateException("Can't create a favorite-thread, because no parent thread assigned yet."); 135 } else if (parentForumID<0) { 136 throw new CreateException("Can't create a favorite-thread, because no parent forum assigned yet."); 137 } else if ( (memberName==null) || (memberName.equals("")) ) { 138 throw new CreateException("Can't create a favorite-thread for a member with empty MemberName."); 139 } else { 140 java.sql.Timestamp favoriteCreationDate1; 141 int favoriteType1; 142 int favoriteOption1; 143 int favoriteStatus1; 144 try { 145 favoriteCreationDate1= XMLUtil.stringToSqlTimestampDefNow(favoriteCreationDate); 146 favoriteType1= XMLUtil.stringToIntDef(favoriteType, 0); 147 favoriteOption1= XMLUtil.stringToIntDef(favoriteOption, 0); 148 favoriteStatus1= XMLUtil.stringToIntDef(favoriteStatus, 0); 149 } catch (NumberFormatException e) { 150 throw new CreateException("Invalid data for a favorite-thread. Expected a number."); 151 } 152 153 int memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName); 154 DAOFactory.getFavoriteThreadDAO().create( 155 memberID, parentThreadID, parentForumID, 156 favoriteCreationDate1, favoriteType1, 157 favoriteOption1, favoriteStatus1); 158 159 } 160 } 161 162 } 163 164 | Popular Tags |