From 817affa04c19f3aacaecc8f111ab48961fd26490 Mon Sep 17 00:00:00 2001 From: yanhuqing666 Date: Mon, 28 Nov 2016 14:39:47 +0800 Subject: [PATCH] add meta for insert without columns --- pom.xml | 16 +- src/main/java/io/mycat/MycatServer.java | 60 +- src/main/java/io/mycat/config/Versions.java | 2 +- .../io/mycat/config/model/TableConfig.java | 9 +- .../MySQLTableStructureDetector.java | 108 - .../structure/TableStructureProcessor.java | 13 - src/main/java/io/mycat/meta/IndexMeta.java | 44 + .../meta/MySQLTableStructureDetector.java | 25 + .../java/io/mycat/meta/ProxyMetaManager.java | 678 +++ src/main/java/io/mycat/meta/SchemaMeta.java | 74 + .../io/mycat/meta/protocol/MyCatMeta.java | 3825 +++++++++++++++++ .../io/mycat/meta/protocol/MyCatMeta.protocol | 65 + .../meta/table/MultiTableMetaHandler.java | 35 + .../mycat/meta/table/SchemaMetaHandler.java | 61 + .../io/mycat/meta/table/TableMetaHandler.java | 195 + .../route/impl/DruidMycatRouteStrategy.java | 2 +- .../parser/druid/impl/DruidInsertParser.java | 104 +- 17 files changed, 5126 insertions(+), 190 deletions(-) delete mode 100644 src/main/java/io/mycat/config/table/structure/MySQLTableStructureDetector.java delete mode 100644 src/main/java/io/mycat/config/table/structure/TableStructureProcessor.java create mode 100644 src/main/java/io/mycat/meta/IndexMeta.java create mode 100644 src/main/java/io/mycat/meta/MySQLTableStructureDetector.java create mode 100644 src/main/java/io/mycat/meta/ProxyMetaManager.java create mode 100644 src/main/java/io/mycat/meta/SchemaMeta.java create mode 100644 src/main/java/io/mycat/meta/protocol/MyCatMeta.java create mode 100644 src/main/java/io/mycat/meta/protocol/MyCatMeta.protocol create mode 100644 src/main/java/io/mycat/meta/table/MultiTableMetaHandler.java create mode 100644 src/main/java/io/mycat/meta/table/SchemaMetaHandler.java create mode 100644 src/main/java/io/mycat/meta/table/TableMetaHandler.java diff --git a/pom.xml b/pom.xml index 13802b3d6..59bffc71c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,8 +3,8 @@ 4.0.0 io.mycat - Mycat-server - 1.6.5-DEV + Action_Mycat + 0.1.1-DEV jar Mycat-server The project of Mycat-server @@ -17,8 +17,11 @@ yyyy-MM-dd HH:mm:ss version.txt.template version.txt + + UTF-8 + - + scm:git:ssh://apachemycat@github.com/MyCATApache/Mycat-Server.git scm:git:ssh://apachemycat@github.com/MyCATApache/Mycat-Server.git scm:git:ssh://apachemycat@github.com/MyCATApache/Mycat-Server.git @@ -45,6 +48,11 @@ + + com.google.protobuf + protobuf-java + 2.6.1 + org.mongodb mongo-java-driver @@ -535,7 +543,6 @@ - org.apache.maven.plugins maven-scm-plugin @@ -553,7 +560,6 @@ - org.codehaus.mojo buildnumber-maven-plugin diff --git a/src/main/java/io/mycat/MycatServer.java b/src/main/java/io/mycat/MycatServer.java index dfc518956..81c189d46 100644 --- a/src/main/java/io/mycat/MycatServer.java +++ b/src/main/java/io/mycat/MycatServer.java @@ -23,7 +23,34 @@ */ package io.mycat; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.AsynchronousChannelGroup; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; + +import org.apache.curator.framework.CuratorFramework; +import org.apache.curator.framework.recipes.locks.InterProcessMutex; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.google.common.io.Files; +import com.google.common.util.concurrent.ListeningExecutorService; +import com.google.common.util.concurrent.MoreExecutors; + import io.mycat.backend.BackendConnection; import io.mycat.backend.datasource.PhysicalDBNode; import io.mycat.backend.datasource.PhysicalDBPool; @@ -44,9 +71,10 @@ import io.mycat.config.loader.zkprocess.comm.ZkParamCfg; import io.mycat.config.model.SchemaConfig; import io.mycat.config.model.SystemConfig; import io.mycat.config.model.TableConfig; -import io.mycat.config.table.structure.MySQLTableStructureDetector; import io.mycat.manager.ManagerConnectionFactory; import io.mycat.memory.MyCatMemory; +import io.mycat.meta.MySQLTableStructureDetector; +import io.mycat.meta.ProxyMetaManager; import io.mycat.net.AIOAcceptor; import io.mycat.net.AIOConnector; import io.mycat.net.NIOAcceptor; @@ -70,26 +98,7 @@ import io.mycat.statistic.stat.UserStatAnalyzer; import io.mycat.util.ExecutorUtil; import io.mycat.util.NameableExecutor; import io.mycat.util.TimeUtil; - -import java.io.*; -import java.nio.channels.AsynchronousChannelGroup; -import java.util.*; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; - import io.mycat.util.ZKUtils; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.recipes.locks.InterProcessMutex; -import org.apache.zookeeper.data.Stat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.util.concurrent.ListeningExecutorService; -import com.google.common.util.concurrent.MoreExecutors; /** * @author mycat @@ -108,6 +117,7 @@ public class MycatServer { private final RouteService routerService; private final CacheService cacheService; private Properties dnIndexProperties; + private ProxyMetaManager tmManager; //AIO连接群组 private AsynchronousChannelGroup[] asyncChannelGroups; @@ -181,7 +191,7 @@ public class MycatServer { } catch (Exception e) { throw new RuntimeException(e); } - + //catlet加载器 catletClassLoader = new DynaClassLoader(SystemConfig.getHomePath() + File.separator + "catlet", config.getSystem().getCatletClassCheckSeconds()); @@ -268,7 +278,6 @@ public class MycatServer { } public void startup() throws IOException { - SystemConfig system = config.getSystem(); int processorCount = system.getProcessors(); @@ -402,6 +411,9 @@ public class MycatServer { server = new NIOAcceptor(DirectByteBufferPool.LOCAL_BUF_THREAD_PREX + NAME + "Server", system.getBindIp(), system.getServerPort(), sf, reactorPool); } + tmManager = new ProxyMetaManager(); + tmManager.init(); + // manager start manager.start(); LOGGER.info(manager.getName() + " is started and listening on " + manager.getPort()); @@ -724,6 +736,10 @@ public class MycatServer { isOnline.set(true); } + public ProxyMetaManager getTmManager() { + return tmManager; + } + // 系统时间定时更新任务 private Runnable updateTime() { return new Runnable() { diff --git a/src/main/java/io/mycat/config/Versions.java b/src/main/java/io/mycat/config/Versions.java index 11a09dad9..2d860b266 100644 --- a/src/main/java/io/mycat/config/Versions.java +++ b/src/main/java/io/mycat/config/Versions.java @@ -32,7 +32,7 @@ public abstract class Versions { public static final byte PROTOCOL_VERSION = 10; /**服务器版本**/ - public static byte[] SERVER_VERSION = "5.6.29-mycat-1.6-BETA-20160929210846".getBytes(); + public static byte[] SERVER_VERSION = "5.6.29-mycat-0.1.1-DEV-20161128111259".getBytes(); public static void setServerVersion(String version) { byte[] mysqlVersionPart = version.getBytes(); diff --git a/src/main/java/io/mycat/config/model/TableConfig.java b/src/main/java/io/mycat/config/model/TableConfig.java index dd2ede1a3..e8bbf2d52 100644 --- a/src/main/java/io/mycat/config/model/TableConfig.java +++ b/src/main/java/io/mycat/config/model/TableConfig.java @@ -23,12 +23,15 @@ */ package io.mycat.config.model; -import java.util.*; -import java.util.concurrent.locks.ReentrantLock; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.Set; import java.util.concurrent.locks.ReentrantReadWriteLock; -import com.alibaba.druid.sql.ast.SQLDataType; import com.alibaba.druid.sql.ast.statement.SQLTableElement; + import io.mycat.config.model.rule.RuleConfig; import io.mycat.util.SplitUtil; diff --git a/src/main/java/io/mycat/config/table/structure/MySQLTableStructureDetector.java b/src/main/java/io/mycat/config/table/structure/MySQLTableStructureDetector.java deleted file mode 100644 index ef996d859..000000000 --- a/src/main/java/io/mycat/config/table/structure/MySQLTableStructureDetector.java +++ /dev/null @@ -1,108 +0,0 @@ -package io.mycat.config.table.structure; - -import io.mycat.MycatServer; -import io.mycat.backend.datasource.PhysicalDBNode; -import io.mycat.config.model.SchemaConfig; -import io.mycat.config.model.TableConfig; -import io.mycat.sqlengine.OneRawSQLQueryResultHandler; -import io.mycat.sqlengine.SQLJob; -import io.mycat.sqlengine.SQLQueryResult; -import io.mycat.sqlengine.SQLQueryResultListener; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.concurrent.ConcurrentHashMap; - -/** - * 表结构结果处理 - * - * @author Hash Zhang - * @version 1.0 - * @time 00:09:03 2016/5/11 - */ -public class MySQLTableStructureDetector implements Runnable { - private static final Logger LOGGER = LoggerFactory.getLogger(MySQLTableStructureDetector.class); - private static final String[] MYSQL_SHOW_CREATE_TABLE_COLMS = new String[]{ - "Table", - "Create Table"}; - private static final String sqlPrefix = "show create table "; - - @Override - public void run() { - for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) { - for (TableConfig table : schema.getTables().values()) { - for (String dataNode : table.getDataNodes()) { - try { - table.getReentrantReadWriteLock().writeLock().lock(); - ConcurrentHashMap> map = new ConcurrentHashMap<>(); - table.setDataNodeTableStructureSQLMap(map); - } finally { - table.getReentrantReadWriteLock().writeLock().unlock(); - } - OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLMS, new MySQLTableStructureListener(dataNode, table)); - resultHandler.setMark("Table Structure"); - PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode); - SQLJob sqlJob = new SQLJob(sqlPrefix + table.getName(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource()); - sqlJob.run(); - } - } - } - } - - private static class MySQLTableStructureListener implements SQLQueryResultListener>> { - private String dataNode; - private TableConfig table; - - public MySQLTableStructureListener(String dataNode, TableConfig table) { - this.dataNode = dataNode; - this.table = table; - } - - /** - * @param result - * @// TODO: 2016/5/11 检查表元素,来确定是哪个元素不一致,未来还有其他用 - */ - @Override - public void onResult(SQLQueryResult> result) { - try { - table.getReentrantReadWriteLock().writeLock().lock(); - if (!result.isSuccess()) { - LOGGER.warn("Can't get table " + table.getName() + "'s config from DataNode:" + dataNode + "! Maybe the table is not initialized!"); - return; - } - String currentSql = result.getResult().get(MYSQL_SHOW_CREATE_TABLE_COLMS[1]); - Map> dataNodeTableStructureSQLMap = table.getDataNodeTableStructureSQLMap(); - if (dataNodeTableStructureSQLMap.containsKey(currentSql)) { - List dataNodeList = dataNodeTableStructureSQLMap.get(currentSql); - dataNodeList.add(dataNode); - } else { - List dataNodeList = new LinkedList<>(); - dataNodeList.add(dataNode); - dataNodeTableStructureSQLMap.put(currentSql,dataNodeList); - } - if (dataNodeTableStructureSQLMap.size() > 1) { - LOGGER.warn("Table [" + table.getName() + "] structure are not consistent!"); - LOGGER.warn("Currently detected: "); - for(String sql : dataNodeTableStructureSQLMap.keySet()){ - StringBuilder stringBuilder = new StringBuilder(); - for(String dn : dataNodeTableStructureSQLMap.get(sql)){ - stringBuilder.append("DataNode:[").append(dn).append("]"); - } - stringBuilder.append(":").append(sql); - LOGGER.warn(stringBuilder.toString()); - } - } - } finally { - table.getReentrantReadWriteLock().writeLock().unlock(); - } - } - } - -// public static void main(String[] args) { -// System.out.println(UUID.randomUUID()); -// } -} diff --git a/src/main/java/io/mycat/config/table/structure/TableStructureProcessor.java b/src/main/java/io/mycat/config/table/structure/TableStructureProcessor.java deleted file mode 100644 index 11aa7941f..000000000 --- a/src/main/java/io/mycat/config/table/structure/TableStructureProcessor.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.mycat.config.table.structure; - -/** - * 将表结构持久化 - * - * @author Hash Zhang - * @version 1.0 - * @time 00:09:03 2016/5/11 - */ -public abstract class TableStructureProcessor { - public abstract void saveTableStructure(); - public abstract void loadTableStructure(); -} diff --git a/src/main/java/io/mycat/meta/IndexMeta.java b/src/main/java/io/mycat/meta/IndexMeta.java new file mode 100644 index 000000000..94401b96b --- /dev/null +++ b/src/main/java/io/mycat/meta/IndexMeta.java @@ -0,0 +1,44 @@ +package io.mycat.meta; + +import java.util.List; + +public class IndexMeta { + public static enum IndexType { + PRI, UNI, MUL + } + + private final String name; + private final String table; + private final IndexType indexType; + + private List indexColumns; + + public IndexMeta(String name, String table, String type, List columns) { + this.name = name; + this.table = table; + this.indexType = IndexType.valueOf(type); + if (indexType == null) { + throw new IllegalArgumentException("unknown index type " + type); + } + this.indexColumns = columns; + } + + public String getName() { + return name; + } + + public String getTable() { + return table; + } + + public IndexType getIndexType() { + return indexType; + } + + public boolean indexCanUsed(String column) { + if (indexColumns.size()>0 && indexColumns.get(0).equals(column)) { + return true; + } + return false; + } +} diff --git a/src/main/java/io/mycat/meta/MySQLTableStructureDetector.java b/src/main/java/io/mycat/meta/MySQLTableStructureDetector.java new file mode 100644 index 000000000..4278702d7 --- /dev/null +++ b/src/main/java/io/mycat/meta/MySQLTableStructureDetector.java @@ -0,0 +1,25 @@ +package io.mycat.meta; + +import io.mycat.MycatServer; +import io.mycat.config.model.SchemaConfig; +import io.mycat.config.model.TableConfig; +import io.mycat.meta.table.TableMetaHandler; + +/** + * 表结构结果处理 + * + * @author Hash Zhang + * @version 1.0 + * @time 00:09:03 2016/5/11 + */ +public class MySQLTableStructureDetector implements Runnable { + @Override + public void run() { + for (SchemaConfig schema : MycatServer.getInstance().getConfig().getSchemas().values()) { + for (TableConfig table : schema.getTables().values()) { + TableMetaHandler tableMeta = new TableMetaHandler(null, schema.getName(), table); + tableMeta.execute(); + } + } + } +} diff --git a/src/main/java/io/mycat/meta/ProxyMetaManager.java b/src/main/java/io/mycat/meta/ProxyMetaManager.java new file mode 100644 index 000000000..2923c730f --- /dev/null +++ b/src/main/java/io/mycat/meta/ProxyMetaManager.java @@ -0,0 +1,678 @@ +package io.mycat.meta; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import io.mycat.MycatServer; +import io.mycat.meta.protocol.MyCatMeta.TableMeta; +import io.mycat.meta.table.SchemaMetaHandler; + +public class ProxyMetaManager { + /* catalog,table,tablemeta */ + private final Map catalogs; + + public ProxyMetaManager() { + this.catalogs = new ConcurrentHashMap(); + } + + public Map getCatalogs() { + return catalogs; + } + + public SchemaMeta getSchema(String schema) { + if (schema == null) + return null; + return this.catalogs.get(schema); + } + + /** + * synchronously getting schemas from cluster. just for show databases + * command + * + * @return + */ + public synchronized Map getSchemas() { + return catalogs; + } + + /** + * @param schema + * @return 是否真实create + */ + public boolean createDatabase(String schema) { + SchemaMeta schemaMeta = catalogs.get(schema); + if (schemaMeta == null) { + schemaMeta = new SchemaMeta(); + catalogs.put(schema, schemaMeta); + return true; + } else { + return false; + } + } + + /** + * Checking the existence of the database in which the view is to be created + * + * @param db + * @return + */ + public boolean checkDbExists(String schema) { + if (schema == null) + return false; + return this.catalogs.containsKey(schema); + } + + public void addIndex(String schema, IndexMeta indexMeta) { + String name = indexMeta.getName() + "." + indexMeta.getTable(); + SchemaMeta schemaMeta = catalogs.get(schema); + if (schemaMeta != null) { + schemaMeta.addIndexMeta(name, indexMeta); + } + } + + public List getTableNames(String schema) { + List tbNames; + SchemaMeta schemaMeta = catalogs.get(schema); + if (schemaMeta == null) + return new ArrayList(); + tbNames = schemaMeta.getTables(); + Collections.sort(tbNames); + return tbNames; + } + + public void dropDatabase(String schema) { + catalogs.remove(schema); + } + +// private boolean containTable(String schema, String tbName) { +// SchemaMeta schemaMeta = catalogs.get(schema); +// if (schemaMeta == null) +// return false; +// return schemaMeta.getTableMetas().containsKey(tbName); +// } + + public void addTable(String schema, TableMeta tm) { + String tbName = tm.getTableName(); + SchemaMeta schemaMeta = catalogs.get(schema); + if (schemaMeta != null) { + schemaMeta.addTableMeta(tbName, tm); + } + } + + public void flushTable(String schema, TableMeta tm) { + String table = tm.getTableName(); + SchemaMeta schemaMeta = catalogs.get(schema); + if (schemaMeta != null) { + schemaMeta.addTableMeta(table, tm); + } + } + +// private void dropTable(String schema, String tbName) { +// SchemaMeta schemaMeta = catalogs.get(schema); +// if (schemaMeta != null) +// schemaMeta.dropTable(tbName); +// } + + + + public TableMeta getTableMeta(String schema, String tbName) { + return catalogs.get(schema).getTableMeta(tbName); + } + + + + public TableMeta removeTableMetaNosync(String schema, String tbName) { + SchemaMeta schemaMeta = catalogs.remove(schema); + if (schemaMeta == null) { + return null; + } + return schemaMeta.dropTable(tbName); + } + +// public void createView(String schema, String viewName, String createSql, List columns, PlanNode selectNode, +// ViewCreateMode mode, boolean writeToZk) { +// if (!checkDbExists(schema)) { +// throw new MySQLOutPutException(1049, "42000", String.format("Unknown database '%s'", schema)); +// } +// SchemaMeta schemaMeta = getSchema(schema); +// if (mode == ViewCreateMode.VIEW_CREATE_NEW && schemaMeta.getViewMeta(viewName) != null) +// throw new MySQLOutPutException(1050, "42S01", String.format("Table '%s' already exists", viewName)); +// if (mode == ViewCreateMode.VIEW_ALTER && schemaMeta.getViewMeta(viewName) == null) +// throw new MySQLOutPutException(1146, "42S02", String.format("Table '%s' doesn't exist", viewName)); +// // see mysql_create_view.cc for more check to do +// selectNode.setUpFields(); +// selectNode = SubQueryPreProcessor.optimize(selectNode); +// /* view list (list of view fields names) */ +// if (columns != null && columns.size() > 0) { +// List sels = selectNode.getColumnsSelected(); +// if (sels.size() != columns.size()) { +// throw new MySQLOutPutException(1353, "HY000", +// String.format("View's SELECT and view's field list have different column counts")); +// } +// for (int index = 0; index < columns.size(); index++) { +// Item sel = sels.get(index); +// String columnName = columns.get(index); +// if (!StringUtils.equals(sel.getItemName(), columnName)) +// sel.setAlias(columnName); +// } +// } +// ViewMeta vm = new ViewMeta(new ViewNode(schema, viewName, selectNode, createSql)); +// String path = DATA_ROOT_PATH + "/" + schema + "/view/" + viewName; +// byte[] data = null; +// try { +// data = createSql.getBytes("UTF-8"); +// } catch (UnsupportedEncodingException e) { +// // ignore +// } +// if (writeToZk) { +// switch (mode) { +// case VIEW_CREATE_NEW: +// zkClientDao.create(path, data, CreateMode.PERSISTENT); +// break; +// case VIEW_CREATE_OR_REPLACE: +// if (!zkClientDao.exists(path)) { +// zkClientDao.create(path, data, CreateMode.PERSISTENT); +// } else { +// zkClientDao.writeData(path, data); +// } +// break; +// default: +// zkClientDao.writeData(path, data); +// break; +// } +// } +// schemaMeta.addViewMeta(viewName, vm); +// } + +// @Override +// public void dropView(List> views, boolean ifExists) { +// StringBuilder unknownTable = new StringBuilder(); +// boolean isFirst = true; +// for (Pair view : views) { +// String schema = view.getKey(); +// String viewName = view.getValue(); +// if (!containsView(schema, viewName) && ifExists == false) { +// if (isFirst) { +// isFirst = false; +// } else { +// unknownTable.append(","); +// } +// unknownTable.append(SqlMaker.getFullName(schema, viewName)); +// } else { +// SchemaMeta schemaMeta = getSchema(schema); +// String path = DATA_ROOT_PATH + "/" + schema + "/view/" + viewName; +// schemaMeta.dropView(viewName); +// zkClientDao.delete(path); +// } +// +// } +// if (unknownTable.length() > 0) { +// throw new MySQLOutPutException(1051, "42S02", String.format("Unknown table '%s'", unknownTable.toString())); +// } +// } +// +// public boolean containsViewNoSync(String schema, String viewName) { +// SchemaMeta schemaMeta = this.catalogs.get(schema); +// if (schemaMeta == null) +// return false; +// return schemaMeta.containsView(viewName); +// } +// +// public boolean containsView(String schema, String viewName) { +// if (!checkDbExists(schema)) { +// return false; +// } else { +// String path = DATA_ROOT_PATH + "/" + schema + "/view/" + viewName; +// boolean zkExisted = zkClientDao.exists(path); +// boolean rst = getSchema(schema).containsView(viewName); +// if (zkExisted != rst) { +// if (zkExisted) { +// try { +// byte[] data = zkClientDao.readData(path); +// String sql = new String(data, "UTF-8"); +// compileView(schema, sql); +// } catch (UnsupportedEncodingException e) { +// // ignore +// } +// } else { +// getSchema(schema).dropView(viewName); +// } +// } +// return zkExisted; +// } +// } +// +// public void compileView(String schema, String sql) { +// try { +// SQLStatement stmt = new SQLParserDelegate().parse(sql); +// MySQLPlanNodeVisitor visitor = new MySQLPlanNodeVisitor(schema); +// visitor.setWriteToZk(false); +// stmt.accept(visitor); +// } catch (Exception e) { +// logger.debug("compile view for [" + sql + "] error:", e); +// } +// } +// +// /** +// * need call contains first +// * +// * @param user +// * @param schema +// * @param viewName +// * @return +// */ +// public String getViewSQL(String schema, String viewName) { +// SchemaMeta schemaMeta = getSchema(schema); +// if (schemaMeta == null) +// return null; +// ViewMeta viewMeta = schemaMeta.getViewMeta(viewName); +// if (viewMeta == null) +// return null; +// return viewMeta.getCreateSql(); +// } +// +// @Override +// public ViewNode getView(String schema, String viewName) { +// if (!containsViewNoSync(schema, viewName)) +// return null; +// SchemaMeta schemaMeta = getSchema(schema); +// ViewMeta vm = schemaMeta.getViewMeta(viewName); +// return vm.getViewNode(); +// } + + public void init() { + SchemaMetaHandler handler = new SchemaMetaHandler(MycatServer.getInstance().getConfig()); + handler.execute(); + } + +// /** +// * 有sql语句执行了,需要查看是否有DDL语句 +// * +// * @param sql +// */ +// // TODO +// public void noticeSql(String schema, String sql, ClientConnection c) { +// // 是否是ddl语句,是ddl语句的okresponse则需要通知tmmanager +// try { +// SQLStatement ast = new SQLParserDelegate().parse(sql); +// if (ast instanceof DDLStatement) { +// logger.info("current ddl sql is :" + sql); +// if (ast instanceof DDLCreateDatabaseStatement) { +// createDatabase((DDLCreateDatabaseStatement) ast); +// } else if (ast instanceof DDLDropDatabaseStatement) { +// dropDatabase((DDLDropDatabaseStatement) ast); +// } else if (ast instanceof DDLCreateTableStatement) { +// createTable(schema, (DDLCreateTableStatement) ast); +// } else if (ast instanceof DDLDropTableStatement) { +// dropTable(schema, (DDLDropTableStatement) ast); +// } else if (ast instanceof DDLTruncateTableStatement) { +// truncateTable(schema, (DDLTruncateTableStatement) ast); +// } else if (ast instanceof DDLAlterTableStatement) { +// alterTable(schema, (DDLAlterTableStatement) ast); +// } else { +// // to do further +// } +// } +// } catch (SQLSyntaxErrorException e) { +// // ignore +// } finally { +// c.unlockTable(); +// } +// +// } + +// private synchronized void createDatabase(DDLCreateDatabaseStatement ast) { +// String schema = ast.getDatabase().getIdTextUnescape(); +// createDatabase(schema); +// String path = DATA_ROOT_PATH + "/" + schema; +// if (zkClientDao.exists(path)) +// return; +// zkClientDao.create(path, null, CreateMode.PERSISTENT); +// String tblPath = path + "/table"; +// zkClientDao.create(tblPath, null, CreateMode.PERSISTENT); +// String viewPath = path + "/view"; +// zkClientDao.create(viewPath, null, CreateMode.PERSISTENT); +// } +// +// private synchronized void dropDatabase(DDLDropDatabaseStatement ast) { +// String schema = ast.getDatabase().getIdTextUnescape(); +// dropDatabase(schema); +// String path = DATA_ROOT_PATH + "/" + schema; +// if (zkClientDao.exists(path)) +// zkClientDao.deleteRecursive(path); +// } +// +// private synchronized void createTable(String schema, DDLCreateTableStatement ast) { +// Identifier tbIdentifier = ast.getTable(); +// if (tbIdentifier.getParent() != null) +// schema = tbIdentifier.getParent().getIdTextUnescape(); +// String tbName = ast.getTable().getIdTextUnescape(); +// boolean ifNotExist = ast.isIfNotExists(); +// if (ifNotExist && containTable(schema, tbName)) { +// return; +// } +// +// TableMeta.Builder tmBuilder = TableMeta.newBuilder(); +// List columnMetas = new LinkedList(); +// boolean hasAutoIncrement = false; +// if (ast.getCreateDefs() != null) { +// for (int i = 0; i < ast.getCreateDefs().size(); i++) { +// CreateDefinition createDef = ast.getCreateDefs().get(i); +// if (createDef.getColName() != null) { +// String colName = createDef.getColName().getIdTextUnescape(); +// ColumnDefinition columnDef = createDef.getColDef(); +// ColumnMeta colMeta = constructColumnMeta(tbName, colName, columnDef); +// if (colMeta.getAutoIncre()) { +// tmBuilder.setAiColPos(columnMetas.size()); +// hasAutoIncrement = true; +// } +// columnMetas.add(colMeta); +// } +// } +// } +// tmBuilder.setCatalog(schema).setTableName(tbName).addAllAllColumns(columnMetas); +// long offset = -1; +// if (ast.getTableOptions() != null && ast.getTableOptions().getAutoIncrement() != null) { +// Object obj = ast.getTableOptions().getAutoIncrement() +// .evaluation(ExprEvaluationUtil.getEvaluationParameters()); +// if (obj instanceof Number) { +// offset = ((Number) obj).longValue(); +// } +// tmBuilder.setAiOffset(offset); +// } +// long version = System.currentTimeMillis(); +// tmBuilder.setVersion(version); +// TableMeta tblMeta = tmBuilder.build(); +// if (hasAutoIncrement) { +// ProxyServer.getInstance().addSequence(schema, tbName, offset); +// } +// if (!standalone) { +// String path = DATA_ROOT_PATH + "/" + schema + "/table/" + tbName; +// zkClientDao.create(path, tblMeta.toByteArray(), CreateMode.PERSISTENT); +// } +// addTable(schema, tblMeta); +// } +// +// private synchronized void truncateTable(String schema, DDLTruncateTableStatement ast) { +// String table = ast.getTable().getIdTextUnescape(); +// TableMeta tbMeta = getTableMeta(schema, table); +// if (tbMeta == null) +// return; +// TableMeta.Builder tmBuilder = tbMeta.toBuilder(); +// long version = System.currentTimeMillis(); +// tmBuilder.setVersion(version); +// tbMeta = tmBuilder.build(); +// if (ProxyServer.getInstance().removeSequence(schema, table)) { +// long offset = tbMeta.getAiOffset(); +// ProxyServer.getInstance().addSequence(schema, table, offset); +// } +// if (!standalone) { +// String path = DATA_ROOT_PATH + "/" + schema + "/table/" + table; +// zkClientDao.writeData(path, tbMeta.toByteArray()); +// } +// addTable(schema, tbMeta); +// } +// +// private synchronized void dropTable(String schema, DDLDropTableStatement ast) { +// for (Identifier tbIndentifier : ast.getTableNames()) { +// if (tbIndentifier.getParent() != null) +// schema = tbIndentifier.getParent().getIdTextUnescape(); +// String table = tbIndentifier.getIdTextUnescape(); +// dropTable(schema, table); +// if (!standalone) { +// String path = DATA_ROOT_PATH + "/" + schema + "/table/" + table; +// if (zkClientDao.exists(path)) +// zkClientDao.delete(path); +// } +// ProxyServer.getInstance().removeSequence(schema, table); +// } +// } + +// +// public void renameTable(String schema, DDLRenameTableStatement ast) { +// for (Pair pair : ast.getList()) { +// String orgSchema = schema; +// String newSchema = schema; +// if (pair.getKey().getParent() != null) +// orgSchema = pair.getKey().getParent().getIdTextUnescape(); +// if (pair.getValue().getParent() != null) +// newSchema = pair.getValue().getParent().getIdTextUnescape(); +// String orgTable = pair.getKey().getIdTextUnescape(); +// String newTable = pair.getValue().getIdTextUnescape(); +// renameTable(orgSchema, orgTable, newSchema, newTable); +// } +// } + +// private synchronized void alterTable(String schema, DDLAlterTableStatement ast) { +// if (ast.getTable().getParent() != null) +// schema = ast.getTable().getParent().getIdTextUnescape(); +// String table = ast.getTable().getIdTextUnescape(); +// TableMeta orgTbMeta = getTableMeta(schema, table); +// if (orgTbMeta == null) +// return; +// TableMeta.Builder tmBuilder = orgTbMeta.toBuilder(); +// List cols = new ArrayList(); +// cols.addAll(orgTbMeta.getAllColumnsList()); +// for (AlterSpecification alter : ast.getAlters()) { +// if (alter instanceof AddColumn) { +// addColumn(orgTbMeta, cols, (AddColumn) alter); +// } else if (alter instanceof AddColumns) { +// addColumns(orgTbMeta, cols, (AddColumns) alter); +// } else if (alter instanceof ChangeColumn) { +// changeColumn(orgTbMeta, cols, (ChangeColumn) alter); +// } else if (alter instanceof DropColumn) { +// dropColumn(cols, (DropColumn) alter); +// } else if (alter instanceof ModifyColumn) { +// modifyColumn(orgTbMeta, cols, (ModifyColumn) alter); +// } else { +// // to do fur +// } +// } +// tmBuilder.clearAllColumns().addAllAllColumns(cols); +// long offset = -1; +// if (ast.getTableOptions() != null && ast.getTableOptions().getAutoIncrement() != null) { +// Object obj = ast.getTableOptions().getAutoIncrement() +// .evaluation(ExprEvaluationUtil.getEvaluationParameters()); +// if (obj instanceof Number) { +// offset = ((Number) obj).longValue(); +// } +// tmBuilder.setAiOffset(offset); +// } +// long version = System.currentTimeMillis(); +// tmBuilder.setVersion(version); +// tmBuilder.setType(1); +// TableMeta newTblMeta = tmBuilder.build(); +// /* add for view to rebuild */ +// onTableChange(schema, table); +// /* autoIncrement change */ +// if (offset != -1) { +// ProxyServer.getInstance().addSequence(schema, table, offset); +// } +// if (!standalone) { +// String path = DATA_ROOT_PATH + "/" + schema + "/table/" + table; +// zkClientDao.writeData(path, newTblMeta.toByteArray()); +// } +// addTable(schema, newTblMeta); +// } + + +// private void renameTable(String orgSchema, String orgTable, String newSchema, String newTable) { +// TableMeta orgTbMeta = removeTableMetaNosync(orgSchema, orgTable); +// if (orgTbMeta == null) +// return; +// List orgCols = orgTbMeta.getAllColumnsList(); +// List newCols = new ArrayList(); +// for (ColumnMeta orgCol : orgCols) { +// ColumnMeta.Builder cmBuilder = orgCol.toBuilder(); +// cmBuilder.setTableName(newTable); +// newCols.add(cmBuilder.build()); +// } +// TableMeta.Builder tmBuilder = orgTbMeta.toBuilder(); +// tmBuilder.setCatalog(newSchema).setTableName(newTable).clearAllColumns().addAllAllColumns(newCols); +// addTable(newSchema, tmBuilder.build()); +// } + +// private void addColumn(TableMeta tbMeta, List columnMetas, AddColumn addColumn) { +// String addColName = addColumn.getColumnName().getIdTextUnescape(); +// if (tbMeta.getColumn(addColName) == null) { +// ColumnMeta colMeta = constructColumnMeta(tbMeta.getTableName(), addColName, addColumn.getColumnDefine()); +// int index = -1; +// if (addColumn.isFirst()) { +// index = 0; +// } else if (addColumn.getAfterColumn() != null) { +// String afterColName = addColumn.getAfterColumn().getIdTextUnescape(); +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (afterColName.equalsIgnoreCase(colName)) { +// index = i + 1; +// break; +// } +// } +// if (index == -1) { +// throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "42S22", +// String.format("Unknown column '%s' in '%s'", afterColName, tbMeta.getTableName())); +// } +// } else { +// index = columnMetas.size(); +// } +// columnMetas.add(index, colMeta); +// } +// } +// +// private void addColumns(TableMeta tbMeta, List columnMetas, AddColumns addColumns) { +// for (Pair pair : addColumns.getColumns()) { +// String colName = pair.getKey().getIdTextUnescape(); +// if (tbMeta.getColumn(colName) == null) { +// ColumnMeta colMeta = constructColumnMeta(tbMeta.getTableName(), colName, pair.getValue()); +// columnMetas.add(colMeta); +// } +// } +// } +// +// private ColumnMeta constructColumnMeta(String tbName, String colName, ColumnDefinition columnDef) { +// ColumnMeta.Builder colBuilder = ColumnMeta.newBuilder(); +// colBuilder.setTableName(tbName).setName(colName); +// if (columnDef == null) { +// return colBuilder.build(); +// } +// colBuilder.setCanNull(!columnDef.isNotNull()); +// if (columnDef.getSpecialIndex() != null) { +// switch (columnDef.getSpecialIndex()) { +// case PRIMARY: +// colBuilder.setKey("PRI"); +// break; +// case UNIQUE: +// colBuilder.setKey("UNI"); +// break; +// } +// } +// if (columnDef.getDefaultValue() != null) { +// StringBuilder builder = new StringBuilder(); +// MySQLOutputASTVisitor visitor = new MySQLOutputASTVisitor(builder); +// columnDef.getDefaultValue().accept(visitor); +// colBuilder.setSdefault(builder.toString()); +// } +// colBuilder.setAutoIncre(columnDef.isAutoIncrement()); +// return colBuilder.build(); +// } +// +// private void changeColumn(TableMeta tbMeta, List columnMetas, ChangeColumn changeColumn) { +// String oldColName = changeColumn.getOldName().getIdTextUnescape(); +// String newColName = changeColumn.getNewName().getIdTextUnescape(); +// ColumnMeta colMeta = constructColumnMeta(tbMeta.getTableName(), newColName, changeColumn.getColDef()); +// int index = -1; +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (oldColName.equalsIgnoreCase(colName)) { +// index = i; +// columnMetas.remove(i); +// break; +// } +// } +// +// if (index == -1) { +// throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "42S22", +// String.format("Unknown column '%s' in '%s'", oldColName, tbMeta.getTableName())); +// } +// +// if (changeColumn.isFirst()) { +// index = 0; +// } else if (changeColumn.getAfterColumn() != null) { +// index = -1; +// String afterColName = changeColumn.getAfterColumn().getIdTextUnescape(); +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (afterColName.equalsIgnoreCase(colName)) { +// index = i + 1; +// break; +// } +// } +// +// if (index == -1) { +// throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "42S22", +// String.format("Unknown column '%s' in '%s'", afterColName, tbMeta.getTableName())); +// } +// } +// columnMetas.add(index, colMeta); +// } +// +// private void dropColumn(List columnMetas, DropColumn dropColumn) { +// String dropColName = dropColumn.getColName().getIdTextUnescape(); +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (dropColName.equalsIgnoreCase(colName)) { +// columnMetas.remove(i); +// return; +// } +// } +// } +// +// private void modifyColumn(TableMeta tbMeta, List columnMetas, ModifyColumn modifyColumn) { +// String modifyColName = modifyColumn.getColName().getIdTextUnescape(); +// ColumnMeta colMeta = constructColumnMeta(tbMeta.getTableName(), modifyColName, modifyColumn.getColDef()); +// int index = -1; +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (modifyColName.equalsIgnoreCase(colName)) { +// index = i; +// columnMetas.remove(i); +// break; +// } +// } +// +// if (index == -1) { +// throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "42S22", +// String.format("Unknown column '%s' in '%s'", modifyColName, tbMeta.getTableName())); +// } +// +// if (modifyColumn.isFirst()) { +// index = 0; +// } else if (modifyColumn.getAfterColumn() != null) { +// index = -1; +// String afterColName = modifyColumn.getAfterColumn().getIdTextUnescape(); +// for (int i = 0; i < columnMetas.size(); i++) { +// String colName = columnMetas.get(i).getName(); +// if (afterColName.equalsIgnoreCase(colName)) { +// index = i + 1; +// break; +// } +// } +// +// if (index == -1) { +// throw new MySQLOutPutException(ErrorCode.ER_BAD_FIELD_ERROR, "42S22", +// String.format("Unknown column '%s' in '%s'", modifyColName, tbMeta.getTableName())); +// } +// } +// +// columnMetas.add(index, colMeta); +// } + +// private void onTableChange(String schema, String tbName) { +// // TODO +// } + + +} diff --git a/src/main/java/io/mycat/meta/SchemaMeta.java b/src/main/java/io/mycat/meta/SchemaMeta.java new file mode 100644 index 000000000..d129c7df7 --- /dev/null +++ b/src/main/java/io/mycat/meta/SchemaMeta.java @@ -0,0 +1,74 @@ +package io.mycat.meta; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import io.mycat.meta.protocol.MyCatMeta.TableMeta; + +public class SchemaMeta { + + /** */ + private final Map tableMetas; +// private final Map viewMetas; + /** */ + private final Map indexMetas; + + public SchemaMeta() { + this.tableMetas = new ConcurrentHashMap(); +// this.viewMetas = new ConcurrentHashMap(); + this.indexMetas = new ConcurrentHashMap(); + } + + public Map getTableMetas() { + return tableMetas; + } + +// public Map getViewMetas() { +// return viewMetas; +// } + + public void addTableMeta(String tbName, TableMeta tblMeta) { + this.tableMetas.put(tbName, tblMeta); + } + + public TableMeta dropTable(String tbName) { + return this.tableMetas.remove(tbName); + } + + public TableMeta getTableMeta(String tbName) { + return this.tableMetas.get(tbName); + } + +// public boolean containsView(String viewName) { +// return this.viewMetas.containsKey(viewName); +// } +// +// public void addViewMeta(String viewName, ViewMeta viewMeta) { +// this.viewMetas.put(viewName, viewMeta); +// } +// +// public void dropView(String viewName) { +// this.viewMetas.remove(viewName); +// } + +// public ViewMeta getViewMeta(String viewName) { +// return this.viewMetas.get(viewName); +// } + + public void addIndexMeta(String name, IndexMeta indexMeta) { + this.indexMetas.put(name, indexMeta); + } + + public IndexMeta getIndexMeta(String name) { + return this.indexMetas.get(name); + } + + public List getTables() { + List tbList = new ArrayList(); + tbList.addAll(tableMetas.keySet()); +// tbList.addAll(viewMetas.keySet()); + return tbList; + } +} diff --git a/src/main/java/io/mycat/meta/protocol/MyCatMeta.java b/src/main/java/io/mycat/meta/protocol/MyCatMeta.java new file mode 100644 index 000000000..c35418873 --- /dev/null +++ b/src/main/java/io/mycat/meta/protocol/MyCatMeta.java @@ -0,0 +1,3825 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: MyCatMeta.protocol + +package io.mycat.meta.protocol; + +public final class MyCatMeta { + private MyCatMeta() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + } + /** + * Protobuf enum {@code io.mycat.meta.protocol.MySqlDataType} + */ + public enum MySqlDataType + implements com.google.protobuf.ProtocolMessageEnum { + /** + * DECIMAL = 0; + */ + DECIMAL(0, 0), + /** + * TINY = 1; + */ + TINY(1, 1), + /** + * SHORT = 2; + */ + SHORT(2, 2), + /** + * LONG = 3; + */ + LONG(3, 3), + /** + * FLOAT = 4; + */ + FLOAT(4, 4), + /** + * DOUBLE = 5; + */ + DOUBLE(5, 5), + /** + * NULL = 6; + */ + NULL(6, 6), + /** + * TIMESTAMP = 7; + */ + TIMESTAMP(7, 7), + /** + * LONGLONG = 8; + */ + LONGLONG(8, 8), + /** + * INT24 = 9; + */ + INT24(9, 9), + /** + * DATE = 10; + */ + DATE(10, 10), + /** + * TIME = 11; + */ + TIME(11, 11), + /** + * DATETIME = 12; + */ + DATETIME(12, 12), + /** + * YEAR = 13; + */ + YEAR(13, 13), + /** + * NEWDATE = 14; + */ + NEWDATE(14, 14), + /** + * VARCHAR = 15; + */ + VARCHAR(15, 15), + /** + * BIT = 16; + */ + BIT(16, 16), + /** + * TIMESTAMP2 = 17; + */ + TIMESTAMP2(17, 17), + /** + * DATETIME2 = 18; + */ + DATETIME2(18, 18), + /** + * TIME2 = 19; + */ + TIME2(19, 19), + /** + * NEWDECIMAL = 246; + */ + NEWDECIMAL(20, 246), + /** + * ENUM = 247; + */ + ENUM(21, 247), + /** + * SET = 248; + */ + SET(22, 248), + /** + * TINYBLOB = 249; + */ + TINYBLOB(23, 249), + /** + * MEDIUMBLOB = 250; + */ + MEDIUMBLOB(24, 250), + /** + * LONGBLOB = 251; + */ + LONGBLOB(25, 251), + /** + * BLOB = 252; + */ + BLOB(26, 252), + /** + * VARSTRING = 253; + */ + VARSTRING(27, 253), + /** + * STRING = 254; + */ + STRING(28, 254), + /** + * GEOMETRY = 255; + */ + GEOMETRY(29, 255), + ; + + /** + * DECIMAL = 0; + */ + public static final int DECIMAL_VALUE = 0; + /** + * TINY = 1; + */ + public static final int TINY_VALUE = 1; + /** + * SHORT = 2; + */ + public static final int SHORT_VALUE = 2; + /** + * LONG = 3; + */ + public static final int LONG_VALUE = 3; + /** + * FLOAT = 4; + */ + public static final int FLOAT_VALUE = 4; + /** + * DOUBLE = 5; + */ + public static final int DOUBLE_VALUE = 5; + /** + * NULL = 6; + */ + public static final int NULL_VALUE = 6; + /** + * TIMESTAMP = 7; + */ + public static final int TIMESTAMP_VALUE = 7; + /** + * LONGLONG = 8; + */ + public static final int LONGLONG_VALUE = 8; + /** + * INT24 = 9; + */ + public static final int INT24_VALUE = 9; + /** + * DATE = 10; + */ + public static final int DATE_VALUE = 10; + /** + * TIME = 11; + */ + public static final int TIME_VALUE = 11; + /** + * DATETIME = 12; + */ + public static final int DATETIME_VALUE = 12; + /** + * YEAR = 13; + */ + public static final int YEAR_VALUE = 13; + /** + * NEWDATE = 14; + */ + public static final int NEWDATE_VALUE = 14; + /** + * VARCHAR = 15; + */ + public static final int VARCHAR_VALUE = 15; + /** + * BIT = 16; + */ + public static final int BIT_VALUE = 16; + /** + * TIMESTAMP2 = 17; + */ + public static final int TIMESTAMP2_VALUE = 17; + /** + * DATETIME2 = 18; + */ + public static final int DATETIME2_VALUE = 18; + /** + * TIME2 = 19; + */ + public static final int TIME2_VALUE = 19; + /** + * NEWDECIMAL = 246; + */ + public static final int NEWDECIMAL_VALUE = 246; + /** + * ENUM = 247; + */ + public static final int ENUM_VALUE = 247; + /** + * SET = 248; + */ + public static final int SET_VALUE = 248; + /** + * TINYBLOB = 249; + */ + public static final int TINYBLOB_VALUE = 249; + /** + * MEDIUMBLOB = 250; + */ + public static final int MEDIUMBLOB_VALUE = 250; + /** + * LONGBLOB = 251; + */ + public static final int LONGBLOB_VALUE = 251; + /** + * BLOB = 252; + */ + public static final int BLOB_VALUE = 252; + /** + * VARSTRING = 253; + */ + public static final int VARSTRING_VALUE = 253; + /** + * STRING = 254; + */ + public static final int STRING_VALUE = 254; + /** + * GEOMETRY = 255; + */ + public static final int GEOMETRY_VALUE = 255; + + + public final int getNumber() { return value; } + + public static MySqlDataType valueOf(int value) { + switch (value) { + case 0: return DECIMAL; + case 1: return TINY; + case 2: return SHORT; + case 3: return LONG; + case 4: return FLOAT; + case 5: return DOUBLE; + case 6: return NULL; + case 7: return TIMESTAMP; + case 8: return LONGLONG; + case 9: return INT24; + case 10: return DATE; + case 11: return TIME; + case 12: return DATETIME; + case 13: return YEAR; + case 14: return NEWDATE; + case 15: return VARCHAR; + case 16: return BIT; + case 17: return TIMESTAMP2; + case 18: return DATETIME2; + case 19: return TIME2; + case 246: return NEWDECIMAL; + case 247: return ENUM; + case 248: return SET; + case 249: return TINYBLOB; + case 250: return MEDIUMBLOB; + case 251: return LONGBLOB; + case 252: return BLOB; + case 253: return VARSTRING; + case 254: return STRING; + case 255: return GEOMETRY; + default: return null; + } + } + + public static com.google.protobuf.Internal.EnumLiteMap + internalGetValueMap() { + return internalValueMap; + } + private static com.google.protobuf.Internal.EnumLiteMap + internalValueMap = + new com.google.protobuf.Internal.EnumLiteMap() { + public MySqlDataType findValueByNumber(int number) { + return MySqlDataType.valueOf(number); + } + }; + + public final com.google.protobuf.Descriptors.EnumValueDescriptor + getValueDescriptor() { + return getDescriptor().getValues().get(index); + } + public final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptorForType() { + return getDescriptor(); + } + public static final com.google.protobuf.Descriptors.EnumDescriptor + getDescriptor() { + return io.mycat.meta.protocol.MyCatMeta.getDescriptor().getEnumTypes().get(0); + } + + private static final MySqlDataType[] VALUES = values(); + + public static MySqlDataType valueOf( + com.google.protobuf.Descriptors.EnumValueDescriptor desc) { + if (desc.getType() != getDescriptor()) { + throw new java.lang.IllegalArgumentException( + "EnumValueDescriptor is not for this type."); + } + return VALUES[desc.getIndex()]; + } + + private final int index; + private final int value; + + private MySqlDataType(int index, int value) { + this.index = index; + this.value = value; + } + + // @@protoc_insertion_point(enum_scope:io.mycat.meta.protocol.MySqlDataType) + } + + public interface ColumnMetaOrBuilder extends + // @@protoc_insertion_point(interface_extends:io.mycat.meta.protocol.ColumnMeta) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string tableName = 1; + */ + boolean hasTableName(); + /** + * optional string tableName = 1; + */ + java.lang.String getTableName(); + /** + * optional string tableName = 1; + */ + com.google.protobuf.ByteString + getTableNameBytes(); + + /** + * optional string name = 2; + */ + boolean hasName(); + /** + * optional string name = 2; + */ + java.lang.String getName(); + /** + * optional string name = 2; + */ + com.google.protobuf.ByteString + getNameBytes(); + + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + boolean hasDataType(); + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + io.mycat.meta.protocol.MyCatMeta.MySqlDataType getDataType(); + + /** + * optional int32 length = 4; + */ + boolean hasLength(); + /** + * optional int32 length = 4; + */ + int getLength(); + + /** + * optional int32 precision = 5; + */ + boolean hasPrecision(); + /** + * optional int32 precision = 5; + */ + int getPrecision(); + + /** + * optional int32 scale = 6; + */ + boolean hasScale(); + /** + * optional int32 scale = 6; + */ + int getScale(); + + /** + * optional bool canNull = 7; + */ + boolean hasCanNull(); + /** + * optional bool canNull = 7; + */ + boolean getCanNull(); + + /** + * optional string sdefault = 8; + */ + boolean hasSdefault(); + /** + * optional string sdefault = 8; + */ + java.lang.String getSdefault(); + /** + * optional string sdefault = 8; + */ + com.google.protobuf.ByteString + getSdefaultBytes(); + + /** + * optional bool auto_incre = 9; + */ + boolean hasAutoIncre(); + /** + * optional bool auto_incre = 9; + */ + boolean getAutoIncre(); + + /** + * optional bool isUnsigned = 10; + */ + boolean hasIsUnsigned(); + /** + * optional bool isUnsigned = 10; + */ + boolean getIsUnsigned(); + + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + boolean hasKey(); + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + java.lang.String getKey(); + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + com.google.protobuf.ByteString + getKeyBytes(); + + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + boolean hasCharsetname(); + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + java.lang.String getCharsetname(); + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + com.google.protobuf.ByteString + getCharsetnameBytes(); + } + /** + * Protobuf type {@code io.mycat.meta.protocol.ColumnMeta} + */ + public static final class ColumnMeta extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:io.mycat.meta.protocol.ColumnMeta) + ColumnMetaOrBuilder { + // Use ColumnMeta.newBuilder() to construct. + private ColumnMeta(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private ColumnMeta(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final ColumnMeta defaultInstance; + public static ColumnMeta getDefaultInstance() { + return defaultInstance; + } + + public ColumnMeta getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private ColumnMeta( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + @SuppressWarnings("unused") + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + tableName_ = bs; + break; + } + case 18: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000002; + name_ = bs; + break; + } + case 24: { + int rawValue = input.readEnum(); + io.mycat.meta.protocol.MyCatMeta.MySqlDataType value = io.mycat.meta.protocol.MyCatMeta.MySqlDataType.valueOf(rawValue); + if (value == null) { + unknownFields.mergeVarintField(3, rawValue); + } else { + bitField0_ |= 0x00000004; + dataType_ = value; + } + break; + } + case 32: { + bitField0_ |= 0x00000008; + length_ = input.readInt32(); + break; + } + case 40: { + bitField0_ |= 0x00000010; + precision_ = input.readInt32(); + break; + } + case 48: { + bitField0_ |= 0x00000020; + scale_ = input.readInt32(); + break; + } + case 56: { + bitField0_ |= 0x00000040; + canNull_ = input.readBool(); + break; + } + case 66: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000080; + sdefault_ = bs; + break; + } + case 72: { + bitField0_ |= 0x00000100; + autoIncre_ = input.readBool(); + break; + } + case 80: { + bitField0_ |= 0x00000200; + isUnsigned_ = input.readBool(); + break; + } + case 90: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000400; + key_ = bs; + break; + } + case 98: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000800; + charsetname_ = bs; + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_ColumnMeta_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.mycat.meta.protocol.MyCatMeta.ColumnMeta.class, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public ColumnMeta parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new ColumnMeta(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + public static final int TABLENAME_FIELD_NUMBER = 1; + private java.lang.Object tableName_; + /** + * optional string tableName = 1; + */ + public boolean hasTableName() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string tableName = 1; + */ + public java.lang.String getTableName() { + java.lang.Object ref = tableName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + tableName_ = s; + } + return s; + } + } + /** + * optional string tableName = 1; + */ + public com.google.protobuf.ByteString + getTableNameBytes() { + java.lang.Object ref = tableName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + tableName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int NAME_FIELD_NUMBER = 2; + private java.lang.Object name_; + /** + * optional string name = 2; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string name = 2; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } + } + /** + * optional string name = 2; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int DATATYPE_FIELD_NUMBER = 3; + private io.mycat.meta.protocol.MyCatMeta.MySqlDataType dataType_; + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public boolean hasDataType() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public io.mycat.meta.protocol.MyCatMeta.MySqlDataType getDataType() { + return dataType_; + } + + public static final int LENGTH_FIELD_NUMBER = 4; + private int length_; + /** + * optional int32 length = 4; + */ + public boolean hasLength() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional int32 length = 4; + */ + public int getLength() { + return length_; + } + + public static final int PRECISION_FIELD_NUMBER = 5; + private int precision_; + /** + * optional int32 precision = 5; + */ + public boolean hasPrecision() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional int32 precision = 5; + */ + public int getPrecision() { + return precision_; + } + + public static final int SCALE_FIELD_NUMBER = 6; + private int scale_; + /** + * optional int32 scale = 6; + */ + public boolean hasScale() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional int32 scale = 6; + */ + public int getScale() { + return scale_; + } + + public static final int CANNULL_FIELD_NUMBER = 7; + private boolean canNull_; + /** + * optional bool canNull = 7; + */ + public boolean hasCanNull() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bool canNull = 7; + */ + public boolean getCanNull() { + return canNull_; + } + + public static final int SDEFAULT_FIELD_NUMBER = 8; + private java.lang.Object sdefault_; + /** + * optional string sdefault = 8; + */ + public boolean hasSdefault() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional string sdefault = 8; + */ + public java.lang.String getSdefault() { + java.lang.Object ref = sdefault_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + sdefault_ = s; + } + return s; + } + } + /** + * optional string sdefault = 8; + */ + public com.google.protobuf.ByteString + getSdefaultBytes() { + java.lang.Object ref = sdefault_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + sdefault_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int AUTO_INCRE_FIELD_NUMBER = 9; + private boolean autoIncre_; + /** + * optional bool auto_incre = 9; + */ + public boolean hasAutoIncre() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional bool auto_incre = 9; + */ + public boolean getAutoIncre() { + return autoIncre_; + } + + public static final int ISUNSIGNED_FIELD_NUMBER = 10; + private boolean isUnsigned_; + /** + * optional bool isUnsigned = 10; + */ + public boolean hasIsUnsigned() { + return ((bitField0_ & 0x00000200) == 0x00000200); + } + /** + * optional bool isUnsigned = 10; + */ + public boolean getIsUnsigned() { + return isUnsigned_; + } + + public static final int KEY_FIELD_NUMBER = 11; + private java.lang.Object key_; + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + public boolean hasKey() { + return ((bitField0_ & 0x00000400) == 0x00000400); + } + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + public java.lang.String getKey() { + java.lang.Object ref = key_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + key_ = s; + } + return s; + } + } + /** + * optional string key = 11 [default = ""]; + * + *
+     *有pri,unique
+     * 
+ */ + public com.google.protobuf.ByteString + getKeyBytes() { + java.lang.Object ref = key_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + key_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int CHARSETNAME_FIELD_NUMBER = 12; + private java.lang.Object charsetname_; + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public boolean hasCharsetname() { + return ((bitField0_ & 0x00000800) == 0x00000800); + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public java.lang.String getCharsetname() { + java.lang.Object ref = charsetname_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + charsetname_ = s; + } + return s; + } + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public com.google.protobuf.ByteString + getCharsetnameBytes() { + java.lang.Object ref = charsetname_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + charsetname_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + private void initFields() { + tableName_ = ""; + name_ = ""; + dataType_ = io.mycat.meta.protocol.MyCatMeta.MySqlDataType.DECIMAL; + length_ = 0; + precision_ = 0; + scale_ = 0; + canNull_ = false; + sdefault_ = ""; + autoIncre_ = false; + isUnsigned_ = false; + key_ = ""; + charsetname_ = "utf8"; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getTableNameBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getNameBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeEnum(3, dataType_.getNumber()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeInt32(4, length_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeInt32(5, precision_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeInt32(6, scale_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeBool(7, canNull_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + output.writeBytes(8, getSdefaultBytes()); + } + if (((bitField0_ & 0x00000100) == 0x00000100)) { + output.writeBool(9, autoIncre_); + } + if (((bitField0_ & 0x00000200) == 0x00000200)) { + output.writeBool(10, isUnsigned_); + } + if (((bitField0_ & 0x00000400) == 0x00000400)) { + output.writeBytes(11, getKeyBytes()); + } + if (((bitField0_ & 0x00000800) == 0x00000800)) { + output.writeBytes(12, getCharsetnameBytes()); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getTableNameBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getNameBytes()); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeEnumSize(3, dataType_.getNumber()); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(4, length_); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(5, precision_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(6, scale_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(7, canNull_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(8, getSdefaultBytes()); + } + if (((bitField0_ & 0x00000100) == 0x00000100)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(9, autoIncre_); + } + if (((bitField0_ & 0x00000200) == 0x00000200)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(10, isUnsigned_); + } + if (((bitField0_ & 0x00000400) == 0x00000400)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(11, getKeyBytes()); + } + if (((bitField0_ & 0x00000800) == 0x00000800)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(12, getCharsetnameBytes()); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.ColumnMeta parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(io.mycat.meta.protocol.MyCatMeta.ColumnMeta prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code io.mycat.meta.protocol.ColumnMeta} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:io.mycat.meta.protocol.ColumnMeta) + io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_ColumnMeta_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.mycat.meta.protocol.MyCatMeta.ColumnMeta.class, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder.class); + } + + // Construct using io.mycat.meta.protocol.MyCatMeta.ColumnMeta.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + tableName_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + name_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + dataType_ = io.mycat.meta.protocol.MyCatMeta.MySqlDataType.DECIMAL; + bitField0_ = (bitField0_ & ~0x00000004); + length_ = 0; + bitField0_ = (bitField0_ & ~0x00000008); + precision_ = 0; + bitField0_ = (bitField0_ & ~0x00000010); + scale_ = 0; + bitField0_ = (bitField0_ & ~0x00000020); + canNull_ = false; + bitField0_ = (bitField0_ & ~0x00000040); + sdefault_ = ""; + bitField0_ = (bitField0_ & ~0x00000080); + autoIncre_ = false; + bitField0_ = (bitField0_ & ~0x00000100); + isUnsigned_ = false; + bitField0_ = (bitField0_ & ~0x00000200); + key_ = ""; + bitField0_ = (bitField0_ & ~0x00000400); + charsetname_ = "utf8"; + bitField0_ = (bitField0_ & ~0x00000800); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor; + } + + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta getDefaultInstanceForType() { + return io.mycat.meta.protocol.MyCatMeta.ColumnMeta.getDefaultInstance(); + } + + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta build() { + io.mycat.meta.protocol.MyCatMeta.ColumnMeta result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta buildPartial() { + io.mycat.meta.protocol.MyCatMeta.ColumnMeta result = new io.mycat.meta.protocol.MyCatMeta.ColumnMeta(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.tableName_ = tableName_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.name_ = name_; + if (((from_bitField0_ & 0x00000004) == 0x00000004)) { + to_bitField0_ |= 0x00000004; + } + result.dataType_ = dataType_; + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000008; + } + result.length_ = length_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000010; + } + result.precision_ = precision_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000020; + } + result.scale_ = scale_; + if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + to_bitField0_ |= 0x00000040; + } + result.canNull_ = canNull_; + if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + to_bitField0_ |= 0x00000080; + } + result.sdefault_ = sdefault_; + if (((from_bitField0_ & 0x00000100) == 0x00000100)) { + to_bitField0_ |= 0x00000100; + } + result.autoIncre_ = autoIncre_; + if (((from_bitField0_ & 0x00000200) == 0x00000200)) { + to_bitField0_ |= 0x00000200; + } + result.isUnsigned_ = isUnsigned_; + if (((from_bitField0_ & 0x00000400) == 0x00000400)) { + to_bitField0_ |= 0x00000400; + } + result.key_ = key_; + if (((from_bitField0_ & 0x00000800) == 0x00000800)) { + to_bitField0_ |= 0x00000800; + } + result.charsetname_ = charsetname_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.mycat.meta.protocol.MyCatMeta.ColumnMeta) { + return mergeFrom((io.mycat.meta.protocol.MyCatMeta.ColumnMeta)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.mycat.meta.protocol.MyCatMeta.ColumnMeta other) { + if (other == io.mycat.meta.protocol.MyCatMeta.ColumnMeta.getDefaultInstance()) return this; + if (other.hasTableName()) { + bitField0_ |= 0x00000001; + tableName_ = other.tableName_; + onChanged(); + } + if (other.hasName()) { + bitField0_ |= 0x00000002; + name_ = other.name_; + onChanged(); + } + if (other.hasDataType()) { + setDataType(other.getDataType()); + } + if (other.hasLength()) { + setLength(other.getLength()); + } + if (other.hasPrecision()) { + setPrecision(other.getPrecision()); + } + if (other.hasScale()) { + setScale(other.getScale()); + } + if (other.hasCanNull()) { + setCanNull(other.getCanNull()); + } + if (other.hasSdefault()) { + bitField0_ |= 0x00000080; + sdefault_ = other.sdefault_; + onChanged(); + } + if (other.hasAutoIncre()) { + setAutoIncre(other.getAutoIncre()); + } + if (other.hasIsUnsigned()) { + setIsUnsigned(other.getIsUnsigned()); + } + if (other.hasKey()) { + bitField0_ |= 0x00000400; + key_ = other.key_; + onChanged(); + } + if (other.hasCharsetname()) { + bitField0_ |= 0x00000800; + charsetname_ = other.charsetname_; + onChanged(); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.mycat.meta.protocol.MyCatMeta.ColumnMeta parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.mycat.meta.protocol.MyCatMeta.ColumnMeta) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.lang.Object tableName_ = ""; + /** + * optional string tableName = 1; + */ + public boolean hasTableName() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string tableName = 1; + */ + public java.lang.String getTableName() { + java.lang.Object ref = tableName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + tableName_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string tableName = 1; + */ + public com.google.protobuf.ByteString + getTableNameBytes() { + java.lang.Object ref = tableName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + tableName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string tableName = 1; + */ + public Builder setTableName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + tableName_ = value; + onChanged(); + return this; + } + /** + * optional string tableName = 1; + */ + public Builder clearTableName() { + bitField0_ = (bitField0_ & ~0x00000001); + tableName_ = getDefaultInstance().getTableName(); + onChanged(); + return this; + } + /** + * optional string tableName = 1; + */ + public Builder setTableNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + tableName_ = value; + onChanged(); + return this; + } + + private java.lang.Object name_ = ""; + /** + * optional string name = 2; + */ + public boolean hasName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string name = 2; + */ + public java.lang.String getName() { + java.lang.Object ref = name_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + name_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string name = 2; + */ + public com.google.protobuf.ByteString + getNameBytes() { + java.lang.Object ref = name_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + name_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string name = 2; + */ + public Builder setName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + name_ = value; + onChanged(); + return this; + } + /** + * optional string name = 2; + */ + public Builder clearName() { + bitField0_ = (bitField0_ & ~0x00000002); + name_ = getDefaultInstance().getName(); + onChanged(); + return this; + } + /** + * optional string name = 2; + */ + public Builder setNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + name_ = value; + onChanged(); + return this; + } + + private io.mycat.meta.protocol.MyCatMeta.MySqlDataType dataType_ = io.mycat.meta.protocol.MyCatMeta.MySqlDataType.DECIMAL; + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public boolean hasDataType() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public io.mycat.meta.protocol.MyCatMeta.MySqlDataType getDataType() { + return dataType_; + } + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public Builder setDataType(io.mycat.meta.protocol.MyCatMeta.MySqlDataType value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000004; + dataType_ = value; + onChanged(); + return this; + } + /** + * optional .io.mycat.meta.protocol.MySqlDataType dataType = 3; + */ + public Builder clearDataType() { + bitField0_ = (bitField0_ & ~0x00000004); + dataType_ = io.mycat.meta.protocol.MyCatMeta.MySqlDataType.DECIMAL; + onChanged(); + return this; + } + + private int length_ ; + /** + * optional int32 length = 4; + */ + public boolean hasLength() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional int32 length = 4; + */ + public int getLength() { + return length_; + } + /** + * optional int32 length = 4; + */ + public Builder setLength(int value) { + bitField0_ |= 0x00000008; + length_ = value; + onChanged(); + return this; + } + /** + * optional int32 length = 4; + */ + public Builder clearLength() { + bitField0_ = (bitField0_ & ~0x00000008); + length_ = 0; + onChanged(); + return this; + } + + private int precision_ ; + /** + * optional int32 precision = 5; + */ + public boolean hasPrecision() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional int32 precision = 5; + */ + public int getPrecision() { + return precision_; + } + /** + * optional int32 precision = 5; + */ + public Builder setPrecision(int value) { + bitField0_ |= 0x00000010; + precision_ = value; + onChanged(); + return this; + } + /** + * optional int32 precision = 5; + */ + public Builder clearPrecision() { + bitField0_ = (bitField0_ & ~0x00000010); + precision_ = 0; + onChanged(); + return this; + } + + private int scale_ ; + /** + * optional int32 scale = 6; + */ + public boolean hasScale() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional int32 scale = 6; + */ + public int getScale() { + return scale_; + } + /** + * optional int32 scale = 6; + */ + public Builder setScale(int value) { + bitField0_ |= 0x00000020; + scale_ = value; + onChanged(); + return this; + } + /** + * optional int32 scale = 6; + */ + public Builder clearScale() { + bitField0_ = (bitField0_ & ~0x00000020); + scale_ = 0; + onChanged(); + return this; + } + + private boolean canNull_ ; + /** + * optional bool canNull = 7; + */ + public boolean hasCanNull() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional bool canNull = 7; + */ + public boolean getCanNull() { + return canNull_; + } + /** + * optional bool canNull = 7; + */ + public Builder setCanNull(boolean value) { + bitField0_ |= 0x00000040; + canNull_ = value; + onChanged(); + return this; + } + /** + * optional bool canNull = 7; + */ + public Builder clearCanNull() { + bitField0_ = (bitField0_ & ~0x00000040); + canNull_ = false; + onChanged(); + return this; + } + + private java.lang.Object sdefault_ = ""; + /** + * optional string sdefault = 8; + */ + public boolean hasSdefault() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional string sdefault = 8; + */ + public java.lang.String getSdefault() { + java.lang.Object ref = sdefault_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + sdefault_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string sdefault = 8; + */ + public com.google.protobuf.ByteString + getSdefaultBytes() { + java.lang.Object ref = sdefault_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + sdefault_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string sdefault = 8; + */ + public Builder setSdefault( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000080; + sdefault_ = value; + onChanged(); + return this; + } + /** + * optional string sdefault = 8; + */ + public Builder clearSdefault() { + bitField0_ = (bitField0_ & ~0x00000080); + sdefault_ = getDefaultInstance().getSdefault(); + onChanged(); + return this; + } + /** + * optional string sdefault = 8; + */ + public Builder setSdefaultBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000080; + sdefault_ = value; + onChanged(); + return this; + } + + private boolean autoIncre_ ; + /** + * optional bool auto_incre = 9; + */ + public boolean hasAutoIncre() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional bool auto_incre = 9; + */ + public boolean getAutoIncre() { + return autoIncre_; + } + /** + * optional bool auto_incre = 9; + */ + public Builder setAutoIncre(boolean value) { + bitField0_ |= 0x00000100; + autoIncre_ = value; + onChanged(); + return this; + } + /** + * optional bool auto_incre = 9; + */ + public Builder clearAutoIncre() { + bitField0_ = (bitField0_ & ~0x00000100); + autoIncre_ = false; + onChanged(); + return this; + } + + private boolean isUnsigned_ ; + /** + * optional bool isUnsigned = 10; + */ + public boolean hasIsUnsigned() { + return ((bitField0_ & 0x00000200) == 0x00000200); + } + /** + * optional bool isUnsigned = 10; + */ + public boolean getIsUnsigned() { + return isUnsigned_; + } + /** + * optional bool isUnsigned = 10; + */ + public Builder setIsUnsigned(boolean value) { + bitField0_ |= 0x00000200; + isUnsigned_ = value; + onChanged(); + return this; + } + /** + * optional bool isUnsigned = 10; + */ + public Builder clearIsUnsigned() { + bitField0_ = (bitField0_ & ~0x00000200); + isUnsigned_ = false; + onChanged(); + return this; + } + + private java.lang.Object key_ = ""; + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public boolean hasKey() { + return ((bitField0_ & 0x00000400) == 0x00000400); + } + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public java.lang.String getKey() { + java.lang.Object ref = key_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + key_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public com.google.protobuf.ByteString + getKeyBytes() { + java.lang.Object ref = key_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + key_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public Builder setKey( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000400; + key_ = value; + onChanged(); + return this; + } + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public Builder clearKey() { + bitField0_ = (bitField0_ & ~0x00000400); + key_ = getDefaultInstance().getKey(); + onChanged(); + return this; + } + /** + * optional string key = 11 [default = ""]; + * + *
+       *有pri,unique
+       * 
+ */ + public Builder setKeyBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000400; + key_ = value; + onChanged(); + return this; + } + + private java.lang.Object charsetname_ = "utf8"; + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public boolean hasCharsetname() { + return ((bitField0_ & 0x00000800) == 0x00000800); + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public java.lang.String getCharsetname() { + java.lang.Object ref = charsetname_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + charsetname_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public com.google.protobuf.ByteString + getCharsetnameBytes() { + java.lang.Object ref = charsetname_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + charsetname_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public Builder setCharsetname( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000800; + charsetname_ = value; + onChanged(); + return this; + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public Builder clearCharsetname() { + bitField0_ = (bitField0_ & ~0x00000800); + charsetname_ = getDefaultInstance().getCharsetname(); + onChanged(); + return this; + } + /** + * optional string charsetname = 12 [default = "utf8"]; + */ + public Builder setCharsetnameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000800; + charsetname_ = value; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:io.mycat.meta.protocol.ColumnMeta) + } + + static { + defaultInstance = new ColumnMeta(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:io.mycat.meta.protocol.ColumnMeta) + } + + public interface TableMetaOrBuilder extends + // @@protoc_insertion_point(interface_extends:io.mycat.meta.protocol.TableMeta) + com.google.protobuf.MessageOrBuilder { + + /** + * optional string catalog = 1; + */ + boolean hasCatalog(); + /** + * optional string catalog = 1; + */ + java.lang.String getCatalog(); + /** + * optional string catalog = 1; + */ + com.google.protobuf.ByteString + getCatalogBytes(); + + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + boolean hasTableName(); + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + java.lang.String getTableName(); + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + com.google.protobuf.ByteString + getTableNameBytes(); + + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + java.util.List + getAllColumnsList(); + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + io.mycat.meta.protocol.MyCatMeta.ColumnMeta getAllColumns(int index); + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + int getAllColumnsCount(); + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + java.util.List + getAllColumnsOrBuilderList(); + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder getAllColumnsOrBuilder( + int index); + + /** + * optional bool isView = 4 [default = false]; + */ + boolean hasIsView(); + /** + * optional bool isView = 4 [default = false]; + */ + boolean getIsView(); + + /** + * optional string createSql = 5; + */ + boolean hasCreateSql(); + /** + * optional string createSql = 5; + */ + java.lang.String getCreateSql(); + /** + * optional string createSql = 5; + */ + com.google.protobuf.ByteString + getCreateSqlBytes(); + + /** + * optional int64 version = 6; + */ + boolean hasVersion(); + /** + * optional int64 version = 6; + */ + long getVersion(); + + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + boolean hasAiOffset(); + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + long getAiOffset(); + + /** + * optional int32 type = 8; + */ + boolean hasType(); + /** + * optional int32 type = 8; + */ + int getType(); + + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + boolean hasAiColPos(); + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + int getAiColPos(); + } + /** + * Protobuf type {@code io.mycat.meta.protocol.TableMeta} + */ + public static final class TableMeta extends + com.google.protobuf.GeneratedMessage implements + // @@protoc_insertion_point(message_implements:io.mycat.meta.protocol.TableMeta) + TableMetaOrBuilder { + // Use TableMeta.newBuilder() to construct. + private TableMeta(com.google.protobuf.GeneratedMessage.Builder builder) { + super(builder); + this.unknownFields = builder.getUnknownFields(); + } + private TableMeta(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); } + + private static final TableMeta defaultInstance; + public static TableMeta getDefaultInstance() { + return defaultInstance; + } + + public TableMeta getDefaultInstanceForType() { + return defaultInstance; + } + + private final com.google.protobuf.UnknownFieldSet unknownFields; + @java.lang.Override + public final com.google.protobuf.UnknownFieldSet + getUnknownFields() { + return this.unknownFields; + } + private TableMeta( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + initFields(); + int mutable_bitField0_ = 0; + com.google.protobuf.UnknownFieldSet.Builder unknownFields = + com.google.protobuf.UnknownFieldSet.newBuilder(); + try { + boolean done = false; + while (!done) { + int tag = input.readTag(); + switch (tag) { + case 0: + done = true; + break; + default: { + if (!parseUnknownField(input, unknownFields, + extensionRegistry, tag)) { + done = true; + } + break; + } + case 10: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000001; + catalog_ = bs; + break; + } + case 18: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000002; + tableName_ = bs; + break; + } + case 26: { + if (!((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + allColumns_ = new java.util.ArrayList(); + mutable_bitField0_ |= 0x00000004; + } + allColumns_.add(input.readMessage(io.mycat.meta.protocol.MyCatMeta.ColumnMeta.PARSER, extensionRegistry)); + break; + } + case 32: { + bitField0_ |= 0x00000004; + isView_ = input.readBool(); + break; + } + case 42: { + com.google.protobuf.ByteString bs = input.readBytes(); + bitField0_ |= 0x00000008; + createSql_ = bs; + break; + } + case 48: { + bitField0_ |= 0x00000010; + version_ = input.readInt64(); + break; + } + case 56: { + bitField0_ |= 0x00000020; + aiOffset_ = input.readInt64(); + break; + } + case 64: { + bitField0_ |= 0x00000040; + type_ = input.readInt32(); + break; + } + case 72: { + bitField0_ |= 0x00000080; + aiColPos_ = input.readInt32(); + break; + } + } + } + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + throw e.setUnfinishedMessage(this); + } catch (java.io.IOException e) { + throw new com.google.protobuf.InvalidProtocolBufferException( + e.getMessage()).setUnfinishedMessage(this); + } finally { + if (((mutable_bitField0_ & 0x00000004) == 0x00000004)) { + allColumns_ = java.util.Collections.unmodifiableList(allColumns_); + } + this.unknownFields = unknownFields.build(); + makeExtensionsImmutable(); + } + } + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_TableMeta_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_TableMeta_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.mycat.meta.protocol.MyCatMeta.TableMeta.class, io.mycat.meta.protocol.MyCatMeta.TableMeta.Builder.class); + } + + public static com.google.protobuf.Parser PARSER = + new com.google.protobuf.AbstractParser() { + public TableMeta parsePartialFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return new TableMeta(input, extensionRegistry); + } + }; + + @java.lang.Override + public com.google.protobuf.Parser getParserForType() { + return PARSER; + } + + private int bitField0_; + public static final int CATALOG_FIELD_NUMBER = 1; + private java.lang.Object catalog_; + /** + * optional string catalog = 1; + */ + public boolean hasCatalog() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string catalog = 1; + */ + public java.lang.String getCatalog() { + java.lang.Object ref = catalog_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + catalog_ = s; + } + return s; + } + } + /** + * optional string catalog = 1; + */ + public com.google.protobuf.ByteString + getCatalogBytes() { + java.lang.Object ref = catalog_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + catalog_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int TABLENAME_FIELD_NUMBER = 2; + private java.lang.Object tableName_; + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + public boolean hasTableName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + public java.lang.String getTableName() { + java.lang.Object ref = tableName_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + tableName_ = s; + } + return s; + } + } + /** + * optional string tableName = 2; + * + *
+     *不带dbname的表名:如table1
+     * 
+ */ + public com.google.protobuf.ByteString + getTableNameBytes() { + java.lang.Object ref = tableName_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + tableName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int ALLCOLUMNS_FIELD_NUMBER = 3; + private java.util.List allColumns_; + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + public java.util.List getAllColumnsList() { + return allColumns_; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + public java.util.List + getAllColumnsOrBuilderList() { + return allColumns_; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + public int getAllColumnsCount() { + return allColumns_.size(); + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta getAllColumns(int index) { + return allColumns_.get(index); + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+     *所有的列属性,有序
+     * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder getAllColumnsOrBuilder( + int index) { + return allColumns_.get(index); + } + + public static final int ISVIEW_FIELD_NUMBER = 4; + private boolean isView_; + /** + * optional bool isView = 4 [default = false]; + */ + public boolean hasIsView() { + return ((bitField0_ & 0x00000004) == 0x00000004); + } + /** + * optional bool isView = 4 [default = false]; + */ + public boolean getIsView() { + return isView_; + } + + public static final int CREATESQL_FIELD_NUMBER = 5; + private java.lang.Object createSql_; + /** + * optional string createSql = 5; + */ + public boolean hasCreateSql() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional string createSql = 5; + */ + public java.lang.String getCreateSql() { + java.lang.Object ref = createSql_; + if (ref instanceof java.lang.String) { + return (java.lang.String) ref; + } else { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + createSql_ = s; + } + return s; + } + } + /** + * optional string createSql = 5; + */ + public com.google.protobuf.ByteString + getCreateSqlBytes() { + java.lang.Object ref = createSql_; + if (ref instanceof java.lang.String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + createSql_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + + public static final int VERSION_FIELD_NUMBER = 6; + private long version_; + /** + * optional int64 version = 6; + */ + public boolean hasVersion() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional int64 version = 6; + */ + public long getVersion() { + return version_; + } + + public static final int AIOFFSET_FIELD_NUMBER = 7; + private long aiOffset_; + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public boolean hasAiOffset() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public long getAiOffset() { + return aiOffset_; + } + + public static final int TYPE_FIELD_NUMBER = 8; + private int type_; + /** + * optional int32 type = 8; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional int32 type = 8; + */ + public int getType() { + return type_; + } + + public static final int AICOLPOS_FIELD_NUMBER = 9; + private int aiColPos_; + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public boolean hasAiColPos() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public int getAiColPos() { + return aiColPos_; + } + + private void initFields() { + catalog_ = ""; + tableName_ = ""; + allColumns_ = java.util.Collections.emptyList(); + isView_ = false; + createSql_ = ""; + version_ = 0L; + aiOffset_ = -1L; + type_ = 0; + aiColPos_ = -1; + } + private byte memoizedIsInitialized = -1; + public final boolean isInitialized() { + byte isInitialized = memoizedIsInitialized; + if (isInitialized == 1) return true; + if (isInitialized == 0) return false; + + memoizedIsInitialized = 1; + return true; + } + + public void writeTo(com.google.protobuf.CodedOutputStream output) + throws java.io.IOException { + getSerializedSize(); + if (((bitField0_ & 0x00000001) == 0x00000001)) { + output.writeBytes(1, getCatalogBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + output.writeBytes(2, getTableNameBytes()); + } + for (int i = 0; i < allColumns_.size(); i++) { + output.writeMessage(3, allColumns_.get(i)); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + output.writeBool(4, isView_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + output.writeBytes(5, getCreateSqlBytes()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + output.writeInt64(6, version_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + output.writeInt64(7, aiOffset_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + output.writeInt32(8, type_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + output.writeInt32(9, aiColPos_); + } + getUnknownFields().writeTo(output); + } + + private int memoizedSerializedSize = -1; + public int getSerializedSize() { + int size = memoizedSerializedSize; + if (size != -1) return size; + + size = 0; + if (((bitField0_ & 0x00000001) == 0x00000001)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(1, getCatalogBytes()); + } + if (((bitField0_ & 0x00000002) == 0x00000002)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(2, getTableNameBytes()); + } + for (int i = 0; i < allColumns_.size(); i++) { + size += com.google.protobuf.CodedOutputStream + .computeMessageSize(3, allColumns_.get(i)); + } + if (((bitField0_ & 0x00000004) == 0x00000004)) { + size += com.google.protobuf.CodedOutputStream + .computeBoolSize(4, isView_); + } + if (((bitField0_ & 0x00000008) == 0x00000008)) { + size += com.google.protobuf.CodedOutputStream + .computeBytesSize(5, getCreateSqlBytes()); + } + if (((bitField0_ & 0x00000010) == 0x00000010)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(6, version_); + } + if (((bitField0_ & 0x00000020) == 0x00000020)) { + size += com.google.protobuf.CodedOutputStream + .computeInt64Size(7, aiOffset_); + } + if (((bitField0_ & 0x00000040) == 0x00000040)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(8, type_); + } + if (((bitField0_ & 0x00000080) == 0x00000080)) { + size += com.google.protobuf.CodedOutputStream + .computeInt32Size(9, aiColPos_); + } + size += getUnknownFields().getSerializedSize(); + memoizedSerializedSize = size; + return size; + } + + private static final long serialVersionUID = 0L; + @java.lang.Override + protected java.lang.Object writeReplace() + throws java.io.ObjectStreamException { + return super.writeReplace(); + } + + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + com.google.protobuf.ByteString data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + com.google.protobuf.ByteString data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom(byte[] data) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + byte[] data, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws com.google.protobuf.InvalidProtocolBufferException { + return PARSER.parseFrom(data, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseDelimitedFrom(java.io.InputStream input) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseDelimitedFrom( + java.io.InputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseDelimitedFrom(input, extensionRegistry); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + com.google.protobuf.CodedInputStream input) + throws java.io.IOException { + return PARSER.parseFrom(input); + } + public static io.mycat.meta.protocol.MyCatMeta.TableMeta parseFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + return PARSER.parseFrom(input, extensionRegistry); + } + + public static Builder newBuilder() { return Builder.create(); } + public Builder newBuilderForType() { return newBuilder(); } + public static Builder newBuilder(io.mycat.meta.protocol.MyCatMeta.TableMeta prototype) { + return newBuilder().mergeFrom(prototype); + } + public Builder toBuilder() { return newBuilder(this); } + + @java.lang.Override + protected Builder newBuilderForType( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + Builder builder = new Builder(parent); + return builder; + } + /** + * Protobuf type {@code io.mycat.meta.protocol.TableMeta} + */ + public static final class Builder extends + com.google.protobuf.GeneratedMessage.Builder implements + // @@protoc_insertion_point(builder_implements:io.mycat.meta.protocol.TableMeta) + io.mycat.meta.protocol.MyCatMeta.TableMetaOrBuilder { + public static final com.google.protobuf.Descriptors.Descriptor + getDescriptor() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_TableMeta_descriptor; + } + + protected com.google.protobuf.GeneratedMessage.FieldAccessorTable + internalGetFieldAccessorTable() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_TableMeta_fieldAccessorTable + .ensureFieldAccessorsInitialized( + io.mycat.meta.protocol.MyCatMeta.TableMeta.class, io.mycat.meta.protocol.MyCatMeta.TableMeta.Builder.class); + } + + // Construct using io.mycat.meta.protocol.MyCatMeta.TableMeta.newBuilder() + private Builder() { + maybeForceBuilderInitialization(); + } + + private Builder( + com.google.protobuf.GeneratedMessage.BuilderParent parent) { + super(parent); + maybeForceBuilderInitialization(); + } + private void maybeForceBuilderInitialization() { + if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) { + getAllColumnsFieldBuilder(); + } + } + private static Builder create() { + return new Builder(); + } + + public Builder clear() { + super.clear(); + catalog_ = ""; + bitField0_ = (bitField0_ & ~0x00000001); + tableName_ = ""; + bitField0_ = (bitField0_ & ~0x00000002); + if (allColumnsBuilder_ == null) { + allColumns_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + } else { + allColumnsBuilder_.clear(); + } + isView_ = false; + bitField0_ = (bitField0_ & ~0x00000008); + createSql_ = ""; + bitField0_ = (bitField0_ & ~0x00000010); + version_ = 0L; + bitField0_ = (bitField0_ & ~0x00000020); + aiOffset_ = -1L; + bitField0_ = (bitField0_ & ~0x00000040); + type_ = 0; + bitField0_ = (bitField0_ & ~0x00000080); + aiColPos_ = -1; + bitField0_ = (bitField0_ & ~0x00000100); + return this; + } + + public Builder clone() { + return create().mergeFrom(buildPartial()); + } + + public com.google.protobuf.Descriptors.Descriptor + getDescriptorForType() { + return io.mycat.meta.protocol.MyCatMeta.internal_static_io_mycat_meta_protocol_TableMeta_descriptor; + } + + public io.mycat.meta.protocol.MyCatMeta.TableMeta getDefaultInstanceForType() { + return io.mycat.meta.protocol.MyCatMeta.TableMeta.getDefaultInstance(); + } + + public io.mycat.meta.protocol.MyCatMeta.TableMeta build() { + io.mycat.meta.protocol.MyCatMeta.TableMeta result = buildPartial(); + if (!result.isInitialized()) { + throw newUninitializedMessageException(result); + } + return result; + } + + public io.mycat.meta.protocol.MyCatMeta.TableMeta buildPartial() { + io.mycat.meta.protocol.MyCatMeta.TableMeta result = new io.mycat.meta.protocol.MyCatMeta.TableMeta(this); + int from_bitField0_ = bitField0_; + int to_bitField0_ = 0; + if (((from_bitField0_ & 0x00000001) == 0x00000001)) { + to_bitField0_ |= 0x00000001; + } + result.catalog_ = catalog_; + if (((from_bitField0_ & 0x00000002) == 0x00000002)) { + to_bitField0_ |= 0x00000002; + } + result.tableName_ = tableName_; + if (allColumnsBuilder_ == null) { + if (((bitField0_ & 0x00000004) == 0x00000004)) { + allColumns_ = java.util.Collections.unmodifiableList(allColumns_); + bitField0_ = (bitField0_ & ~0x00000004); + } + result.allColumns_ = allColumns_; + } else { + result.allColumns_ = allColumnsBuilder_.build(); + } + if (((from_bitField0_ & 0x00000008) == 0x00000008)) { + to_bitField0_ |= 0x00000004; + } + result.isView_ = isView_; + if (((from_bitField0_ & 0x00000010) == 0x00000010)) { + to_bitField0_ |= 0x00000008; + } + result.createSql_ = createSql_; + if (((from_bitField0_ & 0x00000020) == 0x00000020)) { + to_bitField0_ |= 0x00000010; + } + result.version_ = version_; + if (((from_bitField0_ & 0x00000040) == 0x00000040)) { + to_bitField0_ |= 0x00000020; + } + result.aiOffset_ = aiOffset_; + if (((from_bitField0_ & 0x00000080) == 0x00000080)) { + to_bitField0_ |= 0x00000040; + } + result.type_ = type_; + if (((from_bitField0_ & 0x00000100) == 0x00000100)) { + to_bitField0_ |= 0x00000080; + } + result.aiColPos_ = aiColPos_; + result.bitField0_ = to_bitField0_; + onBuilt(); + return result; + } + + public Builder mergeFrom(com.google.protobuf.Message other) { + if (other instanceof io.mycat.meta.protocol.MyCatMeta.TableMeta) { + return mergeFrom((io.mycat.meta.protocol.MyCatMeta.TableMeta)other); + } else { + super.mergeFrom(other); + return this; + } + } + + public Builder mergeFrom(io.mycat.meta.protocol.MyCatMeta.TableMeta other) { + if (other == io.mycat.meta.protocol.MyCatMeta.TableMeta.getDefaultInstance()) return this; + if (other.hasCatalog()) { + bitField0_ |= 0x00000001; + catalog_ = other.catalog_; + onChanged(); + } + if (other.hasTableName()) { + bitField0_ |= 0x00000002; + tableName_ = other.tableName_; + onChanged(); + } + if (allColumnsBuilder_ == null) { + if (!other.allColumns_.isEmpty()) { + if (allColumns_.isEmpty()) { + allColumns_ = other.allColumns_; + bitField0_ = (bitField0_ & ~0x00000004); + } else { + ensureAllColumnsIsMutable(); + allColumns_.addAll(other.allColumns_); + } + onChanged(); + } + } else { + if (!other.allColumns_.isEmpty()) { + if (allColumnsBuilder_.isEmpty()) { + allColumnsBuilder_.dispose(); + allColumnsBuilder_ = null; + allColumns_ = other.allColumns_; + bitField0_ = (bitField0_ & ~0x00000004); + allColumnsBuilder_ = + com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders ? + getAllColumnsFieldBuilder() : null; + } else { + allColumnsBuilder_.addAllMessages(other.allColumns_); + } + } + } + if (other.hasIsView()) { + setIsView(other.getIsView()); + } + if (other.hasCreateSql()) { + bitField0_ |= 0x00000010; + createSql_ = other.createSql_; + onChanged(); + } + if (other.hasVersion()) { + setVersion(other.getVersion()); + } + if (other.hasAiOffset()) { + setAiOffset(other.getAiOffset()); + } + if (other.hasType()) { + setType(other.getType()); + } + if (other.hasAiColPos()) { + setAiColPos(other.getAiColPos()); + } + this.mergeUnknownFields(other.getUnknownFields()); + return this; + } + + public final boolean isInitialized() { + return true; + } + + public Builder mergeFrom( + com.google.protobuf.CodedInputStream input, + com.google.protobuf.ExtensionRegistryLite extensionRegistry) + throws java.io.IOException { + io.mycat.meta.protocol.MyCatMeta.TableMeta parsedMessage = null; + try { + parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry); + } catch (com.google.protobuf.InvalidProtocolBufferException e) { + parsedMessage = (io.mycat.meta.protocol.MyCatMeta.TableMeta) e.getUnfinishedMessage(); + throw e; + } finally { + if (parsedMessage != null) { + mergeFrom(parsedMessage); + } + } + return this; + } + private int bitField0_; + + private java.lang.Object catalog_ = ""; + /** + * optional string catalog = 1; + */ + public boolean hasCatalog() { + return ((bitField0_ & 0x00000001) == 0x00000001); + } + /** + * optional string catalog = 1; + */ + public java.lang.String getCatalog() { + java.lang.Object ref = catalog_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + catalog_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string catalog = 1; + */ + public com.google.protobuf.ByteString + getCatalogBytes() { + java.lang.Object ref = catalog_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + catalog_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string catalog = 1; + */ + public Builder setCatalog( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + catalog_ = value; + onChanged(); + return this; + } + /** + * optional string catalog = 1; + */ + public Builder clearCatalog() { + bitField0_ = (bitField0_ & ~0x00000001); + catalog_ = getDefaultInstance().getCatalog(); + onChanged(); + return this; + } + /** + * optional string catalog = 1; + */ + public Builder setCatalogBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000001; + catalog_ = value; + onChanged(); + return this; + } + + private java.lang.Object tableName_ = ""; + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public boolean hasTableName() { + return ((bitField0_ & 0x00000002) == 0x00000002); + } + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public java.lang.String getTableName() { + java.lang.Object ref = tableName_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + tableName_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public com.google.protobuf.ByteString + getTableNameBytes() { + java.lang.Object ref = tableName_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + tableName_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public Builder setTableName( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + tableName_ = value; + onChanged(); + return this; + } + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public Builder clearTableName() { + bitField0_ = (bitField0_ & ~0x00000002); + tableName_ = getDefaultInstance().getTableName(); + onChanged(); + return this; + } + /** + * optional string tableName = 2; + * + *
+       *不带dbname的表名:如table1
+       * 
+ */ + public Builder setTableNameBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000002; + tableName_ = value; + onChanged(); + return this; + } + + private java.util.List allColumns_ = + java.util.Collections.emptyList(); + private void ensureAllColumnsIsMutable() { + if (!((bitField0_ & 0x00000004) == 0x00000004)) { + allColumns_ = new java.util.ArrayList(allColumns_); + bitField0_ |= 0x00000004; + } + } + + private com.google.protobuf.RepeatedFieldBuilder< + io.mycat.meta.protocol.MyCatMeta.ColumnMeta, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder, io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder> allColumnsBuilder_; + + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public java.util.List getAllColumnsList() { + if (allColumnsBuilder_ == null) { + return java.util.Collections.unmodifiableList(allColumns_); + } else { + return allColumnsBuilder_.getMessageList(); + } + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public int getAllColumnsCount() { + if (allColumnsBuilder_ == null) { + return allColumns_.size(); + } else { + return allColumnsBuilder_.getCount(); + } + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta getAllColumns(int index) { + if (allColumnsBuilder_ == null) { + return allColumns_.get(index); + } else { + return allColumnsBuilder_.getMessage(index); + } + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder setAllColumns( + int index, io.mycat.meta.protocol.MyCatMeta.ColumnMeta value) { + if (allColumnsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureAllColumnsIsMutable(); + allColumns_.set(index, value); + onChanged(); + } else { + allColumnsBuilder_.setMessage(index, value); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder setAllColumns( + int index, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder builderForValue) { + if (allColumnsBuilder_ == null) { + ensureAllColumnsIsMutable(); + allColumns_.set(index, builderForValue.build()); + onChanged(); + } else { + allColumnsBuilder_.setMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder addAllColumns(io.mycat.meta.protocol.MyCatMeta.ColumnMeta value) { + if (allColumnsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureAllColumnsIsMutable(); + allColumns_.add(value); + onChanged(); + } else { + allColumnsBuilder_.addMessage(value); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder addAllColumns( + int index, io.mycat.meta.protocol.MyCatMeta.ColumnMeta value) { + if (allColumnsBuilder_ == null) { + if (value == null) { + throw new NullPointerException(); + } + ensureAllColumnsIsMutable(); + allColumns_.add(index, value); + onChanged(); + } else { + allColumnsBuilder_.addMessage(index, value); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder addAllColumns( + io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder builderForValue) { + if (allColumnsBuilder_ == null) { + ensureAllColumnsIsMutable(); + allColumns_.add(builderForValue.build()); + onChanged(); + } else { + allColumnsBuilder_.addMessage(builderForValue.build()); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder addAllColumns( + int index, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder builderForValue) { + if (allColumnsBuilder_ == null) { + ensureAllColumnsIsMutable(); + allColumns_.add(index, builderForValue.build()); + onChanged(); + } else { + allColumnsBuilder_.addMessage(index, builderForValue.build()); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder addAllAllColumns( + java.lang.Iterable values) { + if (allColumnsBuilder_ == null) { + ensureAllColumnsIsMutable(); + com.google.protobuf.AbstractMessageLite.Builder.addAll( + values, allColumns_); + onChanged(); + } else { + allColumnsBuilder_.addAllMessages(values); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder clearAllColumns() { + if (allColumnsBuilder_ == null) { + allColumns_ = java.util.Collections.emptyList(); + bitField0_ = (bitField0_ & ~0x00000004); + onChanged(); + } else { + allColumnsBuilder_.clear(); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public Builder removeAllColumns(int index) { + if (allColumnsBuilder_ == null) { + ensureAllColumnsIsMutable(); + allColumns_.remove(index); + onChanged(); + } else { + allColumnsBuilder_.remove(index); + } + return this; + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder getAllColumnsBuilder( + int index) { + return getAllColumnsFieldBuilder().getBuilder(index); + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder getAllColumnsOrBuilder( + int index) { + if (allColumnsBuilder_ == null) { + return allColumns_.get(index); } else { + return allColumnsBuilder_.getMessageOrBuilder(index); + } + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public java.util.List + getAllColumnsOrBuilderList() { + if (allColumnsBuilder_ != null) { + return allColumnsBuilder_.getMessageOrBuilderList(); + } else { + return java.util.Collections.unmodifiableList(allColumns_); + } + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder addAllColumnsBuilder() { + return getAllColumnsFieldBuilder().addBuilder( + io.mycat.meta.protocol.MyCatMeta.ColumnMeta.getDefaultInstance()); + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder addAllColumnsBuilder( + int index) { + return getAllColumnsFieldBuilder().addBuilder( + index, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.getDefaultInstance()); + } + /** + * repeated .io.mycat.meta.protocol.ColumnMeta allColumns = 3; + * + *
+       *所有的列属性,有序
+       * 
+ */ + public java.util.List + getAllColumnsBuilderList() { + return getAllColumnsFieldBuilder().getBuilderList(); + } + private com.google.protobuf.RepeatedFieldBuilder< + io.mycat.meta.protocol.MyCatMeta.ColumnMeta, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder, io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder> + getAllColumnsFieldBuilder() { + if (allColumnsBuilder_ == null) { + allColumnsBuilder_ = new com.google.protobuf.RepeatedFieldBuilder< + io.mycat.meta.protocol.MyCatMeta.ColumnMeta, io.mycat.meta.protocol.MyCatMeta.ColumnMeta.Builder, io.mycat.meta.protocol.MyCatMeta.ColumnMetaOrBuilder>( + allColumns_, + ((bitField0_ & 0x00000004) == 0x00000004), + getParentForChildren(), + isClean()); + allColumns_ = null; + } + return allColumnsBuilder_; + } + + private boolean isView_ ; + /** + * optional bool isView = 4 [default = false]; + */ + public boolean hasIsView() { + return ((bitField0_ & 0x00000008) == 0x00000008); + } + /** + * optional bool isView = 4 [default = false]; + */ + public boolean getIsView() { + return isView_; + } + /** + * optional bool isView = 4 [default = false]; + */ + public Builder setIsView(boolean value) { + bitField0_ |= 0x00000008; + isView_ = value; + onChanged(); + return this; + } + /** + * optional bool isView = 4 [default = false]; + */ + public Builder clearIsView() { + bitField0_ = (bitField0_ & ~0x00000008); + isView_ = false; + onChanged(); + return this; + } + + private java.lang.Object createSql_ = ""; + /** + * optional string createSql = 5; + */ + public boolean hasCreateSql() { + return ((bitField0_ & 0x00000010) == 0x00000010); + } + /** + * optional string createSql = 5; + */ + public java.lang.String getCreateSql() { + java.lang.Object ref = createSql_; + if (!(ref instanceof java.lang.String)) { + com.google.protobuf.ByteString bs = + (com.google.protobuf.ByteString) ref; + java.lang.String s = bs.toStringUtf8(); + if (bs.isValidUtf8()) { + createSql_ = s; + } + return s; + } else { + return (java.lang.String) ref; + } + } + /** + * optional string createSql = 5; + */ + public com.google.protobuf.ByteString + getCreateSqlBytes() { + java.lang.Object ref = createSql_; + if (ref instanceof String) { + com.google.protobuf.ByteString b = + com.google.protobuf.ByteString.copyFromUtf8( + (java.lang.String) ref); + createSql_ = b; + return b; + } else { + return (com.google.protobuf.ByteString) ref; + } + } + /** + * optional string createSql = 5; + */ + public Builder setCreateSql( + java.lang.String value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + createSql_ = value; + onChanged(); + return this; + } + /** + * optional string createSql = 5; + */ + public Builder clearCreateSql() { + bitField0_ = (bitField0_ & ~0x00000010); + createSql_ = getDefaultInstance().getCreateSql(); + onChanged(); + return this; + } + /** + * optional string createSql = 5; + */ + public Builder setCreateSqlBytes( + com.google.protobuf.ByteString value) { + if (value == null) { + throw new NullPointerException(); + } + bitField0_ |= 0x00000010; + createSql_ = value; + onChanged(); + return this; + } + + private long version_ ; + /** + * optional int64 version = 6; + */ + public boolean hasVersion() { + return ((bitField0_ & 0x00000020) == 0x00000020); + } + /** + * optional int64 version = 6; + */ + public long getVersion() { + return version_; + } + /** + * optional int64 version = 6; + */ + public Builder setVersion(long value) { + bitField0_ |= 0x00000020; + version_ = value; + onChanged(); + return this; + } + /** + * optional int64 version = 6; + */ + public Builder clearVersion() { + bitField0_ = (bitField0_ & ~0x00000020); + version_ = 0L; + onChanged(); + return this; + } + + private long aiOffset_ = -1L; + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public boolean hasAiOffset() { + return ((bitField0_ & 0x00000040) == 0x00000040); + } + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public long getAiOffset() { + return aiOffset_; + } + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public Builder setAiOffset(long value) { + bitField0_ |= 0x00000040; + aiOffset_ = value; + onChanged(); + return this; + } + /** + * optional int64 aiOffset = 7 [default = -1]; + */ + public Builder clearAiOffset() { + bitField0_ = (bitField0_ & ~0x00000040); + aiOffset_ = -1L; + onChanged(); + return this; + } + + private int type_ ; + /** + * optional int32 type = 8; + */ + public boolean hasType() { + return ((bitField0_ & 0x00000080) == 0x00000080); + } + /** + * optional int32 type = 8; + */ + public int getType() { + return type_; + } + /** + * optional int32 type = 8; + */ + public Builder setType(int value) { + bitField0_ |= 0x00000080; + type_ = value; + onChanged(); + return this; + } + /** + * optional int32 type = 8; + */ + public Builder clearType() { + bitField0_ = (bitField0_ & ~0x00000080); + type_ = 0; + onChanged(); + return this; + } + + private int aiColPos_ = -1; + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public boolean hasAiColPos() { + return ((bitField0_ & 0x00000100) == 0x00000100); + } + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public int getAiColPos() { + return aiColPos_; + } + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public Builder setAiColPos(int value) { + bitField0_ |= 0x00000100; + aiColPos_ = value; + onChanged(); + return this; + } + /** + * optional int32 aiColPos = 9 [default = -1]; + */ + public Builder clearAiColPos() { + bitField0_ = (bitField0_ & ~0x00000100); + aiColPos_ = -1; + onChanged(); + return this; + } + + // @@protoc_insertion_point(builder_scope:io.mycat.meta.protocol.TableMeta) + } + + static { + defaultInstance = new TableMeta(true); + defaultInstance.initFields(); + } + + // @@protoc_insertion_point(class_scope:io.mycat.meta.protocol.TableMeta) + } + + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_io_mycat_meta_protocol_ColumnMeta_fieldAccessorTable; + private static final com.google.protobuf.Descriptors.Descriptor + internal_static_io_mycat_meta_protocol_TableMeta_descriptor; + private static + com.google.protobuf.GeneratedMessage.FieldAccessorTable + internal_static_io_mycat_meta_protocol_TableMeta_fieldAccessorTable; + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n\022MyCatMeta.protocol\022\026io.mycat.meta.prot" + + "ocol\"\215\002\n\nColumnMeta\022\021\n\ttableName\030\001 \001(\t\022\014" + + "\n\004name\030\002 \001(\t\0227\n\010dataType\030\003 \001(\0162%.io.myca" + + "t.meta.protocol.MySqlDataType\022\016\n\006length\030" + + "\004 \001(\005\022\021\n\tprecision\030\005 \001(\005\022\r\n\005scale\030\006 \001(\005\022" + + "\017\n\007canNull\030\007 \001(\010\022\020\n\010sdefault\030\010 \001(\t\022\022\n\nau" + + "to_incre\030\t \001(\010\022\022\n\nisUnsigned\030\n \001(\010\022\r\n\003ke" + + "y\030\013 \001(\t:\000\022\031\n\013charsetname\030\014 \001(\t:\004utf8\"\334\001\n" + + "\tTableMeta\022\017\n\007catalog\030\001 \001(\t\022\021\n\ttableName" + + "\030\002 \001(\t\0226\n\nallColumns\030\003 \003(\0132\".io.mycat.me", + "ta.protocol.ColumnMeta\022\025\n\006isView\030\004 \001(\010:\005" + + "false\022\021\n\tcreateSql\030\005 \001(\t\022\017\n\007version\030\006 \001(" + + "\003\022\024\n\010aiOffset\030\007 \001(\003:\002-1\022\014\n\004type\030\010 \001(\005\022\024\n" + + "\010aiColPos\030\t \001(\005:\002-1*\211\003\n\rMySqlDataType\022\013\n" + + "\007DECIMAL\020\000\022\010\n\004TINY\020\001\022\t\n\005SHORT\020\002\022\010\n\004LONG\020" + + "\003\022\t\n\005FLOAT\020\004\022\n\n\006DOUBLE\020\005\022\010\n\004NULL\020\006\022\r\n\tTI" + + "MESTAMP\020\007\022\014\n\010LONGLONG\020\010\022\t\n\005INT24\020\t\022\010\n\004DA" + + "TE\020\n\022\010\n\004TIME\020\013\022\014\n\010DATETIME\020\014\022\010\n\004YEAR\020\r\022\013" + + "\n\007NEWDATE\020\016\022\013\n\007VARCHAR\020\017\022\007\n\003BIT\020\020\022\016\n\nTIM" + + "ESTAMP2\020\021\022\r\n\tDATETIME2\020\022\022\t\n\005TIME2\020\023\022\017\n\nN", + "EWDECIMAL\020\366\001\022\t\n\004ENUM\020\367\001\022\010\n\003SET\020\370\001\022\r\n\010TIN" + + "YBLOB\020\371\001\022\017\n\nMEDIUMBLOB\020\372\001\022\r\n\010LONGBLOB\020\373\001" + + "\022\t\n\004BLOB\020\374\001\022\016\n\tVARSTRING\020\375\001\022\013\n\006STRING\020\376\001" + + "\022\r\n\010GEOMETRY\020\377\001B%\n\026io.mycat.meta.protoco" + + "lB\tMyCatMetaH\001" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + }, assigner); + internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor = + getDescriptor().getMessageTypes().get(0); + internal_static_io_mycat_meta_protocol_ColumnMeta_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_io_mycat_meta_protocol_ColumnMeta_descriptor, + new java.lang.String[] { "TableName", "Name", "DataType", "Length", "Precision", "Scale", "CanNull", "Sdefault", "AutoIncre", "IsUnsigned", "Key", "Charsetname", }); + internal_static_io_mycat_meta_protocol_TableMeta_descriptor = + getDescriptor().getMessageTypes().get(1); + internal_static_io_mycat_meta_protocol_TableMeta_fieldAccessorTable = new + com.google.protobuf.GeneratedMessage.FieldAccessorTable( + internal_static_io_mycat_meta_protocol_TableMeta_descriptor, + new java.lang.String[] { "Catalog", "TableName", "AllColumns", "IsView", "CreateSql", "Version", "AiOffset", "Type", "AiColPos", }); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/src/main/java/io/mycat/meta/protocol/MyCatMeta.protocol b/src/main/java/io/mycat/meta/protocol/MyCatMeta.protocol new file mode 100644 index 000000000..93ad3427a --- /dev/null +++ b/src/main/java/io/mycat/meta/protocol/MyCatMeta.protocol @@ -0,0 +1,65 @@ +package io.mycat.meta.protocol; + +option java_package = "io.mycat.meta.protocol"; +option java_outer_classname = "MyCatMeta"; +option optimize_for = SPEED; + +enum MySqlDataType { + DECIMAL = 0; + TINY = 1; + SHORT = 2; + LONG = 3; + FLOAT = 4; + DOUBLE = 5; + NULL = 6; + TIMESTAMP = 7; + LONGLONG = 8; + INT24 = 9; + DATE = 10; + TIME = 11; + DATETIME = 12; + YEAR = 13; + NEWDATE = 14; + VARCHAR = 15; + BIT = 16; + TIMESTAMP2 = 17; + DATETIME2 = 18; + TIME2 = 19; + NEWDECIMAL = 246; + ENUM = 247; + SET = 248; + TINYBLOB = 249; + MEDIUMBLOB = 250; + LONGBLOB = 251; + BLOB = 252; + VARSTRING = 253; + STRING = 254; + GEOMETRY = 255; +} + +message ColumnMeta{ + optional string tableName = 1; + optional string name = 2; + optional MySqlDataType dataType = 3; + optional int32 length = 4; + optional int32 precision = 5; + optional int32 scale = 6; + optional bool canNull = 7; + optional string sdefault = 8; + optional bool auto_incre = 9; + optional bool isUnsigned = 10; + optional string key = 11[default = ""];//有pri,unique + optional string charsetname = 12 [default = "utf8"]; +} + +message TableMeta{ + optional string catalog = 1; + optional string tableName = 2;//不带dbname的表名:如table1 + repeated ColumnMeta allColumns = 3;//所有的列属性,有序 + optional bool isView = 4[default = false]; + optional string createSql = 5; + optional int64 version = 6; + optional int64 aiOffset = 7[default=-1]; + optional int32 type = 8; + optional int32 aiColPos = 9[default=-1]; +} diff --git a/src/main/java/io/mycat/meta/table/MultiTableMetaHandler.java b/src/main/java/io/mycat/meta/table/MultiTableMetaHandler.java new file mode 100644 index 000000000..db7ac22ce --- /dev/null +++ b/src/main/java/io/mycat/meta/table/MultiTableMetaHandler.java @@ -0,0 +1,35 @@ +package io.mycat.meta.table; + +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicInteger; + +import io.mycat.MycatServer; +import io.mycat.config.model.SchemaConfig; +import io.mycat.config.model.TableConfig; + +public class MultiTableMetaHandler { + private AtomicInteger tableNumbers; + private String schema; + private SchemaConfig config; + private SchemaMetaHandler schemaMetaHandler; + + public MultiTableMetaHandler(SchemaMetaHandler schemaMetaHandler, SchemaConfig config) { + this.schemaMetaHandler = schemaMetaHandler; + this.config = config; + this.schema = config.getName(); + tableNumbers = new AtomicInteger(config.getTables().size()); + } + + public void execute() { + MycatServer.getInstance().getTmManager().createDatabase(schema); + for (Entry entry : config.getTables().entrySet()) { + TableMetaHandler table = new TableMetaHandler(this, schema, entry.getValue()); + table.execute(); + } + } + + public void countDown() { + if (tableNumbers.decrementAndGet() == 0) + schemaMetaHandler.countDown(); + } +} diff --git a/src/main/java/io/mycat/meta/table/SchemaMetaHandler.java b/src/main/java/io/mycat/meta/table/SchemaMetaHandler.java new file mode 100644 index 000000000..324ecdac2 --- /dev/null +++ b/src/main/java/io/mycat/meta/table/SchemaMetaHandler.java @@ -0,0 +1,61 @@ +package io.mycat.meta.table; + +import java.util.Map.Entry; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import io.mycat.config.MycatConfig; +import io.mycat.config.model.SchemaConfig; + +public class SchemaMetaHandler { + + // 1、根据用户、DataSourceConfig获取所有的节点数据源。 + //  2、show databases 获取当前节点的schema。 + // 3、如果是分库schema,只有节点0需要获取table信息。 + // 4、一次获取每个schema下的表信息、索引信息。(如配置了二级拆分规则,则该表忽略) + + private Lock lock; + private Condition allSchemaDone; + private int schemaNumber; + + private MycatConfig config; + + public SchemaMetaHandler(MycatConfig config) { + this.lock = new ReentrantLock(); + this.allSchemaDone = lock.newCondition(); + this.config = config; + schemaNumber = config.getSchemas().size(); + } + + public void execute() { + for (Entry entry : config.getSchemas().entrySet()) { + MultiTableMetaHandler multiTableMeta = new MultiTableMetaHandler(this, entry.getValue()); + multiTableMeta.execute(); + } + waitAllNodeDone(); + } + + public void countDown() { + lock.lock(); + try { + if (--schemaNumber == 0) + allSchemaDone.signal(); + } finally { + lock.unlock(); + } + } + + public void waitAllNodeDone() { + lock.lock(); + try { + if (schemaNumber == 0) + return; + allSchemaDone.await(); + } catch (InterruptedException e) { + // ignore + } finally { + lock.unlock(); + } + } +} diff --git a/src/main/java/io/mycat/meta/table/TableMetaHandler.java b/src/main/java/io/mycat/meta/table/TableMetaHandler.java new file mode 100644 index 000000000..e83c13606 --- /dev/null +++ b/src/main/java/io/mycat/meta/table/TableMetaHandler.java @@ -0,0 +1,195 @@ +package io.mycat.meta.table; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicInteger; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.statement.SQLColumnConstraint; +import com.alibaba.druid.sql.ast.statement.SQLColumnDefinition; +import com.alibaba.druid.sql.ast.statement.SQLColumnPrimaryKey; +import com.alibaba.druid.sql.ast.statement.SQLColumnUniqueKey; +import com.alibaba.druid.sql.ast.statement.SQLCreateTableStatement; +import com.alibaba.druid.sql.ast.statement.SQLNotNullConstraint; +import com.alibaba.druid.sql.ast.statement.SQLNullConstraint; +import com.alibaba.druid.sql.ast.statement.SQLTableElement; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlPrimaryKey; +import com.alibaba.druid.sql.dialect.mysql.ast.MySqlUnique; +import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlTableIndex; +import com.alibaba.druid.sql.dialect.mysql.parser.MySqlStatementParser; +import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlOutputVisitor; +import com.alibaba.druid.sql.parser.SQLStatementParser; + +import io.mycat.MycatServer; +import io.mycat.backend.datasource.PhysicalDBNode; +import io.mycat.config.model.TableConfig; +import io.mycat.meta.IndexMeta; +import io.mycat.meta.MySQLTableStructureDetector; +import io.mycat.meta.protocol.MyCatMeta.ColumnMeta; +import io.mycat.meta.protocol.MyCatMeta.TableMeta; +import io.mycat.sqlengine.OneRawSQLQueryResultHandler; +import io.mycat.sqlengine.SQLJob; +import io.mycat.sqlengine.SQLQueryResult; +import io.mycat.sqlengine.SQLQueryResultListener; + +public class TableMetaHandler { + private static final Logger LOGGER = LoggerFactory.getLogger(MySQLTableStructureDetector.class); + private static final String[] MYSQL_SHOW_CREATE_TABLE_COLMS = new String[]{ + "Table", + "Create Table"}; + private static final String sqlPrefix = "show create table "; + + private MultiTableMetaHandler multiTableMetaHandler; + private TableConfig tbConfig; + private AtomicInteger nodesNumber; + private TableMeta.Builder tmBuilder; + private String schema; + public TableMetaHandler(MultiTableMetaHandler multiTableMetaHandler, String schema, TableConfig tbConfig){ + this.multiTableMetaHandler = multiTableMetaHandler; + this.tbConfig = tbConfig; + this.nodesNumber = new AtomicInteger(tbConfig.getDataNodes().size()); + this.tmBuilder = TableMeta.newBuilder(); + tmBuilder.setCatalog(schema).setTableName(tbConfig.getName()); + this.schema = schema; + } + public void execute(){ + for (String dataNode : tbConfig.getDataNodes()) { + try { + tbConfig.getReentrantReadWriteLock().writeLock().lock(); + ConcurrentHashMap> map = new ConcurrentHashMap<>(); + tbConfig.setDataNodeTableStructureSQLMap(map); + } finally { + tbConfig.getReentrantReadWriteLock().writeLock().unlock(); + } + OneRawSQLQueryResultHandler resultHandler = new OneRawSQLQueryResultHandler(MYSQL_SHOW_CREATE_TABLE_COLMS, new MySQLTableStructureListener(dataNode)); + resultHandler.setMark("Table Structure"); + PhysicalDBNode dn = MycatServer.getInstance().getConfig().getDataNodes().get(dataNode); + SQLJob sqlJob = new SQLJob(sqlPrefix + tbConfig.getName(), dn.getDatabase(), resultHandler, dn.getDbPool().getSource()); + sqlJob.run(); + } + } + private class MySQLTableStructureListener implements SQLQueryResultListener>> { + private String dataNode; + + public MySQLTableStructureListener(String dataNode) { + this.dataNode = dataNode; + } + + @Override + public void onResult(SQLQueryResult> result) { + try { + tbConfig.getReentrantReadWriteLock().writeLock().lock(); + if (!result.isSuccess()) { + LOGGER.warn("Can't get table " + tbConfig.getName() + "'s config from DataNode:" + dataNode + "! Maybe the table is not initialized!"); + return; + } + String currentSql = result.getResult().get(MYSQL_SHOW_CREATE_TABLE_COLMS[1]); + Map> dataNodeTableStructureSQLMap = tbConfig.getDataNodeTableStructureSQLMap(); + if (dataNodeTableStructureSQLMap.containsKey(currentSql)) { + List dataNodeList = dataNodeTableStructureSQLMap.get(currentSql); + dataNodeList.add(dataNode); + } else { + List dataNodeList = new LinkedList<>(); + dataNodeList.add(dataNode); + dataNodeTableStructureSQLMap.put(currentSql,dataNodeList); + } + + if (nodesNumber.decrementAndGet() == 0) { + if (dataNodeTableStructureSQLMap.size() > 1) { + LOGGER.warn("Table [" + tbConfig.getName() + "] structure are not consistent!"); + LOGGER.warn("Currently detected: "); + for(String sql : dataNodeTableStructureSQLMap.keySet()){ + StringBuilder stringBuilder = new StringBuilder(); + for(String dn : dataNodeTableStructureSQLMap.get(sql)){ + stringBuilder.append("DataNode:[").append(dn).append("]"); + } + stringBuilder.append(":").append(sql); + LOGGER.warn(stringBuilder.toString()); + } + } + List indexMetas = new ArrayList(); + initTableMeta(tbConfig.getName(),currentSql, tmBuilder, indexMetas); + tmBuilder.setVersion(System.currentTimeMillis()); + MycatServer.getInstance().getTmManager().addTable(schema, tmBuilder.build()); + for(IndexMeta indexMeta: indexMetas){ + MycatServer.getInstance().getTmManager().addIndex(schema, indexMeta); + } + if(multiTableMetaHandler != null){ + multiTableMetaHandler.countDown(); + } + } + } finally { + tbConfig.getReentrantReadWriteLock().writeLock().unlock(); + } + } + + private void initTableMeta(String table, String sql, TableMeta.Builder tmBuilder ,List indexMetas) { + SQLStatementParser parser = new MySqlStatementParser(sql); + SQLCreateTableStatement createStment = parser.parseCreateTable(); + for (SQLTableElement tableElement : createStment.getTableElementList()) { + if (tableElement instanceof SQLColumnDefinition) { + ColumnMeta.Builder cmBuilder = ColumnMeta.newBuilder(); + SQLColumnDefinition column = (SQLColumnDefinition) tableElement; + cmBuilder.setTableName(table); + cmBuilder.setName(column.getName().getSimpleName()); + for (SQLColumnConstraint constraint : column.getConstraints()) { + if (constraint instanceof SQLNotNullConstraint) { + cmBuilder.setCanNull(false); + } else if (constraint instanceof SQLNullConstraint) { + cmBuilder.setCanNull(true); + } else if (constraint instanceof SQLColumnPrimaryKey) { + cmBuilder.setKey("PRI"); + } else if (constraint instanceof SQLColumnUniqueKey) { + cmBuilder.setKey("UNI"); + } else { + // ignore + } + } + if (column.getDefaultExpr() != null) { + StringBuilder builder = new StringBuilder(); + MySqlOutputVisitor visitor = new MySqlOutputVisitor(builder); + column.getDefaultExpr().accept(visitor); + cmBuilder.setSdefault(builder.toString()); + } + if (column.isAutoIncrement()) { + cmBuilder.setAutoIncre(true); + tmBuilder.setAiColPos(tmBuilder.getAllColumnsCount()); + } + tmBuilder.addAllColumns(cmBuilder.build()); + } else if (tableElement instanceof MySqlPrimaryKey) { + MySqlPrimaryKey primaryKey = (MySqlPrimaryKey)tableElement; + List columns = new ArrayList(); + for (int i = 0; i < primaryKey.getColumns().size(); i++) { + SQLIdentifierExpr column = (SQLIdentifierExpr)primaryKey.getColumns().get(i); + columns.add(column.getName()); + } + indexMetas.add(new IndexMeta("PRIMARY", table, "PRI", columns)); + } else if (tableElement instanceof MySqlUnique) { + MySqlUnique unique = (MySqlUnique)tableElement; + List columns = new ArrayList(); + for (int i = 0; i < unique.getColumns().size(); i++) { + SQLIdentifierExpr column = (SQLIdentifierExpr)unique.getColumns().get(i); + columns.add(column.getName()); + } + indexMetas.add(new IndexMeta(unique.getName().getSimpleName(), table, "UNI", columns)); + } else if (tableElement instanceof MySqlTableIndex) { + MySqlTableIndex index = (MySqlTableIndex)tableElement; + List columns = new ArrayList(); + for (int i = 0; i < index.getColumns().size(); i++) { + SQLIdentifierExpr column = (SQLIdentifierExpr)index.getColumns().get(i); + columns.add(column.getName()); + } + indexMetas.add(new IndexMeta(index.getName().getSimpleName(), table, "MUL", columns)); + } else { + // ignore + } + } + } + } +} diff --git a/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java b/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java index c79a54d53..51caf1c1b 100644 --- a/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java +++ b/src/main/java/io/mycat/route/impl/DruidMycatRouteStrategy.java @@ -120,7 +120,7 @@ public class DruidMycatRouteStrategy extends AbstractRouteStrategy { //分表 /** * subTables="t_order$1-2,t_order3" - *目前分表 1.6 开始支持 幵丏 dataNode 在分表条件下只能配置一个,分表条件下不支持join。 + *目前分表 1.6 开始支持dataNode 在分表条件下只能配置一个,分表条件下不支持join。 */ if(rrs.isDistTable()){ return this.routeDisTable(statement,rrs); diff --git a/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java b/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java index eaa10539e..9cdab8dfc 100644 --- a/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java +++ b/src/main/java/io/mycat/route/parser/druid/impl/DruidInsertParser.java @@ -1,7 +1,6 @@ package io.mycat.route.parser.druid.impl; import java.sql.SQLNonTransientException; -import java.sql.SQLSyntaxErrorException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -15,14 +14,15 @@ import com.alibaba.druid.sql.ast.expr.SQLIntegerExpr; import com.alibaba.druid.sql.ast.statement.SQLInsertStatement.ValuesClause; import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlInsertStatement; +import io.mycat.MycatServer; import io.mycat.backend.mysql.nio.handler.FetchStoreNodeOfChildTableHandler; import io.mycat.config.model.SchemaConfig; import io.mycat.config.model.TableConfig; +import io.mycat.meta.protocol.MyCatMeta.TableMeta; import io.mycat.route.RouteResultset; import io.mycat.route.RouteResultsetNode; import io.mycat.route.function.AbstractPartitionAlgorithm; import io.mycat.route.parser.druid.MycatSchemaStatVisitor; -import io.mycat.route.parser.druid.RouteCalculateUnit; import io.mycat.route.util.RouterUtil; import io.mycat.server.parser.ServerParse; import io.mycat.util.StringUtil; @@ -50,8 +50,7 @@ public class DruidInsertParser extends DefaultDruidParser { TableConfig tc = schema.getTables().get(tableName); if(tc == null) { - String msg = "can't find table define in schema " - + tableName + " schema:" + schema.getName(); + String msg = "can't find table [" + tableName + "] define in schema:" + schema.getName(); LOGGER.warn(msg); throw new SQLNonTransientException(msg); } else { @@ -63,17 +62,9 @@ public class DruidInsertParser extends DefaultDruidParser { String partitionColumn = tc.getPartitionColumn(); - if(partitionColumn != null) {//分片表 - //拆分表必须给出column list,否则无法寻找分片字段的值 - if(insert.getColumns() == null || insert.getColumns().size() == 0) { - throw new SQLSyntaxErrorException("partition table, insert must provide ColumnList"); - } - + if(partitionColumn != null) { //批量insert if(isMultiInsert(insert)) { -// String msg = "multi insert not provided" ; -// LOGGER.warn(msg); -// throw new SQLNonTransientException(msg); parserBatchInsert(schema, rrs, partitionColumn, tableName, insert); } else { parserSingleInsert(schema, rrs, partitionColumn, tableName, insert); @@ -164,26 +155,37 @@ public class DruidInsertParser extends DefaultDruidParser { */ private void parserSingleInsert(SchemaConfig schema, RouteResultset rrs, String partitionColumn, String tableName, MySqlInsertStatement insertStmt) throws SQLNonTransientException { - boolean isFound = false; - for(int i = 0; i < insertStmt.getColumns().size(); i++) { - if(partitionColumn.equalsIgnoreCase(StringUtil.removeBackquote(insertStmt.getColumns().get(i).toString()))) {//找到分片字段 - isFound = true; - String column = StringUtil.removeBackquote(insertStmt.getColumns().get(i).toString()); - - String value = StringUtil.removeBackquote(insertStmt.getValues().getValues().get(i).toString()); - - RouteCalculateUnit routeCalculateUnit = new RouteCalculateUnit(); - routeCalculateUnit.addShardingExpr(tableName, column, value); - ctx.addRouteCalculateUnit(routeCalculateUnit); - //mycat是单分片键,找到了就返回 - break; - } - } - if(!isFound) {//分片表的 + int shardingColIndex = getShardingColIndex(schema, insertStmt, partitionColumn); + if(shardingColIndex == -1) { String msg = "bad insert sql (sharding column:"+ partitionColumn + " not provided," + insertStmt; LOGGER.warn(msg); throw new SQLNonTransientException(msg); } + + SQLExpr valueExpr = insertStmt.getValues().getValues().get(shardingColIndex); + 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(); + } + TableConfig tableConfig = schema.getTables().get(tableName); + AbstractPartitionAlgorithm algorithm = tableConfig.getRule().getRuleAlgorithm(); + Integer nodeIndex = algorithm.calculate(shardingValue); + //没找到插入的分片 + if(nodeIndex == null) { + String msg = "can't find any valid datanode :" + tableName + + " -> " + partitionColumn + " -> " + shardingValue; + LOGGER.warn(msg); + throw new SQLNonTransientException(msg); + } + RouteResultsetNode[] nodes = new RouteResultsetNode[1]; + nodes[0] = new RouteResultsetNode(tableConfig.getDataNodes().get(nodeIndex), rrs.getSqlType(), + insertStmt.toString()); + nodes[0].setSource(rrs); + // insert into .... on duplicateKey //such as :INSERT INTO TABLEName (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE b=VALUES(b); //INSERT INTO TABLEName (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; @@ -199,6 +201,8 @@ public class DruidInsertParser extends DefaultDruidParser { } } } + rrs.setNodes(nodes); + rrs.setFinishedRoute(true); } /** @@ -213,8 +217,8 @@ public class DruidInsertParser extends DefaultDruidParser { //insert into table() values (),(),.... if(insertStmt.getValuesList().size() > 1) { //字段列数 - int columnNum = insertStmt.getColumns().size(); - int shardingColIndex = getShardingColIndex(insertStmt, partitionColumn); + int columnNum = getTableColumns(schema, insertStmt); + int shardingColIndex = getShardingColIndex(schema, insertStmt, partitionColumn); if(shardingColIndex == -1) { String msg = "bad insert sql (sharding column:"+ partitionColumn + " not provided," + insertStmt; LOGGER.warn(msg); @@ -284,14 +288,40 @@ public class DruidInsertParser extends DefaultDruidParser { * @param partitionColumn * @return */ - private int getShardingColIndex(MySqlInsertStatement insertStmt,String partitionColumn) { + private int getShardingColIndex(SchemaConfig schema, MySqlInsertStatement insertStmt, String partitionColumn) { int shardingColIndex = -1; - for(int i = 0; i < insertStmt.getColumns().size(); i++) { - if(partitionColumn.equalsIgnoreCase(StringUtil.removeBackquote(insertStmt.getColumns().get(i).toString()))) {//找到分片字段 - shardingColIndex = i; - return shardingColIndex; + if (insertStmt.getColumns() == null || insertStmt.getColumns().size() == 0) { + String table = StringUtil.removeBackquote(insertStmt.getTableName().getSimpleName()).toUpperCase(); + TableMeta tbMeta = MycatServer.getInstance().getTmManager().getTableMeta(schema.getName(), table); + if (tbMeta != null) { + for (int i = 0; i < tbMeta.getAllColumnsCount(); i++) { + if (partitionColumn.equalsIgnoreCase(StringUtil.removeBackquote(tbMeta.getAllColumns(i).getName()))) { + return i; + } + } + } + return shardingColIndex; + } + for (int i = 0; i < insertStmt.getColumns().size(); i++) { + if (partitionColumn.equalsIgnoreCase(StringUtil.removeBackquote(insertStmt.getColumns().get(i).toString()))) { + return i; } } return shardingColIndex; } -} + + private int getTableColumns(SchemaConfig schema, MySqlInsertStatement insertStmt) throws SQLNonTransientException { + if (insertStmt.getColumns() == null || insertStmt.getColumns().size() == 0) { + String table = StringUtil.removeBackquote(insertStmt.getTableName().getSimpleName()).toUpperCase(); + TableMeta tbMeta = MycatServer.getInstance().getTmManager().getTableMeta(schema.getName(), table); + if (tbMeta == null) { + String msg = "can't find table [" + table + "] define in schema:" + schema.getName(); + LOGGER.warn(msg); + throw new SQLNonTransientException(msg); + } + return tbMeta.getAllColumnsCount(); + } else { + return insertStmt.getColumns().size(); + } + } +} \ No newline at end of file