idx int64 0 41.2k | question stringlengths 74 4.21k | target stringlengths 5 888 |
|---|---|---|
23,700 | public static KeyStore createTrustStore ( String capem ) throws IOException , CertificateException , KeyStoreException , NoSuchAlgorithmException { try ( Reader certReader = new StringReader ( capem ) ) { return createTrustStore ( certReader ) ; } } | ca . pem from String |
23,701 | public static KeyStore createTrustStore ( final Reader certReader ) throws IOException , CertificateException , KeyStoreException , NoSuchAlgorithmException { try ( PEMParser pemParser = new PEMParser ( certReader ) ) { KeyStore trustStore = KeyStore . getInstance ( "JKS" ) ; trustStore . load ( null ) ; int index = 1 ; Object pemCert ; while ( ( pemCert = pemParser . readObject ( ) ) != null ) { Certificate caCertificate = new JcaX509CertificateConverter ( ) . setProvider ( BouncyCastleProvider . PROVIDER_NAME ) . getCertificate ( ( X509CertificateHolder ) pemCert ) ; trustStore . setCertificateEntry ( "ca-" + index , caCertificate ) ; index ++ ; } return trustStore ; } } | ca . pem from Reader |
23,702 | public FiltersBuilder withLabels ( Map < String , String > labels ) { withFilter ( "label" , labelsMapToList ( labels ) . toArray ( new String [ labels . size ( ) ] ) ) ; return this ; } | Filter by labels |
23,703 | public boolean isPullSuccessIndicated ( ) { if ( isErrorIndicated ( ) || getStatus ( ) == null ) { return false ; } return ( getStatus ( ) . contains ( DOWNLOAD_COMPLETE ) || getStatus ( ) . contains ( IMAGE_UP_TO_DATE ) || getStatus ( ) . contains ( DOWNLOADED_NEWER_IMAGE ) || getStatus ( ) . contains ( LEGACY_REGISTRY ) || getStatus ( ) . contains ( DOWNLOADED_SWARM ) ) ; } | Returns whether the status indicates a successful pull operation |
23,704 | public static void tar ( Path inputPath , Path outputPath , boolean gZipped , boolean childrenOnly ) throws IOException { if ( ! Files . exists ( inputPath ) ) { throw new FileNotFoundException ( "File not found " + inputPath ) ; } FileUtils . touch ( outputPath . toFile ( ) ) ; try ( TarArchiveOutputStream tarArchiveOutputStream = buildTarStream ( outputPath , gZipped ) ) { if ( ! Files . isDirectory ( inputPath ) ) { TarArchiveEntry tarEntry = new TarArchiveEntry ( inputPath . getFileName ( ) . toString ( ) ) ; if ( inputPath . toFile ( ) . canExecute ( ) ) { tarEntry . setMode ( tarEntry . getMode ( ) | 0755 ) ; } putTarEntry ( tarArchiveOutputStream , tarEntry , inputPath ) ; } else { Path sourcePath = inputPath ; if ( ! childrenOnly ) { sourcePath = inputPath . getParent ( ) ; } Files . walkFileTree ( inputPath , EnumSet . of ( FOLLOW_LINKS ) , Integer . MAX_VALUE , new TarDirWalker ( sourcePath , tarArchiveOutputStream ) ) ; } tarArchiveOutputStream . flush ( ) ; } } | Recursively tar file |
23,705 | private void parseTrailerHeaders ( ) throws IOException { try { this . footers = AbstractMessageParser . parseHeaders ( in , constraints . getMaxHeaderCount ( ) , constraints . getMaxLineLength ( ) , null ) ; } catch ( final HttpException ex ) { final IOException ioe = new MalformedChunkCodingException ( "Invalid footer: " + ex . getMessage ( ) ) ; ioe . initCause ( ex ) ; throw ioe ; } } | Reads and stores the Trailer headers . |
23,706 | public static Optional < ? extends DockerfileStatement > createFromLine ( String cmd ) { if ( cmd . trim ( ) . isEmpty ( ) || cmd . startsWith ( "#" ) ) { return Optional . absent ( ) ; } Optional < ? extends DockerfileStatement > line ; line = Add . create ( cmd ) ; if ( line . isPresent ( ) ) { return line ; } line = Env . create ( cmd ) ; if ( line . isPresent ( ) ) { return line ; } return Optional . of ( new OtherLine ( cmd ) ) ; } | Return a dockerfile statement |
23,707 | public static List < String > match ( List < String > patterns , String name ) { List < String > matches = new ArrayList < String > ( ) ; for ( String pattern : patterns ) { if ( match ( pattern , name ) ) { matches . add ( pattern ) ; } } return matches ; } | Returns the matching patterns for the given string |
23,708 | public String awaitImageId ( long timeout , TimeUnit timeUnit ) { try { awaitCompletion ( timeout , timeUnit ) ; } catch ( InterruptedException e ) { throw new DockerClientException ( "Awaiting image id interrupted: " , e ) ; } return getImageId ( ) ; } | Awaits the image id from the response stream . |
23,709 | public static void setColumnsMap ( Record record , Map < String , Object > columns ) { record . setColumnsMap ( columns ) ; } | Return the columns map of the record |
23,710 | public Routes add ( String controllerKey , Class < ? extends Controller > controllerClass ) { return add ( controllerKey , controllerClass , controllerKey ) ; } | Add route . The viewPath is controllerKey |
23,711 | public Routes addInterceptor ( Interceptor interceptor ) { if ( com . jfinal . aop . AopManager . me ( ) . isInjectDependency ( ) ) { com . jfinal . aop . Aop . inject ( interceptor ) ; } injectInters . add ( interceptor ) ; return this ; } | Add inject interceptor for controller in this Routes |
23,712 | public Routes setBaseViewPath ( String baseViewPath ) { if ( StrKit . isBlank ( baseViewPath ) ) { throw new IllegalArgumentException ( "baseViewPath can not be blank" ) ; } baseViewPath = baseViewPath . trim ( ) ; if ( ! baseViewPath . startsWith ( "/" ) ) { baseViewPath = "/" + baseViewPath ; } if ( baseViewPath . endsWith ( "/" ) ) { baseViewPath = baseViewPath . substring ( 0 , baseViewPath . length ( ) - 1 ) ; } this . baseViewPath = baseViewPath ; return this ; } | Set base view path for controller in this routes |
23,713 | public final void invoke ( ) { if ( index < inters . length ) inters [ index ++ ] . intercept ( this ) ; else if ( index ++ == inters . length ) invocation . invoke ( ) ; } | Invoke the action |
23,714 | public void addSharedFunction ( String fileName ) { fileName = fileName . replace ( "\\" , "/" ) ; ISource source = sourceFactory . getSource ( baseTemplatePath , fileName , encoding ) ; doAddSharedFunction ( source , fileName ) ; } | Add shared function with file |
23,715 | public void addSharedFunctionByString ( String content ) { StringSource stringSource = new StringSource ( content , false ) ; doAddSharedFunction ( stringSource , null ) ; } | Add shared function by string content |
23,716 | public void addSharedFunction ( ISource source ) { String fileName = source instanceof FileSource ? ( ( FileSource ) source ) . getFileName ( ) : null ; doAddSharedFunction ( source , fileName ) ; } | Add shared function by ISource |
23,717 | Define getSharedFunction ( String functionName ) { Define func = sharedFunctionMap . get ( functionName ) ; if ( func == null ) { return null ; } if ( devMode && reloadModifiedSharedFunctionInDevMode ) { if ( func . isSourceModifiedForDevMode ( ) ) { synchronized ( this ) { func = sharedFunctionMap . get ( functionName ) ; if ( func . isSourceModifiedForDevMode ( ) ) { reloadSharedFunctionSourceList ( ) ; func = sharedFunctionMap . get ( functionName ) ; } } } } return func ; } | Get shared function by Env |
23,718 | private synchronized void reloadSharedFunctionSourceList ( ) { Map < String , Define > newMap = createSharedFunctionMap ( ) ; for ( int i = 0 , size = sharedFunctionSourceList . size ( ) ; i < size ; i ++ ) { ISource source = sharedFunctionSourceList . get ( i ) ; String fileName = source instanceof FileSource ? ( ( FileSource ) source ) . getFileName ( ) : null ; Env env = new Env ( this ) ; new Parser ( env , source . getContent ( ) , fileName ) . parse ( ) ; addToSharedFunctionMap ( newMap , env ) ; if ( devMode ) { env . addSource ( source ) ; } } this . sharedFunctionMap = newMap ; } | Reload shared function source list |
23,719 | public Connection getConnection ( ) throws SQLException { Connection conn = threadLocal . get ( ) ; if ( conn != null ) return conn ; return showSql ? new SqlReporter ( dataSource . getConnection ( ) ) . getConnection ( ) : dataSource . getConnection ( ) ; } | Get Connection . Support transaction if Connection in ThreadLocal |
23,720 | public Interceptors add ( Interceptor globalActionInterceptor ) { if ( globalActionInterceptor == null ) { throw new IllegalArgumentException ( "globalActionInterceptor can not be null." ) ; } InterceptorManager . me ( ) . addGlobalActionInterceptor ( globalActionInterceptor ) ; return this ; } | The same as addGlobalActionInterceptor . It is used to compatible with earlier version of jfinal |
23,721 | public Interceptors addGlobalServiceInterceptor ( Interceptor globalServiceInterceptor ) { if ( globalServiceInterceptor == null ) { throw new IllegalArgumentException ( "globalServiceInterceptor can not be null." ) ; } InterceptorManager . me ( ) . addGlobalServiceInterceptor ( globalServiceInterceptor ) ; return this ; } | Add the global service interceptor to intercept all the method enhanced by aop Enhancer . |
23,722 | public static void createToken ( Controller controller , String tokenName , int secondsOfTimeOut ) { if ( tokenCache == null ) { String tokenId = String . valueOf ( random . nextLong ( ) ) ; controller . setAttr ( tokenName , tokenId ) ; controller . setSessionAttr ( tokenName , tokenId ) ; createTokenHiddenField ( controller , tokenName , tokenId ) ; } else { createTokenUseTokenIdGenerator ( controller , tokenName , secondsOfTimeOut ) ; } } | Create Token . |
23,723 | public static boolean validateToken ( Controller controller , String tokenName ) { String clientTokenId = controller . getPara ( tokenName ) ; if ( tokenCache == null ) { String serverTokenId = controller . getSessionAttr ( tokenName ) ; controller . removeSessionAttr ( tokenName ) ; return StrKit . notBlank ( clientTokenId ) && clientTokenId . equals ( serverTokenId ) ; } else { Token token = new Token ( clientTokenId ) ; boolean result = tokenCache . contains ( token ) ; tokenCache . remove ( token ) ; return result ; } } | Check token to prevent resubmit . |
23,724 | @ SuppressWarnings ( "unchecked" ) public Map < String , Object > getColumns ( ) { if ( columns == null ) { if ( DbKit . config == null ) columns = DbKit . brokenConfig . containerFactory . getColumnsMap ( ) ; else columns = DbKit . config . containerFactory . getColumnsMap ( ) ; } return columns ; } | Return columns map . |
23,725 | public Record remove ( String ... columns ) { if ( columns != null ) for ( String c : columns ) this . getColumns ( ) . remove ( c ) ; return this ; } | Remove columns of this record . |
23,726 | public Record removeNullValueColumns ( ) { for ( java . util . Iterator < Entry < String , Object > > it = getColumns ( ) . entrySet ( ) . iterator ( ) ; it . hasNext ( ) ; ) { Entry < String , Object > e = it . next ( ) ; if ( e . getValue ( ) == null ) { it . remove ( ) ; } } return this ; } | Remove columns if it is null . |
23,727 | public Record keep ( String ... columns ) { if ( columns != null && columns . length > 0 ) { Map < String , Object > newColumns = new HashMap < String , Object > ( columns . length ) ; for ( String c : columns ) if ( this . getColumns ( ) . containsKey ( c ) ) newColumns . put ( c , this . getColumns ( ) . get ( c ) ) ; this . getColumns ( ) . clear ( ) ; this . getColumns ( ) . putAll ( newColumns ) ; } else this . getColumns ( ) . clear ( ) ; return this ; } | Keep columns of this record and remove other columns . |
23,728 | public Record keep ( String column ) { if ( getColumns ( ) . containsKey ( column ) ) { Object keepIt = getColumns ( ) . get ( column ) ; getColumns ( ) . clear ( ) ; getColumns ( ) . put ( column , keepIt ) ; } else getColumns ( ) . clear ( ) ; return this ; } | Keep column of this record and remove other columns . |
23,729 | public Record set ( String column , Object value ) { getColumns ( ) . put ( column , value ) ; return this ; } | Set column to record . |
23,730 | @ SuppressWarnings ( "unchecked" ) public < T > T get ( String column ) { return ( T ) getColumns ( ) . get ( column ) ; } | Get column of any mysql type |
23,731 | @ SuppressWarnings ( "unchecked" ) public < T > T get ( String column , Object defaultValue ) { Object result = getColumns ( ) . get ( column ) ; return ( T ) ( result != null ? result : defaultValue ) ; } | Get column of any mysql type . Returns defaultValue if null . |
23,732 | public String [ ] getColumnNames ( ) { Set < String > attrNameSet = getColumns ( ) . keySet ( ) ; return attrNameSet . toArray ( new String [ attrNameSet . size ( ) ] ) ; } | Return column names of this record . |
23,733 | public Object [ ] getColumnValues ( ) { java . util . Collection < Object > attrValueCollection = getColumns ( ) . values ( ) ; return attrValueCollection . toArray ( new Object [ attrValueCollection . size ( ) ] ) ; } | Return column values of this record . |
23,734 | public Controller setAttr ( String name , Object value ) { request . setAttribute ( name , value ) ; return this ; } | Stores an attribute in this request |
23,735 | public Controller setAttrs ( Map < String , Object > attrMap ) { for ( Map . Entry < String , Object > entry : attrMap . entrySet ( ) ) request . setAttribute ( entry . getKey ( ) , entry . getValue ( ) ) ; return this ; } | Stores attributes in this request key of the map as attribute name and value of the map as attribute value |
23,736 | public String getPara ( String name , String defaultValue ) { String result = request . getParameter ( name ) ; return result != null && ! "" . equals ( result ) ? result : defaultValue ; } | Returns the value of a request parameter as a String or default value if the parameter does not exist . |
23,737 | public Integer [ ] getParaValuesToInt ( String name ) { String [ ] values = request . getParameterValues ( name ) ; if ( values == null || values . length == 0 ) { return null ; } Integer [ ] result = new Integer [ values . length ] ; for ( int i = 0 ; i < result . length ; i ++ ) { result [ i ] = StrKit . isBlank ( values [ i ] ) ? null : Integer . parseInt ( values [ i ] ) ; } return result ; } | Returns an array of Integer objects containing all of the values the given request parameter has or null if the parameter does not exist . If the parameter has a single value the array has a length of 1 . |
23,738 | public Integer getParaToInt ( String name , Integer defaultValue ) { return toInt ( request . getParameter ( name ) , defaultValue ) ; } | Returns the value of a request parameter and convert to Integer with a default value if it is null . |
23,739 | public Long getParaToLong ( String name , Long defaultValue ) { return toLong ( request . getParameter ( name ) , defaultValue ) ; } | Returns the value of a request parameter and convert to Long with a default value if it is null . |
23,740 | public Boolean getParaToBoolean ( String name , Boolean defaultValue ) { return toBoolean ( request . getParameter ( name ) , defaultValue ) ; } | Returns the value of a request parameter and convert to Boolean with a default value if it is null . |
23,741 | public Date getParaToDate ( String name , Date defaultValue ) { return toDate ( request . getParameter ( name ) , defaultValue ) ; } | Returns the value of a request parameter and convert to Date with a default value if it is null . |
23,742 | public < T > T getSessionAttr ( String key ) { HttpSession session = request . getSession ( false ) ; return session != null ? ( T ) session . getAttribute ( key ) : null ; } | Return a Object from session . |
23,743 | public Controller removeSessionAttr ( String key ) { HttpSession session = request . getSession ( false ) ; if ( session != null ) session . removeAttribute ( key ) ; return this ; } | Remove Object in session . |
23,744 | public String getCookie ( String name , String defaultValue ) { Cookie cookie = getCookieObject ( name ) ; return cookie != null ? cookie . getValue ( ) : defaultValue ; } | Get cookie value by cookie name . |
23,745 | public Integer getCookieToInt ( String name , Integer defaultValue ) { String result = getCookie ( name ) ; return result != null ? Integer . parseInt ( result ) : defaultValue ; } | Get cookie value by cookie name and convert to Integer . |
23,746 | public Long getCookieToLong ( String name ) { String result = getCookie ( name ) ; return result != null ? Long . parseLong ( result ) : null ; } | Get cookie value by cookie name and convert to Long . |
23,747 | public Cookie getCookieObject ( String name ) { Cookie [ ] cookies = request . getCookies ( ) ; if ( cookies != null ) for ( Cookie cookie : cookies ) if ( cookie . getName ( ) . equals ( name ) ) return cookie ; return null ; } | Get cookie object by cookie name . |
23,748 | public Cookie [ ] getCookieObjects ( ) { Cookie [ ] result = request . getCookies ( ) ; return result != null ? result : new Cookie [ 0 ] ; } | Get all cookie objects . |
23,749 | public Controller setCookie ( String name , String value , int maxAgeInSeconds , String path , boolean isHttpOnly ) { return doSetCookie ( name , value , maxAgeInSeconds , path , null , isHttpOnly ) ; } | Set Cookie to response . |
23,750 | public String getPara ( int index ) { if ( index < 0 ) return getPara ( ) ; if ( urlParaArray == null ) { if ( urlPara == null || "" . equals ( urlPara ) ) urlParaArray = NULL_URL_PARA_ARRAY ; else urlParaArray = urlPara . split ( URL_PARA_SEPARATOR ) ; for ( int i = 0 ; i < urlParaArray . length ; i ++ ) if ( "" . equals ( urlParaArray [ i ] ) ) urlParaArray [ i ] = null ; } return urlParaArray . length > index ? urlParaArray [ index ] : null ; } | Get para from url . The index of first url para is 0 . |
23,751 | public String getPara ( int index , String defaultValue ) { String result = getPara ( index ) ; return result != null && ! "" . equals ( result ) ? result : defaultValue ; } | Get para from url with default value if it is null or . |
23,752 | public < T > T getModel ( Class < T > modelClass ) { return ( T ) Injector . injectModel ( modelClass , request , false ) ; } | Get model from http request . |
23,753 | public List < UploadFile > getFiles ( String uploadPath , Integer maxPostSize , String encoding ) { if ( request instanceof MultipartRequest == false ) request = new MultipartRequest ( request , uploadPath , maxPostSize , encoding ) ; return ( ( MultipartRequest ) request ) . getFiles ( ) ; } | Get upload file from multipart request . |
23,754 | public Controller keepPara ( ) { Map < String , String [ ] > map = request . getParameterMap ( ) ; for ( Entry < String , String [ ] > e : map . entrySet ( ) ) { String [ ] values = e . getValue ( ) ; if ( values . length == 1 ) request . setAttribute ( e . getKey ( ) , values [ 0 ] ) ; else request . setAttribute ( e . getKey ( ) , values ) ; } return this ; } | Keep all parameter s value except model value |
23,755 | public Controller keepPara ( String ... names ) { for ( String name : names ) { String [ ] values = request . getParameterValues ( name ) ; if ( values != null ) { if ( values . length == 1 ) request . setAttribute ( name , values [ 0 ] ) ; else request . setAttribute ( name , values ) ; } } return this ; } | Keep parameter s value names pointed model value can not be kept |
23,756 | public Controller keepPara ( Class type , String name ) { String [ ] values = request . getParameterValues ( name ) ; if ( values != null ) { if ( values . length == 1 ) try { request . setAttribute ( name , TypeConverter . me ( ) . convert ( type , values [ 0 ] ) ) ; } catch ( ParseException e ) { com . jfinal . kit . LogKit . logNothing ( e ) ; } else request . setAttribute ( name , values ) ; } return this ; } | Convert para to special type and keep it |
23,757 | public void addFunction ( Define function ) { String fn = function . getFunctionName ( ) ; if ( functionMap . containsKey ( fn ) ) { Define previous = functionMap . get ( fn ) ; throw new ParseException ( "Template function \"" + fn + "\" already defined in " + getAlreadyDefinedLocation ( previous . getLocation ( ) ) , function . getLocation ( ) ) ; } functionMap . put ( fn , function ) ; } | Add template function |
23,758 | public Define getFunction ( String functionName ) { Define func = functionMap . get ( functionName ) ; return func != null ? func : engineConfig . getSharedFunction ( functionName ) ; } | Get function of current template first getting shared function if null before |
23,759 | public synchronized static Engine create ( String engineName ) { if ( StrKit . isBlank ( engineName ) ) { throw new IllegalArgumentException ( "Engine name can not be blank" ) ; } engineName = engineName . trim ( ) ; if ( engineMap . containsKey ( engineName ) ) { throw new IllegalArgumentException ( "Engine already exists : " + engineName ) ; } Engine newEngine = new Engine ( engineName ) ; engineMap . put ( engineName , newEngine ) ; return newEngine ; } | Create engine with engine name managed by JFinal |
23,760 | public synchronized static Engine remove ( String engineName ) { Engine removed = engineMap . remove ( engineName ) ; if ( removed != null && MAIN_ENGINE_NAME . equals ( removed . name ) ) { Engine . MAIN_ENGINE = null ; } return removed ; } | Remove engine with engine name managed by JFinal |
23,761 | public synchronized static void setMainEngine ( Engine engine ) { if ( engine == null ) { throw new IllegalArgumentException ( "Engine can not be null" ) ; } engine . name = Engine . MAIN_ENGINE_NAME ; engineMap . put ( Engine . MAIN_ENGINE_NAME , engine ) ; Engine . MAIN_ENGINE = engine ; } | Set main engine |
23,762 | public Template getTemplate ( String fileName ) { if ( fileName . charAt ( 0 ) != '/' ) { char [ ] arr = new char [ fileName . length ( ) + 1 ] ; fileName . getChars ( 0 , fileName . length ( ) , arr , 1 ) ; arr [ 0 ] = '/' ; fileName = new String ( arr ) ; } Template template = templateCache . get ( fileName ) ; if ( template == null ) { template = buildTemplateBySourceFactory ( fileName ) ; templateCache . put ( fileName , template ) ; } else if ( devMode ) { if ( template . isModified ( ) ) { template = buildTemplateBySourceFactory ( fileName ) ; templateCache . put ( fileName , template ) ; } } return template ; } | Get template by file name |
23,763 | public Template getTemplateByString ( String content , boolean cache ) { if ( ! cache ) { return buildTemplateBySource ( new StringSource ( content , cache ) ) ; } String cacheKey = HashKit . md5 ( content ) ; Template template = templateCache . get ( cacheKey ) ; if ( template == null ) { template = buildTemplateBySource ( new StringSource ( content , cache ) ) ; templateCache . put ( cacheKey , template ) ; } else if ( devMode ) { if ( template . isModified ( ) ) { template = buildTemplateBySource ( new StringSource ( content , cache ) ) ; templateCache . put ( cacheKey , template ) ; } } return template ; } | Get template by string content |
23,764 | public Template getTemplate ( ISource source ) { String cacheKey = source . getCacheKey ( ) ; if ( cacheKey == null ) { return buildTemplateBySource ( source ) ; } Template template = templateCache . get ( cacheKey ) ; if ( template == null ) { template = buildTemplateBySource ( source ) ; templateCache . put ( cacheKey , template ) ; } else if ( devMode ) { if ( template . isModified ( ) ) { template = buildTemplateBySource ( source ) ; templateCache . put ( cacheKey , template ) ; } } return template ; } | Get template by implementation of ISource |
23,765 | public Engine addSharedObject ( String name , Object object ) { config . addSharedObject ( name , object ) ; return this ; } | Add shared object |
23,766 | public static void addConfig ( Config config ) { if ( config == null ) { throw new IllegalArgumentException ( "Config can not be null" ) ; } if ( configNameToConfig . containsKey ( config . getName ( ) ) ) { throw new IllegalArgumentException ( "Config already exists: " + config . getName ( ) ) ; } configNameToConfig . put ( config . getName ( ) , config ) ; if ( MAIN_CONFIG_NAME . equals ( config . getName ( ) ) ) { DbKit . config = config ; Db . init ( DbKit . config . getName ( ) ) ; } if ( DbKit . config == null ) { DbKit . config = config ; Db . init ( DbKit . config . getName ( ) ) ; } } | Add Config object |
23,767 | public int update ( String sql , Object ... paras ) { Connection conn = null ; try { conn = config . getConnection ( ) ; return update ( config , conn , sql , paras ) ; } catch ( Exception e ) { throw new ActiveRecordException ( e ) ; } finally { config . close ( conn ) ; } } | Execute update insert or delete sql statement . |
23,768 | public Record findFirstByCache ( String cacheName , Object key , String sql , Object ... paras ) { ICache cache = config . getCache ( ) ; Record result = cache . get ( cacheName , key ) ; if ( result == null ) { result = findFirst ( sql , paras ) ; cache . put ( cacheName , key , result ) ; } return result ; } | Find first record by cache . I recommend add limit 1 in your sql . |
23,769 | public int [ ] batchSave ( List < ? extends Model > modelList , int batchSize ) { if ( modelList == null || modelList . size ( ) == 0 ) return new int [ 0 ] ; Model model = modelList . get ( 0 ) ; Map < String , Object > attrs = model . _getAttrs ( ) ; int index = 0 ; StringBuilder columns = new StringBuilder ( ) ; for ( Entry < String , Object > e : attrs . entrySet ( ) ) { if ( config . dialect . isOracle ( ) ) { Object value = e . getValue ( ) ; if ( value instanceof String && ( ( String ) value ) . endsWith ( ".nextval" ) ) { continue ; } } if ( index ++ > 0 ) { columns . append ( ',' ) ; } columns . append ( e . getKey ( ) ) ; } StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forModelSave ( TableMapping . me ( ) . getTable ( model . getClass ( ) ) , attrs , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns . toString ( ) , modelList , batchSize ) ; } | Batch save models using the insert into ... sql generated by the first model in modelList . Ensure all the models can use the same sql as the first model . |
23,770 | public int [ ] batchSave ( String tableName , List < Record > recordList , int batchSize ) { if ( recordList == null || recordList . size ( ) == 0 ) return new int [ 0 ] ; Record record = recordList . get ( 0 ) ; Map < String , Object > cols = record . getColumns ( ) ; int index = 0 ; StringBuilder columns = new StringBuilder ( ) ; for ( Entry < String , Object > e : cols . entrySet ( ) ) { if ( config . dialect . isOracle ( ) ) { Object value = e . getValue ( ) ; if ( value instanceof String && ( ( String ) value ) . endsWith ( ".nextval" ) ) { continue ; } } if ( index ++ > 0 ) { columns . append ( ',' ) ; } columns . append ( e . getKey ( ) ) ; } String [ ] pKeysNoUse = new String [ 0 ] ; StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forDbSave ( tableName , pKeysNoUse , record , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns . toString ( ) , recordList , batchSize ) ; } | Batch save records using the insert into ... sql generated by the first record in recordList . Ensure all the record can use the same sql as the first record . |
23,771 | public int [ ] batchUpdate ( List < ? extends Model > modelList , int batchSize ) { if ( modelList == null || modelList . size ( ) == 0 ) return new int [ 0 ] ; Model model = modelList . get ( 0 ) ; Table table = TableMapping . me ( ) . getTable ( model . getClass ( ) ) ; String [ ] pKeys = table . getPrimaryKey ( ) ; Map < String , Object > attrs = model . _getAttrs ( ) ; List < String > attrNames = new ArrayList < String > ( ) ; for ( Entry < String , Object > e : attrs . entrySet ( ) ) { String attr = e . getKey ( ) ; if ( config . dialect . isPrimaryKey ( attr , pKeys ) == false && table . hasColumnLabel ( attr ) ) attrNames . add ( attr ) ; } for ( String pKey : pKeys ) attrNames . add ( pKey ) ; String columns = StrKit . join ( attrNames . toArray ( new String [ attrNames . size ( ) ] ) , "," ) ; Set < String > modifyFlag = attrs . keySet ( ) ; StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forModelUpdate ( TableMapping . me ( ) . getTable ( model . getClass ( ) ) , attrs , modifyFlag , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns , modelList , batchSize ) ; } | Batch update models using the attrs names of the first model in modelList . Ensure all the models can use the same sql as the first model . |
23,772 | public int [ ] batchUpdate ( String tableName , String primaryKey , List < Record > recordList , int batchSize ) { if ( recordList == null || recordList . size ( ) == 0 ) return new int [ 0 ] ; String [ ] pKeys = primaryKey . split ( "," ) ; config . dialect . trimPrimaryKeys ( pKeys ) ; Record record = recordList . get ( 0 ) ; Map < String , Object > cols = record . getColumns ( ) ; List < String > colNames = new ArrayList < String > ( ) ; for ( Entry < String , Object > e : cols . entrySet ( ) ) { String col = e . getKey ( ) ; if ( config . dialect . isPrimaryKey ( col , pKeys ) == false ) colNames . add ( col ) ; } for ( String pKey : pKeys ) colNames . add ( pKey ) ; String columns = StrKit . join ( colNames . toArray ( new String [ colNames . size ( ) ] ) , "," ) ; Object [ ] idsNoUse = new Object [ pKeys . length ] ; StringBuilder sql = new StringBuilder ( ) ; List < Object > parasNoUse = new ArrayList < Object > ( ) ; config . dialect . forDbUpdate ( tableName , pKeys , idsNoUse , record , sql , parasNoUse ) ; return batch ( sql . toString ( ) , columns , recordList , batchSize ) ; } | Batch update records using the columns names of the first record in recordList . Ensure all the records can use the same sql as the first record . |
23,773 | public int [ ] batchUpdate ( String tableName , List < Record > recordList , int batchSize ) { return batchUpdate ( tableName , config . dialect . getDefaultPrimaryKey ( ) , recordList , batchSize ) ; } | Batch update records with default primary key using the columns names of the first record in recordList . Ensure all the records can use the same sql as the first record . |
23,774 | @ SuppressWarnings ( "deprecation" ) public static Handler getHandler ( List < Handler > handlerList , Handler actionHandler ) { Handler result = actionHandler ; for ( int i = handlerList . size ( ) - 1 ; i >= 0 ; i -- ) { Handler temp = handlerList . get ( i ) ; temp . next = result ; temp . nextHandler = result ; result = temp ; } return result ; } | Build handler chain |
23,775 | protected void addError ( String errorKey , String errorMessage ) { invalid = true ; controller . setAttr ( errorKey , errorMessage ) ; if ( shortCircuit ) { throw new ValidateException ( ) ; } } | Add message when validate failure . |
23,776 | protected void validateRequired ( String field , String errorKey , String errorMessage ) { String value = controller . getPara ( field ) ; if ( value == null || "" . equals ( value ) ) { addError ( errorKey , errorMessage ) ; } } | Validate Required . Allow space characters . |
23,777 | protected void validateRequired ( int index , String errorKey , String errorMessage ) { String value = controller . getPara ( index ) ; if ( value == null ) { addError ( errorKey , errorMessage ) ; } } | Validate Required for urlPara . |
23,778 | protected void validateRequiredString ( String field , String errorKey , String errorMessage ) { if ( StrKit . isBlank ( controller . getPara ( field ) ) ) { addError ( errorKey , errorMessage ) ; } } | Validate required string . |
23,779 | protected void validateInteger ( String field , String errorKey , String errorMessage ) { validateIntegerValue ( controller . getPara ( field ) , errorKey , errorMessage ) ; } | Validate integer . |
23,780 | protected void validateInteger ( int index , String errorKey , String errorMessage ) { String value = controller . getPara ( index ) ; if ( value != null && ( value . startsWith ( "N" ) || value . startsWith ( "n" ) ) ) { value = "-" + value . substring ( 1 ) ; } validateIntegerValue ( value , errorKey , errorMessage ) ; } | Validate integer for urlPara . |
23,781 | protected void validateLong ( String field , long min , long max , String errorKey , String errorMessage ) { validateLongValue ( controller . getPara ( field ) , min , max , errorKey , errorMessage ) ; } | Validate long . |
23,782 | protected void validateLong ( int index , long min , long max , String errorKey , String errorMessage ) { String value = controller . getPara ( index ) ; if ( value != null && ( value . startsWith ( "N" ) || value . startsWith ( "n" ) ) ) { value = "-" + value . substring ( 1 ) ; } validateLongValue ( value , min , max , errorKey , errorMessage ) ; } | Validate long for urlPara . |
23,783 | protected void validateDouble ( String field , double min , double max , String errorKey , String errorMessage ) { String value = controller . getPara ( field ) ; if ( StrKit . isBlank ( value ) ) { addError ( errorKey , errorMessage ) ; return ; } try { double temp = Double . parseDouble ( value . trim ( ) ) ; if ( temp < min || temp > max ) { addError ( errorKey , errorMessage ) ; } } catch ( Exception e ) { addError ( errorKey , errorMessage ) ; } } | Validate double . |
23,784 | protected void validateDate ( String field , Date min , Date max , String errorKey , String errorMessage ) { String value = controller . getPara ( field ) ; if ( StrKit . isBlank ( value ) ) { addError ( errorKey , errorMessage ) ; return ; } try { Date temp = new SimpleDateFormat ( getDatePattern ( ) ) . parse ( value . trim ( ) ) ; if ( temp . before ( min ) || temp . after ( max ) ) { addError ( errorKey , errorMessage ) ; } } catch ( Exception e ) { addError ( errorKey , errorMessage ) ; } } | Validate date . |
23,785 | protected void validateEqualField ( String field_1 , String field_2 , String errorKey , String errorMessage ) { String value_1 = controller . getPara ( field_1 ) ; String value_2 = controller . getPara ( field_2 ) ; if ( value_1 == null || value_2 == null || ( ! value_1 . equals ( value_2 ) ) ) { addError ( errorKey , errorMessage ) ; } } | Validate equal field . Usually validate password and password again |
23,786 | protected void validateEqualString ( String s1 , String s2 , String errorKey , String errorMessage ) { if ( s1 == null || s2 == null || ( ! s1 . equals ( s2 ) ) ) { addError ( errorKey , errorMessage ) ; } } | Validate equal string . |
23,787 | protected void validateEqualInteger ( Integer i1 , Integer i2 , String errorKey , String errorMessage ) { if ( i1 == null || i2 == null || ( i1 . intValue ( ) != i2 . intValue ( ) ) ) { addError ( errorKey , errorMessage ) ; } } | Validate equal integer . |
23,788 | protected void validateEmail ( String field , String errorKey , String errorMessage ) { validateRegex ( field , emailAddressPattern , false , errorKey , errorMessage ) ; } | Validate email . |
23,789 | protected void validateUrl ( String field , String errorKey , String errorMessage ) { String value = controller . getPara ( field ) ; if ( StrKit . isBlank ( value ) ) { addError ( errorKey , errorMessage ) ; return ; } try { value = value . trim ( ) ; if ( value . startsWith ( "https://" ) ) { value = "http://" + value . substring ( 8 ) ; } new URL ( value ) ; } catch ( MalformedURLException e ) { addError ( errorKey , errorMessage ) ; } } | Validate URL . |
23,790 | protected void validateRegex ( String field , String regExpression , boolean isCaseSensitive , String errorKey , String errorMessage ) { String value = controller . getPara ( field ) ; if ( value == null ) { addError ( errorKey , errorMessage ) ; return ; } Pattern pattern = isCaseSensitive ? Pattern . compile ( regExpression ) : Pattern . compile ( regExpression , Pattern . CASE_INSENSITIVE ) ; Matcher matcher = pattern . matcher ( value ) ; if ( ! matcher . matches ( ) ) { addError ( errorKey , errorMessage ) ; } } | Validate regular expression . |
23,791 | protected void validateRegex ( String field , String regExpression , String errorKey , String errorMessage ) { validateRegex ( field , regExpression , true , errorKey , errorMessage ) ; } | Validate regular expression and case sensitive . |
23,792 | protected void validateString ( String field , int minLen , int maxLen , String errorKey , String errorMessage ) { validateStringValue ( controller . getPara ( field ) , minLen , maxLen , errorKey , errorMessage ) ; } | Validate string . |
23,793 | protected void validateBoolean ( String field , String errorKey , String errorMessage ) { validateBooleanValue ( controller . getPara ( field ) , errorKey , errorMessage ) ; } | validate boolean . |
23,794 | protected void validateBoolean ( int index , String errorKey , String errorMessage ) { validateBooleanValue ( controller . getPara ( index ) , errorKey , errorMessage ) ; } | validate boolean for urlPara . |
23,795 | public void setRenderFactory ( IRenderFactory renderFactory ) { if ( renderFactory == null ) { throw new IllegalArgumentException ( "renderFactory can not be null." ) ; } RenderManager . me ( ) . setRenderFactory ( renderFactory ) ; } | Set the renderFactory |
23,796 | public void setUrlParaSeparator ( String urlParaSeparator ) { if ( StrKit . isBlank ( urlParaSeparator ) || urlParaSeparator . contains ( "/" ) ) { throw new IllegalArgumentException ( "urlParaSepartor can not be blank and can not contains \"/\"" ) ; } this . urlParaSeparator = urlParaSeparator ; } | Set urlPara separator . The default value is - |
23,797 | public String [ ] _getAttrNames ( ) { Set < String > attrNameSet = attrs . keySet ( ) ; return attrNameSet . toArray ( new String [ attrNameSet . size ( ) ] ) ; } | Return attribute names of this model . |
23,798 | public Object [ ] _getAttrValues ( ) { java . util . Collection < Object > attrValueCollection = attrs . values ( ) ; return attrValueCollection . toArray ( new Object [ attrValueCollection . size ( ) ] ) ; } | Return attribute values of this model . |
23,799 | public M _setAttrs ( Map < String , Object > attrs ) { for ( Entry < String , Object > e : attrs . entrySet ( ) ) set ( e . getKey ( ) , e . getValue ( ) ) ; return ( M ) this ; } | Set attributes with Map . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.