idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
29,400 | public boolean isApprovalNeeded ( final Rollout rollout ) { final UserDetails userDetails = this . getActor ( rollout ) ; final boolean approvalEnabled = this . tenantConfigurationManagement . getConfigurationValue ( TenantConfigurationKey . ROLLOUT_APPROVAL_ENABLED , Boolean . class ) . getValue ( ) ; return approvalEnabled && userDetails . getAuthorities ( ) . stream ( ) . noneMatch ( authority -> SpPermission . APPROVE_ROLLOUT . equals ( authority . getAuthority ( ) ) ) ; } | Returns true if rollout approval is enabled and rollout creator doesn t have approval role . |
29,401 | protected Date handleUnparsableDateString ( final String value ) throws ConversionException { try { return durationFormat . parse ( value ) ; } catch ( final ParseException e1 ) { try { return additionalFormat . parse ( "000000" . substring ( value . length ( ) <= 6 ? value . length ( ) : 6 ) + value ) ; } catch ( final ParseException e2 ) { } } throw new ConversionException ( "input is not in HH:MM:SS format." ) ; } | This method is called to handle a non - empty date string from the client if the client could not parse it as a Date . In the current case two different parsing schemas are tried . If parsing is not possible a ConversionException is thrown which marks the DurationField as invalid . |
29,402 | public void setDuration ( final Duration duration ) { if ( duration . compareTo ( MAXIMUM_DURATION ) > 0 ) { throw new IllegalArgumentException ( "The duaration has to be smaller than 23:59:59." ) ; } super . setValue ( durationToDate ( duration ) ) ; } | Sets the duration value |
29,403 | public void setMinimumDuration ( final Duration minimumDuration ) { if ( minimumDuration . compareTo ( MAXIMUM_DURATION ) > 0 ) { throw new IllegalArgumentException ( "The minimum duaration has to be smaller than 23:59:59." ) ; } this . minimumDuration = durationToDate ( minimumDuration ) ; } | Sets the minimal allowed duration value as a String |
29,404 | public void setMaximumDuration ( final Duration maximumDuration ) { if ( maximumDuration . compareTo ( MAXIMUM_DURATION ) > 0 ) { throw new IllegalArgumentException ( "The maximum duaration has to be smaller than 23:59:59." ) ; } this . maximumDuration = durationToDate ( maximumDuration ) ; } | Sets the maximum allowed duration value as a String |
29,405 | private int compareTimeOfDates ( final Date d1 , final Date d2 ) { final LocalTime lt1 = LocalDateTime . ofInstant ( d1 . toInstant ( ) , ZONEID_UTC ) . toLocalTime ( ) ; final LocalTime lt2 = LocalDateTime . ofInstant ( d2 . toInstant ( ) , ZONEID_UTC ) . toLocalTime ( ) ; return lt1 . compareTo ( lt2 ) ; } | Because parsing done by base class returns a different date than parsing done by the user or converting duration to a date . But for the DurationField comparison only the time is important . This function helps comparing the time and ignores the values for day month and year . |
29,406 | private void maxArtifactDetails ( ) { final Boolean flag = ( Boolean ) maxMinButton . getData ( ) ; if ( flag == null || Boolean . FALSE . equals ( flag ) ) { maximizedArtifactDetailsView ( ) ; } else { minimizedArtifactDetailsView ( ) ; } } | will be used by button click listener of action history expand icon . |
29,407 | public void createMaxArtifactDetailsTable ( ) { maxArtifactDetailsTable = createArtifactDetailsTable ( ) ; maxArtifactDetailsTable . setId ( UIComponentIdProvider . UPLOAD_ARTIFACT_DETAILS_TABLE_MAX ) ; maxArtifactDetailsTable . setContainerDataSource ( artifactDetailsTable . getContainerDataSource ( ) ) ; addGeneratedColumn ( maxArtifactDetailsTable ) ; if ( ! readOnly ) { addGeneratedColumnButton ( maxArtifactDetailsTable ) ; } setTableColumnDetails ( maxArtifactDetailsTable ) ; } | Create Max artifact details Table . |
29,408 | public void populateArtifactDetails ( final SoftwareModule softwareModule ) { if ( softwareModule == null ) { populateArtifactDetails ( null , null ) ; } else { populateArtifactDetails ( softwareModule . getId ( ) , HawkbitCommonUtil . getFormattedNameVersion ( softwareModule . getName ( ) , softwareModule . getVersion ( ) ) ) ; } } | Populate artifact details . |
29,409 | private void setTitleOfLayoutHeader ( ) { titleOfArtifactDetails . setValue ( HawkbitCommonUtil . getArtifactoryDetailsLabelId ( "" , i18n ) ) ; titleOfArtifactDetails . setContentMode ( ContentMode . HTML ) ; } | Set title of artifact details header layout . |
29,410 | public RolloutGroupConditionBuilder successCondition ( final RolloutGroupSuccessCondition condition , final String expression ) { conditions . setSuccessCondition ( condition ) ; conditions . setSuccessConditionExp ( expression ) ; return this ; } | Sets the finish condition and expression on the builder . |
29,411 | public RolloutGroupConditionBuilder successAction ( final RolloutGroupSuccessAction action , final String expression ) { conditions . setSuccessAction ( action ) ; conditions . setSuccessActionExp ( expression ) ; return this ; } | Sets the success action and expression on the builder . |
29,412 | public RolloutGroupConditionBuilder errorCondition ( final RolloutGroupErrorCondition condition , final String expression ) { conditions . setErrorCondition ( condition ) ; conditions . setErrorConditionExp ( expression ) ; return this ; } | Sets the error condition and expression on the builder . |
29,413 | public RolloutGroupConditionBuilder errorAction ( final RolloutGroupErrorAction action , final String expression ) { conditions . setErrorAction ( action ) ; conditions . setErrorActionExp ( expression ) ; return this ; } | Sets the error action and expression on the builder . |
29,414 | public RolloutGroupConditionBuilder withDefaults ( ) { successCondition ( RolloutGroupSuccessCondition . THRESHOLD , "50" ) ; successAction ( RolloutGroupSuccessAction . NEXTGROUP , "" ) ; errorCondition ( RolloutGroupErrorCondition . THRESHOLD , "50" ) ; errorAction ( RolloutGroupErrorAction . PAUSE , "" ) ; return this ; } | Sets condition defaults . |
29,415 | public AnonymousIpResponse anonymousIp ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , AnonymousIpResponse . class , "GeoIP2-Anonymous-IP" ) ; } | Look up an IP address in a GeoIP2 Anonymous IP . |
29,416 | public AsnResponse asn ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , AsnResponse . class , "GeoLite2-ASN" ) ; } | Look up an IP address in a GeoLite2 ASN database . |
29,417 | public ConnectionTypeResponse connectionType ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , ConnectionTypeResponse . class , "GeoIP2-Connection-Type" ) ; } | Look up an IP address in a GeoIP2 Connection Type database . |
29,418 | public DomainResponse domain ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , DomainResponse . class , "GeoIP2-Domain" ) ; } | Look up an IP address in a GeoIP2 Domain database . |
29,419 | public EnterpriseResponse enterprise ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , EnterpriseResponse . class , "Enterprise" ) ; } | Look up an IP address in a GeoIP2 Enterprise database . |
29,420 | public IspResponse isp ( InetAddress ipAddress ) throws IOException , GeoIp2Exception { return this . get ( ipAddress , IspResponse . class , "GeoIP2-ISP" ) ; } | Look up an IP address in a GeoIP2 ISP database . |
29,421 | public void addListener ( Listener listener , long listenerCheckMillis ) { queue . add ( listener ) ; long newFrequency = Math . min ( MINIMUM_CHECK_DELAY_MILLIS , listenerCheckMillis ) ; if ( currentScheduledFrequency . get ( ) == - 1 ) { if ( currentScheduledFrequency . compareAndSet ( - 1 , newFrequency ) ) { fixedSizedScheduler . schedule ( checker , listenerCheckMillis , TimeUnit . MILLISECONDS ) ; } } else { long frequency = currentScheduledFrequency . get ( ) ; if ( frequency > newFrequency ) { currentScheduledFrequency . compareAndSet ( frequency , newFrequency ) ; } } } | Add listener to validation list . |
29,422 | public void removeListener ( Listener listener ) { queue . remove ( listener ) ; if ( queue . isEmpty ( ) ) { synchronized ( queue ) { if ( currentScheduledFrequency . get ( ) > 0 && queue . isEmpty ( ) ) { currentScheduledFrequency . set ( - 1 ) ; } } } } | Remove listener to validation list . |
29,423 | public TraceObject put ( TraceObject value ) { String key = increment . incrementAndGet ( ) + "- " + DateTimeFormatter . ISO_INSTANT . format ( Instant . now ( ) ) ; return put ( key , value ) ; } | Add value to map . |
29,424 | public synchronized String printStack ( ) { StringBuilder sb = new StringBuilder ( ) ; Set < Map . Entry < String , TraceObject > > set = entrySet ( ) ; for ( Map . Entry < String , TraceObject > entry : set ) { TraceObject traceObj = entry . getValue ( ) ; String key = entry . getKey ( ) ; String indicator = "" ; switch ( traceObj . getIndicatorFlag ( ) ) { case TraceObject . NOT_COMPRESSED : break ; case TraceObject . COMPRESSED_PROTOCOL_NOT_COMPRESSED_PACKET : indicator = " (compressed protocol - packet not compressed)" ; break ; case TraceObject . COMPRESSED_PROTOCOL_COMPRESSED_PACKET : indicator = " (compressed protocol - packet compressed)" ; break ; default : break ; } if ( traceObj . isSend ( ) ) { sb . append ( "\nsend at -exchange:" ) ; } else { sb . append ( "\nread at -exchange:" ) ; } sb . append ( key ) . append ( indicator ) . append ( Utils . hexdump ( traceObj . getBuf ( ) ) ) ; traceObj . remove ( ) ; } this . clear ( ) ; return sb . toString ( ) ; } | Value of trace cache in a readable format . |
29,425 | public synchronized void clearMemory ( ) { Collection < TraceObject > traceObjects = values ( ) ; for ( TraceObject traceObject : traceObjects ) { traceObject . remove ( ) ; } this . clear ( ) ; } | Permit to clear array s of array to help garbage . |
29,426 | private Object handleFailOver ( SQLException qe , Method method , Object [ ] args , Protocol protocol ) throws Throwable { HostAddress failHostAddress = null ; boolean failIsMaster = true ; if ( protocol != null ) { failHostAddress = protocol . getHostAddress ( ) ; failIsMaster = protocol . isMasterConnection ( ) ; } HandleErrorResult handleErrorResult = listener . handleFailover ( qe , method , args , protocol ) ; if ( handleErrorResult . mustThrowError ) { listener . throwFailoverMessage ( failHostAddress , failIsMaster , qe , handleErrorResult . isReconnected ) ; } return handleErrorResult . resultObject ; } | After a connection exception launch failover . |
29,427 | public boolean hasToHandleFailover ( SQLException exception ) { return exception . getSQLState ( ) != null && ( exception . getSQLState ( ) . startsWith ( "08" ) || ( exception . getSQLState ( ) . equals ( "70100" ) && 1927 == exception . getErrorCode ( ) ) ) ; } | Check if this Sqlerror is a connection exception . if that s the case must be handle by failover |
29,428 | public void reconnect ( ) throws SQLException { try { listener . reconnect ( ) ; } catch ( SQLException e ) { ExceptionMapper . throwException ( e , null , null ) ; } } | Launch reconnect implementation . |
29,429 | public String readStringNullEnd ( final Charset charset ) { int initialPosition = position ; int cnt = 0 ; while ( remaining ( ) > 0 && ( buf [ position ++ ] != 0 ) ) { cnt ++ ; } return new String ( buf , initialPosition , cnt , charset ) ; } | Reads a string from the buffer looks for a 0 to end the string . |
29,430 | public byte [ ] readBytesNullEnd ( ) { int initialPosition = position ; int cnt = 0 ; while ( remaining ( ) > 0 && ( buf [ position ++ ] != 0 ) ) { cnt ++ ; } final byte [ ] tmpArr = new byte [ cnt ] ; System . arraycopy ( buf , initialPosition , tmpArr , 0 , cnt ) ; return tmpArr ; } | Reads a byte array from the buffer looks for a 0 to end the array . |
29,431 | public String readStringLengthEncoded ( final Charset charset ) { int length = ( int ) getLengthEncodedNumeric ( ) ; String string = new String ( buf , position , length , charset ) ; position += length ; return string ; } | Reads length - encoded string . |
29,432 | public String readString ( final int numberOfBytes ) { position += numberOfBytes ; return new String ( buf , position - numberOfBytes , numberOfBytes ) ; } | Read String with defined length . |
29,433 | public byte [ ] readRawBytes ( final int numberOfBytes ) { final byte [ ] tmpArr = new byte [ numberOfBytes ] ; System . arraycopy ( buf , position , tmpArr , 0 , numberOfBytes ) ; position += numberOfBytes ; return tmpArr ; } | Read raw data . |
29,434 | public void skipLengthEncodedBytes ( ) { int type = this . buf [ this . position ++ ] & 0xff ; switch ( type ) { case 251 : break ; case 252 : position += 2 + ( 0xffff & ( ( ( buf [ position ] & 0xff ) + ( ( buf [ position + 1 ] & 0xff ) << 8 ) ) ) ) ; break ; case 253 : position += 3 + ( 0xffffff & ( ( buf [ position ] & 0xff ) + ( ( buf [ position + 1 ] & 0xff ) << 8 ) + ( ( buf [ position + 2 ] & 0xff ) << 16 ) ) ) ; break ; case 254 : position += 8 + ( ( buf [ position ] & 0xff ) + ( ( long ) ( buf [ position + 1 ] & 0xff ) << 8 ) + ( ( long ) ( buf [ position + 2 ] & 0xff ) << 16 ) + ( ( long ) ( buf [ position + 3 ] & 0xff ) << 24 ) + ( ( long ) ( buf [ position + 4 ] & 0xff ) << 32 ) + ( ( long ) ( buf [ position + 5 ] & 0xff ) << 40 ) + ( ( long ) ( buf [ position + 6 ] & 0xff ) << 48 ) + ( ( long ) ( buf [ position + 7 ] & 0xff ) << 56 ) ) ; break ; default : position += type ; break ; } } | Skip next length encode binary data . |
29,435 | public byte [ ] getLengthEncodedBytes ( ) { int type = this . buf [ this . position ++ ] & 0xff ; int length ; switch ( type ) { case 251 : return null ; case 252 : length = 0xffff & readShort ( ) ; break ; case 253 : length = 0xffffff & read24bitword ( ) ; break ; case 254 : length = ( int ) ( ( buf [ position ++ ] & 0xff ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 8 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 16 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 24 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 32 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 40 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 48 ) + ( ( long ) ( buf [ position ++ ] & 0xff ) << 56 ) ) ; break ; default : length = type ; break ; } byte [ ] tmpBuf = new byte [ length ] ; System . arraycopy ( buf , position , tmpBuf , 0 , length ) ; position += length ; return tmpBuf ; } | Get next data bytes with length encoded prefix . |
29,436 | public void writeStringSmallLength ( byte [ ] value ) { int length = value . length ; while ( remaining ( ) < length + 1 ) { grow ( ) ; } buf [ position ++ ] = ( byte ) length ; System . arraycopy ( value , 0 , buf , position , length ) ; position += length ; } | Write value with length encoded prefix . value length MUST be less than 251 char |
29,437 | public void writeBytes ( byte header , byte [ ] bytes ) { int length = bytes . length ; while ( remaining ( ) < length + 10 ) { grow ( ) ; } writeLength ( length + 1 ) ; buf [ position ++ ] = header ; System . arraycopy ( bytes , 0 , buf , position , length ) ; position += length ; } | Write bytes . |
29,438 | public void writeLength ( long length ) { if ( length < 251 ) { buf [ position ++ ] = ( byte ) length ; } else if ( length < 65536 ) { buf [ position ++ ] = ( byte ) 0xfc ; buf [ position ++ ] = ( byte ) length ; buf [ position ++ ] = ( byte ) ( length >>> 8 ) ; } else if ( length < 16777216 ) { buf [ position ++ ] = ( byte ) 0xfd ; buf [ position ++ ] = ( byte ) length ; buf [ position ++ ] = ( byte ) ( length >>> 8 ) ; buf [ position ++ ] = ( byte ) ( length >>> 16 ) ; } else { buf [ position ++ ] = ( byte ) 0xfe ; buf [ position ++ ] = ( byte ) length ; buf [ position ++ ] = ( byte ) ( length >>> 8 ) ; buf [ position ++ ] = ( byte ) ( length >>> 16 ) ; buf [ position ++ ] = ( byte ) ( length >>> 24 ) ; buf [ position ++ ] = ( byte ) ( length >>> 32 ) ; buf [ position ++ ] = ( byte ) ( length >>> 40 ) ; buf [ position ++ ] = ( byte ) ( length >>> 48 ) ; buf [ position ++ ] = ( byte ) ( length >>> 54 ) ; } } | Write length . |
29,439 | public static void writeCmd ( final int statementId , final ParameterHolder [ ] parameters , final int parameterCount , ColumnType [ ] parameterTypeHeader , final PacketOutputStream pos , final byte cursorFlag ) throws IOException { pos . write ( Packet . COM_STMT_EXECUTE ) ; pos . writeInt ( statementId ) ; pos . write ( cursorFlag ) ; pos . writeInt ( 1 ) ; if ( parameterCount > 0 ) { int nullCount = ( parameterCount + 7 ) / 8 ; byte [ ] nullBitsBuffer = new byte [ nullCount ] ; for ( int i = 0 ; i < parameterCount ; i ++ ) { if ( parameters [ i ] . isNullData ( ) ) { nullBitsBuffer [ i / 8 ] |= ( 1 << ( i % 8 ) ) ; } } pos . write ( nullBitsBuffer , 0 , nullCount ) ; boolean mustSendHeaderType = false ; if ( parameterTypeHeader [ 0 ] == null ) { mustSendHeaderType = true ; } else { for ( int i = 0 ; i < parameterCount ; i ++ ) { if ( ! parameterTypeHeader [ i ] . equals ( parameters [ i ] . getColumnType ( ) ) ) { mustSendHeaderType = true ; break ; } } } if ( mustSendHeaderType ) { pos . write ( ( byte ) 0x01 ) ; for ( int i = 0 ; i < parameterCount ; i ++ ) { parameterTypeHeader [ i ] = parameters [ i ] . getColumnType ( ) ; pos . writeShort ( parameterTypeHeader [ i ] . getType ( ) ) ; } } else { pos . write ( ( byte ) 0x00 ) ; } } for ( int i = 0 ; i < parameterCount ; i ++ ) { ParameterHolder holder = parameters [ i ] ; if ( ! holder . isNullData ( ) && ! holder . isLongData ( ) ) { holder . writeBinary ( pos ) ; } } } | Write COM_STMT_EXECUTE sub - command to output buffer . |
29,440 | public static void send ( final PacketOutputStream pos , final int statementId , final ParameterHolder [ ] parameters , final int parameterCount , ColumnType [ ] parameterTypeHeader , byte cursorFlag ) throws IOException { pos . startPacket ( 0 ) ; writeCmd ( statementId , parameters , parameterCount , parameterTypeHeader , pos , cursorFlag ) ; pos . flush ( ) ; } | Send a prepare statement binary stream . |
29,441 | private void execute ( String command ) throws XAException { try { connection . createStatement ( ) . execute ( command ) ; } catch ( SQLException sqle ) { throw mapXaException ( sqle ) ; } } | Execute a query . |
29,442 | private String exWithQuery ( String message , PrepareResult serverPrepareResult , ParameterHolder [ ] parameters ) { if ( options . dumpQueriesOnException ) { StringBuilder sql = new StringBuilder ( serverPrepareResult . getSql ( ) ) ; if ( serverPrepareResult . getParamCount ( ) > 0 ) { sql . append ( ", parameters [" ) ; if ( parameters . length > 0 ) { for ( int i = 0 ; i < Math . min ( parameters . length , serverPrepareResult . getParamCount ( ) ) ; i ++ ) { sql . append ( parameters [ i ] . toString ( ) ) . append ( "," ) ; } sql = new StringBuilder ( sql . substring ( 0 , sql . length ( ) - 1 ) ) ; } sql . append ( "]" ) ; } if ( options . maxQuerySizeToLog != 0 && sql . length ( ) > options . maxQuerySizeToLog - 3 ) { return message + "\nQuery is: " + sql . substring ( 0 , options . maxQuerySizeToLog - 3 ) + "..." + "\njava thread: " + Thread . currentThread ( ) . getName ( ) ; } else { return message + "\nQuery is: " + sql + "\njava thread: " + Thread . currentThread ( ) . getName ( ) ; } } return message ; } | Return exception message with query . |
29,443 | public byte [ ] getPacketArray ( boolean reUsable ) throws IOException { byte [ ] cachePacket = getNextCachePacket ( ) ; if ( cachePacket != null ) { return cachePacket ; } do { readBlocking ( header , 7 ) ; int compressedLength = ( header [ 0 ] & 0xff ) + ( ( header [ 1 ] & 0xff ) << 8 ) + ( ( header [ 2 ] & 0xff ) << 16 ) ; compressPacketSeq = header [ 3 ] & 0xff ; int decompressedLength = ( header [ 4 ] & 0xff ) + ( ( header [ 5 ] & 0xff ) << 8 ) + ( ( header [ 6 ] & 0xff ) << 16 ) ; byte [ ] rawBytes ; if ( reUsable && decompressedLength == 0 && compressedLength < REUSABLE_BUFFER_LENGTH ) { rawBytes = reusableArray ; } else { rawBytes = new byte [ decompressedLength != 0 ? decompressedLength : compressedLength ] ; } readCompressBlocking ( rawBytes , compressedLength , decompressedLength ) ; if ( traceCache != null ) { int length = decompressedLength != 0 ? decompressedLength : compressedLength ; traceCache . put ( new TraceObject ( false , decompressedLength == 0 ? COMPRESSED_PROTOCOL_NOT_COMPRESSED_PACKET : COMPRESSED_PROTOCOL_COMPRESSED_PACKET , Arrays . copyOfRange ( header , 0 , 7 ) , Arrays . copyOfRange ( rawBytes , 0 , length > 1000 ? 1000 : length ) ) ) ; } if ( logger . isTraceEnabled ( ) ) { int length = decompressedLength != 0 ? decompressedLength : compressedLength ; logger . trace ( "read {} {}{}" , ( decompressedLength == 0 ? "uncompress" : "compress" ) , serverThreadLog , Utils . hexdump ( maxQuerySizeToLog - 7 , 0 , length , header , rawBytes ) ) ; } cache ( rawBytes , decompressedLength == 0 ? compressedLength : decompressedLength ) ; byte [ ] packet = getNextCachePacket ( ) ; if ( packet != null ) { return packet ; } } while ( true ) ; } | Get next packet . Packet can be compressed and if so can contain many standard packet . |
29,444 | public static void throwException ( SQLException exception , MariaDbConnection connection , MariaDbStatement statement ) throws SQLException { throw getException ( exception , connection , statement , false ) ; } | Helper to throw exception . |
29,445 | public static void checkConnectionException ( SQLException exception , MariaDbConnection connection ) { if ( exception . getSQLState ( ) != null ) { SqlStates state = SqlStates . fromString ( exception . getSQLState ( ) ) ; if ( SqlStates . CONNECTION_EXCEPTION . equals ( state ) ) { connection . setHostFailed ( ) ; if ( connection . pooledConnection != null ) { connection . pooledConnection . fireConnectionErrorOccured ( exception ) ; } } } } | Check connection exception to report to poolConnection listeners . |
29,446 | public static MariaDbConnection newConnection ( UrlParser urlParser , GlobalStateInfo globalInfo ) throws SQLException { if ( urlParser . getOptions ( ) . pool ) { return Pools . retrievePool ( urlParser ) . getConnection ( ) ; } Protocol protocol = Utils . retrieveProxy ( urlParser , globalInfo ) ; return new MariaDbConnection ( protocol ) ; } | Create new connection Object . |
29,447 | public static String unquoteIdentifier ( String string ) { if ( string != null && string . startsWith ( "`" ) && string . endsWith ( "`" ) && string . length ( ) >= 2 ) { return string . substring ( 1 , string . length ( ) - 1 ) . replace ( "``" , "`" ) ; } return string ; } | UnQuote string . |
29,448 | public ClientSidePreparedStatement clientPrepareStatement ( final String sql ) throws SQLException { return new ClientSidePreparedStatement ( this , sql , ResultSet . TYPE_FORWARD_ONLY , ResultSet . CONCUR_READ_ONLY , Statement . RETURN_GENERATED_KEYS ) ; } | Create a new client prepared statement . |
29,449 | public ServerSidePreparedStatement serverPrepareStatement ( final String sql ) throws SQLException { return new ServerSidePreparedStatement ( this , sql , ResultSet . TYPE_FORWARD_ONLY , ResultSet . CONCUR_READ_ONLY , Statement . RETURN_GENERATED_KEYS ) ; } | Create a new server prepared statement . |
29,450 | public PreparedStatement prepareStatement ( final String sql ) throws SQLException { return internalPrepareStatement ( sql , ResultSet . TYPE_FORWARD_ONLY , ResultSet . CONCUR_READ_ONLY , Statement . NO_GENERATED_KEYS ) ; } | creates a new prepared statement . |
29,451 | private PreparedStatement internalPrepareStatement ( final String sql , final int resultSetScrollType , final int resultSetConcurrency , final int autoGeneratedKeys ) throws SQLException { if ( sql != null ) { String sqlQuery = Utils . nativeSql ( sql , protocol . noBackslashEscapes ( ) ) ; if ( options . useServerPrepStmts && PREPARABLE_STATEMENT_PATTERN . matcher ( sqlQuery ) . find ( ) ) { checkConnection ( ) ; try { return new ServerSidePreparedStatement ( this , sqlQuery , resultSetScrollType , resultSetConcurrency , autoGeneratedKeys ) ; } catch ( SQLNonTransientConnectionException e ) { throw e ; } catch ( SQLException e ) { } } return new ClientSidePreparedStatement ( this , sqlQuery , resultSetScrollType , resultSetConcurrency , autoGeneratedKeys ) ; } else { throw new SQLException ( "SQL value can not be NULL" ) ; } } | Send ServerPrepareStatement or ClientPrepareStatement depending on SQL query and options If server side and PREPARE can be delayed a facade will be return to have a fallback on client prepareStatement . |
29,452 | public void commit ( ) throws SQLException { lock . lock ( ) ; try { if ( protocol . inTransaction ( ) ) { try ( Statement st = createStatement ( ) ) { st . execute ( "COMMIT" ) ; } } } finally { lock . unlock ( ) ; } } | Sends commit to the server . |
29,453 | public void setReadOnly ( final boolean readOnly ) throws SQLException { try { logger . debug ( "conn={}({}) - set read-only to value {} {}" , protocol . getServerThreadId ( ) , protocol . isMasterConnection ( ) ? "M" : "S" , readOnly ) ; stateFlag |= ConnectionState . STATE_READ_ONLY ; protocol . setReadonly ( readOnly ) ; } catch ( SQLException e ) { throw ExceptionMapper . getException ( e , this , null , false ) ; } } | Sets whether this connection is read only . |
29,454 | public Properties getClientInfo ( ) throws SQLException { checkConnection ( ) ; Properties properties = new Properties ( ) ; try ( Statement statement = createStatement ( ) ) { try ( ResultSet rs = statement . executeQuery ( "SELECT @ApplicationName, @ClientUser, @ClientHostname" ) ) { if ( rs . next ( ) ) { if ( rs . getString ( 1 ) != null ) { properties . setProperty ( "ApplicationName" , rs . getString ( 1 ) ) ; } if ( rs . getString ( 2 ) != null ) { properties . setProperty ( "ClientUser" , rs . getString ( 2 ) ) ; } if ( rs . getString ( 3 ) != null ) { properties . setProperty ( "ClientHostname" , rs . getString ( 3 ) ) ; } return properties ; } } } properties . setProperty ( "ApplicationName" , null ) ; properties . setProperty ( "ClientUser" , null ) ; properties . setProperty ( "ClientHostname" , null ) ; return properties ; } | Returns a list containing the name and current value of each client info property supported by the driver . The value of a client info property may be null if the property has not been set and does not have a default value . |
29,455 | public void setNetworkTimeout ( Executor executor , final int milliseconds ) throws SQLException { if ( this . isClosed ( ) ) { throw ExceptionMapper . getSqlException ( "Connection.setNetworkTimeout cannot be called on a closed connection" ) ; } if ( milliseconds < 0 ) { throw ExceptionMapper . getSqlException ( "Connection.setNetworkTimeout cannot be called with a negative timeout" ) ; } SQLPermission sqlPermission = new SQLPermission ( "setNetworkTimeout" ) ; SecurityManager securityManager = System . getSecurityManager ( ) ; if ( securityManager != null ) { securityManager . checkPermission ( sqlPermission ) ; } try { stateFlag |= ConnectionState . STATE_NETWORK_TIMEOUT ; protocol . setTimeout ( milliseconds ) ; } catch ( SocketException se ) { throw ExceptionMapper . getSqlException ( "Cannot set the network timeout" , se ) ; } } | Change network timeout . |
29,456 | public void reset ( ) throws SQLException { boolean useComReset = options . useResetConnection && ( ( protocol . isServerMariaDb ( ) && protocol . versionGreaterOrEqual ( 10 , 2 , 4 ) ) || ( ! protocol . isServerMariaDb ( ) && protocol . versionGreaterOrEqual ( 5 , 7 , 3 ) ) ) ; if ( useComReset ) { protocol . reset ( ) ; } if ( stateFlag != 0 ) { try { if ( ( stateFlag & ConnectionState . STATE_NETWORK_TIMEOUT ) != 0 ) { setNetworkTimeout ( null , options . socketTimeout ) ; } if ( ( stateFlag & ConnectionState . STATE_AUTOCOMMIT ) != 0 ) { setAutoCommit ( options . autocommit ) ; } if ( ( stateFlag & ConnectionState . STATE_DATABASE ) != 0 ) { protocol . resetDatabase ( ) ; } if ( ( stateFlag & ConnectionState . STATE_READ_ONLY ) != 0 ) { setReadOnly ( false ) ; } if ( ! useComReset && ( stateFlag & ConnectionState . STATE_TRANSACTION_ISOLATION ) != 0 ) { setTransactionIsolation ( defaultTransactionIsolation ) ; } stateFlag = 0 ; } catch ( SQLException sqle ) { throw ExceptionMapper . getSqlException ( "error resetting connection" ) ; } } warningsCleared = true ; } | Reset connection set has it was after creating a fresh new connection . defaultTransactionIsolation must have been initialized . |
29,457 | public int getIndex ( String name ) throws SQLException { if ( name == null ) { throw new SQLException ( "Column name cannot be null" ) ; } String lowerName = name . toLowerCase ( Locale . ROOT ) ; if ( aliasMap == null ) { aliasMap = new HashMap < > ( ) ; int counter = 0 ; for ( ColumnInformation ci : columnInfo ) { String columnAlias = ci . getName ( ) ; if ( columnAlias != null ) { columnAlias = columnAlias . toLowerCase ( Locale . ROOT ) ; aliasMap . putIfAbsent ( columnAlias , counter ) ; String tableName = ci . getTable ( ) ; if ( tableName != null ) { aliasMap . putIfAbsent ( tableName . toLowerCase ( Locale . ROOT ) + "." + columnAlias , counter ) ; } } counter ++ ; } } Integer res = aliasMap . get ( lowerName ) ; if ( res != null ) { return res ; } if ( originalMap == null ) { originalMap = new HashMap < > ( ) ; int counter = 0 ; for ( ColumnInformation ci : columnInfo ) { String columnRealName = ci . getOriginalName ( ) ; if ( columnRealName != null ) { columnRealName = columnRealName . toLowerCase ( Locale . ROOT ) ; originalMap . putIfAbsent ( columnRealName , counter ) ; String tableName = ci . getOriginalTable ( ) ; if ( tableName != null ) { originalMap . putIfAbsent ( tableName . toLowerCase ( Locale . ROOT ) + "." + columnRealName , counter ) ; } } counter ++ ; } } res = originalMap . get ( lowerName ) ; if ( res == null ) { throw ExceptionMapper . get ( "No such column: " + name , "42S22" , 1054 , null , false ) ; } return res ; } | Get column index by name . |
29,458 | public long getPrecision ( ) { switch ( type ) { case OLDDECIMAL : case DECIMAL : if ( isSigned ( ) ) { return length - ( ( decimals > 0 ) ? 2 : 1 ) ; } else { return length - ( ( decimals > 0 ) ? 1 : 0 ) ; } default : return length ; } } | Return metadata precision . |
29,459 | public int getDisplaySize ( ) { int vtype = type . getSqlType ( ) ; if ( vtype == Types . VARCHAR || vtype == Types . CHAR ) { int maxWidth = maxCharlen [ charsetNumber & 0xff ] ; if ( maxWidth == 0 ) { maxWidth = 1 ; } return ( int ) length / maxWidth ; } return ( int ) length ; } | Get column size . |
29,460 | public void addStats ( long updateCount , long insertId , boolean moreResultAvailable ) { if ( cmdInformation == null ) { if ( batch ) { cmdInformation = new CmdInformationBatch ( expectedSize , autoIncrement ) ; } else if ( moreResultAvailable ) { cmdInformation = new CmdInformationMultiple ( expectedSize , autoIncrement ) ; } else { cmdInformation = new CmdInformationSingle ( insertId , updateCount , autoIncrement ) ; return ; } } cmdInformation . addSuccessStat ( updateCount , insertId ) ; } | Add execution statistics . |
29,461 | public void addStatsError ( boolean moreResultAvailable ) { if ( cmdInformation == null ) { if ( batch ) { cmdInformation = new CmdInformationBatch ( expectedSize , autoIncrement ) ; } else if ( moreResultAvailable ) { cmdInformation = new CmdInformationMultiple ( expectedSize , autoIncrement ) ; } else { cmdInformation = new CmdInformationSingle ( 0 , Statement . EXECUTE_FAILED , autoIncrement ) ; return ; } } cmdInformation . addErrorStat ( ) ; } | Indicate that result is an Error to set appropriate results . |
29,462 | public void addResultSet ( SelectResultSet resultSet , boolean moreResultAvailable ) { if ( resultSet . isCallableResult ( ) ) { callableResultSet = resultSet ; return ; } if ( executionResults == null ) { executionResults = new ArrayDeque < > ( ) ; } executionResults . add ( resultSet ) ; if ( cmdInformation == null ) { if ( batch ) { cmdInformation = new CmdInformationBatch ( expectedSize , autoIncrement ) ; } else if ( moreResultAvailable ) { cmdInformation = new CmdInformationMultiple ( expectedSize , autoIncrement ) ; } else { cmdInformation = new CmdInformationSingle ( 0 , - 1 , autoIncrement ) ; return ; } } cmdInformation . addResultSetStat ( ) ; } | Add resultSet to results . |
29,463 | public boolean isFullyLoaded ( Protocol protocol ) { if ( fetchSize == 0 || resultSet == null ) { return true ; } return resultSet . isFullyLoaded ( ) && executionResults . isEmpty ( ) && ! protocol . hasMoreResults ( ) ; } | Indicate if result contain result - set that is still streaming from server . |
29,464 | public boolean getMoreResults ( final int current , Protocol protocol ) throws SQLException { if ( fetchSize != 0 && resultSet != null ) { protocol . getLock ( ) . lock ( ) ; try { if ( current == Statement . CLOSE_CURRENT_RESULT && resultSet != null ) { resultSet . close ( ) ; } else { resultSet . fetchRemaining ( ) ; } if ( protocol . hasMoreResults ( ) ) { protocol . getResult ( this ) ; } } catch ( SQLException e ) { ExceptionMapper . throwException ( e , null , statement ) ; } finally { protocol . getLock ( ) . unlock ( ) ; } } if ( cmdInformation . moreResults ( ) && ! batch ) { if ( current == Statement . CLOSE_CURRENT_RESULT && resultSet != null ) { resultSet . close ( ) ; } if ( executionResults != null ) { resultSet = executionResults . poll ( ) ; } return resultSet != null ; } else { if ( current == Statement . CLOSE_CURRENT_RESULT && resultSet != null ) { resultSet . close ( ) ; } resultSet = null ; return false ; } } | Position to next resultSet . |
29,465 | public String getDatabaseName ( ) { if ( database != null ) { return database ; } return ( urlParser != null && urlParser . getDatabase ( ) != null ) ? urlParser . getDatabase ( ) : "" ; } | Gets the name of the database . |
29,466 | public String getUser ( ) { if ( user != null ) { return user ; } return urlParser != null ? urlParser . getUsername ( ) : null ; } | Gets the username . |
29,467 | public int getPort ( ) { if ( port != null && port != 0 ) { return port ; } return urlParser != null ? urlParser . getHostAddresses ( ) . get ( 0 ) . port : 3306 ; } | Returns the port number . |
29,468 | public String getServerName ( ) { if ( hostname != null ) { return hostname ; } boolean hasHost = urlParser != null && this . urlParser . getHostAddresses ( ) . get ( 0 ) . host != null ; return ( hasHost ) ? this . urlParser . getHostAddresses ( ) . get ( 0 ) . host : "localhost" ; } | Returns the name of the database server . |
29,469 | public static void send ( final PacketOutputStream pos , final String database ) throws IOException { pos . startPacket ( 0 ) ; pos . write ( Packet . COM_INIT_DB ) ; pos . write ( database . getBytes ( "UTF-8" ) ) ; pos . flush ( ) ; } | Send a COM_INIT_DB request to specify the default schema for the connection . |
29,470 | public static GssapiAuth getAuthenticationMethod ( ) { try { if ( Platform . isWindows ( ) ) { try { Class . forName ( "waffle.windows.auth.impl.WindowsAuthProviderImpl" ) ; return new WindowsNativeSspiAuthentication ( ) ; } catch ( ClassNotFoundException cle ) { } } } catch ( Throwable cle ) { } return new StandardGssapiAuthentication ( ) ; } | Get authentication method according to classpath . Windows native authentication is using Waffle - jna . |
29,471 | public void writeTo ( final PacketOutputStream pos ) throws IOException { pos . write ( BINARY_INTRODUCER ) ; if ( length == Long . MAX_VALUE ) { pos . write ( is , true , noBackslashEscapes ) ; } else { pos . write ( is , length , true , noBackslashEscapes ) ; } pos . write ( QUOTE ) ; } | Write stream in text format . |
29,472 | public void writeTo ( final PacketOutputStream pos ) throws IOException { pos . write ( BINARY_INTRODUCER ) ; pos . writeBytesEscaped ( bytes , bytes . length , noBackslashEscapes ) ; pos . write ( QUOTE ) ; } | Write data to socket in text format . |
29,473 | @ SuppressWarnings ( "unchecked" ) public static void init ( boolean mustLog ) { if ( ( hasToLog == null || hasToLog != mustLog ) && mustLog ) { synchronized ( LoggerFactory . class ) { if ( hasToLog == null || hasToLog != mustLog ) { try { Class . forName ( "org.slf4j.LoggerFactory" ) ; hasToLog = Boolean . TRUE ; } catch ( ClassNotFoundException classNotFound ) { System . out . println ( "Logging cannot be activated, missing slf4j dependency" ) ; hasToLog = Boolean . FALSE ; } } } } } | Initialize factory . |
29,474 | public static Logger getLogger ( Class < ? > clazz ) { if ( hasToLog != null && hasToLog ) { return new Slf4JLogger ( org . slf4j . LoggerFactory . getLogger ( clazz ) ) ; } else { return NO_LOGGER ; } } | Initialize logger . |
29,475 | public static Socket standardSocket ( UrlParser urlParser , String host ) throws IOException { SocketFactory socketFactory ; String socketFactoryName = urlParser . getOptions ( ) . socketFactory ; if ( socketFactoryName != null ) { try { @ SuppressWarnings ( "unchecked" ) Class < ? extends SocketFactory > socketFactoryClass = ( Class < ? extends SocketFactory > ) Class . forName ( socketFactoryName ) ; if ( socketFactoryClass != null ) { Constructor < ? extends SocketFactory > constructor = socketFactoryClass . getConstructor ( ) ; socketFactory = constructor . newInstance ( ) ; return socketFactory . createSocket ( ) ; } } catch ( Exception exp ) { throw new IOException ( "Socket factory failed to initialized with option \"socketFactory\" set to \"" + urlParser . getOptions ( ) . socketFactory + "\"" , exp ) ; } } socketFactory = SocketFactory . getDefault ( ) ; return socketFactory . createSocket ( ) ; } | Use standard socket implementation . |
29,476 | public static String escapeString ( String value , boolean noBackslashEscapes ) { if ( ! value . contains ( "'" ) ) { if ( noBackslashEscapes ) { return value ; } if ( ! value . contains ( "\\" ) ) { return value ; } } String escaped = value . replace ( "'" , "''" ) ; if ( noBackslashEscapes ) { return escaped ; } return escaped . replace ( "\\" , "\\\\" ) ; } | Escape String . |
29,477 | public static byte [ ] encryptPassword ( final String password , final byte [ ] seed , String passwordCharacterEncoding ) throws NoSuchAlgorithmException , UnsupportedEncodingException { if ( password == null || password . isEmpty ( ) ) { return new byte [ 0 ] ; } final MessageDigest messageDigest = MessageDigest . getInstance ( "SHA-1" ) ; byte [ ] bytePwd ; if ( passwordCharacterEncoding != null && ! passwordCharacterEncoding . isEmpty ( ) ) { bytePwd = password . getBytes ( passwordCharacterEncoding ) ; } else { bytePwd = password . getBytes ( ) ; } final byte [ ] stage1 = messageDigest . digest ( bytePwd ) ; messageDigest . reset ( ) ; final byte [ ] stage2 = messageDigest . digest ( stage1 ) ; messageDigest . reset ( ) ; messageDigest . update ( seed ) ; messageDigest . update ( stage2 ) ; final byte [ ] digest = messageDigest . digest ( ) ; final byte [ ] returnBytes = new byte [ digest . length ] ; for ( int i = 0 ; i < digest . length ; i ++ ) { returnBytes [ i ] = ( byte ) ( stage1 [ i ] ^ digest [ i ] ) ; } return returnBytes ; } | Encrypts a password . |
29,478 | public static byte [ ] copyWithLength ( byte [ ] orig , int length ) { byte [ ] result = new byte [ length ] ; int howMuchToCopy = length < orig . length ? length : orig . length ; System . arraycopy ( orig , 0 , result , 0 , howMuchToCopy ) ; return result ; } | Copies the original byte array content to a new byte array . The resulting byte array is always length size . If length is smaller than the original byte array the resulting byte array is truncated . If length is bigger than the original byte array the resulting byte array is filled with zero bytes . |
29,479 | public static byte [ ] copyRange ( byte [ ] orig , int from , int to ) { int length = to - from ; byte [ ] result = new byte [ length ] ; int howMuchToCopy = orig . length - from < length ? orig . length - from : length ; System . arraycopy ( orig , from , result , 0 , howMuchToCopy ) ; return result ; } | Copies from original byte array to a new byte array . The resulting byte array is always to - from size . |
29,480 | public static Protocol retrieveProxy ( final UrlParser urlParser , final GlobalStateInfo globalInfo ) throws SQLException { final ReentrantLock lock = new ReentrantLock ( ) ; Protocol protocol ; switch ( urlParser . getHaMode ( ) ) { case AURORA : return getProxyLoggingIfNeeded ( urlParser , ( Protocol ) Proxy . newProxyInstance ( AuroraProtocol . class . getClassLoader ( ) , new Class [ ] { Protocol . class } , new FailoverProxy ( new AuroraListener ( urlParser , globalInfo ) , lock ) ) ) ; case REPLICATION : return getProxyLoggingIfNeeded ( urlParser , ( Protocol ) Proxy . newProxyInstance ( MastersSlavesProtocol . class . getClassLoader ( ) , new Class [ ] { Protocol . class } , new FailoverProxy ( new MastersSlavesListener ( urlParser , globalInfo ) , lock ) ) ) ; case FAILOVER : case SEQUENTIAL : return getProxyLoggingIfNeeded ( urlParser , ( Protocol ) Proxy . newProxyInstance ( MasterProtocol . class . getClassLoader ( ) , new Class [ ] { Protocol . class } , new FailoverProxy ( new MastersFailoverListener ( urlParser , globalInfo ) , lock ) ) ) ; default : protocol = getProxyLoggingIfNeeded ( urlParser , new MasterProtocol ( urlParser , globalInfo , lock ) ) ; protocol . connectWithoutProxy ( ) ; return protocol ; } } | Retrieve protocol corresponding to the failover options . if no failover option protocol will not be proxied . if a failover option is precised protocol will be proxied so that any connection error will be handle directly . |
29,481 | public static Socket createSocket ( UrlParser urlParser , String host ) throws IOException { return socketHandler . apply ( urlParser , host ) ; } | Create socket accordingly to options . |
29,482 | public static String parseSessionVariables ( String sessionVariable ) { StringBuilder out = new StringBuilder ( ) ; StringBuilder sb = new StringBuilder ( ) ; Parse state = Parse . Normal ; boolean iskey = true ; boolean singleQuotes = true ; boolean first = true ; String key = null ; char [ ] chars = sessionVariable . toCharArray ( ) ; for ( char car : chars ) { if ( state == Parse . Escape ) { sb . append ( car ) ; state = singleQuotes ? Parse . Quote : Parse . String ; continue ; } switch ( car ) { case '"' : if ( state == Parse . Normal ) { state = Parse . String ; singleQuotes = false ; } else if ( state == Parse . String && ! singleQuotes ) { state = Parse . Normal ; } break ; case '\'' : if ( state == Parse . Normal ) { state = Parse . String ; singleQuotes = true ; } else if ( state == Parse . String && singleQuotes ) { state = Parse . Normal ; } break ; case '\\' : if ( state == Parse . String ) { state = Parse . Escape ; } break ; case ';' : case ',' : if ( state == Parse . Normal ) { if ( ! iskey ) { if ( ! first ) { out . append ( "," ) ; } out . append ( key ) ; out . append ( sb . toString ( ) ) ; first = false ; } else { key = sb . toString ( ) . trim ( ) ; if ( ! key . isEmpty ( ) ) { if ( ! first ) { out . append ( "," ) ; } out . append ( key ) ; first = false ; } } iskey = true ; key = null ; sb = new StringBuilder ( ) ; continue ; } break ; case '=' : if ( state == Parse . Normal && iskey ) { key = sb . toString ( ) . trim ( ) ; iskey = false ; sb = new StringBuilder ( ) ; } break ; default : } sb . append ( car ) ; } if ( ! iskey ) { if ( ! first ) { out . append ( "," ) ; } out . append ( key ) ; out . append ( sb . toString ( ) ) ; } else { String tmpkey = sb . toString ( ) . trim ( ) ; if ( ! tmpkey . isEmpty ( ) && ! first ) { out . append ( "," ) ; } out . append ( tmpkey ) ; } return out . toString ( ) ; } | Parse the option sessionVariable to ensure having no injection . semi - column not in string will be replaced by comma . |
29,483 | public static int transactionFromString ( String txIsolation ) throws SQLException { switch ( txIsolation ) { case "READ-UNCOMMITTED" : return Connection . TRANSACTION_READ_UNCOMMITTED ; case "READ-COMMITTED" : return Connection . TRANSACTION_READ_COMMITTED ; case "REPEATABLE-READ" : return Connection . TRANSACTION_REPEATABLE_READ ; case "SERIALIZABLE" : return Connection . TRANSACTION_SERIALIZABLE ; default : throw new SQLException ( "unknown transaction isolation level" ) ; } } | Traduce a String value of transaction isolation to corresponding java value . |
29,484 | private void validAllParameters ( ) throws SQLException { setInputOutputParameterMap ( ) ; for ( int index = 0 ; index < params . size ( ) ; index ++ ) { if ( ! params . get ( index ) . isInput ( ) ) { super . setParameter ( index + 1 , new NullParameter ( ) ) ; } } validParameters ( ) ; } | Valid that all parameters are set . |
29,485 | public static int equal ( int b , int c ) { int result = 0 ; int xor = b ^ c ; for ( int i = 0 ; i < 8 ; i ++ ) { result |= xor >> i ; } return ( result ^ 0x01 ) & 0x01 ; } | Constant - time byte comparison . |
29,486 | public static String bytesToHex ( byte [ ] raw ) { if ( raw == null ) { return null ; } final StringBuilder hex = new StringBuilder ( 2 * raw . length ) ; for ( final byte b : raw ) { hex . append ( Character . forDigit ( ( b & 0xF0 ) >> 4 , 16 ) ) . append ( Character . forDigit ( ( b & 0x0F ) , 16 ) ) ; } return hex . toString ( ) ; } | Converts bytes to a hex string . |
29,487 | private HostAddress findClusterHostAddress ( UrlParser urlParser ) throws SQLException { List < HostAddress > hostAddresses = urlParser . getHostAddresses ( ) ; Matcher matcher ; for ( HostAddress hostAddress : hostAddresses ) { matcher = auroraDnsPattern . matcher ( hostAddress . host ) ; if ( matcher . find ( ) ) { if ( clusterDnsSuffix != null ) { if ( ! clusterDnsSuffix . equalsIgnoreCase ( matcher . group ( 3 ) ) ) { throw new SQLException ( "Connection string must contain only one aurora cluster. " + "'" + hostAddress . host + "' doesn't correspond to DNS prefix '" + clusterDnsSuffix + "'" ) ; } } else { clusterDnsSuffix = matcher . group ( 3 ) ; } if ( matcher . group ( 2 ) != null && ! matcher . group ( 2 ) . isEmpty ( ) ) { return hostAddress ; } } else { if ( clusterDnsSuffix == null && hostAddress . host . contains ( "." ) && ! Utils . isIPv4 ( hostAddress . host ) && ! Utils . isIPv6 ( hostAddress . host ) ) { clusterDnsSuffix = hostAddress . host . substring ( hostAddress . host . indexOf ( "." ) + 1 ) ; } } } return null ; } | Retrieves the cluster host address from the UrlParser instance . |
29,488 | public void retrieveAllEndpointsAndSet ( Protocol protocol ) throws SQLException { if ( clusterDnsSuffix != null ) { List < String > endpoints = getCurrentEndpointIdentifiers ( protocol ) ; setUrlParserFromEndpoints ( endpoints , protocol . getPort ( ) ) ; } } | Retrieves the information necessary to add a new endpoint . Calls the methods that retrieves the instance identifiers and sets urlParser accordingly . |
29,489 | private List < String > getCurrentEndpointIdentifiers ( Protocol protocol ) throws SQLException { List < String > endpoints = new ArrayList < > ( ) ; try { proxy . lock . lock ( ) ; try { Results results = new Results ( ) ; protocol . executeQuery ( false , results , "select server_id, session_id from information_schema.replica_host_status " + "where last_update_timestamp > now() - INTERVAL 3 MINUTE" ) ; results . commandEnd ( ) ; ResultSet resultSet = results . getResultSet ( ) ; while ( resultSet . next ( ) ) { endpoints . add ( resultSet . getString ( 1 ) + "." + clusterDnsSuffix ) ; } Collections . shuffle ( endpoints ) ; } finally { proxy . lock . unlock ( ) ; } } catch ( SQLException qe ) { logger . warning ( "SQL exception occurred: " + qe . getMessage ( ) ) ; if ( protocol . getProxy ( ) . hasToHandleFailover ( qe ) ) { if ( masterProtocol == null || masterProtocol . equals ( protocol ) ) { setMasterHostFail ( ) ; } else if ( secondaryProtocol . equals ( protocol ) ) { setSecondaryHostFail ( ) ; } addToBlacklist ( protocol . getHostAddress ( ) ) ; reconnectFailedConnection ( new SearchFilter ( isMasterHostFail ( ) , isSecondaryHostFail ( ) ) ) ; } } return endpoints ; } | Retrieves all endpoints of a cluster from the appropriate database table . |
29,490 | private void setUrlParserFromEndpoints ( List < String > endpoints , int port ) { List < HostAddress > addresses = new ArrayList < > ( ) ; for ( String endpoint : endpoints ) { HostAddress newHostAddress = new HostAddress ( endpoint , port , null ) ; addresses . add ( newHostAddress ) ; } synchronized ( urlParser ) { urlParser . setHostAddresses ( addresses ) ; } } | Sets urlParser accordingly to discovered hosts . |
29,491 | public static org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement p2 ( final Curve curve , final FieldElement X , final FieldElement Y , final FieldElement Z ) { return new org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement ( curve , Representation . P2 , X , Y , Z , null ) ; } | Creates a new group element in P2 representation . |
29,492 | public static org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement p1p1 ( final Curve curve , final FieldElement X , final FieldElement Y , final FieldElement Z , final FieldElement T ) { return new org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement ( curve , Representation . P1P1 , X , Y , Z , T ) ; } | Creates a new group element in P1P1 representation . |
29,493 | public static org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement precomp ( final Curve curve , final FieldElement ypx , final FieldElement ymx , final FieldElement xy2d ) { return new org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement ( curve , Representation . PRECOMP , ypx , ymx , xy2d , null ) ; } | Creates a new group element in PRECOMP representation . |
29,494 | public static org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement cached ( final Curve curve , final FieldElement YpX , final FieldElement YmX , final FieldElement Z , final FieldElement T2d ) { return new org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement ( curve , Representation . CACHED , YpX , YmX , Z , T2d ) ; } | Creates a new group element in CACHED representation . |
29,495 | public byte [ ] toByteArray ( ) { switch ( this . repr ) { case P2 : case P3 : FieldElement recip = Z . invert ( ) ; FieldElement x = X . multiply ( recip ) ; FieldElement y = Y . multiply ( recip ) ; byte [ ] s = y . toByteArray ( ) ; s [ s . length - 1 ] |= ( x . isNegative ( ) ? ( byte ) 0x80 : 0 ) ; return s ; default : return toP2 ( ) . toByteArray ( ) ; } } | Converts the group element to an encoded point on the curve . |
29,496 | public org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement toP2 ( ) { return toRep ( Representation . P2 ) ; } | Converts the group element to the P2 representation . |
29,497 | public org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement toP3 ( ) { return toRep ( Representation . P3 ) ; } | Converts the group element to the P3 representation . |
29,498 | public org . mariadb . jdbc . internal . com . send . authentication . ed25519 . math . GroupElement toCached ( ) { return toRep ( Representation . CACHED ) ; } | Converts the group element to the CACHED representation . |
29,499 | public boolean isOnCurve ( Curve curve ) { switch ( repr ) { case P2 : case P3 : FieldElement recip = Z . invert ( ) ; FieldElement x = X . multiply ( recip ) ; FieldElement y = Y . multiply ( recip ) ; FieldElement xx = x . square ( ) ; FieldElement yy = y . square ( ) ; FieldElement dxxyy = curve . getD ( ) . multiply ( xx ) . multiply ( yy ) ; return curve . getField ( ) . ONE . add ( dxxyy ) . add ( xx ) . equals ( yy ) ; default : return toP2 ( ) . isOnCurve ( curve ) ; } } | Verify that a point is on the curve . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.