idx int64 0 41.2k | question stringlengths 83 4.15k | target stringlengths 5 715 |
|---|---|---|
22,400 | public boolean hasDeploymentSubsystemModel ( final String subsystemName ) { final Resource root = deploymentUnit . getAttachment ( DEPLOYMENT_RESOURCE ) ; final PathElement subsystem = PathElement . pathElement ( SUBSYSTEM , subsystemName ) ; return root . hasChild ( subsystem ) ; } | Checks to see if a subsystem resource has already been registered for the deployment . |
22,401 | public ModelNode getDeploymentSubsystemModel ( final String subsystemName ) { assert subsystemName != null : "The subsystemName cannot be null" ; return getDeploymentSubModel ( subsystemName , PathAddress . EMPTY_ADDRESS , null , deploymentUnit ) ; } | Get the subsystem deployment model root . |
22,402 | public ModelNode registerDeploymentSubsystemResource ( final String subsystemName , final Resource resource ) { assert subsystemName != null : "The subsystemName cannot be null" ; assert resource != null : "The resource cannot be null" ; return registerDeploymentSubResource ( subsystemName , PathAddress . EMPTY_ADDRESS , resource ) ; } | Registers the resource to the parent deployment resource . The model returned is that of the resource parameter . |
22,403 | static Resource getOrCreateSubDeployment ( final String deploymentName , final DeploymentUnit parent ) { final Resource root = parent . getAttachment ( DEPLOYMENT_RESOURCE ) ; return getOrCreate ( root , PathElement . pathElement ( SUBDEPLOYMENT , deploymentName ) ) ; } | Gets or creates the a resource for the sub - deployment on the parent deployments resource . |
22,404 | static void cleanup ( final Resource resource ) { synchronized ( resource ) { for ( final Resource . ResourceEntry entry : resource . getChildren ( SUBSYSTEM ) ) { resource . removeChild ( entry . getPathElement ( ) ) ; } for ( final Resource . ResourceEntry entry : resource . getChildren ( SUBDEPLOYMENT ) ) { resource . removeChild ( entry . getPathElement ( ) ) ; } } } | Cleans up the subsystem children for the deployment and each sub - deployment resource . |
22,405 | Path resolveBaseDir ( final String name , final String dirName ) { final String currentDir = SecurityActions . getPropertyPrivileged ( name ) ; if ( currentDir == null ) { return jbossHomeDir . resolve ( dirName ) ; } return Paths . get ( currentDir ) ; } | Resolves the base directory . If the system property is set that value will be used . Otherwise the path is resolved from the home directory . |
22,406 | static Path resolvePath ( final Path base , final String ... paths ) { return Paths . get ( base . toString ( ) , paths ) ; } | Resolves a path relative to the base path . |
22,407 | static Map < String , Set < String > > getChildAddresses ( final OperationContext context , final PathAddress addr , final ImmutableManagementResourceRegistration registry , Resource resource , final String validChildType ) { Map < String , Set < String > > result = new HashMap < > ( ) ; Predicate < String > validChildTypeFilter = childType -> ( validChildType == null ) || validChildType . equals ( childType ) ; if ( resource != null ) { for ( String childType : registry . getChildNames ( PathAddress . EMPTY_ADDRESS ) ) { if ( validChildTypeFilter . test ( childType ) ) { List < String > list = new ArrayList < > ( ) ; for ( String child : resource . getChildrenNames ( childType ) ) { if ( registry . getSubModel ( PathAddress . pathAddress ( PathElement . pathElement ( childType , child ) ) ) != null ) { list . add ( child ) ; } } result . put ( childType , new LinkedHashSet < > ( list ) ) ; } } } Set < PathElement > paths = registry . getChildAddresses ( PathAddress . EMPTY_ADDRESS ) ; for ( PathElement path : paths ) { String childType = path . getKey ( ) ; if ( validChildTypeFilter . test ( childType ) ) { Set < String > children = result . get ( childType ) ; if ( children == null ) { children = new LinkedHashSet < > ( ) ; result . put ( childType , children ) ; } ImmutableManagementResourceRegistration childRegistration = registry . getSubModel ( PathAddress . pathAddress ( path ) ) ; if ( childRegistration != null ) { AliasEntry aliasEntry = childRegistration . getAliasEntry ( ) ; if ( aliasEntry != null ) { PathAddress childAddr = addr . append ( path ) ; PathAddress target = aliasEntry . convertToTargetAddress ( childAddr , AliasContext . create ( childAddr , context ) ) ; assert ! childAddr . equals ( target ) : "Alias was not translated" ; PathAddress targetParent = target . getParent ( ) ; Resource parentResource = context . readResourceFromRoot ( targetParent , false ) ; if ( parentResource != null ) { PathElement targetElement = target . getLastElement ( ) ; if ( targetElement . isWildcard ( ) ) { children . addAll ( parentResource . getChildrenNames ( targetElement . getKey ( ) ) ) ; } else if ( parentResource . hasChild ( targetElement ) ) { children . add ( path . getValue ( ) ) ; } } } if ( ! path . isWildcard ( ) && childRegistration . isRemote ( ) ) { children . add ( path . getValue ( ) ) ; } } } } return result ; } | Gets the addresses of the child resources under the given resource . |
22,408 | public DiscreteInterval plus ( DiscreteInterval other ) { return new DiscreteInterval ( this . min + other . min , this . max + other . max ) ; } | Returns an interval representing the addition of the given interval with this one . |
22,409 | public DiscreteInterval minus ( DiscreteInterval other ) { return new DiscreteInterval ( this . min - other . max , this . max - other . min ) ; } | Returns an interval representing the subtraction of the given interval from this one . |
22,410 | public Set < Method > findAnnotatedMethods ( String scanBase , Class < ? extends Annotation > annotationClass ) { Set < BeanDefinition > filteredComponents = findCandidateBeans ( scanBase , annotationClass ) ; return extractAnnotatedMethods ( filteredComponents , annotationClass ) ; } | Find all methods on classes under scanBase that are annotated with annotationClass . |
22,411 | public void reset ( ) { state = BreakerState . CLOSED ; isHardTrip = false ; byPass = false ; isAttemptLive = false ; notifyBreakerStateChange ( getStatus ( ) ) ; } | Manually set the breaker to be reset and ready for use . This is only useful after a manual trip otherwise the breaker will trip automatically again if the service is still unavailable . Just like a real breaker . WOOT!!! |
22,412 | public WebMBeanAdapter createWebMBeanAdapter ( String mBeanName , String encoding ) throws JMException , UnsupportedEncodingException { return new WebMBeanAdapter ( mBeanServer , mBeanName , encoding ) ; } | Create a WebMBeanAdaptor for a specified MBean name . |
22,413 | public void mark ( ) { final long currentTimeMillis = clock . currentTimeMillis ( ) ; synchronized ( queue ) { if ( queue . size ( ) == capacity ) { queue . removeFirst ( ) ; } queue . addLast ( currentTimeMillis ) ; } } | Record a new event . |
22,414 | public int tally ( ) { long currentTimeMillis = clock . currentTimeMillis ( ) ; final long removeTimesBeforeMillis = currentTimeMillis - windowMillis ; synchronized ( queue ) { while ( ! queue . isEmpty ( ) && queue . peek ( ) < removeTimesBeforeMillis ) { queue . removeFirst ( ) ; } return queue . size ( ) ; } } | Returns a count of in - window events . |
22,415 | public void setCapacity ( int capacity ) { if ( capacity <= 0 ) { throw new IllegalArgumentException ( "capacity must be greater than 0" ) ; } synchronized ( queue ) { if ( capacity < this . capacity ) { while ( queue . size ( ) > capacity ) { queue . removeFirst ( ) ; } } } this . capacity = capacity ; } | Specifies the maximum capacity of the counter . |
22,416 | @ Around ( "@annotation(retryableAnnotation)" ) public Object call ( final ProceedingJoinPoint pjp , Retryable retryableAnnotation ) throws Throwable { final int maxTries = retryableAnnotation . maxTries ( ) ; final int retryDelayMillies = retryableAnnotation . retryDelayMillis ( ) ; final Class < ? extends Throwable > [ ] retryOn = retryableAnnotation . retryOn ( ) ; final boolean doubleDelay = retryableAnnotation . doubleDelay ( ) ; final boolean throwCauseException = retryableAnnotation . throwCauseException ( ) ; if ( logger . isDebugEnabled ( ) ) { logger . debug ( "Have @Retryable method wrapping call on method {} of target object {}" , new Object [ ] { pjp . getSignature ( ) . getName ( ) , pjp . getTarget ( ) } ) ; } ServiceRetrier serviceRetrier = new ServiceRetrier ( retryDelayMillies , maxTries , doubleDelay , throwCauseException , retryOn ) ; return serviceRetrier . invoke ( new Callable < Object > ( ) { public Object call ( ) throws Exception { try { return pjp . proceed ( ) ; } catch ( Exception e ) { throw e ; } catch ( Error e ) { throw e ; } catch ( Throwable t ) { throw new RuntimeException ( t ) ; } } } ) ; } | Runs a method call with retries . |
22,417 | public Map < String , MBeanAttributeInfo > getAttributeMetadata ( ) { MBeanAttributeInfo [ ] attributeList = mBeanInfo . getAttributes ( ) ; Map < String , MBeanAttributeInfo > attributeMap = new TreeMap < String , MBeanAttributeInfo > ( ) ; for ( MBeanAttributeInfo attribute : attributeList ) { attributeMap . put ( attribute . getName ( ) , attribute ) ; } return attributeMap ; } | Get the Attribute metadata for an MBean by name . |
22,418 | public Map < String , MBeanOperationInfo > getOperationMetadata ( ) { MBeanOperationInfo [ ] operations = mBeanInfo . getOperations ( ) ; Map < String , MBeanOperationInfo > operationMap = new TreeMap < String , MBeanOperationInfo > ( ) ; for ( MBeanOperationInfo operation : operations ) { operationMap . put ( operation . getName ( ) , operation ) ; } return operationMap ; } | Get the Operation metadata for an MBean by name . |
22,419 | public MBeanOperationInfo getOperationInfo ( String operationName ) throws OperationNotFoundException , UnsupportedEncodingException { String decodedOperationName = sanitizer . urlDecode ( operationName , encoding ) ; Map < String , MBeanOperationInfo > operationMap = getOperationMetadata ( ) ; if ( operationMap . containsKey ( decodedOperationName ) ) { return operationMap . get ( decodedOperationName ) ; } throw new OperationNotFoundException ( "Could not find operation " + operationName + " on MBean " + objectName . getCanonicalName ( ) ) ; } | Get the Operation metadata for a single operation on an MBean by name . |
22,420 | public Map < String , Object > getAttributeValues ( ) throws AttributeNotFoundException , InstanceNotFoundException , ReflectionException { HashSet < String > attributeSet = new HashSet < String > ( ) ; for ( MBeanAttributeInfo attributeInfo : mBeanInfo . getAttributes ( ) ) { attributeSet . add ( attributeInfo . getName ( ) ) ; } AttributeList attributeList = mBeanServer . getAttributes ( objectName , attributeSet . toArray ( new String [ attributeSet . size ( ) ] ) ) ; Map < String , Object > attributeValueMap = new TreeMap < String , Object > ( ) ; for ( Attribute attribute : attributeList . asList ( ) ) { attributeValueMap . put ( attribute . getName ( ) , sanitizer . escapeValue ( attribute . getValue ( ) ) ) ; } return attributeValueMap ; } | Get all the attribute values for an MBean by name . The values are HTML escaped . |
22,421 | public String getAttributeValue ( String attributeName ) throws JMException , UnsupportedEncodingException { String decodedAttributeName = sanitizer . urlDecode ( attributeName , encoding ) ; return sanitizer . escapeValue ( mBeanServer . getAttribute ( objectName , decodedAttributeName ) ) ; } | Get the value for a single attribute on an MBean by name . |
22,422 | public String invokeOperation ( String operationName , Map < String , String [ ] > parameterMap ) throws JMException , UnsupportedEncodingException { MBeanOperationInfo operationInfo = getOperationInfo ( operationName ) ; MBeanOperationInvoker invoker = createMBeanOperationInvoker ( mBeanServer , objectName , operationInfo ) ; return sanitizer . escapeValue ( invoker . invokeOperation ( parameterMap ) ) ; } | Invoke an operation on an MBean by name . Note that only basic data types are supported for parameter values . |
22,423 | String urlDecode ( String name , String encoding ) throws UnsupportedEncodingException { return URLDecoder . decode ( name , encoding ) ; } | Convert a URL Encoded name back to the original form . |
22,424 | String escapeValue ( Object value ) { return HtmlUtils . htmlEscape ( value != null ? value . toString ( ) : "<null>" ) ; } | Escape a value to be HTML friendly . |
22,425 | private void registerProxyCreator ( Node source , BeanDefinitionHolder holder , ParserContext context ) { String beanName = holder . getBeanName ( ) ; String proxyName = beanName + "Proxy" ; String interceptorName = beanName + "PerformanceMonitorInterceptor" ; BeanDefinitionBuilder initializer = BeanDefinitionBuilder . rootBeanDefinition ( BeanNameAutoProxyCreator . class ) ; initializer . addPropertyValue ( "beanNames" , beanName ) ; initializer . addPropertyValue ( "interceptorNames" , interceptorName ) ; BeanDefinitionRegistry registry = context . getRegistry ( ) ; registry . registerBeanDefinition ( proxyName , initializer . getBeanDefinition ( ) ) ; } | Registers a BeanNameAutoProxyCreator class that wraps the bean being monitored . The proxy is associated with the PerformanceMonitorInterceptor for the bean which is created when parsing the methods attribute from the springconfiguration xml file . |
22,426 | private Integer getIntegerPropertyOverrideValue ( String name , String key ) { if ( properties != null ) { String propertyName = getPropertyName ( name , key ) ; String propertyOverrideValue = properties . getProperty ( propertyName ) ; if ( propertyOverrideValue != null ) { try { return Integer . parseInt ( propertyOverrideValue ) ; } catch ( NumberFormatException e ) { logger . error ( "Could not parse property override key={}, value={}" , key , propertyOverrideValue ) ; } } } return null ; } | Get an integer property override value . |
22,427 | private boolean shouldWrapMethodCall ( String methodName ) { if ( methodList == null ) { return true ; } if ( methodList . contains ( methodName ) ) { return true ; } return false ; } | Checks if the method being invoked should be wrapped by a service . It looks the method name up in the methodList . If its in the list then the method should be wrapped . If the list is null then all methods are wrapped . |
22,428 | public Object invokeOperation ( Map < String , String [ ] > parameterMap ) throws JMException { MBeanParameterInfo [ ] parameterInfoArray = operationInfo . getSignature ( ) ; Object [ ] values = new Object [ parameterInfoArray . length ] ; String [ ] types = new String [ parameterInfoArray . length ] ; MBeanValueConverter valueConverter = createMBeanValueConverter ( parameterMap ) ; for ( int parameterNum = 0 ; parameterNum < parameterInfoArray . length ; parameterNum ++ ) { MBeanParameterInfo parameterInfo = parameterInfoArray [ parameterNum ] ; String type = parameterInfo . getType ( ) ; types [ parameterNum ] = type ; values [ parameterNum ] = valueConverter . convertParameterValue ( parameterInfo . getName ( ) , type ) ; } return mBeanServer . invoke ( objectName , operationInfo . getName ( ) , values , types ) ; } | Invoke the operation . |
22,429 | private void registerInterceptor ( Node source , String beanName , BeanDefinitionRegistry registry ) { List < String > methodList = buildMethodList ( source ) ; BeanDefinitionBuilder initializer = BeanDefinitionBuilder . rootBeanDefinition ( SingleServiceWrapperInterceptor . class ) ; initializer . addPropertyValue ( "methods" , methodList ) ; String perfMonitorName = beanName + "PerformanceMonitor" ; initializer . addPropertyReference ( "serviceWrapper" , perfMonitorName ) ; String interceptorName = beanName + "PerformanceMonitorInterceptor" ; registry . registerBeanDefinition ( interceptorName , initializer . getBeanDefinition ( ) ) ; } | Register a new SingleServiceWrapperInterceptor for the bean being wrapped associate it with the PerformanceMonitor and tell it which methods to intercept . |
22,430 | public List < String > parseMethodList ( String methods ) { String [ ] methodArray = StringUtils . delimitedListToStringArray ( methods , "," ) ; List < String > methodList = new ArrayList < String > ( ) ; for ( String methodName : methodArray ) { methodList . add ( methodName . trim ( ) ) ; } return methodList ; } | Parse a comma - delimited list of method names into a List of strings . Whitespace is ignored . |
22,431 | private void registerPerformanceMonitor ( String beanName , BeanDefinitionRegistry registry ) { String perfMonitorName = beanName + "PerformanceMonitor" ; if ( ! registry . containsBeanDefinition ( perfMonitorName ) ) { BeanDefinitionBuilder initializer = BeanDefinitionBuilder . rootBeanDefinition ( PerformanceMonitorBean . class ) ; registry . registerBeanDefinition ( perfMonitorName , initializer . getBeanDefinition ( ) ) ; } } | Register a new PerformanceMonitor with Spring if it does not already exist . |
22,432 | public static void forceDelete ( final Path path ) throws IOException { if ( ! java . nio . file . Files . isDirectory ( path ) ) { java . nio . file . Files . delete ( path ) ; } else { java . nio . file . Files . walkFileTree ( path , DeleteDirVisitor . getInstance ( ) ) ; } } | Deletes a path from the filesystem |
22,433 | public PreparedStatementCreator count ( final Dialect dialect ) { return new PreparedStatementCreator ( ) { public PreparedStatement createPreparedStatement ( Connection con ) throws SQLException { return getPreparedStatementCreator ( ) . setSql ( dialect . createCountSelect ( builder . toString ( ) ) ) . createPreparedStatement ( con ) ; } } ; } | Returns a PreparedStatementCreator that returns a count of the rows that this creator would return . |
22,434 | public PreparedStatementCreator page ( final Dialect dialect , final int limit , final int offset ) { return new PreparedStatementCreator ( ) { public PreparedStatement createPreparedStatement ( Connection con ) throws SQLException { return getPreparedStatementCreator ( ) . setSql ( dialect . createPageSelect ( builder . toString ( ) , limit , offset ) ) . createPreparedStatement ( con ) ; } } ; } | Returns a PreparedStatementCreator that returns a page of the underlying result set . |
22,435 | private static String toColumnName ( String fieldName ) { int lastDot = fieldName . indexOf ( '.' ) ; if ( lastDot > - 1 ) { return fieldName . substring ( lastDot + 1 ) ; } else { return fieldName ; } } | Returns the portion of the field name after the last dot as field names may actually be paths . |
22,436 | public static Predicate anyBitsSet ( final String expr , final long bits ) { return new Predicate ( ) { private String param ; public void init ( AbstractSqlCreator creator ) { param = creator . allocateParameter ( ) ; creator . setParameter ( param , bits ) ; } public String toSql ( ) { return String . format ( "(%s & :%s) > 0" , expr , param ) ; } } ; } | Adds a clause that checks whether ANY set bits in a bitmask are present in a numeric expression . |
22,437 | public static Predicate is ( final String sql ) { return new Predicate ( ) { public String toSql ( ) { return sql ; } public void init ( AbstractSqlCreator creator ) { } } ; } | Returns a predicate that takes no parameters . The given SQL expression is used directly . |
22,438 | private static Predicate join ( final String joinWord , final List < Predicate > preds ) { return new Predicate ( ) { public void init ( AbstractSqlCreator creator ) { for ( Predicate p : preds ) { p . init ( creator ) ; } } public String toSql ( ) { StringBuilder sb = new StringBuilder ( ) . append ( "(" ) ; boolean first = true ; for ( Predicate p : preds ) { if ( ! first ) { sb . append ( " " ) . append ( joinWord ) . append ( " " ) ; } sb . append ( p . toSql ( ) ) ; first = false ; } return sb . append ( ")" ) . toString ( ) ; } } ; } | Factory for and and or predicates . |
22,439 | public Mapping < T > addFields ( ) { if ( idColumn == null ) { throw new RuntimeException ( "Map ID column before adding class fields" ) ; } for ( Field f : ReflectionUtils . getDeclaredFieldsInHierarchy ( clazz ) ) { if ( ! Modifier . isStatic ( f . getModifiers ( ) ) && ! isFieldMapped ( f . getName ( ) ) && ! ignoredFields . contains ( f . getName ( ) ) ) { addColumn ( f . getName ( ) ) ; } } return this ; } | Adds mappings for each declared field in the mapped class . Any fields already mapped by addColumn are skipped . |
22,440 | protected T createInstance ( ) { try { Constructor < T > ctor = clazz . getDeclaredConstructor ( ) ; ctor . setAccessible ( true ) ; return ctor . newInstance ( ) ; } catch ( InstantiationException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } catch ( SecurityException e ) { throw new RuntimeException ( e ) ; } catch ( NoSuchMethodException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( InvocationTargetException e ) { throw new RuntimeException ( e ) ; } } | Creates instance of the entity class . This method is called to create the object instances when returning query results . |
22,441 | public void deleteById ( Object id ) { int count = beginDelete ( ) . whereEquals ( idColumn . getColumnName ( ) , id ) . delete ( ) ; if ( count == 0 ) { throw new RowNotFoundException ( table , id ) ; } } | Deletes an entity by its primary key . |
22,442 | public T findById ( Object id ) throws RowNotFoundException , TooManyRowsException { return findWhere ( eq ( idColumn . getColumnName ( ) , id ) ) . getSingleResult ( ) ; } | Finds an entity given its primary key . |
22,443 | public T insert ( T entity ) { if ( ! hasPrimaryKey ( entity ) ) { throw new RuntimeException ( String . format ( "Tried to insert entity of type %s with null or zero primary key" , entity . getClass ( ) . getSimpleName ( ) ) ) ; } InsertCreator insert = new InsertCreator ( table ) ; insert . setValue ( idColumn . getColumnName ( ) , getPrimaryKey ( entity ) ) ; if ( versionColumn != null ) { insert . setValue ( versionColumn . getColumnName ( ) , 0 ) ; } for ( Column column : columns ) { if ( ! column . isReadOnly ( ) ) { insert . setValue ( column . getColumnName ( ) , getFieldValueAsColumn ( entity , column ) ) ; } } new JdbcTemplate ( ormConfig . getDataSource ( ) ) . update ( insert ) ; if ( versionColumn != null ) { ReflectionUtils . setFieldValue ( entity , versionColumn . getFieldName ( ) , 0 ) ; } return entity ; } | Insert entity object . The caller must first initialize the primary key field . |
22,444 | private boolean hasPrimaryKey ( T entity ) { Object pk = getPrimaryKey ( entity ) ; if ( pk == null ) { return false ; } else { if ( pk instanceof Number && ( ( Number ) pk ) . longValue ( ) == 0 ) { return false ; } } return true ; } | Returns true if this entity s primary key is not null and for numeric fields is non - zero . |
22,445 | public T update ( T entity ) throws RowNotFoundException , OptimisticLockException { if ( ! hasPrimaryKey ( entity ) ) { throw new RuntimeException ( String . format ( "Tried to update entity of type %s without a primary key" , entity . getClass ( ) . getSimpleName ( ) ) ) ; } UpdateCreator update = new UpdateCreator ( table ) ; update . whereEquals ( idColumn . getColumnName ( ) , getPrimaryKey ( entity ) ) ; if ( versionColumn != null ) { update . set ( versionColumn . getColumnName ( ) + " = " + versionColumn . getColumnName ( ) + " + 1" ) ; update . whereEquals ( versionColumn . getColumnName ( ) , getVersion ( entity ) ) ; } for ( Column column : columns ) { if ( ! column . isReadOnly ( ) ) { update . setValue ( column . getColumnName ( ) , getFieldValueAsColumn ( entity , column ) ) ; } } int rows = new JdbcTemplate ( ormConfig . getDataSource ( ) ) . update ( update ) ; if ( rows == 1 ) { if ( versionColumn != null ) { ReflectionUtils . setFieldValue ( entity , versionColumn . getFieldName ( ) , getVersion ( entity ) + 1 ) ; } return entity ; } else if ( rows > 1 ) { throw new RuntimeException ( String . format ( "Updating table %s with id %s updated %d rows. There must be a mapping problem. Is column %s really the primary key?" , table , getPrimaryKey ( entity ) , rows , idColumn ) ) ; } else { SelectCreator selectById = new SelectCreator ( ) . column ( "count(*)" ) . from ( table ) . whereEquals ( idColumn . getColumnName ( ) , getPrimaryKey ( entity ) ) ; rows = new JdbcTemplate ( ormConfig . getDataSource ( ) ) . query ( selectById , new ResultSetExtractor < Integer > ( ) { public Integer extractData ( ResultSet rs ) throws SQLException , DataAccessException { rs . next ( ) ; return rs . getInt ( 1 ) ; } } ) ; if ( rows == 0 ) { throw new RowNotFoundException ( table , getPrimaryKey ( entity ) ) ; } else { throw new OptimisticLockException ( table , getPrimaryKey ( entity ) ) ; } } } | Updates value of entity in the table . |
22,446 | public AbstractSqlCreator setParameter ( String name , Object value ) { ppsc . setParameter ( name , value ) ; return this ; } | Sets a parameter for the creator . |
22,447 | public InsertBuilder set ( String column , String value ) { columns . add ( column ) ; values . add ( value ) ; return this ; } | Inserts a column name value pair into the SQL . |
22,448 | public SelectBuilder orderBy ( String name , boolean ascending ) { if ( ascending ) { orderBys . add ( name + " asc" ) ; } else { orderBys . add ( name + " desc" ) ; } return this ; } | Adds an ORDER BY item with a direction indicator . |
22,449 | public List < String > split ( String s ) { List < String > result = new ArrayList < String > ( ) ; if ( s == null ) { return result ; } boolean seenEscape = false ; boolean seenSeparator = false ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { seenSeparator = false ; char c = s . charAt ( i ) ; if ( seenEscape ) { if ( c == escapeChar || c == separator ) { sb . append ( c ) ; } else { sb . append ( escapeChar ) . append ( c ) ; } seenEscape = false ; } else { if ( c == escapeChar ) { seenEscape = true ; } else if ( c == separator ) { if ( sb . length ( ) == 0 && convertEmptyToNull ) { result . add ( null ) ; } else { result . add ( sb . toString ( ) ) ; } sb . setLength ( 0 ) ; seenSeparator = true ; } else { sb . append ( c ) ; } } } if ( seenEscape ) { sb . append ( escapeChar ) ; } if ( sb . length ( ) > 0 || seenSeparator ) { if ( sb . length ( ) == 0 && convertEmptyToNull ) { result . add ( null ) ; } else { result . add ( sb . toString ( ) ) ; } } return result ; } | Splits the given string . |
22,450 | public String join ( List < String > list ) { if ( list == null ) { return null ; } StringBuilder sb = new StringBuilder ( ) ; boolean first = true ; for ( String s : list ) { if ( s == null ) { if ( convertEmptyToNull ) { s = "" ; } else { throw new IllegalArgumentException ( "StringListFlattener does not support null strings in the list. Consider calling setConvertEmptyToNull(true)." ) ; } } if ( ! first ) { sb . append ( separator ) ; } for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char c = s . charAt ( i ) ; if ( c == escapeChar || c == separator ) { sb . append ( escapeChar ) ; } sb . append ( c ) ; } first = false ; } return sb . toString ( ) ; } | Joins the given list into a single string . |
22,451 | protected void appendList ( StringBuilder sql , List < ? > list , String init , String sep ) { boolean first = true ; for ( Object s : list ) { if ( first ) { sql . append ( init ) ; } else { sql . append ( sep ) ; } sql . append ( s ) ; first = false ; } } | Constructs a list of items with given separators . |
22,452 | public static < E extends Enum < E > > EnumStringConverter < E > create ( Class < E > enumType ) { return new EnumStringConverter < E > ( enumType ) ; } | Factory method to create EnumStringConverter |
22,453 | public static Field [ ] getDeclaredFieldsInHierarchy ( Class < ? > clazz ) { if ( clazz . isPrimitive ( ) ) { throw new IllegalArgumentException ( "Primitive types not supported." ) ; } List < Field > result = new ArrayList < Field > ( ) ; while ( true ) { if ( clazz == Object . class ) { break ; } result . addAll ( Arrays . asList ( clazz . getDeclaredFields ( ) ) ) ; clazz = clazz . getSuperclass ( ) ; } return result . toArray ( new Field [ result . size ( ) ] ) ; } | Returns an array of all declared fields in the given class and all super - classes . |
22,454 | public static Field getDeclaredFieldWithPath ( Class < ? > clazz , String path ) { int lastDot = path . lastIndexOf ( '.' ) ; if ( lastDot > - 1 ) { String parentPath = path . substring ( 0 , lastDot ) ; String fieldName = path . substring ( lastDot + 1 ) ; Field parentField = getDeclaredFieldWithPath ( clazz , parentPath ) ; return getDeclaredFieldInHierarchy ( parentField . getType ( ) , fieldName ) ; } else { return getDeclaredFieldInHierarchy ( clazz , path ) ; } } | Returns the Field for a given parent class and a dot - separated path of field names . |
22,455 | public static Object getFieldValue ( Object object , String fieldName ) { try { return getDeclaredFieldInHierarchy ( object . getClass ( ) , fieldName ) . get ( object ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } | Convenience method for getting the value of a private object field without the stress of checked exceptions in the reflection API . |
22,456 | public static void setFieldValue ( Object object , String fieldName , Object value ) { try { getDeclaredFieldInHierarchy ( object . getClass ( ) , fieldName ) . set ( object , value ) ; } catch ( IllegalArgumentException e ) { throw new RuntimeException ( e ) ; } catch ( IllegalAccessException e ) { throw new RuntimeException ( e ) ; } } | Convenience method for setting the value of a private object field without the stress of checked exceptions in the reflection API . |
22,457 | private static void checkPreconditions ( final long min , final long max ) { if ( max < min ) { throw new IllegalArgumentException ( String . format ( "max (%d) should not be < min (%d)" , max , min ) ) ; } } | Checks the preconditions for creating a new LMinMax processor . |
22,458 | public static Method findGetter ( final Object object , final String fieldName ) { if ( object == null ) { throw new NullPointerException ( "object should not be null" ) ; } else if ( fieldName == null ) { throw new NullPointerException ( "fieldName should not be null" ) ; } final Class < ? > clazz = object . getClass ( ) ; final String standardGetterName = getMethodNameForField ( GET_PREFIX , fieldName ) ; Method getter = findGetterWithCompatibleReturnType ( standardGetterName , clazz , false ) ; if ( getter == null ) { final String booleanGetterName = getMethodNameForField ( IS_PREFIX , fieldName ) ; getter = findGetterWithCompatibleReturnType ( booleanGetterName , clazz , true ) ; } if ( getter == null ) { throw new SuperCsvReflectionException ( String . format ( "unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean" , fieldName , clazz . getName ( ) ) ) ; } return getter ; } | Returns the getter method associated with the object s field . |
22,459 | public static < T > void filterListToMap ( final Map < String , T > destinationMap , final String [ ] nameMapping , final List < ? extends T > sourceList ) { if ( destinationMap == null ) { throw new NullPointerException ( "destinationMap should not be null" ) ; } else if ( nameMapping == null ) { throw new NullPointerException ( "nameMapping should not be null" ) ; } else if ( sourceList == null ) { throw new NullPointerException ( "sourceList should not be null" ) ; } else if ( nameMapping . length != sourceList . size ( ) ) { throw new SuperCsvException ( String . format ( "the nameMapping array and the sourceList should be the same size (nameMapping length = %d, sourceList size = %d)" , nameMapping . length , sourceList . size ( ) ) ) ; } destinationMap . clear ( ) ; for ( int i = 0 ; i < nameMapping . length ; i ++ ) { final String key = nameMapping [ i ] ; if ( key == null ) { continue ; } if ( destinationMap . containsKey ( key ) ) { throw new SuperCsvException ( String . format ( "duplicate nameMapping '%s' at index %d" , key , i ) ) ; } destinationMap . put ( key , sourceList . get ( i ) ) ; } } | Converts a List to a Map using the elements of the nameMapping array as the keys of the Map . |
22,460 | public static List < Object > filterMapToList ( final Map < String , ? > map , final String [ ] nameMapping ) { if ( map == null ) { throw new NullPointerException ( "map should not be null" ) ; } else if ( nameMapping == null ) { throw new NullPointerException ( "nameMapping should not be null" ) ; } final List < Object > result = new ArrayList < Object > ( nameMapping . length ) ; for ( final String key : nameMapping ) { result . add ( map . get ( key ) ) ; } return result ; } | Returns a List of all of the values in the Map whose key matches an entry in the nameMapping array . |
22,461 | public static Object [ ] filterMapToObjectArray ( final Map < String , ? > values , final String [ ] nameMapping ) { if ( values == null ) { throw new NullPointerException ( "values should not be null" ) ; } else if ( nameMapping == null ) { throw new NullPointerException ( "nameMapping should not be null" ) ; } final Object [ ] targetArray = new Object [ nameMapping . length ] ; int i = 0 ; for ( final String name : nameMapping ) { targetArray [ i ++ ] = values . get ( name ) ; } return targetArray ; } | Converts a Map to an array of objects adding only those entries whose key is in the nameMapping array . |
22,462 | private static void checkPreconditions ( final Set < Object > possibleValues ) { if ( possibleValues == null ) { throw new NullPointerException ( "possibleValues Set should not be null" ) ; } else if ( possibleValues . isEmpty ( ) ) { throw new IllegalArgumentException ( "possibleValues Set should not be empty" ) ; } } | Checks the preconditions for creating a new IsIncludedIn processor with a Set of Objects . |
22,463 | private static void checkPreconditions ( final int maxSize , final String suffix ) { if ( maxSize <= 0 ) { throw new IllegalArgumentException ( String . format ( "maxSize should be > 0 but was %d" , maxSize ) ) ; } if ( suffix == null ) { throw new NullPointerException ( "suffix should not be null" ) ; } } | Checks the preconditions for creating a new Truncate processor . |
22,464 | protected void writeRow ( final String ... columns ) throws IOException { if ( columns == null ) { throw new NullPointerException ( String . format ( "columns to write should not be null on line %d" , lineNumber ) ) ; } else if ( columns . length == 0 ) { throw new IllegalArgumentException ( String . format ( "columns to write should not be empty on line %d" , lineNumber ) ) ; } StringBuilder builder = new StringBuilder ( ) ; for ( int i = 0 ; i < columns . length ; i ++ ) { columnNumber = i + 1 ; if ( i > 0 ) { builder . append ( ( char ) preference . getDelimiterChar ( ) ) ; } final String csvElement = columns [ i ] ; if ( csvElement != null ) { final CsvContext context = new CsvContext ( lineNumber , rowNumber , columnNumber ) ; final String escapedCsv = encoder . encode ( csvElement , context , preference ) ; builder . append ( escapedCsv ) ; lineNumber = context . getLineNumber ( ) ; } } builder . append ( preference . getEndOfLineSymbols ( ) ) ; writer . write ( builder . toString ( ) ) ; } | Writes one or more String columns as a line to the CsvWriter . |
22,465 | private static void checkPreconditions ( final Map < Object , Object > mapping ) { if ( mapping == null ) { throw new NullPointerException ( "mapping should not be null" ) ; } else if ( mapping . isEmpty ( ) ) { throw new IllegalArgumentException ( "mapping should not be empty" ) ; } } | Checks the preconditions for creating a new HashMapper processor . |
22,466 | private static void checkPreconditions ( final String dateFormat , final Locale locale ) { if ( dateFormat == null ) { throw new NullPointerException ( "dateFormat should not be null" ) ; } else if ( locale == null ) { throw new NullPointerException ( "locale should not be null" ) ; } } | Checks the preconditions for creating a new ParseDateTimeAbstract processor with date format and locale . |
22,467 | private static void checkPreconditions ( final String regex , final String replacement ) { if ( regex == null ) { throw new NullPointerException ( "regex should not be null" ) ; } else if ( regex . length ( ) == 0 ) { throw new IllegalArgumentException ( "regex should not be empty" ) ; } if ( replacement == null ) { throw new NullPointerException ( "replacement should not be null" ) ; } } | Checks the preconditions for creating a new StrRegExReplace processor . |
22,468 | public V get ( final K1 firstKey , final K2 secondKey ) { final HashMap < K2 , V > innerMap = map . get ( firstKey ) ; if ( innerMap == null ) { return null ; } return innerMap . get ( secondKey ) ; } | Fetch a value from the Hashmap . |
22,469 | public Method getGetMethod ( final Object object , final String fieldName ) { if ( object == null ) { throw new NullPointerException ( "object should not be null" ) ; } else if ( fieldName == null ) { throw new NullPointerException ( "fieldName should not be null" ) ; } Method method = getCache . get ( object . getClass ( ) . getName ( ) , fieldName ) ; if ( method == null ) { method = ReflectionUtils . findGetter ( object , fieldName ) ; getCache . set ( object . getClass ( ) . getName ( ) , fieldName , method ) ; } return method ; } | Returns the getter method for field on an object . |
22,470 | public < T > Method getSetMethod ( final Object object , final String fieldName , final Class < ? > argumentType ) { if ( object == null ) { throw new NullPointerException ( "object should not be null" ) ; } else if ( fieldName == null ) { throw new NullPointerException ( "fieldName should not be null" ) ; } else if ( argumentType == null ) { throw new NullPointerException ( "argumentType should not be null" ) ; } Method method = setMethodsCache . get ( object . getClass ( ) , argumentType , fieldName ) ; if ( method == null ) { method = ReflectionUtils . findSetter ( object , fieldName , argumentType ) ; setMethodsCache . set ( object . getClass ( ) , argumentType , fieldName , method ) ; } return method ; } | Returns the setter method for the field on an object . |
22,471 | private static void invokeSetter ( final Object bean , final Method setMethod , final Object fieldValue ) { try { setMethod . setAccessible ( true ) ; setMethod . invoke ( bean , fieldValue ) ; } catch ( final Exception e ) { throw new SuperCsvReflectionException ( String . format ( "error invoking method %s()" , setMethod . getName ( ) ) , e ) ; } } | Invokes the setter on the bean with the supplied value . |
22,472 | private < T > T populateBean ( final T resultBean , final String [ ] nameMapping ) { for ( int i = 0 ; i < nameMapping . length ; i ++ ) { final Object fieldValue = processedColumns . get ( i ) ; if ( nameMapping [ i ] == null || fieldValue == null ) { continue ; } Method setMethod = cache . getSetMethod ( resultBean , nameMapping [ i ] , fieldValue . getClass ( ) ) ; invokeSetter ( resultBean , setMethod , fieldValue ) ; } return resultBean ; } | Populates the bean by mapping the processed columns to the fields of the bean . |
22,473 | private < T > T readIntoBean ( final T bean , final String [ ] nameMapping , final CellProcessor [ ] processors ) throws IOException { if ( readRow ( ) ) { if ( nameMapping . length != length ( ) ) { throw new IllegalArgumentException ( String . format ( "the nameMapping array and the number of columns read " + "should be the same size (nameMapping length = %d, columns = %d)" , nameMapping . length , length ( ) ) ) ; } if ( processors == null ) { processedColumns . clear ( ) ; processedColumns . addAll ( getColumns ( ) ) ; } else { executeProcessors ( processedColumns , processors ) ; } return populateBean ( bean , nameMapping ) ; } return null ; } | Reads a row of a CSV file and populates the bean using the supplied name mapping to map column values to the appropriate fields . If processors are supplied then they are used otherwise the raw String values will be used . |
22,474 | private void checkAndAddLengths ( final int ... requiredLengths ) { for ( final int length : requiredLengths ) { if ( length < 0 ) { throw new IllegalArgumentException ( String . format ( "required length cannot be negative but was %d" , length ) ) ; } this . requiredLengths . add ( length ) ; } } | Adds each required length ensuring it isn t negative . |
22,475 | private static void checkPreconditions ( List < String > requiredSubStrings ) { if ( requiredSubStrings == null ) { throw new NullPointerException ( "requiredSubStrings List should not be null" ) ; } else if ( requiredSubStrings . isEmpty ( ) ) { throw new IllegalArgumentException ( "requiredSubStrings List should not be empty" ) ; } } | Checks the preconditions for creating a new RequireSubStr processor with a List of Strings . |
22,476 | private void checkAndAddRequiredSubStrings ( final List < String > requiredSubStrings ) { for ( String required : requiredSubStrings ) { if ( required == null ) { throw new NullPointerException ( "required substring should not be null" ) ; } this . requiredSubStrings . add ( required ) ; } } | Adds each required substring checking that it s not null . |
22,477 | private static void checkPreconditions ( final List < String > forbiddenSubStrings ) { if ( forbiddenSubStrings == null ) { throw new NullPointerException ( "forbiddenSubStrings list should not be null" ) ; } else if ( forbiddenSubStrings . isEmpty ( ) ) { throw new IllegalArgumentException ( "forbiddenSubStrings list should not be empty" ) ; } } | Checks the preconditions for creating a new ForbidSubStr processor with a List of forbidden substrings . |
22,478 | private void checkAndAddForbiddenStrings ( final List < String > forbiddenSubStrings ) { for ( String forbidden : forbiddenSubStrings ) { if ( forbidden == null ) { throw new NullPointerException ( "forbidden substring should not be null" ) ; } this . forbiddenSubStrings . add ( forbidden ) ; } } | Adds each forbidden substring checking that it s not null . |
22,479 | public HashMap < K2 , HashMap < K3 , V > > get ( final K1 firstKey ) { return map . get ( firstKey ) ; } | Fetch the outermost Hashmap . |
22,480 | public TwoDHashMap < K2 , K3 , V > getAs2d ( final K1 firstKey ) { final HashMap < K2 , HashMap < K3 , V > > innerMap1 = map . get ( firstKey ) ; if ( innerMap1 != null ) { return new TwoDHashMap < K2 , K3 , V > ( innerMap1 ) ; } else { return new TwoDHashMap < K2 , K3 , V > ( ) ; } } | Fetch the outermost Hashmap as a TwoDHashMap . |
22,481 | public int size ( final K1 firstKey ) { final HashMap < K2 , HashMap < K3 , V > > innerMap = map . get ( firstKey ) ; if ( innerMap == null ) { return 0 ; } return innerMap . size ( ) ; } | Returns the number of key - value mappings in this map for the second key . |
22,482 | public int size ( final K1 firstKey , final K2 secondKey ) { final HashMap < K2 , HashMap < K3 , V > > innerMap1 = map . get ( firstKey ) ; if ( innerMap1 == null ) { return 0 ; } final HashMap < K3 , V > innerMap2 = innerMap1 . get ( secondKey ) ; if ( innerMap2 == null ) { return 0 ; } return innerMap2 . size ( ) ; } | Returns the number of key - value mappings in this map for the third key . |
22,483 | public static < T > T createProxy ( final Class < T > proxyInterface ) { if ( proxyInterface == null ) { throw new NullPointerException ( "proxyInterface should not be null" ) ; } return proxyInterface . cast ( Proxy . newProxyInstance ( proxyInterface . getClassLoader ( ) , new Class [ ] { proxyInterface } , new BeanInterfaceProxy ( ) ) ) ; } | Creates a proxy object which implements a given bean interface . |
22,484 | private static String getUnexpectedTypeMessage ( final Class < ? > expectedType , final Object actualValue ) { if ( expectedType == null ) { throw new NullPointerException ( "expectedType should not be null" ) ; } String expectedClassName = expectedType . getName ( ) ; String actualClassName = ( actualValue != null ) ? actualValue . getClass ( ) . getName ( ) : "null" ; return String . format ( "the input value should be of type %s but is %s" , expectedClassName , actualClassName ) ; } | Assembles the exception message when the value received by a CellProcessor isn t of the correct type . |
22,485 | protected List < Object > executeProcessors ( final List < Object > processedColumns , final CellProcessor [ ] processors ) { Util . executeCellProcessors ( processedColumns , getColumns ( ) , processors , getLineNumber ( ) , getRowNumber ( ) ) ; return processedColumns ; } | Executes the supplied cell processors on the last row of CSV that was read and populates the supplied List of processed columns . |
22,486 | public void stopListenting ( ) { if ( channel != null ) { log . info ( "closing server channel" ) ; channel . close ( ) . syncUninterruptibly ( ) ; channel = null ; } } | Closes the server socket . No new clients are accepted afterwards . |
22,487 | Document convertSelectorToDocument ( Document selector ) { Document document = new Document ( ) ; for ( String key : selector . keySet ( ) ) { if ( key . startsWith ( "$" ) ) { continue ; } Object value = selector . get ( key ) ; if ( ! Utils . containsQueryExpression ( value ) ) { Utils . changeSubdocumentValue ( document , key , value , ( AtomicReference < Integer > ) null ) ; } } return document ; } | convert selector used in an upsert statement into a document |
22,488 | String decodeCString ( ByteBuf buffer ) throws IOException { int length = buffer . bytesBefore ( BsonConstants . STRING_TERMINATION ) ; if ( length < 0 ) throw new IOException ( "string termination not found" ) ; String result = buffer . toString ( buffer . readerIndex ( ) , length , StandardCharsets . UTF_8 ) ; buffer . skipBytes ( length + 1 ) ; return result ; } | default visibility for unit test |
22,489 | protected int _countPeriods ( String str ) { int commas = 0 ; for ( int i = 0 , end = str . length ( ) ; i < end ; ++ i ) { int ch = str . charAt ( i ) ; if ( ch < '0' || ch > '9' ) { if ( ch == '.' ) { ++ commas ; } else { return - 1 ; } } } return commas ; } | Helper method to find Strings of form all digits and digits - comma - digits |
22,490 | protected DateTimeException _peelDTE ( DateTimeException e ) { while ( true ) { Throwable t = e . getCause ( ) ; if ( t != null && t instanceof DateTimeException ) { e = ( DateTimeException ) t ; continue ; } break ; } return e ; } | Helper method used to peel off spurious wrappings of DateTimeException |
22,491 | protected void _acceptTimestampVisitor ( JsonFormatVisitorWrapper visitor , JavaType typeHint ) throws JsonMappingException { SerializerProvider prov = visitor . getProvider ( ) ; if ( ( prov != null ) && useNanoseconds ( prov ) ) { JsonNumberFormatVisitor v2 = visitor . expectNumberFormat ( typeHint ) ; if ( v2 != null ) { v2 . numberType ( NumberType . BIG_DECIMAL ) ; } } else { JsonIntegerFormatVisitor v2 = visitor . expectIntegerFormat ( typeHint ) ; if ( v2 != null ) { v2 . numberType ( NumberType . LONG ) ; } } } | Overridden to ensure that our timestamp handling is as expected |
22,492 | public static void applyHyperLinkToElement ( DynamicJasperDesign design , DJHyperLink djlink , JRDesignChart chart , String name ) { JRDesignExpression hlpe = ExpressionUtils . createAndRegisterExpression ( design , name , djlink . getExpression ( ) ) ; chart . setHyperlinkReferenceExpression ( hlpe ) ; chart . setHyperlinkType ( HyperlinkTypeEnum . REFERENCE ) ; if ( djlink . getTooltip ( ) != null ) { JRDesignExpression tooltipExp = ExpressionUtils . createAndRegisterExpression ( design , "tooltip_" + name , djlink . getTooltip ( ) ) ; chart . setHyperlinkTooltipExpression ( tooltipExp ) ; } } | Creates necessary objects to make a chart an hyperlink |
22,493 | private void setCrosstabOptions ( ) { if ( djcross . isUseFullWidth ( ) ) { jrcross . setWidth ( layoutManager . getReport ( ) . getOptions ( ) . getPrintableWidth ( ) ) ; } else { jrcross . setWidth ( djcross . getWidth ( ) ) ; } jrcross . setHeight ( djcross . getHeight ( ) ) ; jrcross . setColumnBreakOffset ( djcross . getColumnBreakOffset ( ) ) ; jrcross . setIgnoreWidth ( djcross . isIgnoreWidth ( ) ) ; } | Sets the options contained in the DJCrosstab to the JRDesignCrosstab . Also fits the correct width |
22,494 | private void setExpressionForPrecalculatedTotalValue ( DJCrosstabColumn [ ] auxCols , DJCrosstabRow [ ] auxRows , JRDesignExpression measureExp , DJCrosstabMeasure djmeasure , DJCrosstabColumn crosstabColumn , DJCrosstabRow crosstabRow , String meausrePrefix ) { String rowValuesExp = "new Object[]{" ; String rowPropsExp = "new String[]{" ; for ( int i = 0 ; i < auxRows . length ; i ++ ) { if ( auxRows [ i ] . getProperty ( ) == null ) continue ; rowValuesExp += "$V{" + auxRows [ i ] . getProperty ( ) . getProperty ( ) + "}" ; rowPropsExp += "\"" + auxRows [ i ] . getProperty ( ) . getProperty ( ) + "\"" ; if ( i + 1 < auxRows . length && auxRows [ i + 1 ] . getProperty ( ) != null ) { rowValuesExp += ", " ; rowPropsExp += ", " ; } } rowValuesExp += "}" ; rowPropsExp += "}" ; String colValuesExp = "new Object[]{" ; String colPropsExp = "new String[]{" ; for ( int i = 0 ; i < auxCols . length ; i ++ ) { if ( auxCols [ i ] . getProperty ( ) == null ) continue ; colValuesExp += "$V{" + auxCols [ i ] . getProperty ( ) . getProperty ( ) + "}" ; colPropsExp += "\"" + auxCols [ i ] . getProperty ( ) . getProperty ( ) + "\"" ; if ( i + 1 < auxCols . length && auxCols [ i + 1 ] . getProperty ( ) != null ) { colValuesExp += ", " ; colPropsExp += ", " ; } } colValuesExp += "}" ; colPropsExp += "}" ; String measureProperty = meausrePrefix + djmeasure . getProperty ( ) . getProperty ( ) ; String expText = "(((" + DJCRosstabMeasurePrecalculatedTotalProvider . class . getName ( ) + ")$P{crosstab-measure__" + measureProperty + "_totalProvider}).getValueFor( " + colPropsExp + ", " + colValuesExp + ", " + rowPropsExp + ", " + rowValuesExp + " ))" ; if ( djmeasure . getValueFormatter ( ) != null ) { String fieldsMap = ExpressionUtils . getTextForFieldsFromScriptlet ( ) ; String parametersMap = ExpressionUtils . getTextForParametersFromScriptlet ( ) ; String variablesMap = ExpressionUtils . getTextForVariablesFromScriptlet ( ) ; String stringExpression = "(((" + DJValueFormatter . class . getName ( ) + ")$P{crosstab-measure__" + measureProperty + "_vf}).evaluate( " + "(" + expText + "), " + fieldsMap + ", " + variablesMap + ", " + parametersMap + " ))" ; measureExp . setText ( stringExpression ) ; measureExp . setValueClassName ( djmeasure . getValueFormatter ( ) . getClassName ( ) ) ; } else { log . debug ( "text for crosstab total provider is: " + expText ) ; measureExp . setText ( expText ) ; String valueClassNameForOperation = ExpressionUtils . getValueClassNameForOperation ( djmeasure . getOperation ( ) , djmeasure . getProperty ( ) ) ; measureExp . setValueClassName ( valueClassNameForOperation ) ; } } | set proper expression text invoking the DJCRosstabMeasurePrecalculatedTotalProvider for the cell |
22,495 | private Style getRowTotalStyle ( DJCrosstabRow crosstabRow ) { return crosstabRow . getTotalStyle ( ) == null ? this . djcross . getRowTotalStyle ( ) : crosstabRow . getTotalStyle ( ) ; } | MOVED INSIDE ExpressionUtils |
22,496 | private void registerRows ( ) { for ( int i = 0 ; i < rows . length ; i ++ ) { DJCrosstabRow crosstabRow = rows [ i ] ; JRDesignCrosstabRowGroup ctRowGroup = new JRDesignCrosstabRowGroup ( ) ; ctRowGroup . setWidth ( crosstabRow . getHeaderWidth ( ) ) ; ctRowGroup . setName ( crosstabRow . getProperty ( ) . getProperty ( ) ) ; JRDesignCrosstabBucket rowBucket = new JRDesignCrosstabBucket ( ) ; rowBucket . setValueClassName ( crosstabRow . getProperty ( ) . getValueClassName ( ) ) ; ctRowGroup . setBucket ( rowBucket ) ; JRDesignExpression bucketExp = ExpressionUtils . createExpression ( "$F{" + crosstabRow . getProperty ( ) . getProperty ( ) + "}" , crosstabRow . getProperty ( ) . getValueClassName ( ) ) ; rowBucket . setExpression ( bucketExp ) ; JRDesignCellContents rowHeaderContents = new JRDesignCellContents ( ) ; JRDesignTextField rowTitle = new JRDesignTextField ( ) ; JRDesignExpression rowTitExp = new JRDesignExpression ( ) ; rowTitExp . setValueClassName ( crosstabRow . getProperty ( ) . getValueClassName ( ) ) ; rowTitExp . setText ( "$V{" + crosstabRow . getProperty ( ) . getProperty ( ) + "}" ) ; rowTitle . setExpression ( rowTitExp ) ; rowTitle . setWidth ( crosstabRow . getHeaderWidth ( ) ) ; int auxHeight = getRowHeaderMaxHeight ( crosstabRow ) ; rowTitle . setHeight ( auxHeight ) ; Style headerstyle = crosstabRow . getHeaderStyle ( ) == null ? this . djcross . getRowHeaderStyle ( ) : crosstabRow . getHeaderStyle ( ) ; if ( headerstyle != null ) { layoutManager . applyStyleToElement ( headerstyle , rowTitle ) ; rowHeaderContents . setBackcolor ( headerstyle . getBackgroundColor ( ) ) ; } rowHeaderContents . addElement ( rowTitle ) ; rowHeaderContents . setMode ( ModeEnum . OPAQUE ) ; boolean fullBorder = i <= 0 ; applyCellBorder ( rowHeaderContents , false , fullBorder ) ; ctRowGroup . setHeader ( rowHeaderContents ) ; if ( crosstabRow . isShowTotals ( ) ) createRowTotalHeader ( ctRowGroup , crosstabRow , fullBorder ) ; try { jrcross . addRowGroup ( ctRowGroup ) ; } catch ( JRException e ) { log . error ( e . getMessage ( ) , e ) ; } } } | Register the Rowgroup buckets and places the header cells for the rows |
22,497 | private void registerColumns ( ) { for ( int i = 0 ; i < cols . length ; i ++ ) { DJCrosstabColumn crosstabColumn = cols [ i ] ; JRDesignCrosstabColumnGroup ctColGroup = new JRDesignCrosstabColumnGroup ( ) ; ctColGroup . setName ( crosstabColumn . getProperty ( ) . getProperty ( ) ) ; ctColGroup . setHeight ( crosstabColumn . getHeaderHeight ( ) ) ; JRDesignCrosstabBucket bucket = new JRDesignCrosstabBucket ( ) ; bucket . setValueClassName ( crosstabColumn . getProperty ( ) . getValueClassName ( ) ) ; JRDesignExpression bucketExp = ExpressionUtils . createExpression ( "$F{" + crosstabColumn . getProperty ( ) . getProperty ( ) + "}" , crosstabColumn . getProperty ( ) . getValueClassName ( ) ) ; bucket . setExpression ( bucketExp ) ; ctColGroup . setBucket ( bucket ) ; JRDesignCellContents colHeaerContent = new JRDesignCellContents ( ) ; JRDesignTextField colTitle = new JRDesignTextField ( ) ; JRDesignExpression colTitleExp = new JRDesignExpression ( ) ; colTitleExp . setValueClassName ( crosstabColumn . getProperty ( ) . getValueClassName ( ) ) ; colTitleExp . setText ( "$V{" + crosstabColumn . getProperty ( ) . getProperty ( ) + "}" ) ; colTitle . setExpression ( colTitleExp ) ; colTitle . setWidth ( crosstabColumn . getWidth ( ) ) ; colTitle . setHeight ( crosstabColumn . getHeaderHeight ( ) ) ; int auxWidth = calculateRowHeaderMaxWidth ( crosstabColumn ) ; colTitle . setWidth ( auxWidth ) ; Style headerstyle = crosstabColumn . getHeaderStyle ( ) == null ? this . djcross . getColumnHeaderStyle ( ) : crosstabColumn . getHeaderStyle ( ) ; if ( headerstyle != null ) { layoutManager . applyStyleToElement ( headerstyle , colTitle ) ; colHeaerContent . setBackcolor ( headerstyle . getBackgroundColor ( ) ) ; } colHeaerContent . addElement ( colTitle ) ; colHeaerContent . setMode ( ModeEnum . OPAQUE ) ; boolean fullBorder = i <= 0 ; applyCellBorder ( colHeaerContent , fullBorder , false ) ; ctColGroup . setHeader ( colHeaerContent ) ; if ( crosstabColumn . isShowTotals ( ) ) createColumTotalHeader ( ctColGroup , crosstabColumn , fullBorder ) ; try { jrcross . addColumnGroup ( ctColGroup ) ; } catch ( JRException e ) { log . error ( e . getMessage ( ) , e ) ; } } } | Registers the Columngroup Buckets and creates the header cell for the columns |
22,498 | private int calculateRowHeaderMaxWidth ( DJCrosstabColumn crosstabColumn ) { int auxWidth = 0 ; boolean firstTime = true ; List < DJCrosstabColumn > auxList = new ArrayList < DJCrosstabColumn > ( djcross . getColumns ( ) ) ; Collections . reverse ( auxList ) ; for ( DJCrosstabColumn col : auxList ) { if ( col . equals ( crosstabColumn ) ) { if ( auxWidth == 0 ) auxWidth = col . getWidth ( ) ; break ; } if ( firstTime ) { auxWidth += col . getWidth ( ) ; firstTime = false ; } if ( col . isShowTotals ( ) ) { auxWidth += col . getWidth ( ) ; } } return auxWidth ; } | The max possible width can be calculated doing the sum of of the inner cells and its totals |
22,499 | protected static JRDesignExpression getExpressionFromVariable ( JRDesignVariable var ) { JRDesignExpression exp = new JRDesignExpression ( ) ; exp . setText ( "$V{" + var . getName ( ) + "}" ) ; exp . setValueClass ( var . getValueClass ( ) ) ; return exp ; } | Generates an expression from a variable |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.