mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -140,13 +140,10 @@ public class DriverIdentifier {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (final DriverMatcher driverMatcher : this.matcherList) {
|
||||
if (driverMatcher.isMatch(jdbcUrl)) {
|
||||
return driverMatcher.getClassName();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return this.matcherList.stream()
|
||||
.filter(driverMatcher -> driverMatcher.test(jdbcUrl))
|
||||
.findFirst()
|
||||
.map(DriverMatcher::getClassName).orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,7 +28,7 @@ public class Db2DriverMatcher implements DriverMatcher {
|
||||
private String jdbcUrl;
|
||||
|
||||
@Override
|
||||
public boolean isMatch(final String jdbcUrl) {
|
||||
public boolean test(final String jdbcUrl) {
|
||||
this.jdbcUrl = jdbcUrl;
|
||||
return jdbcUrl.startsWith("jdbc:db2:");
|
||||
}
|
||||
|
@@ -12,22 +12,16 @@
|
||||
|
||||
package org.dromara.hutool.db.driver.matcher;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* 驱动匹配接口,通过实现此接口,可以:<br>
|
||||
* 通过{@link #isMatch(String)} 判断JDBC URL 是否匹配驱动的要求<br>
|
||||
* 通过{@link #test(Object)} 判断JDBC URL 是否匹配驱动的要求<br>
|
||||
* 通过{@link #getClassName()} 获取对应的驱动类名称
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
public interface DriverMatcher {
|
||||
|
||||
/**
|
||||
* 自定义规则是否匹配 JDBC URL
|
||||
*
|
||||
* @param jdbcUrl JDBC URL
|
||||
* @return 是否匹配
|
||||
*/
|
||||
boolean isMatch(final String jdbcUrl);
|
||||
public interface DriverMatcher extends Predicate<String> {
|
||||
|
||||
/**
|
||||
* 获取对应的驱动类名称
|
||||
|
@@ -34,7 +34,7 @@ public class MysqlDriverMatcher implements DriverMatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(final String jdbcUrl) {
|
||||
public boolean test(final String jdbcUrl) {
|
||||
return jdbcUrl.startsWith("jdbc:mysql:")
|
||||
// 阿里的Mysql分布式集群
|
||||
|| jdbcUrl.startsWith("jdbc:cobar:")
|
||||
|
@@ -35,7 +35,7 @@ public class StartsWithDriverMatcher implements DriverMatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMatch(final String jdbcUrl) {
|
||||
public boolean test(final String jdbcUrl) {
|
||||
for (final String startsWithStr : startsWithStrs) {
|
||||
if (jdbcUrl.startsWith(startsWithStr)) {
|
||||
return true;
|
||||
|
@@ -14,7 +14,7 @@ package org.dromara.hutool.db.ds;
|
||||
|
||||
import org.dromara.hutool.core.exception.CloneException;
|
||||
import org.dromara.hutool.core.io.IoUtil;
|
||||
import org.dromara.hutool.core.func.Wrapper;
|
||||
import org.dromara.hutool.core.lang.wrapper.Wrapper;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.Closeable;
|
||||
|
@@ -12,7 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.db.ds.pooled;
|
||||
|
||||
import org.dromara.hutool.core.func.Wrapper;
|
||||
import org.dromara.hutool.core.lang.wrapper.Wrapper;
|
||||
|
||||
import java.sql.Array;
|
||||
import java.sql.Blob;
|
||||
|
@@ -14,7 +14,7 @@ package org.dromara.hutool.db.sql;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.collection.iter.ArrayIter;
|
||||
import org.dromara.hutool.core.func.SimpleWrapper;
|
||||
import org.dromara.hutool.core.lang.wrapper.SimpleWrapper;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
Reference in New Issue
Block a user