use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class HandshakePacket method readPayload.
public void readPayload(MySQLPayloadReadView buffer) {
protocolVersion = buffer.readByte();
if (protocolVersion != 0x0a) {
throw new MycatException("unsupport HandshakeV9");
}
serverVersion = buffer.readNULString();
connectionId = buffer.readFixInt(4);
authPluginDataPartOne = buffer.readFixString(8);
buffer.skipInReading(1);
capabilities = new MySQLServerCapabilityFlags((int) buffer.readFixInt(2) & 0x0000ffff);
if (!buffer.readFinished()) {
hasPartTwo = true;
characterSet = buffer.readByte();
statusFlags = (int) buffer.readFixInt(2);
long l = buffer.readFixInt(2) << 16;
capabilities.value |= l;
if (capabilities.isPluginAuth()) {
byte b = buffer.readByte();
authPluginDataLen = Byte.toUnsignedInt(b);
} else {
buffer.skipInReading(1);
}
// reserved = buffers.readFixString(10);
buffer.skipInReading(10);
if (capabilities.isCanDo41Anthentication()) {
// todo check length in range [13.authPluginDataLen)
// authPluginDataPartTwo = buffers.readFixString(13);
authPluginDataPartTwo = buffer.readNULString();
}
if (capabilities.isPluginAuth()) {
authPluginName = buffer.readNULString();
}
}
}
use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class DefaultConnection method executeQuery.
public RowBaseIterator executeQuery(String sql) {
try {
Statement statement = connection.createStatement();
statement.setFetchSize(1);
ResultSet resultSet = statement.executeQuery(sql);
return new JdbcRowBaseIterator(null, this, statement, resultSet, new RowIteratorCloseCallback() {
@Override
public void onClose(long rowCount) {
}
}, sql);
} catch (Exception e) {
throw new MycatException(e);
}
}
use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class JdbcConnectionManager method getConnection.
public DefaultConnection getConnection(String name, Boolean autocommit, int transactionIsolation) {
name = resolveDataSource(name);
final JdbcDataSource key = dataSourceMap.get(name);
Objects.requireNonNull(key, "unknown target:" + name);
DefaultConnection defaultConnection;
Connection connection = null;
switch(key.getDbType()) {
default:
{
try {
DatasourceConfig config = key.getConfig();
connection = key.getDataSource().getConnection();
defaultConnection = new DefaultConnection(connection, key, autocommit, transactionIsolation, this);
LOGGER.debug("get connection:{} {}", name, defaultConnection);
if (config.isInitSqlsGetConnection()) {
if (config.getInitSqls() != null && !config.getInitSqls().isEmpty()) {
try (Statement statement = connection.createStatement()) {
for (String initSql : config.getInitSqls()) {
statement.execute(initSql);
}
}
}
}
key.counter.getAndIncrement();
return defaultConnection;
} catch (SQLException e) {
if (connection != null) {
JdbcUtils.close(connection);
}
LOGGER.debug("", e);
throw new MycatException(e);
}
}
case "mongodb":
{
try {
Properties properties = new Properties();
String username = key.getUsername();
String password = key.getPassword();
if (username != null) {
properties.setProperty("username", username);
}
if (password != null) {
properties.setProperty("password", password);
}
Connection connect = new MongoDriver().connect(key.getUrl(), properties);
return new DefaultConnection(connect, key, autocommit, transactionIsolation, this);
} catch (SQLException ex) {
throw new MycatException(ex);
}
}
}
}
use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class JdbcConnectionManager method createDatasourceProvider.
private static DatasourceProvider createDatasourceProvider(String customerDatasourceProvider) {
String defaultDatasourceProvider = Optional.ofNullable(customerDatasourceProvider).orElse(DruidDatasourceProvider.class.getName());
try {
DatasourceProvider o = (DatasourceProvider) Class.forName(defaultDatasourceProvider).getDeclaredConstructor().newInstance();
ServerConfig serverConfig = MetaClusterCurrent.exist(ServerConfig.class) ? MetaClusterCurrent.wrapper(ServerConfig.class) : new ServerConfig();
o.init(serverConfig);
return o;
} catch (Exception e) {
throw new MycatException("can not load datasourceProvider:{}", customerDatasourceProvider);
}
}
use of io.mycat.MycatException in project Mycat2 by MyCATApache.
the class MycatCalciteMySqlNodeVisitor method buildIdentifier.
SqlNode buildIdentifier(SQLPropertyExpr x) {
String name = SQLUtils.normalize(x.getName());
if ("*".equals(name)) {
name = "";
}
SQLExpr owner = x.getOwner();
List<String> names;
if (owner instanceof SQLIdentifierExpr) {
names = Arrays.asList(((SQLIdentifierExpr) owner).normalizedName(), name);
} else if (owner instanceof SQLPropertyExpr) {
names = new ArrayList<String>();
buildIdentifier((SQLPropertyExpr) owner, names);
names.add(name);
} else if (owner instanceof SQLVariantRefExpr) {
return handleSQLVariantRefExpr(name, (SQLVariantRefExpr) owner);
} else {
throw new MycatException("not support : " + owner);
}
return new SqlIdentifier(names, SqlParserPos.ZERO);
}
Aggregations