1 19 20 package org.efs.openreports.actions.admin; 21 22 import com.opensymphony.xwork.ActionSupport; 23 24 import org.apache.log4j.Logger; 25 26 import org.efs.openreports.objects.ReportDataSource; 27 import org.efs.openreports.providers.DataSourceProvider; 28 import org.efs.openreports.providers.DataSourceProviderAware; 29 30 public class EditDataSourceAction extends ActionSupport implements DataSourceProviderAware 31 { 32 protected static Logger log = 33 Logger.getLogger(EditDataSourceAction.class); 34 35 private String command; 36 private String dataSource; 37 private String submitType; 38 39 private int id; 40 private String name; 41 private String driver; 42 private String url; 43 private String userName; 44 private String password; 45 private int maxIdle; 46 private int maxActive; 47 private long maxWait; 48 private String validationQuery; 49 private boolean jndi; 50 51 private DataSourceProvider dataSourceProvider; 52 53 public String execute() 54 { 55 try 56 { 57 ReportDataSource reportDataSource = null; 58 59 if (command.equals("edit")) 60 { 61 reportDataSource = 62 dataSourceProvider.getDataSource(new Integer (id)); 63 } 64 else 65 { 66 reportDataSource = new ReportDataSource(); 67 } 68 69 if (command.equals("edit") && submitType == null) 70 { 71 id = reportDataSource.getId().intValue(); 72 name = reportDataSource.getName(); 73 driver = reportDataSource.getDriverClassName(); 74 url = reportDataSource.getUrl(); 75 userName = reportDataSource.getUsername(); 76 password = reportDataSource.getPassword(); 77 maxIdle = reportDataSource.getMaxIdle(); 78 maxActive = reportDataSource.getMaxActive(); 79 validationQuery = reportDataSource.getValidationQuery(); 80 jndi = reportDataSource.isJndi(); 81 maxWait = reportDataSource.getMaxWait(); 82 } 83 84 if (submitType == null) 85 return INPUT; 86 87 reportDataSource.setName(name); 88 reportDataSource.setDriverClassName(driver); 89 reportDataSource.setUrl(url); 90 reportDataSource.setUsername(userName); 91 reportDataSource.setPassword(password); 92 reportDataSource.setMaxIdle(maxIdle); 93 reportDataSource.setMaxActive(maxActive); 94 reportDataSource.setJndi(jndi); 95 reportDataSource.setMaxWait(maxWait); 96 97 if (validationQuery == null || validationQuery.length() < 1) 98 { 99 reportDataSource.setValidationQuery(null); 100 } 101 else 102 { 103 reportDataSource.setValidationQuery(validationQuery); 104 } 105 106 if (command.equals("edit")) 107 { 108 dataSourceProvider.updateDataSource(reportDataSource); 109 } 110 111 if (command.equals("add")) 112 { 113 reportDataSource = 114 dataSourceProvider.insertDataSource(reportDataSource); 115 } 116 117 return SUCCESS; 118 } 119 catch (Exception e) 120 { 121 log.error(e.toString()); 122 addActionError(e.getMessage()); 123 return INPUT; 124 } 125 } 126 127 public String getCommand() 128 { 129 return command; 130 } 131 132 public String getDataSource() 133 { 134 return dataSource; 135 } 136 137 public void setCommand(String command) 138 { 139 this.command = command; 140 } 141 142 public void setDataSource(String dataSource) 143 { 144 this.dataSource = dataSource; 145 } 146 147 public String getDriver() 148 { 149 return driver; 150 } 151 152 public int getMaxActive() 153 { 154 return maxActive; 155 } 156 157 public int getMaxIdle() 158 { 159 return maxIdle; 160 } 161 162 public String getPassword() 163 { 164 return password; 165 } 166 167 public String getUrl() 168 { 169 return url; 170 } 171 172 public String getUserName() 173 { 174 return userName; 175 } 176 177 public void setDriver(String driver) 178 { 179 this.driver = driver; 180 } 181 182 public void setMaxActive(int maxActive) 183 { 184 this.maxActive = maxActive; 185 } 186 187 public void setMaxIdle(int maxIdle) 188 { 189 this.maxIdle = maxIdle; 190 } 191 192 public void setPassword(String password) 193 { 194 this.password = password; 195 } 196 197 public void setUrl(String url) 198 { 199 this.url = url; 200 } 201 202 public void setUserName(String userName) 203 { 204 this.userName = userName; 205 } 206 207 public String getSubmitType() 208 { 209 return submitType; 210 } 211 212 public void setSubmitType(String submitType) 213 { 214 this.submitType = submitType; 215 } 216 217 public int getId() 218 { 219 return id; 220 } 221 222 public String getName() 223 { 224 return name; 225 } 226 227 public void setId(int id) 228 { 229 this.id = id; 230 } 231 232 public void setName(String name) 233 { 234 this.name = name; 235 } 236 237 public String getValidationQuery() 238 { 239 return validationQuery; 240 } 241 242 public void setValidationQuery(String validationQuery) 243 { 244 this.validationQuery = validationQuery; 245 } 246 247 public boolean isJndi() 248 { 249 return jndi; 250 } 251 252 public void setJndi(boolean jndi) 253 { 254 this.jndi = jndi; 255 } 256 257 public void setDataSourceProvider(DataSourceProvider dataSourceProvider) 258 { 259 this.dataSourceProvider = dataSourceProvider; 260 } 261 262 public long getMaxWait() 263 { 264 return maxWait; 265 } 266 267 public void setMaxWait(long maxWait) 268 { 269 this.maxWait = maxWait; 270 } 271 272 } | Popular Tags |