本文整理匯總了Java中com.taobao.tddl.common.jdbc.ParameterMethod類的典型用法代碼示例。如果您正苦於以下問題:Java ParameterMethod類的具體用法?Java ParameterMethod怎麽用?Java ParameterMethod使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ParameterMethod類屬於com.taobao.tddl.common.jdbc包,在下文中一共展示了ParameterMethod類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testPreparedInsertSql
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testPreparedInsertSql() throws SqlParserException, QueryException {
String sql = "INSERT INTO TABLE1(ID,NAME,SCHOOL) VALUES (?, ?, ?)";
InsertNode in = insert(sql);
Map<Integer, ParameterContext> parameterSettings = null;
parameterSettings = new TreeMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 0, 2 });
ParameterContext p2 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, "sun" });
ParameterContext p3 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, "sysu" });
parameterSettings.put(1, p1);
parameterSettings.put(2, p2);
parameterSettings.put(3, p3);
in.assignment(parameterSettings);
in.build();
TableNode table1 = new TableNode("TABLE1");
InsertNode inExpected = table1.insert("ID NAME SCHOOL", new Comparable[] { 2, "sun", "sysu" });
inExpected.build();
assertEquals(in, inExpected);
}
示例2: testPreparedUpdateSql
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testPreparedUpdateSql() throws SqlParserException {
String sql = "UPDATE TABLE1 SET ID=? WHERE ID>=? AND ID<=?";
UpdateNode un = update(sql);
Map<Integer, ParameterContext> currentParameter = new HashMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 0, 2 });
ParameterContext p2 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, 3 });
ParameterContext p3 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, 5 });
currentParameter.put(1, p1);
currentParameter.put(2, p2);
currentParameter.put(3, p3);
Parameters parameterSettings = new Parameters(currentParameter, false);
un.assignment(parameterSettings);
un.build();
TableNode table1 = new TableNode("TABLE1");
UpdateNode unExpected = table1.update("ID", new Comparable[] { 2 });
table1.query("ID>=3 AND ID<=5");
unExpected.build();
assertEquals(un, unExpected);
}
示例3: testPreparedDeleteSql
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testPreparedDeleteSql() throws SqlParserException, QueryException {
String sql = "DELETE FROM TABLE1 WHERE ID>=? AND ID<=?";
DeleteNode dn = delete(sql);
Map<Integer, ParameterContext> parameterSettings = null;
parameterSettings = new TreeMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 0, 3 });
ParameterContext p2 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, 5 });
parameterSettings.put(1, p1);
parameterSettings.put(2, p2);
dn.assignment(parameterSettings);
dn.build();
TableNode table1 = new TableNode("TABLE1");
DeleteNode dnExpected = table1.delete();
table1.query("ID>=3 AND ID<=5");
dnExpected.build();
assertEquals(dn, dnExpected);
}
示例4: testPreparedUpdateSql
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testPreparedUpdateSql() throws SqlParserException, QueryException {
String sql = "UPDATE TABLE1 SET ID=? WHERE ID>=? AND ID<=?";
UpdateNode un = update(sql);
Map<Integer, ParameterContext> parameterSettings = null;
parameterSettings = new TreeMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 0, 2 });
ParameterContext p2 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, 3 });
ParameterContext p3 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, 5 });
parameterSettings.put(1, p1);
parameterSettings.put(2, p2);
parameterSettings.put(3, p3);
un.assignment(parameterSettings);
un.build();
TableNode table1 = new TableNode("TABLE1");
UpdateNode unExpected = table1.update("ID", new Comparable[] { 2 });
table1.query("ID>=3 AND ID<=5");
unExpected.build();
assertEquals(un, unExpected);
}
示例5: extractHint
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
/**
* 從sql中解出hint,並且將hint裏麵的?替換為參數的String形式
*
* @param sql
* @param parameterSettings
* @return
*/
public static String extractHint(String sql, Map<Integer, ParameterContext> parameterSettings) {
String tddlHint = TStringUtil.getBetween(sql, TDDL_HINT_PREFIX, TDDL_HINT_END);
if (null == tddlHint || "".endsWith(tddlHint)) {
return null;
}
StringBuffer sb = new StringBuffer();
int size = tddlHint.length();
int parameters = 1;
for (int i = 0; i < size; i++) {
if (tddlHint.charAt(i) == '?') {
// TDDLHINT隻能設置簡單值
if (parameterSettings == null) {
throw new SqlParserException("hint中使用了'?'占位符,卻沒有設置setParameter()");
}
ParameterContext param = parameterSettings.get(parameters);
if (param == null) {
throw new SqlParserException("Parameter index out of range (" + parameters
+ " > number of parameters, which is " + parameterSettings.size()
+ ").");
}
Object arg = param.getArgs()[1];
if ((param.getParameterMethod() == ParameterMethod.setString || arg instanceof String)
&& !isQuoteSurround(tddlHint, i)) {
sb.append('\'');
sb.append(arg);
sb.append('\'');
} else {
sb.append(arg);
}
parameters++;
} else {
sb.append(tddlHint.charAt(i));
}
}
return sb.toString();
}
示例6: assignment
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Override
public Object assignment(Parameters parameterSettings) {
Object key = null;
if (name instanceof IBindVal) {
key = ((IBindVal) name).assignment(parameterSettings);
} else if (name instanceof ISelectable) {
key = ((IBindVal) name).assignment(parameterSettings);
} else {
key = name;
}
String k = DataType.StringType.convertFrom(key);
if (parameterSettings != null && parameterSettings.isBatch()) {
if (batchMaxval < 0) {
batchMaxval = SequenceManagerProxy.getInstance().nextValue(k, parameterSettings.getBatchSize());
ThreadLocalMap.put(IDataNodeExecutor.LAST_SEQUENCE_VAL, batchMaxval);// 隻記錄最大的seqId
}
// 返回value用戶做rule計算
value = batchMaxval - parameterSettings.getBatchSize() + parameterSettings.getBatchIndex() + 1;
// 將value加入到綁定變量中
parameterSettings.getCurrentParameter().put(index,
new ParameterContext(ParameterMethod.setLong, new Object[] { index, value }));
return this;
} else {
Long nextval = SequenceManagerProxy.getInstance().nextValue(k);
ThreadLocalMap.put(IDataNodeExecutor.LAST_SEQUENCE_VAL, nextval);// 使用thread變量
return nextval;
}
}
示例7: getParameters
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
public List<Object> getParameters() {
List<Object> parameters = new ArrayList<Object>();
for (ParameterContext context : parameterSettings.values()) {
if (context.getParameterMethod() != ParameterMethod.setNull1
&& context.getParameterMethod() != ParameterMethod.setNull2) {
parameters.add(context.getArgs()[1]);
} else {
parameters.add(null);
}
}
return parameters;
}
示例8: AUTOINC
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testInsert_自增id_綁定變量為null() {
String sql = "INSERT INTO AUTOINC(ID,NAME) VALUES(?,?)";
Map<Integer, ParameterContext> currentParameter = new HashMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 2 });
currentParameter.put(1, p1);
Parameters parameterSettings = new Parameters();
parameterSettings.getCurrentParameter().put(1,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, null }));
parameterSettings.getCurrentParameter().put(2,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, "hello1" }));
parameterSettings.addBatch();
parameterSettings.getCurrentParameter().put(1,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, null }));
parameterSettings.getCurrentParameter().put(2,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, "hello2" }));
parameterSettings.addBatch();
IDataNodeExecutor plan = optimizer.optimizeAndAssignment(sql, parameterSettings, null, false);
Assert.assertTrue(plan instanceof IMerge);
Assert.assertEquals(2, ((IMerge) plan).getSubNodes().size());
// Assert.assertEquals(((IInsert) ((IMerge)
// plan).getSubNodes().get(0)).getBatchIndexs(), Arrays.asList(0));
// Assert.assertEquals(((IInsert) ((IMerge)
// plan).getSubNodes().get(1)).getBatchIndexs(), Arrays.asList(1));
}
示例9: setTime
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Override
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
if (null == cal) {
parameterSettings.put(parameterIndex, new ParameterContext(ParameterMethod.setTime1, new Object[] {
parameterIndex, x }));
} else {
parameterSettings.put(parameterIndex, new ParameterContext(ParameterMethod.setTime2, new Object[] {
parameterIndex, x }));
}
}
示例10: convert
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
protected Map<Integer, ParameterContext> convert(List<Object> args) {
Map<Integer, ParameterContext> map = new HashMap<Integer, ParameterContext>(args.size());
int index = 1;
for (Object obj : args) {
ParameterContext context = new ParameterContext(ParameterMethod.setObject1, new Object[] { index, obj });
map.put(index, context);
index++;
}
return map;
}
示例11: setObject
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Override
public void setObject(int parameterIndex, Object x) throws SQLException {
// /*
// * 對於int long之類的類型,使用反射去調用其專屬的setter,其他的加if判斷,暫不支持
// */
// if (x instanceof java.util.Date)
// x = new Date(((java.util.Date) x).getTime());
parameterSettings.put(parameterIndex, new ParameterContext(ParameterMethod.setObject1, new Object[] {
parameterIndex, x }));
// if (x == null) {
// setNull(parameterIndex -1, x);
// } else if (x instanceof Integer) {
// setInt(parameterIndex -1, (Integer) x);
// } else if (x instanceof Long) {
// setLong(parameterIndex -1, (Long) x);
// } else if (x instanceof String) {
// setString(parameterIndex -1, (String) x);
// } else if (x instanceof Boolean) {
// setBoolean(parameterIndex -1, (Boolean) x);
// } else if (x instanceof Float) {
// setFloat(parameterIndex -1, (Float) x);
// } else if (x instanceof Double) {
// setDouble(parameterIndex -1, (Double) x);
// } else if (x instanceof byte[]) {
// setBytes(parameterIndex -1, (byte[]) x);
// } else if (x instanceof Date) {
// setDate(parameterIndex -1, (Date) x);
// } else if (x instanceof java.util.Date) {
// setDate(parameterIndex -1,new Date(((java.util.Date)x).getTime()));
// }else
// {
// throw new
// UnsupportedOperationException("the type of "+x+" is not supported by prepare statement , index is "+parameterIndex);
// }
}
示例12: ParameterContext
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Test
public void testDelete_範圍查詢() {
String sql = "DELETE FROM TABLE1 WHERE ID > ? AND ID < ?";
Map<Integer, ParameterContext> currentParameter = new HashMap<Integer, ParameterContext>();
ParameterContext p1 = new ParameterContext(ParameterMethod.setObject1, new Object[] { 2 });
currentParameter.put(1, p1);
Parameters parameterSettings = new Parameters();
parameterSettings.getCurrentParameter().put(1,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, 1 }));
parameterSettings.getCurrentParameter().put(2,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, 4 }));
parameterSettings.addBatch();
parameterSettings.getCurrentParameter().put(1,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 1, 2 }));
parameterSettings.getCurrentParameter().put(2,
new ParameterContext(ParameterMethod.setObject1, new Object[] { 2, 5 }));
parameterSettings.addBatch();
IDataNodeExecutor plan = optimizer.optimizeAndAssignment(sql, parameterSettings, null, false);
Assert.assertTrue(plan instanceof IMerge);
Assert.assertEquals(((IDelete) ((IMerge) plan).getSubNodes().get(0)).getBatchIndexs(), Arrays.asList(0));
Assert.assertEquals(((IDelete) ((IMerge) plan).getSubNodes().get(1)).getBatchIndexs(), Arrays.asList(1));
Assert.assertEquals(((IDelete) ((IMerge) plan).getSubNodes().get(2)).getBatchIndexs(), Arrays.asList(0, 1));
}
示例13: setInt
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Override
public void setInt(int parameterIndex, int x) throws SQLException {
parameterSettings.put(parameterIndex, new ParameterContext(ParameterMethod.setInt, new Object[] {
parameterIndex, x }));
}
示例14: setArray
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
public void setArray(int i, Array x) throws SQLException {
parameterSettings.put(i, new ParameterContext(ParameterMethod.setArray, new Object[] { i, x }));
}
示例15: setTimestamp
import com.taobao.tddl.common.jdbc.ParameterMethod; //導入依賴的package包/類
@Override
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
parameterSettings.put(parameterIndex, new ParameterContext(ParameterMethod.setTimestamp1, new Object[] {
parameterIndex, x }));
}