本文整理汇总了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 }));
}