Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
0002702: High CPU usage from Table.getFullyQualifiedTableName()
  • Loading branch information
erilong committed Aug 3, 2016
1 parent 2cad25c commit 8e3166d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
36 changes: 27 additions & 9 deletions symmetric-db/src/main/java/org/jumpmind/db/model/Table.java
Expand Up @@ -76,6 +76,10 @@ public class Table implements Serializable, Cloneable, Comparable<Table> {
private ArrayList<IIndex> indices = new ArrayList<IIndex>();

private String primaryKeyConstraintName;

private String fullyQualifiedTableName;

private String fullyQualifiedTableNameLowerCase;

public Table() {
}
Expand Down Expand Up @@ -141,6 +145,7 @@ public String getCatalog() {
public void setCatalog(String catalog) {
this.oldCatalog = this.catalog != null ? this.catalog : catalog;
this.catalog = catalog;
this.fullyQualifiedTableName = this.fullyQualifiedTableNameLowerCase = null;
}

/**
Expand All @@ -161,6 +166,7 @@ public String getSchema() {
public void setSchema(String schema) {
this.oldSchema = this.schema != null ? this.schema : schema;
this.schema = schema;
this.fullyQualifiedTableName = this.fullyQualifiedTableNameLowerCase = null;
}

/**
Expand Down Expand Up @@ -199,6 +205,7 @@ public String getName() {
*/
public void setName(String name) {
this.name = name;
this.fullyQualifiedTableName = this.fullyQualifiedTableNameLowerCase = null;
}

/**
Expand Down Expand Up @@ -967,7 +974,17 @@ public String getTableKey() {
}

public String getFullyQualifiedTableName() {
return getFullyQualifiedTableName(catalog, schema, name, null, ".", ".");
if (fullyQualifiedTableName == null) {
fullyQualifiedTableName = getFullyQualifiedTableName(catalog, schema, name, null, ".", ".");
}
return fullyQualifiedTableName;
}

public String getFullyQualifiedTableNameLowerCase() {
if (fullyQualifiedTableNameLowerCase == null) {
fullyQualifiedTableNameLowerCase = getFullyQualifiedTableName().toLowerCase();
}
return fullyQualifiedTableNameLowerCase;
}

public static String getFullyQualifiedTableName(String catalogName, String schemaName,
Expand Down Expand Up @@ -996,23 +1013,24 @@ public static String getFullyQualifiedTableName(String catalogName, String schem
if (quoteString == null) {
quoteString = "";
}
return getFullyQualifiedTablePrefix(catalogName, schemaName, quoteString, catalogSeparator, schemaSeparator) + quoteString
+ tableName + quoteString;
StringBuilder sb = new StringBuilder(getFullyQualifiedTablePrefix(catalogName, schemaName, quoteString, catalogSeparator, schemaSeparator));
sb.append(quoteString).append(tableName).append(quoteString);
return sb.toString();
}

public static String getFullyQualifiedTablePrefix(String catalogName, String schemaName,
String quoteString, String catalogSeparator, String schemaSeparator) {
StringBuilder sb = new StringBuilder();
if (quoteString == null) {
quoteString = "";
}
String fullyQualified = "";
if (!StringUtils.isBlank(schemaName)) {
fullyQualified = quoteString + schemaName + quoteString + schemaSeparator + fullyQualified;
}
if (!StringUtils.isBlank(catalogName)) {
fullyQualified = quoteString + catalogName + quoteString + catalogSeparator + fullyQualified;
sb.append(quoteString).append(catalogName).append(quoteString).append(catalogSeparator);
}
if (!StringUtils.isBlank(schemaName)) {
sb.append(quoteString).append(schemaName).append(quoteString).append(schemaSeparator);
}
return fullyQualified;
return sb.toString();
}

public String getQualifiedTablePrefix(String quoteString, String catalogSeparator, String schemaSeparator) {
Expand Down
Expand Up @@ -212,7 +212,7 @@ public void addErrorHandler(IDatabaseWriterErrorHandler handler) {

public Conflict pickConflict(Table table, Batch batch) {
Conflict settings = null;
String fullyQualifiedName = table.getFullyQualifiedTableName().toLowerCase();
String fullyQualifiedName = table.getFullyQualifiedTableNameLowerCase();
if (conflictSettingsByTable != null) {
Conflict found = conflictSettingsByTable.get(fullyQualifiedName);

Expand Down
Expand Up @@ -99,7 +99,7 @@ public void start(Batch batch) {

@Override
public boolean start(Table table) {
activeTransforms = transformsBySourceTable.get(table.getFullyQualifiedTableName().toLowerCase());
activeTransforms = transformsBySourceTable.get(table.getFullyQualifiedTableNameLowerCase());
if (activeTransforms != null && activeTransforms.size() > 0) {
this.sourceTable = table;
return true;
Expand Down

0 comments on commit 8e3166d

Please sign in to comment.