Skip to content

Commit

Permalink
Merge pull request #102 from yg3630536/fixbug/support-mysql-lower
Browse files Browse the repository at this point in the history
Fixbug/support mysql lower
  • Loading branch information
chenhaozx committed Dec 20, 2019
2 parents d0a0006 + 848b44e commit 15393ce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 22 deletions.
6 changes: 6 additions & 0 deletions build-tools/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ function gradle_build_sdk()
fi

done

if [[ $bcos_version == 1 ]];
then
JAVA_OPTS=''
fi

export BLOCKCHIAN_NODE_INFO=$(echo -e ${content})
export WEID_ADDRESS="0x0"
export CPT_ADDRESS="0x0"
Expand Down
5 changes: 3 additions & 2 deletions check-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function check_user_config() {
else
echo "the client.keystore is exists and the MD5 is `md5sum $client_keystore | cut -d " " -f1`"
fi
JAVA_OPTS=''
elif [[ $bcos_version == 2* ]];
then
if [ ! -f "$node_crt" ];
Expand Down Expand Up @@ -257,7 +258,7 @@ function check_node_version() {
isSdk=0
echo "your project includes the weid-java-sdk, this is: "$file
get_the_version $file
if [ `echo "$sdk_version < $version_default" | bc` -eq 1 ]
if [[ $(echo "${sdk_version} < ${version_default}" | bc) -eq 1 ]]
then
echo "WARN: the current version of SDK does not support to check the node version, minimum version 1.4.0"
else
Expand All @@ -275,7 +276,7 @@ function check_node_version() {
if [[ $file == weid-java-sdk-*.jar ]];
then
get_the_version $file
if [ `echo "$sdk_version < $version_default" | bc` -eq 1 ]
if [[ $(echo "${sdk_version} < ${version_default}" | bc) -eq 1 ]]
then
echo "WARN: the current version of SDK does not support to check the node version, minimum version 1.4.0"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,12 @@ public String getTableName() {
public Date getExpire() {
return new Date(System.currentTimeMillis() + this.timeout);
}

/**
* get the currenttime.
* @return now
*/
public Date getNow() {
return new Date();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public class SqlExecutor {
/**
* sql for save.
*/
public static final String SQL_SAVE = "insert into $1(id, data, expire) values(?,?,?)";
public static final String SQL_SAVE = "insert into $1(id, data, expire, created, updated) "
+ "values(?,?,?,?,?)";

/**
* sql for update.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@ public class MysqlDriver implements Persistence {

private static final String CREATE_TABLE_SQL =
"CREATE TABLE `$1` ("
+ "`id` varchar(128) NOT NULL COMMENT 'primary key',"
+ "`data` blob DEFAULT NULL COMMENT 'the save data', "
+ "`created` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'created', "
+ "`updated` datetime DEFAULT CURRENT_TIMESTAMP COMMENT 'updated', "
+ "`protocol` varchar(32) DEFAULT NULL COMMENT 'protocol', "
+ "`expire` datetime DEFAULT NULL COMMENT 'the expire time', "
+ "`version` varchar(10) DEFAULT NULL COMMENT 'the data version', "
+ "`ext1` int DEFAULT NULL COMMENT 'extend field1', "
+ "`ext2` int DEFAULT NULL COMMENT 'extend field2', "
+ "`ext3` varchar(500) DEFAULT NULL COMMENT 'extend field3', "
+ "`ext4` varchar(500) DEFAULT NULL COMMENT 'extend field4', "
+ "PRIMARY KEY (`id`) "
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='the data table'";
+ "`id` varchar(128) NOT NULL COMMENT 'primary key',"
+ "`data` blob DEFAULT NULL COMMENT 'the save data', "
+ "`created` datetime DEFAULT NULL COMMENT 'created', "
+ "`updated` datetime DEFAULT NULL COMMENT 'updated', "
+ "`protocol` varchar(32) DEFAULT NULL COMMENT 'protocol', "
+ "`expire` datetime DEFAULT NULL COMMENT 'the expire time', "
+ "`version` varchar(10) DEFAULT NULL COMMENT 'the data version', "
+ "`ext1` int DEFAULT NULL COMMENT 'extend field1', "
+ "`ext2` int DEFAULT NULL COMMENT 'extend field2', "
+ "`ext3` varchar(500) DEFAULT NULL COMMENT 'extend field3', "
+ "`ext4` varchar(500) DEFAULT NULL COMMENT 'extend field4', "
+ "PRIMARY KEY (`id`) "
+ ") ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='the data table'";

private static final Integer FAILED_STATUS = DataDriverConstant.SQL_EXECUTE_FAILED_STATUS;

Expand Down Expand Up @@ -168,21 +168,29 @@ public ResponseData<Integer> batchSave(String domain, List<String> ids, List<Str
idHashList.add(DataToolUtils.getHash(id));
}
SqlDomain sqlDomain = new SqlDomain(domain);
Date[] dates = new Date[ids.size()];
Arrays.fill(dates, sqlDomain.getExpire());
List<Object> timeoutList = new ArrayList<>();
timeoutList.addAll(Arrays.asList(dates));

List<List<Object>> dataLists = new ArrayList<List<Object>>();
dataLists.add(idHashList);
dataLists.add(Arrays.asList(dataList.toArray()));
dataLists.add(timeoutList);
dataLists.add(fixedListWithDefault(ids.size(), sqlDomain.getExpire()));

//处理创建时间和更新时间
List<Object> nowList = fixedListWithDefault(ids.size(), sqlDomain.getNow());
dataLists.add(nowList);
dataLists.add(nowList);
return new SqlExecutor(sqlDomain).batchSave(SqlExecutor.SQL_SAVE, dataLists);
} catch (WeIdBaseException e) {
logger.error("[mysql->batchSave] batchSave the data error.", e);
return new ResponseData<Integer>(FAILED_STATUS, e.getErrorCode());
}
}

private List<Object> fixedListWithDefault(int size, Object obj) {
Object[] dates = new Object[size];
Arrays.fill(dates, obj);
List<Object> list = new ArrayList<>();
list.addAll(Arrays.asList(dates));
return list;
}

/* (non-Javadoc)
* @see com.webank.weid.connectivity.driver.DBDriver#delete(java.lang.String)
Expand Down

0 comments on commit 15393ce

Please sign in to comment.