use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class MultiUpdateExecutor method beforeImage.
@Override
protected TableRecords beforeImage() throws SQLException {
if (sqlRecognizers.size() == 1) {
UpdateExecutor executor = new UpdateExecutor<>(statementProxy, statementCallback, sqlRecognizers.get(0));
return executor.beforeImage();
}
final TableMeta tmeta = getTableMeta(sqlRecognizers.get(0).getTableName());
final ArrayList<List<Object>> paramAppenderList = new ArrayList<>();
Set<String> updateColumnsSet = new HashSet<>();
StringBuilder whereCondition = new StringBuilder();
boolean noWhereCondition = false;
for (SQLRecognizer recognizer : sqlRecognizers) {
sqlRecognizer = recognizer;
SQLUpdateRecognizer sqlUpdateRecognizer = (SQLUpdateRecognizer) recognizer;
ParametersHolder parametersHolder = statementProxy instanceof ParametersHolder ? (ParametersHolder) statementProxy : null;
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getLimit(parametersHolder, paramAppenderList))) {
throw new NotSupportYetException("Multi update SQL with limit condition is not support yet !");
}
if (StringUtils.isNotBlank(sqlUpdateRecognizer.getOrderBy())) {
throw new NotSupportYetException("Multi update SQL with orderBy condition is not support yet !");
}
List<String> updateColumns = sqlUpdateRecognizer.getUpdateColumns();
updateColumnsSet.addAll(updateColumns);
if (noWhereCondition) {
continue;
}
String whereConditionStr = buildWhereCondition(sqlUpdateRecognizer, paramAppenderList);
if (StringUtils.isBlank(whereConditionStr)) {
noWhereCondition = true;
} else {
if (whereCondition.length() > 0) {
whereCondition.append(" OR ");
}
whereCondition.append(whereConditionStr);
}
}
StringBuilder prefix = new StringBuilder("SELECT ");
final StringBuilder suffix = new StringBuilder(" FROM ").append(getFromTableInSQL());
if (noWhereCondition) {
// select all rows
paramAppenderList.clear();
} else {
suffix.append(" WHERE ").append(whereCondition);
}
suffix.append(" FOR UPDATE");
final StringJoiner selectSQLAppender = new StringJoiner(", ", prefix, suffix.toString());
if (ONLY_CARE_UPDATE_COLUMNS) {
if (!containsPK(new ArrayList<>(updateColumnsSet))) {
selectSQLAppender.add(getColumnNamesInSQL(tmeta.getEscapePkNameList(getDbType())));
}
for (String updateCol : updateColumnsSet) {
selectSQLAppender.add(updateCol);
}
} else {
for (String columnName : tmeta.getAllColumns().keySet()) {
selectSQLAppender.add(ColumnUtils.addEscape(columnName, getDbType()));
}
}
return buildTableRecords(tmeta, selectSQLAppender.toString(), paramAppenderList);
}
use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class AbstractDMLBaseExecutor method executeAutoCommitFalse.
/**
* Execute auto commit false t.
*
* @param args the args
* @return the t
* @throws Exception the exception
*/
protected T executeAutoCommitFalse(Object[] args) throws Exception {
if (!JdbcConstants.MYSQL.equalsIgnoreCase(getDbType()) && isMultiPk()) {
throw new NotSupportYetException("multi pk only support mysql!");
}
TableRecords beforeImage = beforeImage();
T result = statementCallback.execute(statementProxy.getTargetStatement(), args);
TableRecords afterImage = afterImage(beforeImage);
prepareUndoLog(beforeImage, afterImage);
return result;
}
use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class BaseInsertExecutor method parsePkValuesFromStatement.
/**
* parse primary key value from statement.
* @return
*/
protected Map<String, List<Object>> parsePkValuesFromStatement() {
// insert values including PK
SQLInsertRecognizer recognizer = (SQLInsertRecognizer) sqlRecognizer;
final Map<String, Integer> pkIndexMap = getPkIndex();
if (pkIndexMap.isEmpty()) {
throw new ShouldNeverHappenException("pkIndex is not found");
}
Map<String, List<Object>> pkValuesMap = new HashMap<>();
boolean ps = true;
if (statementProxy instanceof PreparedStatementProxy) {
PreparedStatementProxy preparedStatementProxy = (PreparedStatementProxy) statementProxy;
List<List<Object>> insertRows = recognizer.getInsertRows(pkIndexMap.values());
if (insertRows != null && !insertRows.isEmpty()) {
Map<Integer, ArrayList<Object>> parameters = preparedStatementProxy.getParameters();
final int rowSize = insertRows.size();
int totalPlaceholderNum = -1;
for (List<Object> row : insertRows) {
// insert parameter count will than the actual +1
if (row.isEmpty()) {
continue;
}
int currentRowPlaceholderNum = -1;
for (Object r : row) {
if (PLACEHOLDER.equals(r)) {
totalPlaceholderNum += 1;
currentRowPlaceholderNum += 1;
}
}
String pkKey;
int pkIndex;
List<Object> pkValues;
for (Map.Entry<String, Integer> entry : pkIndexMap.entrySet()) {
pkKey = entry.getKey();
pkValues = pkValuesMap.get(pkKey);
if (Objects.isNull(pkValues)) {
pkValues = new ArrayList<>(rowSize);
}
pkIndex = entry.getValue();
Object pkValue = row.get(pkIndex);
if (PLACEHOLDER.equals(pkValue)) {
int currentRowNotPlaceholderNumBeforePkIndex = 0;
for (int n = 0, len = row.size(); n < len; n++) {
Object r = row.get(n);
if (n < pkIndex && !PLACEHOLDER.equals(r)) {
currentRowNotPlaceholderNumBeforePkIndex++;
}
}
int idx = totalPlaceholderNum - currentRowPlaceholderNum + pkIndex - currentRowNotPlaceholderNumBeforePkIndex;
ArrayList<Object> parameter = parameters.get(idx + 1);
pkValues.addAll(parameter);
} else {
pkValues.add(pkValue);
}
if (!pkValuesMap.containsKey(ColumnUtils.delEscape(pkKey, getDbType()))) {
pkValuesMap.put(ColumnUtils.delEscape(pkKey, getDbType()), pkValues);
}
}
}
}
} else {
ps = false;
List<List<Object>> insertRows = recognizer.getInsertRows(pkIndexMap.values());
for (List<Object> row : insertRows) {
pkIndexMap.forEach((pkKey, pkIndex) -> {
List<Object> pkValues = pkValuesMap.get(pkKey);
if (Objects.isNull(pkValues)) {
pkValuesMap.put(ColumnUtils.delEscape(pkKey, getDbType()), Lists.newArrayList(row.get(pkIndex)));
} else {
pkValues.add(row.get(pkIndex));
}
});
}
}
if (pkValuesMap.isEmpty()) {
throw new ShouldNeverHappenException();
}
boolean b = this.checkPkValues(pkValuesMap, ps);
if (!b) {
throw new NotSupportYetException(String.format("not support sql [%s]", sqlRecognizer.getOriginalSQL()));
}
return pkValuesMap;
}
use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class RegistryFactory method getInstance.
public static Registry getInstance() {
RegistryType registryType;
String registryTypeName = ConfigurationFactory.getInstance().getConfig(ConfigurationKeys.METRICS_PREFIX + ConfigurationKeys.METRICS_REGISTRY_TYPE, null);
if (!StringUtils.isNullOrEmpty(registryTypeName)) {
try {
registryType = RegistryType.getType(registryTypeName);
} catch (Exception exx) {
throw new NotSupportYetException("not support metrics registry type: " + registryTypeName);
}
return EnhancedServiceLoader.load(Registry.class, Objects.requireNonNull(registryType).getName());
}
return null;
}
use of io.seata.common.exception.NotSupportYetException in project seata by seata.
the class BeanUtils method mapToObject.
/**
* map to object
*
* @param map the map
* @param clazz the Object class
* @return the object
*/
public static Object mapToObject(Map<String, String> map, Class<?> clazz) {
if (CollectionUtils.isEmpty(map)) {
return null;
}
try {
Object instance = clazz.newInstance();
Field[] fields = instance.getClass().getDeclaredFields();
for (Field field : fields) {
int modifiers = field.getModifiers();
if (Modifier.isStatic(modifiers) || Modifier.isFinal(modifiers)) {
continue;
}
boolean accessible = field.isAccessible();
field.setAccessible(true);
Class<?> type = field.getType();
if (type == Date.class) {
if (!StringUtils.isEmpty(map.get(field.getName()))) {
field.set(instance, new Date(Long.valueOf(map.get(field.getName()))));
}
} else if (type == Long.class) {
if (!StringUtils.isEmpty(map.get(field.getName()))) {
field.set(instance, Long.valueOf(map.get(field.getName())));
}
} else if (type == Integer.class) {
if (!StringUtils.isEmpty(map.get(field.getName()))) {
field.set(instance, Integer.valueOf(map.get(field.getName())));
}
} else if (type == Double.class) {
if (!StringUtils.isEmpty(map.get(field.getName()))) {
field.set(instance, Double.valueOf(map.get(field.getName())));
}
} else if (type == String.class) {
if (!StringUtils.isEmpty(map.get(field.getName()))) {
field.set(instance, map.get(field.getName()));
}
}
field.setAccessible(accessible);
}
return instance;
} catch (IllegalAccessException e) {
throw new NotSupportYetException("map to " + clazz.toString() + " failed:" + e.getMessage(), e);
} catch (InstantiationException e) {
throw new NotSupportYetException("map to " + clazz.toString() + " failed:" + e.getMessage(), e);
}
}
Aggregations