idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
16,100 | public final void parse ( final SQLStatement sqlStatement , final boolean isSingleTableOnly ) { do { parseTableReference ( sqlStatement , isSingleTableOnly ) ; } while ( lexerEngine . skipIfEqual ( Symbol . COMMA ) ) ; } | Parse table references . |
16,101 | public final void parseSingleTableWithoutAlias ( final SQLStatement sqlStatement ) { int beginPosition = lexerEngine . getCurrentToken ( ) . getEndPosition ( ) - lexerEngine . getCurrentToken ( ) . getLiterals ( ) . length ( ) ; String literals = lexerEngine . getCurrentToken ( ) . getLiterals ( ) ; int skippedSchemaNameLength = 0 ; lexerEngine . nextToken ( ) ; if ( lexerEngine . skipIfEqual ( Symbol . DOT ) ) { skippedSchemaNameLength = literals . length ( ) + Symbol . DOT . getLiterals ( ) . length ( ) ; literals = lexerEngine . getCurrentToken ( ) . getLiterals ( ) ; lexerEngine . nextToken ( ) ; } sqlStatement . addSQLToken ( new TableToken ( beginPosition , literals , QuoteCharacter . getQuoteCharacter ( literals ) , skippedSchemaNameLength ) ) ; sqlStatement . getTables ( ) . add ( new Table ( SQLUtil . getExactlyValue ( literals ) , null ) ) ; } | Parse single table without alias . |
16,102 | public static ExecutorService getExecutor ( final boolean isOccupyThreadForPerConnection , final TransactionType transactionType , final ChannelId channelId ) { return ( isOccupyThreadForPerConnection || TransactionType . XA == transactionType || TransactionType . BASE == transactionType ) ? ChannelThreadExecutorGroup . getInstance ( ) . get ( channelId ) : UserExecutorGroup . getInstance ( ) . getExecutorService ( ) ; } | Get executor service . |
16,103 | public void appendPlaceholder ( final ShardingPlaceholder shardingPlaceholder ) { segments . add ( shardingPlaceholder ) ; currentSegment = new StringBuilder ( ) ; segments . add ( currentSegment ) ; } | Append sharding placeholder . |
16,104 | public SQLBuilder rewrite ( final boolean isSingleRouting ) { SQLBuilder result = new SQLBuilder ( parameters ) ; if ( sqlTokens . isEmpty ( ) ) { return appendOriginalLiterals ( result ) ; } appendInitialLiterals ( ! isSingleRouting , result ) ; appendTokensAndPlaceholders ( ! isSingleRouting , result ) ; reviseParameters ( ) ; return result ; } | rewrite SQL . |
16,105 | public SQLUnit generateSQL ( final TableUnit tableUnit , final SQLBuilder sqlBuilder , final ShardingDataSourceMetaData shardingDataSourceMetaData ) { return sqlBuilder . toSQL ( tableUnit , getTableTokens ( tableUnit ) , shardingRule , shardingDataSourceMetaData ) ; } | Generate SQL string . |
16,106 | public static AbstractInsertParser newInstance ( final DatabaseType dbType , final ShardingRule shardingRule , final LexerEngine lexerEngine , final ShardingTableMetaData shardingTableMetaData ) { switch ( dbType ) { case H2 : case MySQL : return new MySQLInsertParser ( shardingRule , lexerEngine , shardingTableMetaData ) ; case Oracle : return new OracleInsertParser ( shardingRule , lexerEngine , shardingTableMetaData ) ; case SQLServer : return new SQLServerInsertParser ( shardingRule , lexerEngine , shardingTableMetaData ) ; case PostgreSQL : return new PostgreSQLInsertParser ( shardingRule , lexerEngine , shardingTableMetaData ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , dbType ) ) ; } } | Create insert parser instance . |
16,107 | public static Properties unmarshalProperties ( final String yamlContent ) { return Strings . isNullOrEmpty ( yamlContent ) ? new Properties ( ) : new Yaml ( ) . loadAs ( yamlContent , Properties . class ) ; } | Unmarshal properties YAML . |
16,108 | public Collection < String > getAllInstanceDataSourceNames ( ) { Collection < String > result = new LinkedList < > ( ) ; for ( Entry < String , DataSourceMetaData > entry : dataSourceMetaDataMap . entrySet ( ) ) { if ( ! isExisted ( entry . getKey ( ) , result ) ) { result . add ( entry . getKey ( ) ) ; } } return result ; } | Get all instance data source names . |
16,109 | public void parse ( final SelectStatement selectStatement ) { if ( ! lexerEngine . skipIfEqual ( SQLServerKeyword . OFFSET ) ) { return ; } int offsetValue = - 1 ; int offsetIndex = - 1 ; if ( lexerEngine . equalAny ( Literals . INT ) ) { offsetValue = Integer . parseInt ( lexerEngine . getCurrentToken ( ) . getLiterals ( ) ) ; } else if ( lexerEngine . equalAny ( Symbol . QUESTION ) ) { offsetIndex = selectStatement . getParametersIndex ( ) ; selectStatement . setParametersIndex ( selectStatement . getParametersIndex ( ) + 1 ) ; } else { throw new SQLParsingException ( lexerEngine ) ; } lexerEngine . nextToken ( ) ; Limit limit = new Limit ( ) ; if ( lexerEngine . skipIfEqual ( DefaultKeyword . FETCH ) ) { lexerEngine . nextToken ( ) ; int rowCountValue = - 1 ; int rowCountIndex = - 1 ; lexerEngine . nextToken ( ) ; if ( lexerEngine . equalAny ( Literals . INT ) ) { rowCountValue = Integer . parseInt ( lexerEngine . getCurrentToken ( ) . getLiterals ( ) ) ; } else if ( lexerEngine . equalAny ( Symbol . QUESTION ) ) { rowCountIndex = selectStatement . getParametersIndex ( ) ; selectStatement . setParametersIndex ( selectStatement . getParametersIndex ( ) + 1 ) ; } else { throw new SQLParsingException ( lexerEngine ) ; } lexerEngine . nextToken ( ) ; lexerEngine . nextToken ( ) ; limit . setRowCount ( new LimitValue ( rowCountValue , rowCountIndex , false ) ) ; limit . setOffset ( new LimitValue ( offsetValue , offsetIndex , true ) ) ; } else { limit . setOffset ( new LimitValue ( offsetValue , offsetIndex , true ) ) ; } selectStatement . setLimit ( limit ) ; } | Parse offset . |
16,110 | public Map < String , List < DataNode > > getDataNodeGroups ( ) { Map < String , List < DataNode > > result = new LinkedHashMap < > ( actualDataNodes . size ( ) , 1 ) ; for ( DataNode each : actualDataNodes ) { String dataSourceName = each . getDataSourceName ( ) ; if ( ! result . containsKey ( dataSourceName ) ) { result . put ( dataSourceName , new LinkedList < DataNode > ( ) ) ; } result . get ( dataSourceName ) . add ( each ) ; } return result ; } | Get data node groups . |
16,111 | public Collection < String > getActualDatasourceNames ( ) { Collection < String > result = new LinkedHashSet < > ( actualDataNodes . size ( ) ) ; for ( DataNode each : actualDataNodes ) { result . add ( each . getDataSourceName ( ) ) ; } return result ; } | Get actual data source names . |
16,112 | public Collection < String > getActualTableNames ( final String targetDataSource ) { Collection < String > result = new LinkedHashSet < > ( actualDataNodes . size ( ) ) ; for ( DataNode each : actualDataNodes ) { if ( targetDataSource . equals ( each . getDataSourceName ( ) ) ) { result . add ( each . getTableName ( ) ) ; } } return result ; } | Get actual table names via target data source name . |
16,113 | public Optional < String > parseSelectItemAlias ( ) { if ( lexerEngine . skipIfEqual ( DefaultKeyword . AS ) ) { return parseWithAs ( null , false , null ) ; } if ( lexerEngine . equalAny ( getDefaultAvailableKeywordsForSelectItemAlias ( ) ) || lexerEngine . equalAny ( getCustomizedAvailableKeywordsForSelectItemAlias ( ) ) ) { return parseAlias ( null , false , null ) ; } return Optional . absent ( ) ; } | Parse alias for select item . |
16,114 | public Optional < String > parseTableAlias ( final SQLStatement sqlStatement , final boolean setTableToken , final String tableName ) { if ( lexerEngine . skipIfEqual ( DefaultKeyword . AS ) ) { return parseWithAs ( sqlStatement , setTableToken , tableName ) ; } if ( lexerEngine . equalAny ( getDefaultAvailableKeywordsForTableAlias ( ) ) || lexerEngine . equalAny ( getCustomizedAvailableKeywordsForTableAlias ( ) ) ) { return parseAlias ( sqlStatement , setTableToken , tableName ) ; } return Optional . absent ( ) ; } | Parse alias for table . |
16,115 | public final synchronized void renew ( final DataSourceChangedEvent dataSourceChangedEvent ) { dataSource . close ( ) ; dataSource = new ShardingDataSource ( DataSourceConverter . getDataSourceMap ( dataSourceChangedEvent . getDataSourceConfigurations ( ) ) , dataSource . getShardingContext ( ) . getShardingRule ( ) , dataSource . getShardingContext ( ) . getShardingProperties ( ) . getProps ( ) ) ; } | Renew sharding data source . |
16,116 | public void processParameters ( final List < Object > parameters , final boolean isFetchAll , final DatabaseType databaseType ) { fill ( parameters ) ; rewrite ( parameters , isFetchAll , databaseType ) ; } | Fill parameters for rewrite limit . |
16,117 | public boolean isNeedRewriteRowCount ( final DatabaseType databaseType ) { return DatabaseType . MySQL == databaseType || DatabaseType . PostgreSQL == databaseType || DatabaseType . H2 == databaseType ; } | Judge is need rewrite row count or not . |
16,118 | public static XAConnection createXAConnection ( final DatabaseType databaseType , final XADataSource xaDataSource , final Connection connection ) { switch ( databaseType ) { case MySQL : return new MySQLXAConnectionWrapper ( ) . wrap ( xaDataSource , connection ) ; case PostgreSQL : return new PostgreSQLXAConnectionWrapper ( ) . wrap ( xaDataSource , connection ) ; case H2 : return new H2XAConnectionWrapper ( ) . wrap ( xaDataSource , connection ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database type: `%s`" , databaseType ) ) ; } } | Create XA connection from normal connection . |
16,119 | public void add ( final OrchestrationShardingSchema orchestrationShardingSchema ) { String schemaName = orchestrationShardingSchema . getSchemaName ( ) ; if ( ! schemaGroup . containsKey ( schemaName ) ) { schemaGroup . put ( schemaName , new LinkedList < String > ( ) ) ; } schemaGroup . get ( schemaName ) . add ( orchestrationShardingSchema . getDataSourceName ( ) ) ; } | Add orchestration sharding schema . |
16,120 | public void put ( final String shardingSchemaName , final Collection < String > dataSourceNames ) { schemaGroup . put ( shardingSchemaName , dataSourceNames ) ; } | Put orchestration sharding schema . |
16,121 | public Collection < String > getDataSourceNames ( final String shardingSchemaName ) { return schemaGroup . containsKey ( shardingSchemaName ) ? schemaGroup . get ( shardingSchemaName ) : Collections . < String > emptyList ( ) ; } | Get data source names . |
16,122 | public OrCondition buildCondition ( final OrPredicateSegment sqlSegment , final SQLStatement sqlStatement ) { OrCondition result = createOrCondition ( sqlSegment , sqlStatement ) ; createEncryptOrPredicateFiller ( ) . fill ( sqlSegment , sqlStatement ) ; return result ; } | Build condition . |
16,123 | public static boolean isDCL ( final TokenType primaryTokenType , final TokenType secondaryTokenType ) { return STATEMENT_PREFIX . contains ( primaryTokenType ) || ( PRIMARY_STATEMENT_PREFIX . contains ( primaryTokenType ) && SECONDARY_STATEMENT_PREFIX . contains ( secondaryTokenType ) ) ; } | Is DCL statement . |
16,124 | public void close ( ) { SHUTDOWN_EXECUTOR . execute ( new Runnable ( ) { public void run ( ) { try { executorService . shutdown ( ) ; while ( ! executorService . awaitTermination ( 5 , TimeUnit . SECONDS ) ) { executorService . shutdownNow ( ) ; } } catch ( final InterruptedException ex ) { Thread . currentThread ( ) . interrupt ( ) ; } } } ) ; } | Close executor service . |
16,125 | public SQLStatement fill ( final Collection < SQLSegment > sqlSegments , final SQLStatementRule rule ) { SQLStatement result = rule . getSqlStatementClass ( ) . newInstance ( ) ; result . setLogicSQL ( sql ) ; for ( SQLSegment each : sqlSegments ) { Optional < SQLSegmentFiller > filler = parsingRuleRegistry . findSQLSegmentFiller ( databaseType , each . getClass ( ) ) ; if ( filler . isPresent ( ) ) { doFill ( each , result , filler . get ( ) ) ; } } return result ; } | Fill SQL statement . |
16,126 | public final List < Connection > getConnections ( final ConnectionMode connectionMode , final String dataSourceName , final int connectionSize ) throws SQLException { DataSource dataSource = getDataSourceMap ( ) . get ( dataSourceName ) ; Preconditions . checkState ( null != dataSource , "Missing the data source name: '%s'" , dataSourceName ) ; Collection < Connection > connections ; synchronized ( cachedConnections ) { connections = cachedConnections . get ( dataSourceName ) ; } List < Connection > result ; if ( connections . size ( ) >= connectionSize ) { result = new ArrayList < > ( connections ) . subList ( 0 , connectionSize ) ; } else if ( ! connections . isEmpty ( ) ) { result = new ArrayList < > ( connectionSize ) ; result . addAll ( connections ) ; List < Connection > newConnections = createConnections ( dataSourceName , connectionMode , dataSource , connectionSize - connections . size ( ) ) ; result . addAll ( newConnections ) ; synchronized ( cachedConnections ) { cachedConnections . putAll ( dataSourceName , newConnections ) ; } } else { result = new ArrayList < > ( createConnections ( dataSourceName , connectionMode , dataSource , connectionSize ) ) ; synchronized ( cachedConnections ) { cachedConnections . putAll ( dataSourceName , result ) ; } } return result ; } | Get database connections . |
16,127 | public final void parse ( final SelectStatement selectStatement ) { if ( ! lexerEngine . skipIfEqual ( DefaultKeyword . ORDER ) ) { return ; } List < OrderItem > result = new LinkedList < > ( ) ; lexerEngine . skipIfEqual ( OracleKeyword . SIBLINGS ) ; lexerEngine . accept ( DefaultKeyword . BY ) ; do { Optional < OrderItem > orderItem = parseSelectOrderByItem ( selectStatement ) ; if ( orderItem . isPresent ( ) ) { result . add ( orderItem . get ( ) ) ; } } while ( lexerEngine . skipIfEqual ( Symbol . COMMA ) ) ; selectStatement . getOrderByItems ( ) . addAll ( result ) ; } | Parse order by . |
16,128 | public boolean isAlwaysFalse ( ) { if ( shardingConditions . isEmpty ( ) ) { return false ; } for ( ShardingCondition each : shardingConditions ) { if ( ! ( each instanceof AlwaysFalseShardingCondition ) ) { return false ; } } return true ; } | Judge sharding conditions is always false or not . |
16,129 | public static boolean isSymbol ( final char ch ) { return '(' == ch || ')' == ch || '[' == ch || ']' == ch || '{' == ch || '}' == ch || '+' == ch || '-' == ch || '*' == ch || '/' == ch || '%' == ch || '^' == ch || '=' == ch || '>' == ch || '<' == ch || '~' == ch || '!' == ch || '?' == ch || '&' == ch || '|' == ch || '.' == ch || ':' == ch || '#' == ch || ',' == ch || ';' == ch ; } | Judge is symbol or not . |
16,130 | @ SuppressWarnings ( "unchecked" ) public < T > T getValue ( final ShardingPropertiesConstant shardingPropertiesConstant ) { if ( cachedProperties . containsKey ( shardingPropertiesConstant ) ) { return ( T ) cachedProperties . get ( shardingPropertiesConstant ) ; } String value = props . getProperty ( shardingPropertiesConstant . getKey ( ) ) ; if ( Strings . isNullOrEmpty ( value ) ) { Object obj = props . get ( shardingPropertiesConstant . getKey ( ) ) ; if ( null == obj ) { value = shardingPropertiesConstant . getDefaultValue ( ) ; } else { value = obj . toString ( ) ; } } Object result ; if ( boolean . class == shardingPropertiesConstant . getType ( ) ) { result = Boolean . valueOf ( value ) ; } else if ( int . class == shardingPropertiesConstant . getType ( ) ) { result = Integer . valueOf ( value ) ; } else if ( long . class == shardingPropertiesConstant . getType ( ) ) { result = Long . valueOf ( value ) ; } else { result = value ; } cachedProperties . put ( shardingPropertiesConstant , result ) ; return ( T ) result ; } | Get property value . |
16,131 | public void init ( final ExtractorRuleDefinitionEntity ruleDefinitionEntity ) { for ( ExtractorRuleEntity each : ruleDefinitionEntity . getRules ( ) ) { rules . put ( each . getId ( ) , ( SQLSegmentExtractor ) Class . forName ( each . getExtractorClass ( ) ) . newInstance ( ) ) ; } } | Initialize SQL extractor rule definition . |
16,132 | public void clear ( ) throws SQLException { clearStatements ( ) ; statements . clear ( ) ; parameterSets . clear ( ) ; connections . clear ( ) ; resultSets . clear ( ) ; executeGroups . clear ( ) ; } | Clear data . |
16,133 | public List < String > splitAndEvaluate ( ) { if ( null == inlineExpression ) { return Collections . emptyList ( ) ; } return flatten ( evaluate ( split ( ) ) ) ; } | Split and evaluate inline expression . |
16,134 | public static boolean isBooleanValue ( final String value ) { return Boolean . TRUE . toString ( ) . equalsIgnoreCase ( value ) || Boolean . FALSE . toString ( ) . equalsIgnoreCase ( value ) ; } | Judge is boolean value or not . |
16,135 | public static boolean isIntValue ( final String value ) { try { Integer . parseInt ( value ) ; return true ; } catch ( final NumberFormatException ex ) { return false ; } } | Judge is int value or not . |
16,136 | public static boolean isLongValue ( final String value ) { try { Long . parseLong ( value ) ; return true ; } catch ( final NumberFormatException ex ) { return false ; } } | Judge is long value or not . |
16,137 | public static void init ( ) { String tracerClassName = System . getProperty ( OPENTRACING_TRACER_CLASS_NAME ) ; Preconditions . checkNotNull ( tracerClassName , "Can not find opentracing tracer implementation class via system property `%s`" , OPENTRACING_TRACER_CLASS_NAME ) ; try { init ( ( Tracer ) Class . forName ( tracerClassName ) . newInstance ( ) ) ; } catch ( final ReflectiveOperationException ex ) { throw new ShardingException ( "Initialize opentracing tracer class failure." , ex ) ; } } | Initialize sharding tracer . |
16,138 | public SQLAST parse ( ) { ParseTree parseTree = SQLParserFactory . newInstance ( databaseType , sql ) . execute ( ) . getChild ( 0 ) ; if ( parseTree instanceof ErrorNode ) { throw new SQLParsingUnsupportedException ( String . format ( "Unsupported SQL of `%s`" , sql ) ) ; } Optional < SQLStatementRule > sqlStatementRule = parsingRuleRegistry . findSQLStatementRule ( databaseType , parseTree . getClass ( ) . getSimpleName ( ) ) ; if ( sqlStatementRule . isPresent ( ) ) { return new SQLAST ( ( ParserRuleContext ) parseTree , sqlStatementRule . get ( ) ) ; } if ( parsingRuleRegistry instanceof EncryptParsingRuleRegistry ) { return new SQLAST ( ( ParserRuleContext ) parseTree ) ; } throw new SQLParsingUnsupportedException ( String . format ( "Unsupported SQL of `%s`" , sql ) ) ; } | Parse SQL to abstract syntax tree . |
16,139 | public String getInstancesNodeFullPath ( final String instanceId ) { return Joiner . on ( "/" ) . join ( "" , name , ROOT , INSTANCES_NODE_PATH , instanceId ) ; } | Get instance node full path . |
16,140 | public String getDataSourcesNodeFullPath ( final String schemaDataSourceName ) { return Joiner . on ( "/" ) . join ( "" , name , ROOT , DATA_SOURCES_NODE_PATH , schemaDataSourceName ) ; } | Get data source node full path . |
16,141 | public static LexerEngine newInstance ( final DatabaseType dbType , final String sql ) { switch ( dbType ) { case H2 : return new LexerEngine ( new H2Lexer ( sql ) ) ; case MySQL : return new LexerEngine ( new MySQLLexer ( sql ) ) ; case Oracle : return new LexerEngine ( new OracleLexer ( sql ) ) ; case SQLServer : return new LexerEngine ( new SQLServerLexer ( sql ) ) ; case PostgreSQL : return new LexerEngine ( new PostgreSQLLexer ( sql ) ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , dbType ) ) ; } } | Create lexical analysis engine instance . |
16,142 | public boolean execute ( final int [ ] columnIndexes ) throws SQLException { return execute ( new Executor ( ) { public boolean execute ( final Statement statement , final String sql ) throws SQLException { return statement . execute ( sql , columnIndexes ) ; } } ) ; } | Execute SQL with column indexes . |
16,143 | public static boolean isTCLUnsafe ( final DatabaseType databaseType , final TokenType tokenType , final LexerEngine lexerEngine ) { if ( DefaultKeyword . SET . equals ( tokenType ) || DatabaseType . SQLServer . equals ( databaseType ) && DefaultKeyword . IF . equals ( tokenType ) ) { lexerEngine . skipUntil ( DefaultKeyword . TRANSACTION , DefaultKeyword . AUTOCOMMIT , DefaultKeyword . IMPLICIT_TRANSACTIONS ) ; if ( ! lexerEngine . isEnd ( ) ) { return true ; } } return false ; } | Is TCL statement . |
16,144 | public void addBatchForRouteUnits ( final SQLRouteResult routeResult ) { handleOldRouteUnits ( createBatchRouteUnits ( routeResult . getRouteUnits ( ) ) ) ; handleNewRouteUnits ( createBatchRouteUnits ( routeResult . getRouteUnits ( ) ) ) ; batchCount ++ ; } | Add batch for route units . |
16,145 | public List < Statement > getStatements ( ) { List < Statement > result = new LinkedList < > ( ) ; for ( ShardingExecuteGroup < StatementExecuteUnit > each : getExecuteGroups ( ) ) { result . addAll ( Lists . transform ( each . getInputs ( ) , new Function < StatementExecuteUnit , Statement > ( ) { public Statement apply ( final StatementExecuteUnit input ) { return input . getStatement ( ) ; } } ) ) ; } return result ; } | Get statements . |
16,146 | public LogicSchema getLogicSchema ( final String schemaName ) { return Strings . isNullOrEmpty ( schemaName ) ? null : logicSchemas . get ( schemaName ) ; } | Get logic schema . |
16,147 | public synchronized void renew ( final SchemaAddedEvent schemaAddedEvent ) { logicSchemas . put ( schemaAddedEvent . getShardingSchemaName ( ) , createLogicSchema ( schemaAddedEvent . getShardingSchemaName ( ) , Collections . singletonMap ( schemaAddedEvent . getShardingSchemaName ( ) , DataSourceConverter . getDataSourceParameterMap ( schemaAddedEvent . getDataSourceConfigurations ( ) ) ) , schemaAddedEvent . getRuleConfiguration ( ) , true ) ) ; } | Renew to add new schema . |
16,148 | public static CommandExecutor newInstance ( final PostgreSQLCommandPacketType commandPacketType , final PostgreSQLCommandPacket commandPacket , final BackendConnection backendConnection ) { log . debug ( "Execute packet type: {}, value: {}" , commandPacketType , commandPacket ) ; switch ( commandPacketType ) { case QUERY : return new PostgreSQLComQueryExecutor ( ( PostgreSQLComQueryPacket ) commandPacket , backendConnection ) ; case PARSE : return new PostgreSQLComParseExecutor ( ( PostgreSQLComParsePacket ) commandPacket , backendConnection ) ; case BIND : return new PostgreSQLComBindExecutor ( ( PostgreSQLComBindPacket ) commandPacket , backendConnection ) ; case DESCRIBE : return new PostgreSQLComDescribeExecutor ( ) ; case EXECUTE : return new PostgreSQLComExecuteExecutor ( ) ; case SYNC : return new PostgreSQLComSyncExecutor ( ) ; case TERMINATE : return new PostgreSQLComTerminationExecutor ( ) ; default : return new PostgreSQLUnsupportedCommandExecutor ( ) ; } } | Create new instance of command executor . |
16,149 | public final void nextToken ( ) { skipIgnoredToken ( ) ; if ( isVariableBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanVariable ( ) ; } else if ( isNCharBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , ++ offset ) . scanChars ( ) ; } else if ( isIdentifierBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanIdentifier ( ) ; } else if ( isHexDecimalBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanHexDecimal ( ) ; } else if ( isNumberBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanNumber ( ) ; } else if ( isSymbolBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanSymbol ( ) ; } else if ( isCharsBegin ( ) ) { currentToken = new Tokenizer ( input , dictionary , offset ) . scanChars ( ) ; } else if ( isEnd ( ) ) { currentToken = new Token ( Assist . END , "" , offset ) ; } else { throw new SQLParsingException ( this , Assist . ERROR ) ; } offset = currentToken . getEndPosition ( ) ; } | Analyse next token . |
16,150 | public final void parse ( ) { Collection < Keyword > unsupportedRestKeywords = new LinkedList < > ( ) ; unsupportedRestKeywords . addAll ( Arrays . asList ( DefaultKeyword . UNION , DefaultKeyword . INTERSECT , DefaultKeyword . EXCEPT , DefaultKeyword . MINUS ) ) ; unsupportedRestKeywords . addAll ( Arrays . asList ( getUnsupportedKeywordsRest ( ) ) ) ; lexerEngine . unsupportedIfEqual ( unsupportedRestKeywords . toArray ( new Keyword [ unsupportedRestKeywords . size ( ) ] ) ) ; } | Parse select rest . |
16,151 | public boolean isSingleTable ( ) { Collection < String > tableNames = new TreeSet < > ( String . CASE_INSENSITIVE_ORDER ) ; for ( Table each : tables ) { tableNames . add ( each . getName ( ) ) ; } return 1 == tableNames . size ( ) ; } | Judge is single table or not . |
16,152 | public Collection < String > getTableNames ( ) { Collection < String > result = new LinkedHashSet < > ( tables . size ( ) , 1 ) ; for ( Table each : tables ) { result . add ( each . getName ( ) ) ; } return result ; } | Get table names . |
16,153 | public Optional < Table > find ( final String tableNameOrAlias ) { Optional < Table > tableFromName = findTableFromName ( tableNameOrAlias ) ; return tableFromName . isPresent ( ) ? tableFromName : findTableFromAlias ( tableNameOrAlias ) ; } | Find table via table name or alias . |
16,154 | public String skipParentheses ( final SQLStatement sqlStatement ) { StringBuilder result = new StringBuilder ( "" ) ; int count = 0 ; if ( Symbol . LEFT_PAREN == lexer . getCurrentToken ( ) . getType ( ) ) { final int beginPosition = lexer . getCurrentToken ( ) . getEndPosition ( ) ; result . append ( Symbol . LEFT_PAREN . getLiterals ( ) ) ; lexer . nextToken ( ) ; while ( true ) { if ( equalAny ( Symbol . QUESTION ) ) { sqlStatement . setParametersIndex ( sqlStatement . getParametersIndex ( ) + 1 ) ; } if ( Assist . END == lexer . getCurrentToken ( ) . getType ( ) || ( Symbol . RIGHT_PAREN == lexer . getCurrentToken ( ) . getType ( ) && 0 == count ) ) { break ; } if ( Symbol . LEFT_PAREN == lexer . getCurrentToken ( ) . getType ( ) ) { count ++ ; } else if ( Symbol . RIGHT_PAREN == lexer . getCurrentToken ( ) . getType ( ) ) { count -- ; } lexer . nextToken ( ) ; } result . append ( lexer . getInput ( ) . substring ( beginPosition , lexer . getCurrentToken ( ) . getEndPosition ( ) ) ) ; lexer . nextToken ( ) ; } return result . toString ( ) ; } | skip all tokens that inside parentheses . |
16,155 | public void accept ( final TokenType tokenType ) { if ( lexer . getCurrentToken ( ) . getType ( ) != tokenType ) { throw new SQLParsingException ( lexer , tokenType ) ; } lexer . nextToken ( ) ; } | Assert current token type should equals input token and go to next token type . |
16,156 | public boolean equalAny ( final TokenType ... tokenTypes ) { for ( TokenType each : tokenTypes ) { if ( each == lexer . getCurrentToken ( ) . getType ( ) ) { return true ; } } return false ; } | Judge current token equals one of input tokens or not . |
16,157 | public void skipAll ( final TokenType ... tokenTypes ) { Set < TokenType > tokenTypeSet = Sets . newHashSet ( tokenTypes ) ; while ( tokenTypeSet . contains ( lexer . getCurrentToken ( ) . getType ( ) ) ) { lexer . nextToken ( ) ; } } | Skip all input tokens . |
16,158 | public void skipUntil ( final TokenType ... tokenTypes ) { Set < TokenType > tokenTypeSet = Sets . newHashSet ( tokenTypes ) ; tokenTypeSet . add ( Assist . END ) ; while ( ! tokenTypeSet . contains ( lexer . getCurrentToken ( ) . getType ( ) ) ) { lexer . nextToken ( ) ; } } | Skip until one of input tokens . |
16,159 | public void parse ( final SelectStatement selectStatement ) { if ( ! lexerEngine . skipIfEqual ( SQLServerKeyword . TOP ) ) { return ; } int beginPosition = lexerEngine . getCurrentToken ( ) . getEndPosition ( ) ; if ( ! lexerEngine . skipIfEqual ( Symbol . LEFT_PAREN ) ) { beginPosition = lexerEngine . getCurrentToken ( ) . getEndPosition ( ) - lexerEngine . getCurrentToken ( ) . getLiterals ( ) . length ( ) ; } SQLExpression sqlExpression = basicExpressionParser . parse ( selectStatement ) ; lexerEngine . skipIfEqual ( Symbol . RIGHT_PAREN ) ; LimitValue rowCountValue ; if ( sqlExpression instanceof SQLNumberExpression ) { int rowCount = ( ( SQLNumberExpression ) sqlExpression ) . getNumber ( ) . intValue ( ) ; rowCountValue = new LimitValue ( rowCount , - 1 , false ) ; selectStatement . addSQLToken ( new RowCountToken ( beginPosition , rowCount ) ) ; } else if ( sqlExpression instanceof SQLParameterMarkerExpression ) { rowCountValue = new LimitValue ( - 1 , ( ( SQLParameterMarkerExpression ) sqlExpression ) . getIndex ( ) , false ) ; } else { throw new SQLParsingException ( lexerEngine ) ; } lexerEngine . unsupportedIfEqual ( SQLServerKeyword . PERCENT ) ; lexerEngine . skipIfEqual ( DefaultKeyword . WITH , SQLServerKeyword . TIES ) ; if ( null == selectStatement . getLimit ( ) ) { Limit limit = new Limit ( ) ; limit . setRowCount ( rowCountValue ) ; selectStatement . setLimit ( limit ) ; } else { selectStatement . getLimit ( ) . setRowCount ( rowCountValue ) ; } } | Parse top . |
16,160 | public static MySQLErrPacket newInstance ( final int sequenceId , final Exception cause ) { if ( cause instanceof SQLException ) { SQLException sqlException = ( SQLException ) cause ; return new MySQLErrPacket ( sequenceId , sqlException . getErrorCode ( ) , sqlException . getSQLState ( ) , sqlException . getMessage ( ) ) ; } if ( cause instanceof ShardingCTLException ) { ShardingCTLException shardingCTLException = ( ShardingCTLException ) cause ; return new MySQLErrPacket ( sequenceId , ShardingCTLErrorCode . valueOf ( shardingCTLException ) , shardingCTLException . getShardingCTL ( ) ) ; } if ( cause instanceof TableModifyInTransactionException ) { return new MySQLErrPacket ( sequenceId , MySQLServerErrorCode . ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE , ( ( TableModifyInTransactionException ) cause ) . getTableName ( ) ) ; } if ( cause instanceof UnknownDatabaseException ) { return new MySQLErrPacket ( sequenceId , MySQLServerErrorCode . ER_BAD_DB_ERROR , ( ( UnknownDatabaseException ) cause ) . getDatabaseName ( ) ) ; } if ( cause instanceof NoDatabaseSelectedException ) { return new MySQLErrPacket ( sequenceId , MySQLServerErrorCode . ER_NO_DB_ERROR ) ; } return new MySQLErrPacket ( sequenceId , CommonErrorCode . UNKNOWN_EXCEPTION , cause . getMessage ( ) ) ; } | New instance of MytSQL ERR packet . |
16,161 | public static < T > void register ( final Class < T > service ) { for ( T each : ServiceLoader . load ( service ) ) { registerServiceClass ( service , each ) ; } } | Register SPI service into map for new instance . |
16,162 | @ SuppressWarnings ( "unchecked" ) public static < T > Collection < T > newServiceInstances ( final Class < T > service ) { Collection < T > result = new LinkedList < > ( ) ; if ( null == SERVICE_MAP . get ( service ) ) { return result ; } for ( Class < ? > each : SERVICE_MAP . get ( service ) ) { result . add ( ( T ) each . newInstance ( ) ) ; } return result ; } | New service instances . |
16,163 | public static void main ( final String [ ] args ) throws IOException { ShardingConfiguration shardingConfig = new ShardingConfigurationLoader ( ) . load ( ) ; int port = getPort ( args ) ; if ( null == shardingConfig . getServerConfiguration ( ) . getOrchestration ( ) ) { startWithoutRegistryCenter ( shardingConfig . getRuleConfigurationMap ( ) , shardingConfig . getServerConfiguration ( ) . getAuthentication ( ) , shardingConfig . getServerConfiguration ( ) . getProps ( ) , port ) ; } else { startWithRegistryCenter ( shardingConfig . getServerConfiguration ( ) , shardingConfig . getRuleConfigurationMap ( ) . keySet ( ) , shardingConfig . getRuleConfigurationMap ( ) , port ) ; } } | Main entrance . |
16,164 | public Collection < ShardingExecuteGroup < StatementExecuteUnit > > getExecuteUnitGroups ( final Collection < RouteUnit > routeUnits , final SQLExecutePrepareCallback callback ) throws SQLException { return getSynchronizedExecuteUnitGroups ( routeUnits , callback ) ; } | Get execute unit groups . |
16,165 | public List < Comparable < ? > > getConditionValues ( final List < ? > parameters ) { List < Comparable < ? > > result = new LinkedList < > ( positionValueMap . values ( ) ) ; for ( Entry < Integer , Integer > entry : positionIndexMap . entrySet ( ) ) { Object parameter = parameters . get ( entry . getValue ( ) ) ; if ( ! ( parameter instanceof Comparable < ? > ) ) { throw new ShardingException ( "Parameter `%s` should extends Comparable for sharding value." , parameter ) ; } if ( entry . getKey ( ) < result . size ( ) ) { result . add ( entry . getKey ( ) , ( Comparable < ? > ) parameter ) ; } else { result . add ( ( Comparable < ? > ) parameter ) ; } } return result ; } | Get condition values . |
16,166 | public static DataSourceConfiguration getDataSourceConfiguration ( final DataSource dataSource ) { DataSourceConfiguration result = new DataSourceConfiguration ( dataSource . getClass ( ) . getName ( ) ) ; result . getProperties ( ) . putAll ( findAllGetterProperties ( dataSource ) ) ; return result ; } | Get data source configuration . |
16,167 | public DataSource createDataSource ( ) { DataSource result = ( DataSource ) Class . forName ( dataSourceClassName ) . newInstance ( ) ; Method [ ] methods = result . getClass ( ) . getMethods ( ) ; for ( Entry < String , Object > entry : properties . entrySet ( ) ) { if ( SKIPPED_PROPERTY_NAMES . contains ( entry . getKey ( ) ) ) { continue ; } Optional < Method > setterMethod = findSetterMethod ( methods , entry . getKey ( ) ) ; if ( setterMethod . isPresent ( ) ) { setterMethod . get ( ) . invoke ( result , entry . getValue ( ) ) ; } } return result ; } | Create data source . |
16,168 | public void setStatus ( final ConnectionStatus update ) { status . getAndSet ( update ) ; if ( ConnectionStatus . TERMINATED == status . get ( ) ) { resourceSynchronizer . doNotify ( ) ; } } | Change connection status using get and set . |
16,169 | public void setRunningStatusIfNecessary ( ) { if ( ConnectionStatus . TRANSACTION != status . get ( ) && ConnectionStatus . RUNNING != status . get ( ) ) { status . getAndSet ( ConnectionStatus . RUNNING ) ; } } | Change connection status to running if necessary . |
16,170 | void doNotifyIfNecessary ( ) { if ( status . compareAndSet ( ConnectionStatus . RUNNING , ConnectionStatus . RELEASE ) || status . compareAndSet ( ConnectionStatus . TERMINATED , ConnectionStatus . RELEASE ) ) { resourceSynchronizer . doNotify ( ) ; } } | Notify connection to finish wait if necessary . |
16,171 | public void waitUntilConnectionReleasedIfNecessary ( ) throws InterruptedException { if ( ConnectionStatus . RUNNING == status . get ( ) || ConnectionStatus . TERMINATED == status . get ( ) ) { while ( ! status . compareAndSet ( ConnectionStatus . RELEASE , ConnectionStatus . RUNNING ) ) { resourceSynchronizer . doAwaitUntil ( ) ; } } } | Wait until connection is released if necessary . |
16,172 | public OrderItem createOrderItem ( ) { if ( orderByItemSegment instanceof IndexOrderByItemSegment ) { return createOrderItem ( ( IndexOrderByItemSegment ) orderByItemSegment ) ; } if ( orderByItemSegment instanceof ColumnOrderByItemSegment ) { return createOrderItem ( selectStatement , ( ColumnOrderByItemSegment ) orderByItemSegment ) ; } if ( orderByItemSegment instanceof ExpressionOrderByItemSegment ) { return createOrderItem ( selectStatement , ( ExpressionOrderByItemSegment ) orderByItemSegment ) ; } throw new UnsupportedOperationException ( ) ; } | Create order item . |
16,173 | public void initListeners ( ) { instanceStateChangedListener . watch ( ChangedType . UPDATED ) ; dataSourceStateChangedListener . watch ( ChangedType . UPDATED , ChangedType . DELETED ) ; } | Initialize all state changed listeners . |
16,174 | public void setTransactionType ( final TransactionType transactionType ) { if ( null == schemaName ) { throw new ShardingException ( "Please select database, then switch transaction type." ) ; } if ( isSwitchFailed ( ) ) { throw new ShardingException ( "Failed to switch transaction type, please terminate current transaction." ) ; } this . transactionType = transactionType ; } | Change transaction type of current channel . |
16,175 | public void setCurrentSchema ( final String schemaName ) { if ( isSwitchFailed ( ) ) { throw new ShardingException ( "Failed to switch schema, please terminate current transaction." ) ; } this . schemaName = schemaName ; this . logicSchema = LogicSchemas . getInstance ( ) . getLogicSchema ( schemaName ) ; } | Change logic schema of current channel . |
16,176 | public List < Connection > getConnections ( final ConnectionMode connectionMode , final String dataSourceName , final int connectionSize ) throws SQLException { if ( stateHandler . isInTransaction ( ) ) { return getConnectionsWithTransaction ( connectionMode , dataSourceName , connectionSize ) ; } else { return getConnectionsWithoutTransaction ( connectionMode , dataSourceName , connectionSize ) ; } } | Get connections of current thread datasource . |
16,177 | public synchronized void close ( final boolean forceClose ) throws SQLException { Collection < SQLException > exceptions = new LinkedList < > ( ) ; MasterVisitedManager . clear ( ) ; exceptions . addAll ( closeResultSets ( ) ) ; exceptions . addAll ( closeStatements ( ) ) ; if ( ! stateHandler . isInTransaction ( ) || forceClose ) { exceptions . addAll ( releaseConnections ( forceClose ) ) ; } stateHandler . doNotifyIfNecessary ( ) ; throwSQLExceptionIfNecessary ( exceptions ) ; } | Close cached connection . |
16,178 | public void parse ( final InsertStatement insertStatement ) { if ( ! lexerEngine . skipIfEqual ( getCustomizedInsertKeywords ( ) ) ) { return ; } lexerEngine . accept ( DefaultKeyword . DUPLICATE ) ; lexerEngine . accept ( DefaultKeyword . KEY ) ; lexerEngine . accept ( DefaultKeyword . UPDATE ) ; do { Column column = new Column ( SQLUtil . getExactlyValue ( lexerEngine . getCurrentToken ( ) . getLiterals ( ) ) , insertStatement . getTables ( ) . getSingleTableName ( ) ) ; if ( shardingRule . isShardingColumn ( column . getName ( ) , column . getTableName ( ) ) ) { throw new SQLParsingException ( "INSERT INTO .... ON DUPLICATE KEY UPDATE can not support on sharding column, token is '%s', literals is '%s'." , lexerEngine . getCurrentToken ( ) . getType ( ) , lexerEngine . getCurrentToken ( ) . getLiterals ( ) ) ; } basicExpressionParser . parse ( insertStatement ) ; lexerEngine . accept ( Symbol . EQ ) ; if ( lexerEngine . skipIfEqual ( DefaultKeyword . VALUES ) ) { lexerEngine . accept ( Symbol . LEFT_PAREN ) ; basicExpressionParser . parse ( insertStatement ) ; lexerEngine . accept ( Symbol . RIGHT_PAREN ) ; } else { lexerEngine . nextToken ( ) ; } } while ( lexerEngine . skipIfEqual ( Symbol . COMMA ) ) ; } | Parse insert duplicate key update . |
16,179 | public static Optional < Condition > createCompareCondition ( final PredicateCompareRightValue compareRightValue , final Column column ) { return compareRightValue . getExpression ( ) instanceof SimpleExpressionSegment ? Optional . of ( new Condition ( column , ( ( SimpleExpressionSegment ) compareRightValue . getExpression ( ) ) . getSQLExpression ( ) ) ) : Optional . < Condition > absent ( ) ; } | Create condition of compare operator . |
16,180 | public static Optional < Condition > createInCondition ( final PredicateInRightValue inRightValue , final Column column ) { List < SQLExpression > sqlExpressions = new LinkedList < > ( ) ; for ( ExpressionSegment each : inRightValue . getSqlExpressions ( ) ) { if ( ! ( each instanceof SimpleExpressionSegment ) ) { sqlExpressions . clear ( ) ; break ; } else { sqlExpressions . add ( ( ( SimpleExpressionSegment ) each ) . getSQLExpression ( ) ) ; } } return sqlExpressions . isEmpty ( ) ? Optional . < Condition > absent ( ) : Optional . of ( new Condition ( column , sqlExpressions ) ) ; } | Create condition of IN operator . |
16,181 | public static Optional < Condition > createBetweenCondition ( final PredicateBetweenRightValue betweenRightValue , final Column column ) { return betweenRightValue . getBetweenExpression ( ) instanceof SimpleExpressionSegment && betweenRightValue . getAndExpression ( ) instanceof SimpleExpressionSegment ? Optional . of ( new Condition ( column , ( ( SimpleExpressionSegment ) betweenRightValue . getBetweenExpression ( ) ) . getSQLExpression ( ) , ( ( SimpleExpressionSegment ) betweenRightValue . getAndExpression ( ) ) . getSQLExpression ( ) ) ) : Optional . < Condition > absent ( ) ; } | Create condition of BETWEEN ... AND ... operator . |
16,182 | public void init ( final DatabaseType databaseType , final Map < String , DataSource > dataSourceMap ) { for ( Entry < TransactionType , ShardingTransactionManager > entry : transactionManagerMap . entrySet ( ) ) { entry . getValue ( ) . init ( databaseType , getResourceDataSources ( dataSourceMap ) ) ; } } | Initialize sharding transaction managers . |
16,183 | public ShardingTransactionManager getTransactionManager ( final TransactionType transactionType ) { ShardingTransactionManager result = transactionManagerMap . get ( transactionType ) ; if ( TransactionType . LOCAL != transactionType ) { Preconditions . checkNotNull ( result , "Cannot find transaction manager of [%s]" , transactionType ) ; } return result ; } | Get sharding transaction manager . |
16,184 | public void close ( ) throws Exception { for ( Entry < TransactionType , ShardingTransactionManager > entry : transactionManagerMap . entrySet ( ) ) { entry . getValue ( ) . close ( ) ; } } | Close sharding transaction managers . |
16,185 | public static AbstractUpdateParser newInstance ( final DatabaseType dbType , final ShardingRule shardingRule , final LexerEngine lexerEngine ) { switch ( dbType ) { case H2 : case MySQL : return new MySQLUpdateParser ( shardingRule , lexerEngine ) ; case Oracle : return new OracleUpdateParser ( shardingRule , lexerEngine ) ; case SQLServer : return new SQLServerUpdateParser ( shardingRule , lexerEngine ) ; case PostgreSQL : return new PostgreSQLUpdateParser ( shardingRule , lexerEngine ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , dbType ) ) ; } } | Create update parser instance . |
16,186 | public static String getSQLStatementRuleDefinitionFileName ( final String rootDir , final DatabaseType databaseType ) { return Joiner . on ( '/' ) . join ( rootDir , databaseType . name ( ) . toLowerCase ( ) , SQL_STATEMENT_RULE_DEFINITION_FILE_NAME ) ; } | Get SQL statement rule definition file name . |
16,187 | public static Optional < GeneratedKey > getGenerateKey ( final ShardingRule shardingRule , final List < Object > parameters , final InsertStatement insertStatement ) { Optional < String > generateKeyColumnName = shardingRule . findGenerateKeyColumnName ( insertStatement . getTables ( ) . getSingleTableName ( ) ) ; if ( ! generateKeyColumnName . isPresent ( ) ) { return Optional . absent ( ) ; } return isContainsGenerateKeyColumn ( insertStatement , generateKeyColumnName . get ( ) ) ? findGeneratedKey ( parameters , insertStatement , generateKeyColumnName . get ( ) ) : Optional . of ( createGeneratedKey ( shardingRule , insertStatement , generateKeyColumnName . get ( ) ) ) ; } | Get generate key . |
16,188 | public static String getDriverClassName ( final String url ) { for ( Entry < String , String > entry : URL_PREFIX_AND_DRIVER_CLASS_NAME_MAPPER . entrySet ( ) ) { if ( url . startsWith ( entry . getKey ( ) ) ) { return entry . getValue ( ) ; } } throw new ShardingException ( "Cannot resolve JDBC url `%s`. Please implements `%s` and add to SPI." , url , JDBCDriverURLRecognizer . class . getName ( ) ) ; } | Get JDBC driver class name . |
16,189 | public static DataSourceMetaData newInstance ( final DatabaseType databaseType , final String url ) { switch ( databaseType ) { case H2 : return new H2DataSourceMetaData ( url ) ; case MySQL : return new MySQLDataSourceMetaData ( url ) ; case Oracle : return new OracleDataSourceMetaData ( url ) ; case PostgreSQL : return new PostgreSQLDataSourceMetaData ( url ) ; case SQLServer : return new SQLServerDataSourceMetaData ( url ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , databaseType ) ) ; } } | Create new instance of data source meta data . |
16,190 | public static XADataSource build ( final DatabaseType databaseType , final DataSource dataSource ) { XADataSource result = createXADataSource ( databaseType ) ; Properties xaProperties = XAPropertiesFactory . createXAProperties ( databaseType ) . build ( SWAPPER . swap ( dataSource ) ) ; PropertyUtils . setProperties ( result , xaProperties ) ; return result ; } | Create XA data source through general data source . |
16,191 | public SQLStatement judge ( ) { LexerEngine lexerEngine = LexerEngineFactory . newInstance ( DatabaseType . MySQL , sql ) ; lexerEngine . nextToken ( ) ; while ( true ) { TokenType tokenType = lexerEngine . getCurrentToken ( ) . getType ( ) ; if ( tokenType instanceof Keyword ) { if ( DQLStatement . isDQL ( tokenType ) ) { return getDQLStatement ( ) ; } if ( DMLStatement . isDML ( tokenType ) ) { return getDMLStatement ( tokenType ) ; } if ( TCLStatement . isTCL ( tokenType ) ) { return getTCLStatement ( ) ; } if ( DALStatement . isDAL ( tokenType ) ) { return getDALStatement ( tokenType , lexerEngine ) ; } lexerEngine . nextToken ( ) ; TokenType secondaryTokenType = lexerEngine . getCurrentToken ( ) . getType ( ) ; if ( DDLStatement . isDDL ( tokenType , secondaryTokenType ) ) { return getDDLStatement ( ) ; } if ( DCLStatement . isDCL ( tokenType , secondaryTokenType ) ) { return getDCLStatement ( ) ; } if ( TCLStatement . isTCLUnsafe ( DatabaseType . MySQL , tokenType , lexerEngine ) ) { return getTCLStatement ( ) ; } if ( DefaultKeyword . SET . equals ( tokenType ) ) { return new SetStatement ( ) ; } } else { lexerEngine . nextToken ( ) ; } if ( sql . toUpperCase ( ) . startsWith ( "CALL" ) ) { return getDQLStatement ( ) ; } if ( tokenType instanceof Assist && Assist . END == tokenType ) { throw new SQLParsingException ( "Unsupported SQL statement: [%s]" , sql ) ; } } } | Judge SQL type only . |
16,192 | public Object getCell ( final int columnIndex ) { Preconditions . checkArgument ( columnIndex > 0 && columnIndex < data . length + 1 ) ; return data [ columnIndex - 1 ] ; } | Get data from cell . |
16,193 | public void setCell ( final int columnIndex , final Object value ) { Preconditions . checkArgument ( columnIndex > 0 && columnIndex < data . length + 1 ) ; data [ columnIndex - 1 ] = value ; } | Set data for cell . |
16,194 | public void parse ( final InsertStatement insertStatement , final ShardingTableMetaData shardingTableMetaData ) { String tableName = insertStatement . getTables ( ) . getSingleTableName ( ) ; insertStatement . getColumnNames ( ) . addAll ( lexerEngine . equalAny ( Symbol . LEFT_PAREN ) ? parseWithColumn ( insertStatement ) : parseWithoutColumn ( shardingTableMetaData , tableName ) ) ; } | Parse insert columns . |
16,195 | public static AbstractDeleteParser newInstance ( final DatabaseType dbType , final ShardingRule shardingRule , final LexerEngine lexerEngine ) { switch ( dbType ) { case H2 : case MySQL : return new MySQLDeleteParser ( shardingRule , lexerEngine ) ; case Oracle : return new OracleDeleteParser ( shardingRule , lexerEngine ) ; case SQLServer : return new SQLServerDeleteParser ( shardingRule , lexerEngine ) ; case PostgreSQL : return new PostgreSQLDeleteParser ( shardingRule , lexerEngine ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , dbType ) ) ; } } | Create delete parser instance . |
16,196 | public static AbstractShowParser newInstance ( final DatabaseType dbType , final ShardingRule shardingRule , final LexerEngine lexerEngine ) { switch ( dbType ) { case H2 : case MySQL : return new MySQLShowParser ( shardingRule , lexerEngine ) ; default : throw new UnsupportedOperationException ( String . format ( "Cannot support database [%s]." , dbType ) ) ; } } | Create show parser instance . |
16,197 | public static boolean isDDL ( final TokenType primaryTokenType , final TokenType secondaryTokenType ) { return PRIMARY_STATEMENT_PREFIX . contains ( primaryTokenType ) && ! NOT_SECONDARY_STATEMENT_PREFIX . contains ( secondaryTokenType ) ; } | Is DDL statement . |
16,198 | public void init ( final Map < String , Map < String , DataSourceConfiguration > > dataSourceConfigurationMap , final Map < String , RuleConfiguration > schemaRuleMap , final Authentication authentication , final Properties props ) { for ( Entry < String , Map < String , DataSourceConfiguration > > entry : dataSourceConfigurationMap . entrySet ( ) ) { configService . persistConfiguration ( entry . getKey ( ) , dataSourceConfigurationMap . get ( entry . getKey ( ) ) , schemaRuleMap . get ( entry . getKey ( ) ) , authentication , props , isOverwrite ) ; } stateService . persistInstanceOnline ( ) ; stateService . persistDataSourcesNode ( ) ; listenerManager . initListeners ( ) ; } | Initialize for orchestration . |
16,199 | public void parse ( final ShardingRule shardingRule , final SQLStatement sqlStatement , final List < SelectItem > items ) { aliasExpressionParser . parseTableAlias ( ) ; if ( lexerEngine . skipIfEqual ( DefaultKeyword . WHERE ) ) { parseWhere ( shardingRule , sqlStatement , items ) ; } } | Parse where . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.