本文整理匯總了Java中com.taobao.tddl.common.model.SqlType類的典型用法代碼示例。如果您正苦於以下問題:Java SqlType類的具體用法?Java SqlType怎麽用?Java SqlType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SqlType類屬於com.taobao.tddl.common.model包,在下文中一共展示了SqlType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeQuery
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
@Override
public ResultSet executeQuery(String sql) throws SQLException {
checkClosed();
ensureResultSetIsEmpty();
boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit();
Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead);
if (conn != null) {
sql = GroupHintParser.removeTddlGroupHint(sql);
return executeQueryOnConnection(conn, sql);
} else {
// hint優先
GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql);
sql = GroupHintParser.removeTddlGroupHint(sql);
if (dataSourceIndex == null) {
dataSourceIndex = ThreadLocalDataSourceIndex.getIndex();
}
return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer,
retryingTimes,
sql,
dataSourceIndex);
}
}
示例2: executeQuery
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
@Override
public ResultSet executeQuery() throws SQLException {
checkClosed();
ensureResultSetIsEmpty();
boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit();
Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead);
if (conn != null) {
sql = GroupHintParser.removeTddlGroupHint(sql);
return executeQueryOnConnection(conn, sql);
} else {
// hint優先
GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql);
sql = GroupHintParser.removeTddlGroupHint(sql);
if (dataSourceIndex == null) {
dataSourceIndex = ThreadLocalDataSourceIndex.getIndex();
}
return tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer,
retryingTimes,
sql,
dataSourceIndex);
}
}
示例3: buildRulePlain
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
/**
* 根據規則生成對應的執行計劃
*/
private IDataNodeExecutor buildRulePlain(SqlType sqlType, List<TargetDB> targetDBs, Map<String, String> sqls) {
List<IDataNodeExecutor> subs = new ArrayList<IDataNodeExecutor>();
for (TargetDB target : targetDBs) {
for (String table : target.getTableNames()) {
subs.add(buildOneDirectPlan(sqlType, target.getDbIndex(), sqls.get(table)));
}
}
if (subs.size() > 1) {
IMerge merge = ASTNodeFactory.getInstance().createMerge();
for (IDataNodeExecutor sub : subs) {
merge.addSubNode(sub);
}
merge.executeOn(subs.get(0).getDataNode());// 選擇第一個
return merge;
} else {
return subs.get(0);
}
}
示例4: execute
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
@Override
public boolean execute() throws SQLException {
if (log.isDebugEnabled()) {
log.debug("invoke execute, sql = " + sql);
}
SqlType sqlType = PreParser.getSqlType(sql);
if (sqlType == SqlType.SELECT || sqlType == SqlType.SELECT_FOR_UPDATE
/**
* show 不支持嗎 || sqlType == SqlType.SHOW
**/
) {
executeQuery();
return true;
} else if (sqlType == SqlType.INSERT || sqlType == SqlType.UPDATE || sqlType == SqlType.DELETE
|| sqlType == SqlType.REPLACE || sqlType == SqlType.TRUNCATE || sqlType == SqlType.CREATE
|| sqlType == SqlType.DROP || sqlType == SqlType.LOAD || sqlType == SqlType.MERGE) {
super.updateCount = executeUpdate();
return false;
} else {
throw new SQLException("only select, insert, update, delete,truncate,create,drop,load,merge sql is supported");
}
}
示例5: executeQuery
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
public ResultSet executeQuery(String sql) throws SQLException {
checkClosed();
ensureResultSetIsEmpty();
boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit();
Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead);
if (conn != null) {
sql = GroupHintParser.removeTddlGroupHint(sql);
return executeQueryOnConnection(conn, sql);
} else {
// hint優先
GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql);
sql = GroupHintParser.removeTddlGroupHint(sql);
if (dataSourceIndex == null) {
dataSourceIndex = ThreadLocalDataSourceIndex.getIndex();
}
return this.tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer,
retryingTimes,
sql,
dataSourceIndex);
}
}
示例6: executeQuery
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
public ResultSet executeQuery() throws SQLException {
checkClosed();
ensureResultSetIsEmpty();
boolean gotoRead = SqlType.SELECT.equals(SqlTypeParser.getSqlType(sql)) && tGroupConnection.getAutoCommit();
Connection conn = tGroupConnection.getBaseConnection(sql, gotoRead);
if (conn != null) {
sql = GroupHintParser.removeTddlGroupHint(sql);
return executeQueryOnConnection(conn, sql);
} else {
// hint優先
GroupIndex dataSourceIndex = GroupHintParser.convertHint2Index(sql);
sql = GroupHintParser.removeTddlGroupHint(sql);
if (dataSourceIndex == null) {
dataSourceIndex = ThreadLocalDataSourceIndex.getIndex();
}
return tGroupDataSource.getDBSelector(gotoRead).tryExecute(executeQueryTryer,
retryingTimes,
sql,
dataSourceIndex);
}
}
示例7: isQuerySqlType
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
public static boolean isQuerySqlType(SqlType sqlType) {
if (sqlType == SqlType.SELECT || sqlType == SqlType.SELECT_FOR_UPDATE || sqlType == SqlType.SHOW
|| sqlType == SqlType.DESC || sqlType == SqlType.DUMP || sqlType == SqlType.DEBUG
|| sqlType == SqlType.EXPLAIN || sqlType == SqlType.SELECT_LAST_INSERT_ID
|| sqlType == SqlType.SELECT_WITHOUT_TABLE || sqlType == SqlType.PROCEDURE) {
return true;
} else {
return false;
}
}
示例8: getAstNode
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
@Override
public ASTNode getAstNode() {
if (sqlType == SqlType.SELECT || sqlType == SqlType.SELECT_LAST_INSERT_ID
|| sqlType == SqlType.SELECT_WITHOUT_TABLE) {
return getQueryTreeNode();
} else if (sqlType == SqlType.UPDATE) {
return getUpdateNode();
} else if (sqlType == SqlType.INSERT) {
return getInsertNode();
} else if (sqlType == SqlType.REPLACE) {
return getReplaceNode();
} else if (sqlType == SqlType.DELETE) {
return getDeleteNode();
} else if (sqlType == SqlType.CREATE_SEQUENCE) {
visited();
return ((SequenceVisitor) visitor).getCreateSequenceInsert();
} else if (sqlType == SqlType.SHOW_SEQUENCES) {
visited();
return ((SequenceVisitor) visitor).getShowSequencesSelect();
} else if (sqlType == SqlType.TDDL_SHOW) {
visited();
return ((MySqlShowVisitor) visitor).getNode();
} else if (sqlType == SqlType.LOAD) {
visited();
ASTNode ast = ((MySqlLoadDataVisitor) visitor).getNode();
ast.setSql(sql);
return ast;
} else if (sqlType == SqlType.GET_SEQUENCE) {
return getSequence;
} else if (sqlType == SqlType.RELOAD) {
visited();
return ((ReloadVisitor) visitor).getNode();
}
throw new NotSupportException(sqlType.toString());
}
示例9: buildRulePlain
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
/**
* 根據規則生成對應的執行計劃
*/
private List<IDataNodeExecutor> buildRulePlain(SqlType sqlType, List<TargetDB> targetDBs, Map<String, String> sqls,
int index) {
List<IDataNodeExecutor> subs = new ArrayList<IDataNodeExecutor>();
for (TargetDB target : targetDBs) {
for (String table : target.getTableNames()) {
subs.add(buildOneDirectPlan(sqlType, target.getDbIndex(), sqls.get(table), index));
}
}
return subs;
}
示例10: buildDirectPlan
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
/**
* 根據指定的庫和表生成執行計劃
*/
private List<IDataNodeExecutor> buildDirectPlan(SqlType sqlType, String dbId, Map<String, String> sqls, int index) {
List<IDataNodeExecutor> plans = new ArrayList<IDataNodeExecutor>();
for (String sql : sqls.values()) {
String[] dbIds = StringUtils.split(dbId, ',');
for (String id : dbIds) {
plans.add(buildOneDirectPlan(sqlType, id, sql, index));
}
}
return plans;
}
示例11: buildOneDirectPlan
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
private IDataNodeExecutor buildOneDirectPlan(SqlType sqlType, String dbId, String sql, int index) {
IDataNodeExecutor executor = null;
switch (sqlType) {
case UPDATE:
executor = ASTNodeFactory.getInstance().createUpdate();
break;
case DELETE:
executor = ASTNodeFactory.getInstance().createDelete();
break;
case INSERT:
executor = ASTNodeFactory.getInstance().createInsert();
break;
case REPLACE:
executor = ASTNodeFactory.getInstance().createReplace();
break;
case SELECT:
executor = ASTNodeFactory.getInstance().createQuery();
break;
default:
if (SqlTypeParser.isQuerySqlType(sqlType)) {
executor = ASTNodeFactory.getInstance().createQuery();
} else {
executor = ASTNodeFactory.getInstance().createUpdate();
}
break;
}
if (executor != null) {
executor.setSql(sql);
executor.executeOn(dbId);
}
if (index > -1 && executor instanceof IPut) {
// 添加batch index
((IPut) executor).getBatchIndexs().add(index);
}
return executor;
}
示例12: update
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
private UpdateNode update(String sql) throws SqlParserException {
SqlAnalysisResult sm = parser.parse(sql, false);
UpdateNode qn = null;
if (sm.getSqlType() == SqlType.UPDATE) {
qn = sm.getUpdateNode();
}
return qn;
}
示例13: delete
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
private DeleteNode delete(String sql) throws SqlParserException {
SqlAnalysisResult sm = parser.parse(sql, false);
DeleteNode qn = null;
if (sm.getSqlType() == SqlType.DELETE) {
qn = sm.getDeleteNode();
}
return qn;
}
示例14: insert
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
private InsertNode insert(String sql) throws SqlParserException {
SqlAnalysisResult sm = parser.parse(sql, false);
InsertNode qn = null;
if (sm.getSqlType() == SqlType.INSERT) {
qn = sm.getInsertNode();
}
return qn;
}
示例15: put
import com.taobao.tddl.common.model.SqlType; //導入依賴的package包/類
private PutNode put(String sql) throws SqlParserException {
SqlAnalysisResult sm = parser.parse(sql, false);
PutNode qn = null;
if (sm.getSqlType() == SqlType.REPLACE) {
qn = sm.getReplaceNode();
}
return qn;
}