Search in sources :

Example 1 with JdbcDatasourcePoolImpl

use of io.mycat.commands.JdbcDatasourcePoolImpl in project Mycat2 by MyCATApache.

the class VertxMycatConnectionPool method call.

@Override
public Future<List<Object>> call(String sql) {
    synchronized (this) {
        Future<List<Object>> future = this.queryCloseFuture.transform(voidAsyncResult -> {
            JdbcDatasourcePoolImpl jdbcDatasourcePool = new JdbcDatasourcePoolImpl(targetName);
            return jdbcDatasourcePool.getConnection().flatMap(connection -> {
                onSend();
                Future<List<Object>> call = connection.call(sql);
                return call.onComplete(event -> {
                    onRev();
                    connection.close();
                });
            });
        });
        this.queryCloseFuture = future.mapEmpty();
        return future;
    }
}
Also used : JdbcDatasourcePoolImpl(io.mycat.commands.JdbcDatasourcePoolImpl) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 2 with JdbcDatasourcePoolImpl

use of io.mycat.commands.JdbcDatasourcePoolImpl in project Mycat2 by MyCATApache.

the class DatasourcePoolTest method main.

@SneakyThrows
public static void main(String[] args) {
    DatasourceConfig datasourceConfig = new DatasourceConfig();
    datasourceConfig.setDbType("mysql");
    datasourceConfig.setUser("root");
    datasourceConfig.setPassword("123456");
    datasourceConfig.setName("prototypeDs");
    datasourceConfig.setUrl("jdbc:mysql://localhost:3307/mysql");
    datasourceConfig.setMaxCon(10);
    Map<String, DatasourceConfig> datasources = Maps.of("prototypeDs", datasourceConfig);
    MetaClusterCurrent.register(JdbcConnectionManager.class, new JdbcConnectionManager(datasources, new DruidDatasourceProvider()));
    MetaClusterCurrent.register(IOExecutor.class, IOExecutor.DEFAULT);
    MycatDatasourcePool jdbcDs = new JdbcDatasourcePoolImpl("prototypeDs");
    NewMycatConnection newMycatConnection = jdbcDs.getConnection().toCompletionStage().toCompletableFuture().get();
    Observable<VectorSchemaRoot> observable = newMycatConnection.prepareQuery("select 1", Collections.emptyList(), new RootAllocator());
    List<VectorSchemaRoot> vectorSchemaRoots = observable.toList().blockingGet();
    System.out.println();
    // ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    MycatDatasourcePool nativeDs = new VertxMySQLDatasourcePoolImpl(datasourceConfig, "prototypeDs");
    MycatRelDataType sqlMycatRelType = getSqlMycatRelDataType();
    TestResult testResult = getTestResult(jdbcDs);
    TestResult testResult2 = getTestResult(nativeDs);
    // List<String> collect = newMycatConnection.prepareQuery(querySql, Collections.emptyList()).toList().blockingGet().stream().map(i -> i.toString()).collect(Collectors.toList());
    MycatRowMetaData mycatRowMetaData1 = testResult.queryResult.getMycatRowMetaData();
    MycatRowMetaData mycatRowMetaData2 = testResult2.queryResult.getMycatRowMetaData();
    MycatRelDataType mycatRelDataType1 = mycatRowMetaData1.getMycatRelDataType();
    MycatRelDataType mycatRelDataType2 = mycatRowMetaData2.getMycatRelDataType();
    System.out.println(mycatRelDataType1);
    System.out.println(mycatRelDataType2);
    System.out.println("=====================================================================================================");
    boolean equals = mycatRelDataType1.equals(mycatRelDataType2);
    // Assert.assertTrue(equals);
    equals = mycatRelDataType1.equals(sqlMycatRelType);
    System.out.println(sqlMycatRelType);
    System.out.println(mycatRelDataType1);
    observable = newMycatConnection.prepareQuery("select * from testSchema.testColumnTable", Collections.emptyList(), new RootAllocator());
    vectorSchemaRoots = observable.toList().blockingGet();
    System.out.println();
}
Also used : VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) MycatDatasourcePool(io.mycat.commands.MycatDatasourcePool) NewMycatConnection(io.mycat.newquery.NewMycatConnection) MycatRelDataType(io.mycat.beans.mycat.MycatRelDataType) ToString(lombok.ToString) DruidDatasourceProvider(io.mycat.datasource.jdbc.DruidDatasourceProvider) DatasourceConfig(io.mycat.config.DatasourceConfig) JdbcDatasourcePoolImpl(io.mycat.commands.JdbcDatasourcePoolImpl) VertxMySQLDatasourcePoolImpl(io.mycat.commands.VertxMySQLDatasourcePoolImpl) JdbcConnectionManager(io.mycat.datasource.jdbc.datasource.JdbcConnectionManager) MycatRowMetaData(io.mycat.beans.mycat.MycatRowMetaData) SneakyThrows(lombok.SneakyThrows)

