微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.sql.SQLNonTransientException的实例源码

项目:dble    文件DruidUpdateParser.java   
/**
 * confirmChildColumnNotUpdated
 *
 * @throws sqlNonTransientException
 */
private void confirmChildColumnNotUpdated(sqlUpdateStatement update,SchemaConfig schema,String tableName) throws sqlNonTransientException {
    if (schema.getFkErRelations() == null) {
        return;
    }
    List<sqlUpdateSetItem> updateSetItem = update.getItems();
    if (updateSetItem != null && updateSetItem.size() > 0) {
        for (sqlUpdateSetItem item : updateSetItem) {
            String column = StringUtil.removeBackQuote(item.getColumn().toString().toupperCase());
            if (isJoinColumn(column,schema,tableName)) {
                String msg = "child relevant column can't be updated " + tableName + "->" + column;
                LOGGER.info(msg);
                throw new sqlNonTransientException(msg);
            }
        }
    }
}
项目:mycat-src-1.6.1-RELEASE    文件DruidCreateTableParser.java   
@Override
public void statementParse(SchemaConfig schema,RouteResultset rrs,sqlStatement stmt) throws sqlNonTransientException {
    MysqLCreateTableStatement createStmt = (MysqLCreateTableStatement)stmt;
    if(createStmt.getQuery() != null) {
        String msg = "create table from other table not supported :" + stmt;
        LOGGER.warn(msg);
        throw new sqlNonTransientException(msg);
    }
    String tableName = StringUtil.removeBackquote(createStmt.getTableSource().toString().toupperCase());
    if(schema.getTables().containsKey(tableName)) {
        TableConfig tableConfig = schema.getTables().get(tableName);
        AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm();
        if(algorithm instanceof SlotFunction){
            sqlColumnDeFinition column = new sqlColumnDeFinition();
            column.setDataType(new sqlCharacterDataType("int"));
            column.setName(new sqlIdentifierExpr("_slot"));
            column.setComment(new sqlCharExpr("自动迁移算法slot,禁止修改"));
            ((sqlCreateTableStatement)stmt).getTableElementList().add(column);
            String sql = createStmt.toString();
            rrs.setStatement(sql);
            ctx.setsql(sql);
        }
    }
    ctx.addTable(tableName);

}
项目:mycat-src-1.6.1-RELEASE    文件DruidSelectParser.java   
private boolean isRoutMultiNode(SchemaConfig schema,RouteResultset rrs)
{
 if(rrs.getNodes()!=null&&rrs.getNodes().length>1)
 {
  return true;
 }
 LayerCachePool tableId2DatanodeCache = (LayerCachePool) MycatServer.getInstance().getCacheService().getCachePool("TableID2DatanodeCache");
 try
 {
  tryRoute(schema,rrs,tableId2DatanodeCache);
  if(rrs.getNodes()!=null&&rrs.getNodes().length>1)
  {
      return true;
  }
 } catch (sqlNonTransientException e)
 {
  throw new RuntimeException(e);
 }
 return false;
}
项目:mycat-src-1.6.1-RELEASE    文件DruidSelectParser.java   
protected void setLimitIFChange(sqlStatement stmt,sqlBinaryOpExpr one,int firstrownum,int lastrownum)
{
    rrs.setLimitStart(firstrownum);
    rrs.setLimitSize(lastrownum - firstrownum);
    LayerCachePool tableId2DatanodeCache = (LayerCachePool) MycatServer.getInstance().getCacheService().getCachePool("TableID2DatanodeCache");
    try
    {
        tryRoute(schema,tableId2DatanodeCache);
    } catch (sqlNonTransientException e)
    {
        throw new RuntimeException(e);
    }
    if (isNeedChangeLimit(rrs))
    {
        one.setRight(new sqlIntegerExpr(0));
           String curentDbType ="db2".equalsIgnoreCase(this.getCurentDbType())?"oracle":getCurentDbType();
           String sql =   sqlUtils.tosqlString(stmt,curentDbType);;
        rrs.changeNodesqlAfteraddLimit(schema,getCurentDbType(),sql,lastrownum,false);
        //设置改写后的sql
        getCtx().setsql(sql);
    }
}
项目:dble    文件RouterUtil.java   
private static void routerForJoinTable(RouteResultset rrs,TableConfig tableConfig,Map<String,Set<ColumnRoutePair>> columnsMap,String joinKey) throws sqlNonTransientException {
    //childTable  (if it's ER JOIN of select)must find root table,remove childTable,only left root table
    Set<ColumnRoutePair> joinkeyvalue = columnsMap.get(joinKey);
    Set<String> datanodeSet = ruleByJoinValueCalculate(rrs,tableConfig,joinkeyvalue);

    if (datanodeSet.isEmpty()) {
        throw new sqlNonTransientException(
                "parent key can't find any valid datanode ");
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("found partion nodes (using parent partion rule directly) for child table to update  " +
                Arrays.toString(datanodeSet.toArray()) + " sql :" + rrs.getStatement());
    }
    if (datanodeSet.size() > 1) {
        routetoMultiNode(rrs.isCacheAble(),datanodeSet);
        rrs.setFinishedRoute(true);
        return;
    } else {
        rrs.setCacheAble(true);
        routetoSingleNode(rrs,datanodeSet.iterator().next());
        return;
    }
}
项目:dble    文件DruidDropTableParser.java   
@Override
public SchemaConfig visitorParse(SchemaConfig schema,sqlStatement stmt,ServerSchemaStatVisitor visitor,ServerConnection sc)
        throws sqlException {
    sqlDropTableStatement dropTable = (sqlDropTableStatement) stmt;
    if (dropTable.getTableSources().size() > 1) {
        String msg = "dropping multi-tables is not supported,sql:" + stmt;
        throw new sqlNonTransientException(msg);
    }
    String schemaName = schema == null ? null : schema.getName();
    SchemaInfo schemaInfo = SchemaUtil.getSchemaInfo(sc.getUser(),schemaName,dropTable.getTableSources().get(0));
    String statement = RouterUtil.removeSchema(rrs.getStatement(),schemaInfo.getSchema());
    rrs.setStatement(statement);
    if (RouterUtil.isNoSharding(schemaInfo.getSchemaConfig(),schemaInfo.getTable())) {
        RouterUtil.routetoSingleDDLNode(schemaInfo,rrs);
        return schemaInfo.getSchemaConfig();
    }
    RouterUtil.routetoDDLNode(schemaInfo,rrs);
    return schemaInfo.getSchemaConfig();
}
项目:mycat-src-1.6.1-RELEASE    文件HintCatletHandler.java   
/**
 * 从全局的schema列表中查询指定的schema是否存在, 如果存在则替换connection属性中原有的schema,
 * 如果不存在,则throws sqlNonTransientException,表示指定的schema 不存在
 * 
 * @param sysConfig
 * @param schema
 * @param sqlType
 * @param realsql
 * @param charset
 * @param info
 * @param cachePool
 * @param hintsqlValue
 * @return
 * @throws sqlNonTransientException
 */
