|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.dtstack.flink.sql.side.tidb; |
| 20 | + |
| 21 | +import com.dtstack.flink.sql.side.AbstractSideTableInfo; |
| 22 | +import com.dtstack.flink.sql.side.FieldInfo; |
| 23 | +import com.dtstack.flink.sql.side.JoinInfo; |
| 24 | +import com.dtstack.flink.sql.side.rdb.all.AbstractRdbAllReqRow; |
| 25 | +import com.dtstack.flink.sql.util.DtStringUtil; |
| 26 | +import com.google.common.collect.Maps; |
| 27 | +import org.apache.flink.api.java.typeutils.RowTypeInfo; |
| 28 | +import org.slf4j.Logger; |
| 29 | +import org.slf4j.LoggerFactory; |
| 30 | + |
| 31 | +import java.sql.Connection; |
| 32 | +import java.sql.DriverManager; |
| 33 | +import java.sql.SQLException; |
| 34 | +import java.util.List; |
| 35 | +import java.util.Map; |
| 36 | + |
| 37 | +/** |
| 38 | + * @author tiezhu |
| 39 | + * Date 2020/6/1 |
| 40 | + * company www.dtstack.com |
| 41 | + */ |
| 42 | +public class TidbAllReqRow extends AbstractRdbAllReqRow { |
| 43 | + |
| 44 | + private static final Logger LOG = LoggerFactory.getLogger(TidbAllReqRow.class); |
| 45 | + |
| 46 | + private static final String TIDB_DRIVER = "com.mysql.jdbc.Driver"; |
| 47 | + |
| 48 | + public TidbAllReqRow(RowTypeInfo rowTypeInfo, JoinInfo joinInfo, List<FieldInfo> outFieldInfoList, AbstractSideTableInfo sideTableInfo) { |
| 49 | + super(new TidbAllSideInfo(rowTypeInfo, joinInfo, outFieldInfoList, sideTableInfo)); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Connection getConn(String dbUrl, String userName, String password) { |
| 54 | + try { |
| 55 | + Class.forName(TIDB_DRIVER); |
| 56 | + Map<String, String> addParams = Maps.newHashMap(); |
| 57 | + addParams.put("userCursorFetch", "true"); |
| 58 | + String targetDbUrl = DtStringUtil.addJdbcParam(dbUrl, addParams, true); |
| 59 | + return DriverManager.getConnection(targetDbUrl, userName, password); |
| 60 | + } catch (ClassNotFoundException | SQLException e) { |
| 61 | + LOG.error("TiDB get connect error!", e); |
| 62 | + throw new RuntimeException("TiDB get connect error! ", e); |
| 63 | + |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public int getFetchSize() { |
| 69 | + return Integer.MIN_VALUE; |
| 70 | + } |
| 71 | +} |
0 commit comments