Commit d327185d authored by haocao's avatar haocao
Browse files

Merge remote-tracking branch 'origin/2.0.0.M1' into 2.0.0.M1

parents 6ca664b8 5fe58cab
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
## 2.0.0.M1

### 缺陷修正

1. [ISSUE #387](https://github.com/shardingjdbc/sharding-jdbc/issues/387) 当函数+列名中存在'`'防止关键字时处理出错
1. [ISSUE #394](https://github.com/shardingjdbc/sharding-jdbc/issues/394) 无法单独close statement

## 1.5.4.1

### 缺陷修正
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ public abstract class AbstractStatementAdapter extends AbstractUnsupportedOperat
    @Override
    public final void close() throws SQLException {
        closed = true;
        getRoutedStatements().clear();
        Collection<SQLException> exceptions = new LinkedList<>();
        for (Statement each : getRoutedStatements()) {
            try {
@@ -55,6 +54,7 @@ public abstract class AbstractStatementAdapter extends AbstractUnsupportedOperat
                exceptions.add(ex);
            }
        }
        getRoutedStatements().clear();
        throwSQLExceptionIfNecessary(exceptions);
    }
    
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
package io.shardingjdbc.core.merger.common;

import io.shardingjdbc.core.merger.ResultSetMerger;
import io.shardingjdbc.core.util.SQLUtil;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@@ -61,7 +62,7 @@ public abstract class AbstractMemoryResultSetMerger implements ResultSetMerger {
        if (Blob.class == type || Clob.class == type || Reader.class == type || InputStream.class == type || SQLXML.class == type) {
            throw new SQLFeatureNotSupportedException();
        }
        Object result =  currentResultSetRow.getCell(labelAndIndexMap.get(columnLabel));
        Object result =  currentResultSetRow.getCell(labelAndIndexMap.containsKey(columnLabel) ? labelAndIndexMap.get(columnLabel) : labelAndIndexMap.get(SQLUtil.getExactlyValue(columnLabel)));
        wasNull = null == result;
        return result;
    }
+67 −0
Original line number Diff line number Diff line
package io.shardingjdbc.core.util;

import com.google.common.collect.Sets;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;

import javax.sql.DataSource;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;

/**
 * Data source utility class.
 *
 * @author zhangliang
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class DataSourceUtil {
    
    private static final String SET_METHOD_PREFIX = "set";
    
    private static Collection<Class<?>> generalClassType;
    
    static {
        generalClassType = Sets.<Class<?>>newHashSet(boolean.class, Boolean.class, int.class, Integer.class, long.class, Long.class, String.class);
    }
    
    /**
     * Get data source.
     * 
     * @param dataSourceClassName Data source class name
     * @param dataSourceProperties Data source properties
     * @return data source instance
     * @throws ReflectiveOperationException reflective operation exception
     */
    public static DataSource getDataSource(final String dataSourceClassName, final Map<String, Object> dataSourceProperties) throws ReflectiveOperationException {
        DataSource result = (DataSource) Class.forName(dataSourceClassName).newInstance();
        for (Entry<String, Object> entry : dataSourceProperties.entrySet()) {
            callSetterMethod(result, getSetterMethodName(entry.getKey()), null == entry.getValue() ? null : entry.getValue().toString());
        }
        return result;
    }
    
    private static String getSetterMethodName(final String propertyName) {
        return SET_METHOD_PREFIX + String.valueOf(propertyName.charAt(0)).toUpperCase() + propertyName.substring(1, propertyName.length());
    }
    
    private static void callSetterMethod(final DataSource dataSource, final String methodName, final String setterValue) {
        for (Class<?> each : generalClassType) {
            try {
                Method method = dataSource.getClass().getDeclaredMethod(methodName, each);
                if (boolean.class == each || Boolean.class == each) {
                    method.invoke(dataSource, Boolean.valueOf(setterValue));
                } else if (int.class == each || Integer.class == each) {
                    method.invoke(dataSource, Integer.parseInt(setterValue));
                } else if (long.class == each || Long.class == each) {
                    method.invoke(dataSource, Long.parseLong(setterValue));
                } else {
                    method.invoke(dataSource, setterValue);
                }
                return;
            } catch (final ReflectiveOperationException ex) {
            }
        }
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -25,4 +25,9 @@
            <data expected="select_aggregate/SelectAvg.xml" />
        </sharding-rule>
    </sql>
    <sql id="assertSelectCountForSpecialSymbol">
        <sharding-rule>
            <data expected="select_aggregate/SelectCount.xml" />
        </sharding-rule>
    </sql>
</sqls>
Loading