package io.ebeaninternal.server.deploy;
import io.ebeaninternal.server.el.ElPropertyDeploy;
import java.util.Set;
public final class DeployUpdateParser extends DeployParser {
private final BeanDescriptor<?> beanDescriptor;
public DeployUpdateParser(BeanDescriptor<?> beanDescriptor) {
this.beanDescriptor = beanDescriptor;
}
@Override
public Set<String> getIncludes() {
return null;
}
@Override
public String convertWord() {
String dbWord = getDeployWord(word);
if (dbWord != null) {
return dbWord;
}
return convertSubword(word);
}
private String convertSubword(String currentWord) {
int start = 0;
StringBuilder localBuffer = null;
while (true) {
int dotPos = currentWord.indexOf('.', start);
if (start == 0 && dotPos == -1) {
return currentWord;
}
if (start == 0) {
localBuffer = new StringBuilder();
}
if (dotPos == -1) {
localBuffer.append(currentWord.substring(start));
return localBuffer.toString();
}
localBuffer.append(currentWord, start, dotPos + 1);
if (dotPos == currentWord.length() - 1) {
return localBuffer.toString();
}
start = dotPos + 1;
String remainder = currentWord.substring(start);
String dbWord = getDeployWord(remainder);
if (dbWord != null) {
localBuffer.append(dbWord);
return localBuffer.toString();
}
}
}
@Override
public String getDeployWord(String expression) {
if (expression.equalsIgnoreCase(beanDescriptor.getName())) {
return beanDescriptor.getBaseTable();
}
ElPropertyDeploy elProp = beanDescriptor.getElPropertyDeploy(expression);
return elProp != null ? elProp.getDbColumn() : null;
}
}