| 1 |
|
package org.apache.torque.engine.platform; |
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
|
| 22 |
|
import java.sql.Connection; |
| 23 |
|
import java.sql.PreparedStatement; |
| 24 |
|
import java.sql.ResultSet; |
| 25 |
|
import java.sql.SQLException; |
| 26 |
|
|
| 27 |
|
import org.apache.commons.lang.StringUtils; |
| 28 |
|
import org.apache.torque.engine.database.model.Domain; |
| 29 |
|
import org.apache.torque.engine.database.model.SchemaType; |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
@version |
| 36 |
|
|
|
|
|
| 0% |
Uncovered Elements: 95 (95) |
Complexity: 21 |
Complexity Density: 0.31 |
|
| 37 |
|
public class PlatformMysqlImpl extends PlatformDefaultImpl { |
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 41 |
0
|
public PlatformMysqlImpl() {... |
| 42 |
0
|
super(); |
| 43 |
0
|
initialize(); |
| 44 |
|
} |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
| 49 |
0
|
private void initialize() {... |
| 50 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.NUMERIC, "DECIMAL")); |
| 51 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.LONGVARCHAR, "MEDIUMTEXT")); |
| 52 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.DATE, "DATETIME")); |
| 53 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.BINARY, "BLOB")); |
| 54 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.VARBINARY, "MEDIUMBLOB")); |
| 55 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.LONGVARBINARY, "LONGBLOB")); |
| 56 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.BLOB, "LONGBLOB")); |
| 57 |
0
|
setSchemaDomainMapping(new Domain(SchemaType.CLOB, "LONGTEXT")); |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
@see |
| 62 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 63 |
0
|
public String getAutoIncrement() {... |
| 64 |
0
|
return "AUTO_INCREMENT"; |
| 65 |
|
} |
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@see |
| 69 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 70 |
0
|
public boolean hasSize(String sqlType) {... |
| 71 |
0
|
return !("MEDIUMTEXT".equals(sqlType) || "LONGTEXT".equals(sqlType) || "BLOB".equals(sqlType) || "MEDIUMBLOB".equals(sqlType) || "LONGBLOB".equals(sqlType)); |
| 72 |
|
} |
| 73 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 74 |
0
|
protected String getBaseUrl(String url) {... |
| 75 |
0
|
if (url == null) { |
| 76 |
0
|
return null; |
| 77 |
|
} |
| 78 |
0
|
url = url.trim(); |
| 79 |
0
|
if (!url.startsWith("jdbc:mysql://")) { |
| 80 |
0
|
return null; |
| 81 |
|
} |
| 82 |
0
|
int count = StringUtils.countMatches(url, "/"); |
| 83 |
0
|
if (count != 3) { |
| 84 |
0
|
return null; |
| 85 |
|
} |
| 86 |
0
|
int pos = url.lastIndexOf("/"); |
| 87 |
0
|
return url.substring(0, pos + 1); |
| 88 |
|
} |
| 89 |
|
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
| 90 |
0
|
protected String getOptions(String url) {... |
| 91 |
0
|
int pos = url.indexOf("?"); |
| 92 |
0
|
if (pos == -1) { |
| 93 |
0
|
return ""; |
| 94 |
|
} |
| 95 |
0
|
return url.substring(pos); |
| 96 |
|
} |
| 97 |
|
|
| 98 |
|
|
| 99 |
|
|
| 100 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 101 |
0
|
@Override... |
| 102 |
|
public String getServerUrl(String url) { |
| 103 |
0
|
String baseUrl = getBaseUrl(url); |
| 104 |
0
|
if (baseUrl == null) { |
| 105 |
0
|
return url; |
| 106 |
|
} |
| 107 |
0
|
String options = getOptions(url); |
| 108 |
0
|
return baseUrl + options; |
| 109 |
|
} |
| 110 |
|
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 111 |
0
|
@Override... |
| 112 |
|
public String getSchemaName(String artifactId) { |
| 113 |
0
|
String s = super.getSchemaName(artifactId); |
| 114 |
0
|
return s.toLowerCase(); |
| 115 |
|
} |
| 116 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 117 |
0
|
@Override... |
| 118 |
|
public String filterInvalidDefaultValues(String defaultValue) { |
| 119 |
0
|
if (defaultValue == null) { |
| 120 |
0
|
return null; |
| 121 |
|
} |
| 122 |
0
|
defaultValue = defaultValue.replace("SYS_GUID()", ""); |
| 123 |
0
|
defaultValue = defaultValue.replace("SYSDATE", ""); |
| 124 |
0
|
defaultValue = defaultValue.replace("USERENV(\'SESSIONID\')", ""); |
| 125 |
0
|
return defaultValue.trim(); |
| 126 |
|
} |
| 127 |
|
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.2 |
|
| 128 |
0
|
@Override... |
| 129 |
|
public Long getSequenceNextVal(Connection con, String schema, String sequenceName) { |
| 130 |
0
|
try { |
| 131 |
0
|
PreparedStatement ps = con.prepareStatement("SELECT auto_increment FROM information_schema.tables WHERE table_schema = ? AND table_name = ?"); |
| 132 |
0
|
Long nextVal = 0L; |
| 133 |
0
|
ps.setString(1, schema); |
| 134 |
0
|
ps.setString(2, sequenceName); |
| 135 |
0
|
ResultSet rs = ps.executeQuery(); |
| 136 |
0
|
if (rs.next()) { |
| 137 |
0
|
nextVal = rs.getLong(1); |
| 138 |
|
} |
| 139 |
0
|
rs.close(); |
| 140 |
0
|
ps.close(); |
| 141 |
0
|
System.out.println("Next Val for " + schema + "." + sequenceName + "=" + nextVal); |
| 142 |
0
|
return nextVal; |
| 143 |
|
} catch (SQLException ex) { |
| 144 |
0
|
System.err.println("Unable to extract sequence definition: " + schema + "." + sequenceName); |
| 145 |
0
|
ex.printStackTrace(); |
| 146 |
0
|
return 0L; |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 16 (16) |
Complexity: 3 |
Complexity Density: 0.21 |
|
| 150 |
0
|
@Override... |
| 151 |
|
public String getViewDefinition(Connection con, String schema, String viewName) { |
| 152 |
0
|
try { |
| 153 |
0
|
PreparedStatement ps = con.prepareStatement("SELECT view_definition FROM information_schema.views WHERE table_schema = ? AND table_name = ?"); |
| 154 |
0
|
String definition = ""; |
| 155 |
0
|
ps.setString(1, schema); |
| 156 |
0
|
ps.setString(2, viewName); |
| 157 |
0
|
ResultSet rs = ps.executeQuery(); |
| 158 |
0
|
if (rs.next()) { |
| 159 |
0
|
definition = rs.getString(1); |
| 160 |
|
} |
| 161 |
0
|
rs.close(); |
| 162 |
0
|
ps.close(); |
| 163 |
0
|
return definition; |
| 164 |
|
} catch (SQLException ex) { |
| 165 |
0
|
System.err.println("Unable to extract view definition: " + schema + "." + viewName); |
| 166 |
0
|
ex.printStackTrace(); |
| 167 |
0
|
return ""; |
| 168 |
|
} |
| 169 |
|
} |
| 170 |
|
|
| 171 |
|
} |