| 1 | |
package org.kuali.core.db.torque; |
| 2 | |
|
| 3 | |
import java.sql.Connection; |
| 4 | |
import java.sql.SQLException; |
| 5 | |
import java.util.List; |
| 6 | |
import java.util.Properties; |
| 7 | |
|
| 8 | |
import org.apache.commons.beanutils.BeanUtils; |
| 9 | |
import org.apache.commons.lang.StringUtils; |
| 10 | |
import org.apache.tools.ant.Task; |
| 11 | |
import org.apache.torque.engine.platform.Platform; |
| 12 | |
import org.kuali.db.ConnectionHandler; |
| 13 | |
import org.kuali.db.Credentials; |
| 14 | |
|
| 15 | 0 | public class DumpTask extends Task { |
| 16 | |
|
| 17 | 0 | Utils utils = new Utils(); |
| 18 | |
|
| 19 | 0 | ConnectionHandler connectionHandler = new ConnectionHandler(); |
| 20 | |
|
| 21 | |
boolean antCompatibilityMode; |
| 22 | |
|
| 23 | |
protected void showConfiguration() { |
| 24 | 0 | log("Schema: " + schema); |
| 25 | 0 | log("Artifact Id: " + artifactId); |
| 26 | 0 | log("Database Vendor: " + getTargetDatabase()); |
| 27 | 0 | if (getEncoding() == null) { |
| 28 | 0 | log("Encoding: " + System.getProperty("file.encoding")); |
| 29 | |
} else { |
| 30 | 0 | log("Encoding: " + getEncoding()); |
| 31 | |
} |
| 32 | 0 | } |
| 33 | |
|
| 34 | |
protected void updateConfiguration(Platform platform) { |
| 35 | 0 | if (StringUtils.isEmpty(schema)) { |
| 36 | 0 | schema = platform.getSchemaName(artifactId); |
| 37 | |
} |
| 38 | 0 | if (StringUtils.isEmpty(username)) { |
| 39 | 0 | username = schema; |
| 40 | |
} |
| 41 | 0 | if (StringUtils.isEmpty(password)) { |
| 42 | 0 | password = schema; |
| 43 | |
} |
| 44 | 0 | } |
| 45 | |
|
| 46 | |
protected Connection getConnection() throws SQLException { |
| 47 | |
try { |
| 48 | 0 | BeanUtils.copyProperties(connectionHandler, this); |
| 49 | 0 | } catch (Exception e) { |
| 50 | 0 | throw new SQLException("Error copying properties", e); |
| 51 | 0 | } |
| 52 | 0 | Credentials credentials = new Credentials(username, password); |
| 53 | 0 | connectionHandler.setCredentials(credentials); |
| 54 | 0 | return connectionHandler.getConnection(); |
| 55 | |
} |
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
String artifactId; |
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
String encoding; |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
List<String> includePatterns; |
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | |
|
| 75 | |
List<String> excludePatterns; |
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
String comment; |
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | |
|
| 85 | |
String url; |
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
String driver; |
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
Properties driverProperties; |
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
String username; |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
String password; |
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
String schema; |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
String targetDatabase; |
| 116 | |
|
| 117 | |
public String getEncoding() { |
| 118 | 0 | return encoding; |
| 119 | |
} |
| 120 | |
|
| 121 | |
public void setEncoding(String encoding) { |
| 122 | 0 | this.encoding = encoding; |
| 123 | 0 | } |
| 124 | |
|
| 125 | |
public List<String> getIncludePatterns() { |
| 126 | 0 | return includePatterns; |
| 127 | |
} |
| 128 | |
|
| 129 | |
public void setIncludePatterns(List<String> includePatterns) { |
| 130 | 0 | this.includePatterns = includePatterns; |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
public List<String> getExcludePatterns() { |
| 134 | 0 | return excludePatterns; |
| 135 | |
} |
| 136 | |
|
| 137 | |
public void setExcludePatterns(List<String> excludePatterns) { |
| 138 | 0 | this.excludePatterns = excludePatterns; |
| 139 | 0 | } |
| 140 | |
|
| 141 | |
public String getComment() { |
| 142 | 0 | return comment; |
| 143 | |
} |
| 144 | |
|
| 145 | |
public void setComment(String comment) { |
| 146 | 0 | this.comment = comment; |
| 147 | 0 | } |
| 148 | |
|
| 149 | |
public String getUrl() { |
| 150 | 0 | return url; |
| 151 | |
} |
| 152 | |
|
| 153 | |
public void setUrl(String url) { |
| 154 | 0 | this.url = url; |
| 155 | 0 | } |
| 156 | |
|
| 157 | |
public String getDriver() { |
| 158 | 0 | return driver; |
| 159 | |
} |
| 160 | |
|
| 161 | |
public void setDriver(String driver) { |
| 162 | 0 | this.driver = driver; |
| 163 | 0 | } |
| 164 | |
|
| 165 | |
public String getUsername() { |
| 166 | 0 | return username; |
| 167 | |
} |
| 168 | |
|
| 169 | |
public void setUsername(String username) { |
| 170 | 0 | this.username = username; |
| 171 | 0 | } |
| 172 | |
|
| 173 | |
public String getPassword() { |
| 174 | 0 | return password; |
| 175 | |
} |
| 176 | |
|
| 177 | |
public void setPassword(String password) { |
| 178 | 0 | this.password = password; |
| 179 | 0 | } |
| 180 | |
|
| 181 | |
public String getSchema() { |
| 182 | 0 | return schema; |
| 183 | |
} |
| 184 | |
|
| 185 | |
public void setSchema(String schema) { |
| 186 | 0 | this.schema = schema; |
| 187 | 0 | } |
| 188 | |
|
| 189 | |
public String getTargetDatabase() { |
| 190 | 0 | return targetDatabase; |
| 191 | |
} |
| 192 | |
|
| 193 | |
public void setTargetDatabase(String targetDatabase) { |
| 194 | 0 | this.targetDatabase = targetDatabase; |
| 195 | 0 | } |
| 196 | |
|
| 197 | |
public ConnectionHandler getConnectionHandler() { |
| 198 | 0 | return connectionHandler; |
| 199 | |
} |
| 200 | |
|
| 201 | |
public void setConnectionHandler(ConnectionHandler connectionHandler) { |
| 202 | 0 | this.connectionHandler = connectionHandler; |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
public String getArtifactId() { |
| 206 | 0 | return artifactId; |
| 207 | |
} |
| 208 | |
|
| 209 | |
public void setArtifactId(String artifactId) { |
| 210 | 0 | this.artifactId = artifactId; |
| 211 | 0 | } |
| 212 | |
|
| 213 | |
public boolean isAntCompatibilityMode() { |
| 214 | 0 | return antCompatibilityMode; |
| 215 | |
} |
| 216 | |
|
| 217 | |
public void setAntCompatibilityMode(boolean antCompatibilityMode) { |
| 218 | 0 | this.antCompatibilityMode = antCompatibilityMode; |
| 219 | 0 | } |
| 220 | |
|
| 221 | |
public Properties getDriverProperties() { |
| 222 | 0 | return driverProperties; |
| 223 | |
} |
| 224 | |
|
| 225 | |
public void setDriverProperties(Properties driverProperties) { |
| 226 | 0 | this.driverProperties = driverProperties; |
| 227 | 0 | } |
| 228 | |
|
| 229 | |
} |