Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(deps): update dependency org.mybatis:mybatis to v3.5.16 #551

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import me.ahoo.cosid.accessor.registry.CosIdAccessorRegistry;

import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
Expand All @@ -35,35 +34,35 @@
*/
@Intercepts({@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})})
public class CosIdPlugin implements Interceptor {

public static final String DEFAULT_LIST_KEY = "list";
private final CosIdAccessorRegistry accessorRegistry;
private final String listKey;

public CosIdPlugin(CosIdAccessorRegistry accessorRegistry) {
this(accessorRegistry, DEFAULT_LIST_KEY);
}

public CosIdPlugin(CosIdAccessorRegistry accessorRegistry, String listKey) {
this.accessorRegistry = accessorRegistry;
this.listKey = listKey;
}

@SuppressWarnings("rawtypes")
@Override
public Object intercept(Invocation invocation) throws Throwable {

Object[] args = invocation.getArgs();
MappedStatement statement = (MappedStatement) args[0];
if (!SqlCommandType.INSERT.equals(statement.getSqlCommandType())) {
return invocation.proceed();
}

Object parameter = args[1];
if (Objects.isNull(parameter)) {
return invocation.proceed();
}

if (!(parameter instanceof Map)) {
accessorRegistry.ensureId(parameter);
return invocation.proceed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,27 @@
import lombok.SneakyThrows;
import org.apache.ibatis.binding.MapperMethod;
import org.apache.ibatis.builder.StaticSqlSource;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.executor.BatchResult;
import org.apache.ibatis.executor.Executor;
import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlCommandType;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.transaction.Transaction;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -149,20 +161,92 @@ public void setId(long id) {
}
}

public static class InvocationTarget {
public static class InvocationTarget implements Executor {

public static final Method INVOKE_METHOD;

static {
try {
INVOKE_METHOD = InvocationTarget.class.getMethod("invoke", MappedStatement.class, Object.class);
INVOKE_METHOD = Executor.class.getMethod("update", MappedStatement.class, Object.class);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

public void invoke(MappedStatement statement, Object entity) {


@Override
public int update(MappedStatement ms, Object parameter) throws SQLException {
return 0;
}

@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql) throws SQLException {
return List.of();
}

@Override
public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
return List.of();
}

@Override
public <E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException {
return null;
}

@Override
public List<BatchResult> flushStatements() throws SQLException {
return List.of();
}

@Override
public void commit(boolean required) throws SQLException {

}

@Override
public void rollback(boolean required) throws SQLException {

}

@Override
public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
return null;
}

@Override
public boolean isCached(MappedStatement ms, CacheKey key) {
return false;
}

@Override
public void clearLocalCache() {

}

@Override
public void deferLoad(MappedStatement ms, MetaObject resultObject, String property, CacheKey key, Class<?> targetType) {

}

@Override
public Transaction getTransaction() {
return null;
}

@Override
public void close(boolean forceRollback) {

}

@Override
public boolean isClosed() {
return false;
}

@Override
public void setExecutorWrapper(Executor executor) {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,83 +30,84 @@ public class ConcurrentGenerateStingSpec implements TestSpec {
private final int concurrentThreads;
private final long idSize;
private final int singleGenerates;

public ConcurrentGenerateStingSpec(IdGenerator... idGenerators) {
this(10, 800000, idGenerators);
}

public ConcurrentGenerateStingSpec(int concurrentThreads, long idSize, IdGenerator... idGenerators) {
Preconditions.checkState(idGenerators.length > 0, "idGenerators can not be empty.");
this.idGenerators = idGenerators;
this.concurrentThreads = concurrentThreads;
this.idSize = idSize;
this.singleGenerates = (int) (idSize / concurrentThreads);
}

public int getConcurrentThreads() {
return concurrentThreads;
}

public long getIdSize() {
return idSize;
}

private IdGenerator getIdGenerator(int threadIdx) {
return idGenerators[threadIdx % (idGenerators.length)];
}

protected void assertSingleEach(String previousId, String id) {
Preconditions.checkState(id.compareTo(previousId) > 0, "id:[%s] must greater then previousId:[%s]", id, previousId);
}

protected void assertGlobalEach(String previousId, String id) {
Preconditions.checkState(id.compareTo(previousId) > 0, "id:[%s] must equals previousId:[%s]+1.", id, previousId);
}

@Override
@SuppressWarnings("unchecked")
public void verify() {

CompletableFuture<String[]>[] completableFutures = new CompletableFuture[concurrentThreads];

for (int i = 0; i < completableFutures.length; i++) {
final IdGenerator idGenerator = getIdGenerator(i);
completableFutures[i] = CompletableFuture
.supplyAsync(() -> {
String[] ids = new String[singleGenerates];
String previousId = "0";
for (int j = 0; j < ids.length; j++) {
String nextId = idGenerator.generateAsString();
ids[j] = nextId;
assertSingleEach(previousId, nextId);
previousId = nextId;
}
return ids;
});
.supplyAsync(() -> {
String[] ids = new String[singleGenerates];
String previousId = "0";
for (int j = 0; j < ids.length; j++) {
String nextId = idGenerator.generateAsString();
ids[j] = nextId;
assertSingleEach(previousId, nextId);
previousId = nextId;
}
return ids;
});
}

CompletableFuture
.allOf(completableFutures)
.thenAccept(nil -> {
final String[] totalIds = new String[(int) idSize];
int totalIdx = 0;
for (CompletableFuture<String[]> completableFuture : completableFutures) {
String[] ids = completableFuture.join();
for (String id : ids) {
totalIds[totalIdx++] = id;
.allOf(completableFutures)
.thenAccept(nil -> {
final String[] totalIds = new String[(int) idSize];
int totalIdx = 0;
for (CompletableFuture<String[]> completableFuture : completableFutures) {
String[] ids = completableFuture.join();
for (String id : ids) {
totalIds[totalIdx++] = id;
}
}
}

Arrays.sort(totalIds);

String previousId = "-1";
for (String id : totalIds) {
if ("-1".equals(previousId)) {

Arrays.sort(totalIds);

String previousId = "-1";
for (String id : totalIds) {
if ("-1".equals(previousId)) {
previousId = id;
continue;
}
assertGlobalEach(previousId, id);
previousId = id;
continue;
}
assertGlobalEach(previousId, id);
previousId = id;
}
}).join();
}).join();
}
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ springCloud = "2023.0.1"
okhttp = "4.12.0"
testcontainers = "1.19.7"
guava = "33.2.0-jre"
mybatis = "3.5.15"
mybatis = "3.5.16"
mybatisSpringBoot = "3.0.3"
junitPioneer = "2.2.0"
axon = "4.9.4"
Expand Down
Loading