Skip to content

Commit e13082e

Browse files
committed
修复sequence bug
1 parent dd6efb2 commit e13082e

File tree

13 files changed

+159
-159
lines changed

13 files changed

+159
-159
lines changed

tddl-matrix/src/main/java/com/taobao/tddl/matrix/jdbc/TConnection.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.taobao.tddl.executor.common.ExecutorContext;
3636
import com.taobao.tddl.executor.cursor.ResultCursor;
3737
import com.taobao.tddl.executor.cursor.impl.ResultSetCursor;
38+
import com.taobao.tddl.executor.spi.ITransaction;
3839
import com.taobao.tddl.group.utils.GroupHintParser;
3940
import com.taobao.tddl.matrix.jdbc.utils.ExceptionUtils;
4041
import com.taobao.tddl.optimizer.OptimizerContext;
@@ -165,7 +166,10 @@ public void commit() throws SQLException {
165166
try {
166167
// 事务结束,清理事务内容
167168
this.executor.commit(this.executionContext);
168-
this.executionContext.getTransaction().close();
169+
ITransaction transtion = this.executionContext.getTransaction();
170+
if (transtion != null) {
171+
transtion.close();
172+
}
169173
this.executionContext = null;
170174
} catch (TddlException e) {
171175
throw new SQLException(e);
@@ -184,7 +188,10 @@ public void rollback() throws SQLException {
184188
try {
185189
this.executor.rollback(executionContext);
186190
// 事务结束,清理事务内容
187-
this.executionContext.getTransaction().close();
191+
ITransaction transtion = this.executionContext.getTransaction();
192+
if (transtion != null) {
193+
transtion.close();
194+
}
188195
this.executionContext = null;
189196
} catch (TddlException e) {
190197
throw new SQLException(e);

tddl-optimizer/src/main/java/com/taobao/tddl/optimizer/config/table/parse/TableMetaParser.java

+44-37
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,44 @@ private static List<ColumnMeta> toColumnMeta(String[] columns, Map<String, Colum
228228
return metas;
229229
}
230230

231+
private static IndexType getIndexType(String type) {
232+
if ("BTREE".equalsIgnoreCase(type)) {
233+
return IndexType.BTREE;
234+
} else if ("HASH".equalsIgnoreCase(type)) {
235+
return IndexType.HASH;
236+
} else if ("INVERSE".equalsIgnoreCase(type)) {
237+
return IndexType.INVERSE;
238+
}
239+
return IndexType.NONE;
240+
}
241+
242+
private static Relationship getRelationship(String rel) {
243+
if ("MANY_TO_MANY".equalsIgnoreCase(rel)) {
244+
return Relationship.MANY_TO_MANY;
245+
} else if ("ONE_TO_ONE".equalsIgnoreCase(rel)) {
246+
return Relationship.ONE_TO_ONE;
247+
} else if ("MANY_TO_ONE".equalsIgnoreCase(rel)) {
248+
return Relationship.MANY_TO_ONE;
249+
} else if ("ONE_TO_MANY".equalsIgnoreCase(rel)) {
250+
return Relationship.ONE_TO_MANY;
251+
}
252+
253+
return Relationship.NONE;
254+
}
255+
256+
public static DataType jdbcTypeToDataType(int jdbcType) {
257+
return getDataType(jdbcTypeToDataTypeString(jdbcType));
258+
}
259+
231260
private static DataType getDataType(String type) {
232261
if ("INT".equalsIgnoreCase(type) || "INTEGER".equalsIgnoreCase(type)) {
233262
return DataType.IntegerType;
234263
} else if ("LONG".equalsIgnoreCase(type)) {
235264
return DataType.LongType;
236265
} else if ("SHORT".equalsIgnoreCase(type)) {
237266
return DataType.ShortType;
267+
} else if ("BIGINTEGER".equalsIgnoreCase(type)) {
268+
return DataType.BigIntegerType;
238269
} else if ("BIGDECIMAL".equalsIgnoreCase(type)) {
239270
return DataType.BigDecimalType;
240271
} else if ("FLOAT".equalsIgnoreCase(type)) {
@@ -259,51 +290,29 @@ private static DataType getDataType(String type) {
259290
return DataType.BlobType;
260291
} else if ("BIT".equalsIgnoreCase(type)) {
261292
return DataType.BitType;
293+
} else {
294+
throw new IllegalArgumentException("不支持的类型:" + type);
262295
}
263-
264-
return null;
265-
}
266-
267-
private static IndexType getIndexType(String type) {
268-
if ("BTREE".equalsIgnoreCase(type)) {
269-
return IndexType.BTREE;
270-
} else if ("HASH".equalsIgnoreCase(type)) {
271-
return IndexType.HASH;
272-
} else if ("INVERSE".equalsIgnoreCase(type)) {
273-
return IndexType.INVERSE;
274-
}
275-
return IndexType.NONE;
276-
}
277-
278-
private static Relationship getRelationship(String rel) {
279-
if ("MANY_TO_MANY".equalsIgnoreCase(rel)) {
280-
return Relationship.MANY_TO_MANY;
281-
} else if ("ONE_TO_ONE".equalsIgnoreCase(rel)) {
282-
return Relationship.ONE_TO_ONE;
283-
} else if ("MANY_TO_ONE".equalsIgnoreCase(rel)) {
284-
return Relationship.MANY_TO_ONE;
285-
} else if ("ONE_TO_MANY".equalsIgnoreCase(rel)) {
286-
return Relationship.ONE_TO_MANY;
287-
}
288-
289-
return Relationship.NONE;
290-
}
291-
292-
public static DataType jdbcTypeToDataType(int jdbcType) {
293-
return getDataType(jdbcTypeToDataTypeString(jdbcType));
294296
}
295297

296298
public static String jdbcTypeToDataTypeString(int jdbcType) {
297299
String type = null;
298300
switch (jdbcType) {
299301
case Types.BIGINT:
302+
// 考虑unsigned
303+
type = "BIGINTEGER";
304+
break;
305+
case Types.NUMERIC:
300306
case Types.DECIMAL:
301-
type = "LONG";
307+
type = "BIGDECIMAL";
302308
break;
303309
case Types.INTEGER:
310+
// 考虑unsigned
311+
type = "LONG";
312+
break;
304313
case Types.TINYINT:
305314
case Types.SMALLINT:
306-
case Types.NUMERIC:
315+
// 考虑unsigned
307316
type = "INT";
308317
break;
309318
case Types.DATE:
@@ -320,6 +329,7 @@ public static String jdbcTypeToDataTypeString(int jdbcType) {
320329
case Types.DOUBLE:
321330
type = "DOUBLE";
322331
break;
332+
case Types.CHAR:
323333
case Types.VARCHAR:
324334
case Types.NCHAR:
325335
case Types.NVARCHAR:
@@ -333,17 +343,14 @@ public static String jdbcTypeToDataTypeString(int jdbcType) {
333343
case Types.LONGVARBINARY:
334344
type = "BYTES";
335345
break;
336-
case Types.CHAR:
337-
type = "STRING";
338-
break;
339346
case Types.BLOB:
340347
type = "BLOB";
341348
break;
342349
case Types.BIT:
343350
type = "BIT";
344351
break;
345352
default:
346-
type = null;
353+
throw new IllegalArgumentException("不支持的类型:" + jdbcType);
347354
}
348355

349356
return type;

tddl-qatest/src/test/java/com/taobao/tddl/qatest/BaseAtomGroupTestCase.java

+54
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22

33
import java.lang.reflect.Field;
44
import java.sql.ResultSet;
5+
import java.text.MessageFormat;
56
import java.util.Date;
7+
import java.util.HashMap;
68
import java.util.Map;
79

810
import org.apache.commons.lang.RandomStringUtils;
11+
import org.apache.commons.lang.StringUtils;
912
import org.junit.AfterClass;
1013
import org.junit.BeforeClass;
1114
import org.junit.Ignore;
1215
import org.springframework.context.support.ClassPathXmlApplicationContext;
1316
import org.springframework.jdbc.core.JdbcTemplate;
1417

18+
import com.taobao.diamond.mockserver.MockServer;
1519
import com.taobao.tddl.atom.TAtomDataSource;
1620
import com.taobao.tddl.atom.common.TAtomConstants;
1721
import com.taobao.tddl.atom.config.TAtomConfParser;
1822
import com.taobao.tddl.atom.config.TAtomDsConfDO;
23+
import com.taobao.tddl.config.ConfigServerHelper;
24+
import com.taobao.tddl.group.jdbc.TGroupDataSource;
1925
import com.taobao.tddl.qatest.util.DateUtil;
2026
import com.taobao.tddl.qatest.util.FixDataSource;
2127
import com.taobao.tddl.qatest.util.LoadPropsUtil;
@@ -133,6 +139,54 @@ protected static void initAtomConfig(String path, String appName, String dbKey)
133139
passwdStr);
134140
}
135141

142+
protected static void setMatrixMockInfo(String groupsPath, String key) throws Exception {
143+
setMatrixMockInfo(groupsPath, key, false);
144+
}
145+
146+
protected static void setMatrixMockInfo(String groupsPath, String key, boolean isOracle) throws Exception {
147+
// -----------------获取groups信息
148+
String groupsStr = LoadPropsUtil.loadProps2OneLine(groupsPath, key);
149+
if (groupsStr == null || StringUtils.isBlank(groupsStr)) {
150+
throw new Exception("指定path = " + groupsPath + ",key = " + key + "的groups信息为null或者为空字符。");
151+
}
152+
153+
// -----------------oracle or mysql
154+
String groupPath = BaseAtomGroupTestCase.GROUP_PATH;
155+
String atomPath = BaseAtomGroupTestCase.ATOM_PATH;
156+
if (isOracle) {
157+
groupPath = BaseAtomGroupTestCase.GROUP_ORA_PATH;
158+
atomPath = BaseAtomGroupTestCase.ATOM_ORA_PATH;
159+
}
160+
161+
// -----------------获取group信息
162+
BaseAtomGroupTestCase.dataMap = new HashMap<String, String>();
163+
String[] groupArr = groupsStr.split(",");
164+
165+
for (String group : groupArr) {
166+
group = group.trim();
167+
String groupStr = "";
168+
groupStr = LoadPropsUtil.loadProps2OneLine(groupPath + group + BaseAtomGroupTestCase.PROPERTIES_FILE, group);
169+
if (groupsStr != null && StringUtils.isNotBlank(groupsStr)) {
170+
// 获取atom信息
171+
String[] atomArr = groupStr.split(",");
172+
for (String atom : atomArr) {
173+
atom = atom.trim();
174+
atom = atom.substring(0, atom.indexOf(":"));
175+
BaseAtomGroupTestCase.initAtomConfig(atomPath + atom, BaseAtomGroupTestCase.APPNAME, atom);
176+
}
177+
// 获取groupkey
178+
BaseAtomGroupTestCase.dataMap.put(TGroupDataSource.getFullDbGroupKey(group), groupStr);
179+
}
180+
}
181+
182+
// -----------------dbgroups
183+
BaseAtomGroupTestCase.dataMap.put(new MessageFormat(ConfigServerHelper.DATA_ID_DB_GROUP_KEYS).format(new Object[] { BaseAtomGroupTestCase.APPNAME }),
184+
groupsStr);
185+
186+
// 建立MockServer
187+
MockServer.setConfigInfos(BaseAtomGroupTestCase.dataMap);
188+
}
189+
136190
protected static void clearData(JdbcTemplate tddlJTX, String sql, Object[] args) {
137191
if (args == null) {
138192
args = new Object[] {};

tddl-qatest/src/test/java/com/taobao/tddl/qatest/BaseMatrixTestCase.java

-51
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
package com.taobao.tddl.qatest;
22

33
import java.sql.SQLException;
4-
import java.text.MessageFormat;
54
import java.util.HashMap;
65
import java.util.Map;
76
import java.util.concurrent.ExecutorService;
87
import java.util.concurrent.Executors;
98

10-
import org.apache.commons.lang.StringUtils;
119
import org.apache.commons.lang.exception.ExceptionUtils;
1210
import org.junit.After;
1311
import org.junit.Assert;
@@ -18,8 +16,6 @@
1816

1917
import com.taobao.diamond.mockserver.MockServer;
2018
import com.taobao.tddl.common.model.ExtraCmd;
21-
import com.taobao.tddl.config.ConfigServerHelper;
22-
import com.taobao.tddl.group.jdbc.TGroupDataSource;
2319
import com.taobao.tddl.matrix.jdbc.TDataSource;
2420
import com.taobao.tddl.qatest.util.LoadPropsUtil;
2521
import com.taobao.tddl.qatest.util.PrepareData;
@@ -121,51 +117,4 @@ public static JdbcTemplate JdbcTemplateClient(String dbType) throws Exception {
121117
return new JdbcTemplate(us);
122118
}
123119

124-
protected static void setMatrixMockInfo(String groupsPath, String key) throws Exception {
125-
setMatrixMockInfo(groupsPath, key, false);
126-
}
127-
128-
protected static void setMatrixMockInfo(String groupsPath, String key, boolean isOracle) throws Exception {
129-
// -----------------获取groups信息
130-
String groupsStr = LoadPropsUtil.loadProps2OneLine(groupsPath, key);
131-
if (groupsStr == null || StringUtils.isBlank(groupsStr)) {
132-
throw new Exception("指定path = " + groupsPath + ",key = " + key + "的groups信息为null或者为空字符。");
133-
}
134-
135-
// -----------------oracle or mysql
136-
String groupPath = BaseAtomGroupTestCase.GROUP_PATH;
137-
String atomPath = BaseAtomGroupTestCase.ATOM_PATH;
138-
if (isOracle) {
139-
groupPath = BaseAtomGroupTestCase.GROUP_ORA_PATH;
140-
atomPath = BaseAtomGroupTestCase.ATOM_ORA_PATH;
141-
}
142-
143-
// -----------------获取group信息
144-
BaseAtomGroupTestCase.dataMap = new HashMap<String, String>();
145-
String[] groupArr = groupsStr.split(",");
146-
147-
for (String group : groupArr) {
148-
group = group.trim();
149-
String groupStr = "";
150-
groupStr = LoadPropsUtil.loadProps2OneLine(groupPath + group + BaseAtomGroupTestCase.PROPERTIES_FILE, group);
151-
if (groupsStr != null && StringUtils.isNotBlank(groupsStr)) {
152-
// 获取atom信息
153-
String[] atomArr = groupStr.split(",");
154-
for (String atom : atomArr) {
155-
atom = atom.trim();
156-
atom = atom.substring(0, atom.indexOf(":"));
157-
BaseAtomGroupTestCase.initAtomConfig(atomPath + atom, BaseAtomGroupTestCase.APPNAME, atom);
158-
}
159-
// 获取groupkey
160-
BaseAtomGroupTestCase.dataMap.put(TGroupDataSource.getFullDbGroupKey(group), groupStr);
161-
}
162-
}
163-
164-
// -----------------dbgroups
165-
BaseAtomGroupTestCase.dataMap.put(new MessageFormat(ConfigServerHelper.DATA_ID_DB_GROUP_KEYS).format(new Object[] { BaseAtomGroupTestCase.APPNAME }),
166-
groupsStr);
167-
168-
// 建立MockServer
169-
MockServer.setConfigInfos(BaseAtomGroupTestCase.dataMap);
170-
}
171120
}

tddl-qatest/src/test/java/com/taobao/tddl/qatest/matrix/transaction/TranscationSingleTableTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Arrays;
77
import java.util.List;
88

9+
import org.apache.commons.lang.exception.ExceptionUtils;
910
import org.junit.After;
1011
import org.junit.Assert;
1112
import org.junit.Before;
@@ -194,7 +195,7 @@ public void insertRollbackTest() throws Exception {
194195
andorCon.rollback();
195196
andorCon.rollback();
196197
} catch (Exception e) {
197-
Assert.fail(e.toString());
198+
Assert.fail(ExceptionUtils.getFullStackTrace(e));
198199
}
199200
}
200201

0 commit comments

Comments
 (0)