Example 3 with JdbcDatasourcePoolImpl

use of io.mycat.commands.JdbcDatasourcePoolImpl in project Mycat2 by MyCATApache.

the class MycatNativeDatasourcePool method getConnection.

@Override
public Future<NewMycatConnection> getConnection() {
    return vertxPoolConnection.getConnection().map(connection -> {
        DatabaseInstanceEntry stat = DatabaseInstanceEntry.stat(targetName);
        stat.plusCon();
        stat.plusQps();
        return new VertxMycatConnectionPool(targetName, connection, vertxPoolConnection) {

            long start;

            @Override
            public void onSend() {
                start = System.currentTimeMillis();
            }

            @Override
            public void onRev() {
                long end = System.currentTimeMillis();
                InstanceMonitor.plusPrt(end - start);
            }

            @Override
            public Future<Void> close() {
                stat.decCon();
                return super.close();
            }

            @Override
            public Observable<VectorSchemaRoot> prepareQuery(String sql, List<Object> params, BufferAllocator allocator) {
                return Observable.create(emitter -> {
                    JdbcDatasourcePoolImpl jdbcDatasourcePool = new JdbcDatasourcePoolImpl(targetName);
                    Future<NewMycatConnection> connectionFuture = jdbcDatasourcePool.getConnection();
                    connectionFuture.onSuccess(event -> {
                        Observable<VectorSchemaRoot> observable = event.prepareQuery(sql, params, allocator);
                        observable.subscribe(vectorSchemaRoot -> emitter.onNext(vectorSchemaRoot), throwable -> emitter.onError(throwable), () -> emitter.onComplete());
                    });
                    connectionFuture.onFailure(event -> emitter.onError(event));
                });
            }

            @Override
            public Future<List<Object>> call(String sql) {
                JdbcDatasourcePoolImpl jdbcDatasourcePool = new JdbcDatasourcePoolImpl(targetName);
                Future<NewMycatConnection> connectionFuture = jdbcDatasourcePool.getConnection();
                return connectionFuture.flatMap(connection -> connection.call(sql));
            }
        };
    });
}
Also used : DatabaseInstanceEntry(io.mycat.monitor.DatabaseInstanceEntry) VectorSchemaRoot(org.apache.arrow.vector.VectorSchemaRoot) NewMycatConnection(io.mycat.newquery.NewMycatConnection) JdbcDatasourcePoolImpl(io.mycat.commands.JdbcDatasourcePoolImpl) List(java.util.List) BufferAllocator(org.apache.arrow.memory.BufferAllocator)

Aggregations

JdbcDatasourcePoolImpl (io.mycat.commands.JdbcDatasourcePoolImpl)3 NewMycatConnection (io.mycat.newquery.NewMycatConnection)2 List (java.util.List)2 VectorSchemaRoot (org.apache.arrow.vector.VectorSchemaRoot)2 ImmutableList (com.google.common.collect.ImmutableList)1 MycatRelDataType (io.mycat.beans.mycat.MycatRelDataType)1 MycatRowMetaData (io.mycat.beans.mycat.MycatRowMetaData)1 MycatDatasourcePool (io.mycat.commands.MycatDatasourcePool)1 VertxMySQLDatasourcePoolImpl (io.mycat.commands.VertxMySQLDatasourcePoolImpl)1 DatasourceConfig (io.mycat.config.DatasourceConfig)1 DruidDatasourceProvider (io.mycat.datasource.jdbc.DruidDatasourceProvider)1 JdbcConnectionManager (io.mycat.datasource.jdbc.datasource.JdbcConnectionManager)1 DatabaseInstanceEntry (io.mycat.monitor.DatabaseInstanceEntry)1 SneakyThrows (lombok.SneakyThrows)1 ToString (lombok.ToString)1 BufferAllocator (org.apache.arrow.memory.BufferAllocator)1