@Override
public RouteResultset route(SystemConfig sysConfig,int sqlType,String realsql,String charset,ServerConnection sc,LayerCachePool cachePool,String hintsqlValue,int hintsqlType,Map hintMap)
        throws sqlNonTransientException {
    // sc.setEngineCtx ctx
    String cateletClass = hintsqlValue;
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("load catelet class:" + hintsqlValue + " to run sql "
                + realsql);
    }
    try {
        Catlet catlet = (Catlet) MycatServer.getInstance()
                .getCatletClassLoader().getInstanceofClass(cateletClass);
        catlet.route(sysConfig,sqlType,realsql,charset,sc,cachePool);
        catlet.processsql(realsql,new EngineCtx(sc.getSession2()));
    } catch (Exception e) {
        LOGGER.warn("catlet error "+e);
        throw new sqlNonTransientException(e);
    }
    return null;
}
项目:dble    文件ServerConnection.java   
private void routeEndExecutesql(String sql,int type,SchemaConfig schema) {
    RouteResultset rrs;
    try {
        rrs = DbleServer.getInstance().getRouterService().route(schema,type,this);
        if (rrs == null) {
            return;
        }
        if (rrs.getsqlType() == ServerParse.DDL) {
            addTableMetaLock(rrs);
            if (DbleServer.getInstance().getTmManager().getCatalogs().get(rrs.getSchema()).getView(rrs.getTable()) != null) {
                DbleServer.getInstance().getTmManager().removeMetaLock(rrs.getSchema(),rrs.getTable());
                String msg = "Table '" + rrs.getTable() + "' already exists as a view";
                LOGGER.info(msg);
                throw new sqlNonTransientException(msg);
            }
        }
    } catch (Exception e) {
        executeException(e,sql);
        return;
    }
    session.execute(rrs);
}
项目:dble    文件DruidInsertParser.java   
private void genDuplicate(boolean isGlobalCheck,StringBuilder sb,List<sqlExpr> dku) throws sqlNonTransientException {
    boolean flag = false;
    sb.append(" on duplicate key update ");
    for (int i = 0; i < dku.size(); i++) {
        sqlExpr exp = dku.get(i);
        if (!(exp instanceof sqlBinaryOpExpr)) {
            String msg = "not supported! on duplicate key update exp is " + exp.getClass();
            LOGGER.info(msg);
            throw new sqlNonTransientException(msg);
        }
        sqlBinaryOpExpr binaryOpExpr = (sqlBinaryOpExpr) exp;
        if (isGlobalCheck && !flag && GlobalTableutil.GLOBAL_TABLE_CHECK_COLUMN.equals(binaryOpExpr.getLeft().toString())) {
            flag = true;
            onDuplicateGlobalColumn(sb);
        } else {
            sb.append(binaryOpExpr.toString());
        }
        if (i < dku.size() - 1) {
            sb.append(",");
        }
    }
    if (isGlobalCheck && !flag) {
        sb.append(",");
        onDuplicateGlobalColumn(sb);
    }
}
项目:mycat-src-1.6.1-RELEASE    文件PartitionByRangeDateHashTest.java   
@Test
public void testRange() throws sqlNonTransientException {
    String sql = "select * from offer1  where col_date between '2014-01-01 00:00:00'  and '2014-01-03 23:59:59'     order by id desc limit 100";
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(),-1,null,cachePool);
    junit.framework.Assert.assertEquals(6,rrs.getNodes().length);

    sql = "select * from offer1  where col_date between '2014-01-01 00:00:00'  and '2014-01-04 00:00:59'      order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(),cachePool);
    junit.framework.Assert.assertEquals(12,rrs.getNodes().length);

    sql = "select * from offer1  where col_date between '2014-01-04 00:00:00'  and '2014-01-06 23:59:59'      order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(),rrs.getNodes().length);


}
项目:mycat-src-1.6.1-RELEASE    文件PartitionByRangeModTest.java   
@Test
public void testRange() throws sqlNonTransientException {
    String sql = "select * from offer  where id between 2000000  and 4000001     order by id desc limit 100";
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(),cachePool);
    Assert.assertEquals(10,rrs.getNodes().length);

    sql = "select * from offer  where id between 9  and 2000     order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(),cachePool);
    Assert.assertEquals(5,rrs.getNodes().length);

    sql = "select * from offer  where id between 4000001  and 6005001     order by id desc limit 100";
    rrs = routeStrategy.route(new SystemConfig(),cachePool);
    Assert.assertEquals(8,rrs.getNodes().length);


}
项目:mycat-src-1.6.1-RELEASE    文件DruidMysqLHavingTest.java   
@Test
public void testHaving() throws sqlNonTransientException {
    String sql = "select avg(offer_id) avgofferid,member_id from offer_detail group by member_id having avgofferid > 100";
    SchemaConfig schema = schemaMap.get("cndb");
       RouteResultset rrs = routeStrategy.route(new SystemConfig(),cachePool);
       Assert.assertEquals(3,rrs.getsqlMerge().getHavingColsName().length);

    sql = "select avg(offer_id) avgofferid,member_id from offer_detail group by member_id having avg(offer_id) > 100";
       rrs = routeStrategy.route(new SystemConfig(),rrs.getsqlMerge().getHavingColsName().length);

       sql = "select count(offer_id) countofferid,member_id from offer_detail group by member_id having countofferid > 100";
       rrs = routeStrategy.route(new SystemConfig(),member_id from offer_detail group by member_id having count(offer_id) > 100";
       rrs = routeStrategy.route(new SystemConfig(),rrs.getsqlMerge().getHavingColsName().length);

}
项目:dble    文件DefaultDruidParser.java   
@Override
public SchemaConfig visitorParse(SchemaConfig schema,ServerConnection sc)
        throws sqlException {
    stmt.accept(visitor);
    if (visitor.getNotSupportMsg() != null) {
        throw new sqlNonTransientException(visitor.getNotSupportMsg());
    }
    List<List<Condition>> mergedConditionList = new ArrayList<>();
    if (visitor.hasOrCondition()) {
        mergedConditionList = visitor.splitConditions();
    } else {
        mergedConditionList.add(visitor.getConditions());
    }
    Map<String,String> tableAliasMap = getTableAliasMap(visitor.getAliasMap());
    ctx.setRouteCalculateUnits(this.buildrouteCalculateUnits(tableAliasMap,mergedConditionList));
    return schema;
}
项目:openjdk-jdk10    文件sqlNonTransientExceptionTests.java   
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using Traditional while loop
 */
@Test
public void test12() {
    sqlNonTransientException ex = new sqlNonTransientException("Exception 1",t1);
    sqlNonTransientException ex1 = new sqlNonTransientException("Exception 2");
    sqlNonTransientException ex2 = new sqlNonTransientException("Exception 3",t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    sqlException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
项目:dble    文件HintDatanodeHandler.java   
@Override
public RouteResultset route(SchemaConfig schema,Map hintMap)
        throws sqlNonTransientException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("route datanode sql hint from " + realsql);
    }

    RouteResultset rrs = new RouteResultset(realsql,sqlType);
    Physicaldbnode datanode = DbleServer.getInstance().getConfig().getDatanodes().get(hintsqlValue);
    if (datanode != null) {
        rrs = RouterUtil.routetoSingleNode(rrs,datanode.getName());
    } else {
        String msg = "can't find hint datanode:" + hintsqlValue;
        LOGGER.info(msg);
        throw new sqlNonTransientException(msg);
    }

    return rrs;
}
项目:dble    文件DruidInsertReplaceParser.java   
protected static RouteResultset routeByERParentKey(RouteResultset rrs,TableConfig tc,String joinkeyval)
        throws sqlNonTransientException {
    if (tc.getDirectRouteTC() != null) {
        Set<ColumnRoutePair> parentColVal = new HashSet<>(1);
        ColumnRoutePair pair = new ColumnRoutePair(joinkeyval);
        parentColVal.add(pair);
        Set<String> datanodeSet = RouterUtil.ruleCalculate(tc.getDirectRouteTC(),parentColVal);
        if (datanodeSet.isEmpty() || datanodeSet.size() > 1) {
            throw new sqlNonTransientException("parent key can't find  valid data node,expect 1 but found: " + datanodeSet.size());
        }
        String dn = datanodeSet.iterator().next();
        if (sqlJob.LOGGER.isDebugEnabled()) {
            sqlJob.LOGGER.debug("found partion node (using parent partition rule directly) for child table to insert  " + dn + " sql :" + rrs.getStatement());
        }
        return RouterUtil.routetoSingleNode(rrs,dn);
    }
    return null;
}
项目:dble    文件DruidSelectParser.java   
private void tryRouteSingleTable(SchemaConfig schema,LayerCachePool cachePool)
        throws sqlException {
    if (rrs.isFinishedRoute()) {
        return;
    }
    SortedSet<RouteResultsetNode> nodeSet = new TreeSet<>();
    String table = ctx.getTables().get(0);
    if (RouterUtil.isNoSharding(schema,table)) {
        RouterUtil.routetoSingleNode(rrs,schema.getDatanode());
        return;
    }
    for (RouteCalculateUnit unit : ctx.getRouteCalculateUnits()) {
        RouteResultset rrsTmp = RouterUtil.tryRouteForOneTable(schema,unit,table,true,cachePool);
        if (rrsTmp != null && rrsTmp.getNodes() != null) {
            Collections.addAll(nodeSet,rrsTmp.getNodes());
            if (rrsTmp.isGlobalTable()) {
                break;
            }
        }
    }
    if (nodeSet.size() == 0) {
        String msg = " find no Route:" + rrs.getStatement();
        LOGGER.info(msg);
        throw new sqlNonTransientException(msg);
    }

    RouteResultsetNode[] nodes = new RouteResultsetNode[nodeSet.size()];
    int i = 0;
    for (RouteResultsetNode aNodeSet : nodeSet) {
        nodes[i] = aNodeSet;
        i++;
    }

    rrs.setNodes(nodes);
    rrs.setFinishedRoute(true);
}
项目:mycat-src-1.6.1-RELEASE    文件DruidUpdateParser.java   
private static boolean columnInExpr(sqlExpr sqlExpr,String colName) throws sqlNonTransientException {
    String column;
    if (sqlExpr instanceof sqlIdentifierExpr) {
        column = StringUtil.removeBackquote(((sqlIdentifierExpr) sqlExpr).getName()).toupperCase();
    } else if (sqlExpr instanceof sqlPropertyExpr) {
        column = StringUtil.removeBackquote(((sqlPropertyExpr) sqlExpr).getName()).toupperCase();
    } else {
        throw new sqlNonTransientException("Unhandled sql AST node type encountered: " + sqlExpr.getClass());
    }

    return column.equals(colName.toupperCase());
}
项目:dble    文件HintSchemaHandler.java   
/**
 * @param schema
 * @param sqlType
 * @param realsql
 * @param sc
 * @param cachePool
 * @param hintsqlValue
 * @return
 * @throws sqlNonTransientException
 */
@Override
public RouteResultset route(SchemaConfig schema,Map hintMap)
        throws sqlException {
    SchemaConfig tempSchema = DbleServer.getInstance().getConfig().getSchemas().get(hintsqlValue);
    if (tempSchema != null) {
        return routeStrategy.route(tempSchema,cachePool);
    } else {
        String msg = "can't find hint schema:" + hintsqlValue;
        LOGGER.info(msg);
        throw new sqlNonTransientException(msg);
    }
}
项目:dble    文件IncrSequenceMysqLHandler.java   
private Long getNextValidSeqVal(SequenceVal seqVal) throws sqlNonTransientException {
    Long nexVal = seqVal.nextValue();
    if (seqVal.isNexValValid(nexVal)) {
        return nexVal;
    } else {
        seqVal.fetching.compareAndSet(true,false);
        return getSeqValueFromDB(seqVal);
    }
}
项目:mycat-src-1.6.1-RELEASE    文件RouterUtil.java   
public static boolean processInsert(SchemaConfig schema,String origsql,ServerConnection sc) throws sqlNonTransientException {
    String tableName = StringUtil.getTableName(origsql).toupperCase();
    TableConfig tableConfig = schema.getTables().get(tableName);
    boolean processedInsert=false;
    //判断是有自增字段
    if (null != tableConfig && tableConfig.isAutoIncrement()) {
        String primaryKey = tableConfig.getPrimaryKey();
        processedInsert=processInsert(sc,origsql,tableName,primaryKey);
    }
    return processedInsert;
}
项目:mycat-src-1.6.1-RELEASE    文件AbstractRouteStrategy.java   
/**
 * 路由之前必要的处理
 * 主要是全局序列号插入,还有子表插入
 */
private boolean beforeRouteProcess(SchemaConfig schema,ServerConnection sc)
        throws sqlNonTransientException {

    return RouterUtil.processWithMycatSeq(schema,sc)
            || (sqlType == ServerParse.INSERT && RouterUtil.processERChildTable(schema,sc))
            || (sqlType == ServerParse.INSERT && RouterUtil.processInsert(schema,sc));
}
项目:mycat-src-1.6.1-RELEASE    文件DruidUpdateParserTest.java   
public void throwExceptionParse(String sql,boolean throwException) throws NoSuchMethodException {
    MysqLStatementParser parser = new MysqLStatementParser(sql);
    List<sqlStatement> statementList = parser.parseStatementList();
    sqlStatement sqlStatement = statementList.get(0);
    MysqLUpdateStatement update = (MysqLUpdateStatement) sqlStatement;
    SchemaConfig schemaConfig = mock(SchemaConfig.class);
    Map<String,TableConfig> tables = mock(Map.class);
    TableConfig tableConfig = mock(TableConfig.class);
    String tableName = "hotnews";
    when((schemaConfig).getTables()).thenReturn(tables);
    when(tables.get(tableName)).thenReturn(tableConfig);
    when(tableConfig.getParentTC()).thenReturn(null);
    RouteResultset routeResultset = new RouteResultset(sql,11);
    Class c = DruidUpdateParser.class;
    Method method = c.getDeclaredMethod("confirmShardColumnNotUpdated",new Class[]{sqlUpdateStatement.class,SchemaConfig.class,String.class,RouteResultset.class});
    method.setAccessible(true);
    try {
        method.invoke(c.newInstance(),update,schemaConfig,"ID","",routeResultset);
        if (throwException) {
            System.out.println("未抛异常,解析通过则不对!");
            Assert.assertTrue(false);
        } else {
            System.out.println("未抛异常,解析通过,此情况分片字段可能在update语句中但是实际不会被更新");
            Assert.assertTrue(true);
        }
    } catch (Exception e) {
        if (throwException) {
            System.out.println(e.getCause().getClass());
            Assert.assertTrue(e.getCause() instanceof sqlNonTransientException);
            System.out.println("抛异常原因为sqlNonTransientException则正确");
        } else {
            System.out.println("抛异常,需要检查");
            Assert.assertTrue(false);
        }
    }
}
项目:dble    文件DruidInsertReplaceParser.java   
protected static String shardingValuetoSting(sqlExpr valueExpr) throws sqlNonTransientException {
    String shardingValue = null;
    if (valueExpr instanceof sqlIntegerExpr) {
        sqlIntegerExpr intExpr = (sqlIntegerExpr) valueExpr;
        shardingValue = intExpr.getNumber() + "";
    } else if (valueExpr instanceof sqlCharExpr) {
        sqlCharExpr charExpr = (sqlCharExpr) valueExpr;
        shardingValue = charExpr.getText();
    }
    if (shardingValue == null) {
        throw new sqlNonTransientException("Not Supported of Sharding Value EXPR :" + valueExpr.toString());
    }
    return shardingValue;
}
项目:mycat-src-1.6.1-RELEASE    文件DruidsqlServersqlParserTest.java   
@Test
public void testTopPagesql() throws sqlNonTransientException {
    SchemaConfig schema = schemaMap.get("sqlserverdb");
    RouteResultset rrs = null;

String    sql="SELECT TOP 10  *  \n" +
            " FROM offer1  where sts<>'N' and asf like '%'+'akka'+'%' \n" +
            " ORDER BY sid desc"  ;
    rrs = routeStrategy.route(new SystemConfig(),cachePool);

    Assert.assertEquals(1,rrs.getNodes().length);
    Assert.assertEquals(0,rrs.getLimitStart());
    Assert.assertEquals(10,rrs.getLimitSize());
    Assert.assertEquals(0,rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(10,rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals(sql,rrs.getNodes()[0].getStatement()) ;
    Assert.assertEquals("sqlserver_1",rrs.getNodes()[0].getName());


    sql="SELECT TOP 10  offer1.name,offer1.id  \n" +
            " FROM offer1  where sts<>'N' and asf like '%'+'akka'+'%' \n" +
            " ORDER BY sid desc"  ;
    rrs = routeStrategy.route(new SystemConfig(),rrs.getNodes()[0].getName());

}
项目:mycat-src-1.6.1-RELEASE    文件DruidDb2sqlParserTest.java   
@Test
public void testLimitToDb2Page() throws sqlNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("db2db");
       RouteResultset rrs = routeStrategy.route(new SystemConfig(),cachePool);
       Assert.assertEquals(2,rrs.getNodes().length);
       Assert.assertEquals(5,rrs.getLimitStart());
       Assert.assertEquals(10,rrs.getLimitSize());
       Assert.assertEquals(0,rrs.getNodes()[0].getLimitStart());
       Assert.assertEquals(15,rrs.getNodes()[0].getLimitSize());
       Assert.assertEquals("db2_1",rrs.getNodes()[0].getName());
       Assert.assertEquals("db2_2",rrs.getNodes()[1].getName());

       sql= rrs.getNodes()[0].getStatement() ;
       rrs = routeStrategy.route(new SystemConfig(),cachePool);
       Assert.assertEquals(0,rrs.getNodes()[0].getLimitSize());
       Assert.assertEquals(0,rrs.getLimitStart());
       Assert.assertEquals(15,rrs.getLimitSize());

       sql="select * from offer1 order by id desc limit 5,10" ;
       rrs = routeStrategy.route(new SystemConfig(),cachePool);
       Assert.assertEquals(1,rrs.getLimitSize());
       Assert.assertEquals(5,rrs.getNodes()[0].getLimitStart());
       Assert.assertEquals(10,rrs.getNodes()[0].getName());

}
项目:mycat-src-1.6.1-RELEASE    文件ShardingMultiTableSpace.java   
/**
 * 路由到tableSpace的性能测试
 * 
 * @throws sqlNonTransientException
 */
public void testTableSpace() throws sqlNonTransientException {
    SchemaConfig schema = getSchema();
    String sql = "select id,member_id,gmt_create from offer where member_id in ('1','22','333','1124','4525')";
    for (int i = 0; i < total; i++) {
        RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(),cachePool);
    }
}
项目:mycat-src-1.6.1-RELEASE    文件ShardingDefaultSpace.java   
/**
 * 路由到defaultSpace的性能测试
 */
public void testDefaultSpace() throws sqlNonTransientException {
    SchemaConfig schema = this.getSchema();
    String sql = "insert into offer (member_id,gmt_create) values ('1','2001-09-13 20:20:33')";
    for (int i = 0; i < total; i++) {
        RouteStrategyFactory.getRouteStrategy().route(new SystemConfig(),cachePool);
    }
}
项目:mycat-src-1.6.1-RELEASE    文件NoShardingSpace.java   
public void testDefaultSpace() throws sqlNonTransientException {
    SchemaConfig schema = this.schema;
    String stmt = "insert into offer (member_id,stmt,cachePool);
    }
}
项目:mycat-src-1.6.1-RELEASE    文件NoShardingSpace.java   
public static void main(String[] args) throws sqlNonTransientException {
    NoShardingSpace test = new NoShardingSpace();
    System.currentTimeMillis();

    long start = System.currentTimeMillis();
    test.testDefaultSpace();
    long end = System.currentTimeMillis();
    System.out.println("take " + (end - start) + " ms. avg "+(end-start+0.0)/total);
}
项目:mycat-src-1.6.1-RELEASE    文件DruidOraclesqlParserTest.java   
@Test
public void testLimitToOraclePage() throws sqlNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("oracledb");
       RouteResultset rrs = routeStrategy.route(new SystemConfig(),rrs.getNodes()[0].getLimitSize());
       Assert.assertEquals("d_oracle1",rrs.getNodes()[0].getName());
       Assert.assertEquals("d_oracle2",rrs.getNodes()[0].getName());
}
项目:mycat-src-1.6.1-RELEASE    文件DruidPostgresqlsqlParserTest.java   
@Test
public void testLimitToPgPage() throws sqlNonTransientException {
    String sql = "select * from offer order by id desc limit 5,10";
    SchemaConfig schema = schemaMap.get("pgdb");
       RouteResultset rrs = routeStrategy.route(new SystemConfig(),rrs.getNodes()[0].getLimitSize());

       sql= rrs.getNodes()[0].getStatement() ;
       rrs = routeStrategy.route(new SystemConfig(),rrs.getNodes()[0].getLimitSize());
}
项目:mycat-src-1.6.1-RELEASE    文件DruidPostgresqlsqlParserTest.java   
@Test
public void testPGPagesql() throws sqlNonTransientException {
    String sql = "select sid from offer order by sid limit 10 offset 5";
    SchemaConfig schema = schemaMap.get("pgdb");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(),cachePool);
    Assert.assertEquals(2,rrs.getNodes().length);
    Assert.assertEquals(5,rrs.getNodes()[0].getLimitStart());
    Assert.assertEquals(15,rrs.getNodes()[0].getLimitSize());

    sql = "select sid from offer1 order by sid limit 10 offset 5";
    rrs = routeStrategy.route(new SystemConfig(),cachePool);
    Assert.assertEquals(1,rrs.getLimitSize());
    Assert.assertEquals(5,rrs.getNodes()[0].getLimitSize());
    Assert.assertEquals("SELECT sid\n" +
            "FROM offer1\n" +
            "ORDER BY sid\n" +
            "LIMIT 10 OFFSET 5",rrs.getNodes()[0].getStatement()) ;




}
项目:mycat-src-1.6.1-RELEASE    文件DruidMysqLsqlParserTest.java   
@Test
public void testLockTablesql() throws sqlNonTransientException{
    String sql = "lock tables goods write";
    SchemaConfig schema = schemaMap.get("TESTDB");
    RouteResultset rrs = routeStrategy.route(new SystemConfig(),ServerParse.LOCK,cachePool);
    Assert.assertEquals(3,rrs.getNodes().length);
}
项目:lams    文件sqlExceptionSubclasstranslator.java   
@Override
protected DataAccessException doTranslate(String task,String sql,sqlException ex) {
    if (ex instanceof sqlTransientException) {
        if (ex instanceof sqlTransientConnectionException) {
            return new TransientDataAccessResourceException(buildMessage(task,ex),ex);
        }
        else if (ex instanceof sqlTransactionRollbackException) {
            return new ConcurrencyFailureException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlTimeoutException) {
            return new QueryTimeoutException(buildMessage(task,ex);
        }
    }
    else if (ex instanceof sqlNonTransientException) {
        if (ex instanceof sqlNonTransientConnectionException) {
            return new DataAccessResourceFailureException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlDataException) {
            return new DataIntegrityViolationException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlIntegrityConstraintViolationException) {
            return new DataIntegrityViolationException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlInvalidAuthorizationSpecException) {
            return new PermissionDeniedDataAccessException(buildMessage(task,ex);
        }
        else if (ex instanceof sqlSyntaxErrorException) {
            return new BadsqlGrammarException(task,ex);
        }
        else if (ex instanceof sqlFeatureNotSupportedException) {
            return new InvalidDataAccessApiUsageException(buildMessage(task,ex);
        }
    }
    else if (ex instanceof sqlRecoverableException) {
        return new RecoverableDataAccessException(buildMessage(task,ex);
    }

    // Fallback to Spring's own sql state translation...
    return null;
}
项目:dble    文件DruidUpdateParserTest.java   
public void throwExceptionParse(String sql,routeResultset);
        if (throwException) {
            System.out.println("Not passed without exception is not correct");
            Assert.assertTrue(false);
        } else {
            System.out.println("Passed without exception. Maybe the partition key exists in update statement,but not update in fact");
            Assert.assertTrue(true);
        }
    } catch (Exception e) {
        if (throwException) {
            System.out.println(e.getCause().getClass());
            Assert.assertTrue(e.getCause() instanceof sqlNonTransientException);
            System.out.println("sqlNonTransientException is expected");
        } else {
            System.out.println("need checked");
            Assert.assertTrue(false);
        }
    }
}
项目:jdk8u-jdk    文件sqlNonTransientExceptionTests.java   
/**
 * Create sqlNonTransientException and setting all objects to null
 */
@Test
public void test() {
    sqlNonTransientException e = new sqlNonTransientException(null,errorCode,null);
    assertTrue(e.getMessage() == null && e.getsqlState() == null
            && e.getCause() == null && e.getErrorCode() == errorCode);
}
项目:jdk8u-jdk    文件sqlNonTransientExceptionTests.java   
/**
 * Create sqlNonTransientException with no-arg constructor
 */
@Test
public void test1() {
    sqlNonTransientException ex = new sqlNonTransientException();
    assertTrue(ex.getMessage() == null
            && ex.getsqlState() == null
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
项目:jdk8u-jdk    文件sqlNonTransientExceptionTests.java   
/**
 * Create sqlNonTransientException with message,and sqlState
 */
@Test
public void test3() {
    sqlNonTransientException ex = new sqlNonTransientException(reason,state);
    assertTrue(ex.getMessage().equals(reason)
            && ex.getsqlState().equals(state)
            && ex.getCause() == null
            && ex.getErrorCode() == 0);
}
项目:dble    文件IncrSequenceMysqLHandler.java   
private long getSeqValueFromDB(SequenceVal seqVal) throws sqlNonTransientException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("get next segement of sequence from db for sequence:" + seqVal.seqName + " curVal " + seqVal.curVal);
    }
    if (seqVal.fetching.compareAndSet(false,true)) {
        seqVal.dbretVal = null;
        seqVal.dbfinished = false;
        seqVal.newValueSetted.set(false);
        MysqLSeqFetcher.execute(seqVal);
    }
    Long[] values = seqVal.waitFinish();
    if (values == null) {
        seqVal.fetching.compareAndSet(true,false);
        throw new RuntimeException("can't fetch sequence in db,sequence :" + seqVal.seqName + " detail:" +
                                   MysqLSeqFetcher.getLastError(seqVal.seqName));
    } else if (values[0] == 0) {
        seqVal.fetching.compareAndSet(true,false);
        String msg = "sequence," + seqVal.seqName + "has not been set,please check configure in dble_sequence";
        LOGGER.info(msg);
        throw new sqlNonTransientException(msg);
    } else {
        if (seqVal.newValueSetted.compareAndSet(false,true)) {
            seqVal.setCurValue(values[0]);
            seqVal.maxSegValue = values[1];
            return values[0];
        } else {
            return seqVal.nextValue();
        }

    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。