idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
36,000 | private boolean isCollectionAttribute ( PluralAttribute < ? super X , ? , ? > attribute ) { return attribute != null && attribute . getCollectionType ( ) . equals ( CollectionType . COLLECTION ) ; } | Checks if is collection attribute . |
36,001 | private boolean isListAttribute ( PluralAttribute < ? super X , ? , ? > attribute ) { return attribute != null && attribute . getCollectionType ( ) . equals ( CollectionType . LIST ) ; } | Checks if is list attribute . |
36,002 | private boolean isSetAttribute ( PluralAttribute < ? super X , ? , ? > attribute ) { return attribute != null && attribute . getCollectionType ( ) . equals ( CollectionType . SET ) ; } | Checks if is sets the attribute . |
36,003 | private boolean isMapAttribute ( PluralAttribute < ? super X , ? , ? > attribute ) { return attribute != null && attribute . getCollectionType ( ) . equals ( CollectionType . MAP ) ; } | Checks if is map attribute . |
36,004 | private < E > boolean isBindable ( Bindable < ? > attribute , Class < E > elementType ) { return attribute != null && attribute . getBindableJavaType ( ) . equals ( elementType ) ; } | Checks if is bindable . |
36,005 | private void checkForValid ( String paramName , Attribute < ? super X , ? > attribute ) { if ( attribute == null ) { throw new IllegalArgumentException ( "attribute of the given name and type is not present in the managed type, for name:" + paramName ) ; } } | Check for valid . |
36,006 | private Attribute < X , ? > getDeclaredAttribute ( String paramName , boolean checkValidity ) { Attribute < X , ? > attribute = ( Attribute < X , ? > ) getSingularAttribute ( paramName , false ) ; if ( attribute == null ) { attribute = ( Attribute < X , ? > ) getDeclaredPluralAttribute ( paramName ) ; } if ( checkValidity ) { checkForValid ( paramName , attribute ) ; } return attribute ; } | Gets the declared attribute . |
36,007 | private void onValidity ( String paramString , boolean checkValidity , SingularAttribute < ? super X , ? > attribute ) { if ( checkValidity ) { checkForValid ( paramString , attribute ) ; } } | On validity check . |
36,008 | private void bindTypeAnnotations ( ) { for ( Class < ? extends Annotation > ann : validJPAAnnotations ) { if ( getJavaType ( ) . isAnnotationPresent ( ann ) ) { checkForValid ( ) ; Annotation annotation = getJavaType ( ) . getAnnotation ( ann ) ; if ( ann . isAssignableFrom ( AttributeOverride . class ) ) { bindAttribute ( annotation ) ; } else if ( ann . isAssignableFrom ( AttributeOverrides . class ) ) { AttributeOverride [ ] attribAnns = ( ( AttributeOverrides ) annotation ) . value ( ) ; for ( AttributeOverride attribOverann : attribAnns ) { bindAttribute ( attribOverann ) ; } } } } } | Bind type annotations . |
36,009 | private void bindAttribute ( Annotation annotation ) { String fieldname = ( ( AttributeOverride ) annotation ) . name ( ) ; Column column = ( ( AttributeOverride ) annotation ) . column ( ) ; ( ( AbstractManagedType ) this . superClazzType ) . columnBindings . put ( fieldname , column ) ; } | Bind attribute . |
36,010 | private InheritanceModel buildInheritenceModel ( ) { InheritanceModel model = null ; if ( superClazzType != null ) { if ( superClazzType . getPersistenceType ( ) . equals ( PersistenceType . ENTITY ) && superClazzType . getJavaType ( ) . isAnnotationPresent ( Inheritance . class ) ) { Inheritance inheritenceAnn = superClazzType . getJavaType ( ) . getAnnotation ( Inheritance . class ) ; InheritanceType strategyType = inheritenceAnn . strategy ( ) ; String descriminator = null ; String descriminatorValue = null ; String tableName = null ; String schemaName = null ; tableName = superClazzType . getJavaType ( ) . getSimpleName ( ) ; if ( superClazzType . getJavaType ( ) . isAnnotationPresent ( Table . class ) ) { tableName = superClazzType . getJavaType ( ) . getAnnotation ( Table . class ) . name ( ) ; schemaName = superClazzType . getJavaType ( ) . getAnnotation ( Table . class ) . schema ( ) ; } model = onStrategyType ( model , strategyType , descriminator , descriminatorValue , tableName , schemaName ) ; } } return model ; } | Build inheritance model . |
36,011 | private InheritanceModel onStrategyType ( InheritanceModel model , InheritanceType strategyType , String descriminator , String descriminatorValue , String tableName , String schemaName ) { switch ( strategyType ) { case SINGLE_TABLE : if ( superClazzType . getJavaType ( ) . isAnnotationPresent ( DiscriminatorColumn . class ) ) { descriminator = superClazzType . getJavaType ( ) . getAnnotation ( DiscriminatorColumn . class ) . name ( ) ; descriminatorValue = getJavaType ( ) . getAnnotation ( DiscriminatorValue . class ) . value ( ) ; } model = new InheritanceModel ( InheritanceType . SINGLE_TABLE , descriminator , descriminatorValue , tableName , schemaName ) ; break ; case JOINED : model = new InheritanceModel ( InheritanceType . JOINED , tableName , schemaName ) ; break ; case TABLE_PER_CLASS : model = new InheritanceModel ( InheritanceType . TABLE_PER_CLASS , null , null ) ; break ; default : break ; } return model ; } | On strategy type . |
36,012 | private SchemaManager getSchemaManagerForPu ( final String persistenceUnit ) { SchemaManager schemaManager = null ; Map < String , Object > externalProperties = KunderaCoreUtils . getExternalProperties ( persistenceUnit , externalPropertyMap , persistenceUnits ) ; if ( getSchemaProperty ( persistenceUnit , externalProperties ) != null && ! getSchemaProperty ( persistenceUnit , externalProperties ) . isEmpty ( ) ) { ClientFactory clientFactory = ClientResolver . getClientFactory ( persistenceUnit ) ; schemaManager = clientFactory != null ? clientFactory . getSchemaManager ( externalProperties ) : null ; } return schemaManager ; } | Return schema manager for pu . |
36,013 | private void addTableGenerator ( ApplicationMetadata appMetadata , String persistenceUnit , List < TableInfo > tableInfos , EntityMetadata entityMetadata ) { Metamodel metamodel = appMetadata . getMetamodel ( persistenceUnit ) ; IdDiscriptor keyValue = ( ( MetamodelImpl ) metamodel ) . getKeyValue ( entityMetadata . getEntityClazz ( ) . getName ( ) ) ; if ( keyValue != null && keyValue . getTableDiscriptor ( ) != null ) { TableInfo tableGeneratorDiscriptor = new TableInfo ( keyValue . getTableDiscriptor ( ) . getTable ( ) , "CounterColumnType" , String . class , keyValue . getTableDiscriptor ( ) . getPkColumnName ( ) ) ; if ( ! tableInfos . contains ( tableGeneratorDiscriptor ) ) { tableGeneratorDiscriptor . addColumnInfo ( getJoinColumn ( tableGeneratorDiscriptor , keyValue . getTableDiscriptor ( ) . getValueColumnName ( ) , Long . class ) ) ; tableInfos . add ( tableGeneratorDiscriptor ) ; } } } | Add tableGenerator to table info . |
36,014 | private void addJoinColumnToInfo ( String joinColumn , TableInfo targetTableInfo , List < TableInfo > targetTableInfos , EntityMetadata m ) { if ( ! joinColumn . equals ( targetTableInfo . getIdColumnName ( ) ) ) { if ( ! targetTableInfos . isEmpty ( ) && targetTableInfos . contains ( targetTableInfo ) ) { int idx = targetTableInfos . indexOf ( targetTableInfo ) ; targetTableInfo = targetTableInfos . get ( idx ) ; ColumnInfo columnInfoOfJoinColumn = getJoinColumn ( targetTableInfo , joinColumn , m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; if ( ! targetTableInfo . getColumnMetadatas ( ) . contains ( columnInfoOfJoinColumn ) ) { targetTableInfo . addColumnInfo ( columnInfoOfJoinColumn ) ; } } else { ColumnInfo columnInfoOfJoinColumn = getJoinColumn ( targetTableInfo , joinColumn , m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; if ( ! targetTableInfo . getColumnMetadatas ( ) . contains ( columnInfoOfJoinColumn ) ) { targetTableInfo . addColumnInfo ( columnInfoOfJoinColumn ) ; } targetTableInfos . add ( targetTableInfo ) ; } } } | adds join column name to the table Info of entity . |
36,015 | private EmbeddedColumnInfo getEmbeddedColumn ( TableInfo tableInfo , EmbeddableType embeddableType , String embeddableColName , Class embeddedEntityClass , Field field ) { String [ ] orderByColumns = null ; if ( field . isAnnotationPresent ( OrderBy . class ) ) { OrderBy order = ( OrderBy ) field . getAnnotation ( OrderBy . class ) ; orderByColumns = order . value ( ) . split ( "\\s*,\\s*" ) ; } EmbeddedColumnInfo embeddedColumnInfo = new EmbeddedColumnInfo ( embeddableType ) ; embeddedColumnInfo . setEmbeddedColumnName ( embeddableColName ) ; Map < String , PropertyIndex > indexedColumns = IndexProcessor . getIndexesOnEmbeddable ( embeddedEntityClass ) ; List < ColumnInfo > columns = new ArrayList < ColumnInfo > ( ) ; Set attributes = embeddableType . getAttributes ( ) ; Iterator < Attribute > iter = attributes . iterator ( ) ; while ( iter . hasNext ( ) ) { Attribute attr = iter . next ( ) ; columns . add ( getColumn ( tableInfo , attr , indexedColumns . get ( attr . getName ( ) ) , orderByColumns ) ) ; } embeddedColumnInfo . setColumns ( columns ) ; return embeddedColumnInfo ; } | Get Embedded column info . |
36,016 | private ColumnInfo getColumn ( TableInfo tableInfo , Attribute column , PropertyIndex indexedColumn , String [ ] orderByColumns ) { ColumnInfo columnInfo = new ColumnInfo ( ) ; if ( column . getJavaType ( ) . isAnnotationPresent ( OrderBy . class ) ) { OrderBy order = ( OrderBy ) column . getJavaType ( ) . getAnnotation ( OrderBy . class ) ; orderByColumns = order . value ( ) . split ( "\\s*,\\s*" ) ; } columnInfo . setOrderBy ( getOrderByColumn ( orderByColumns , column ) ) ; if ( column . getJavaType ( ) . isEnum ( ) ) { columnInfo . setType ( String . class ) ; } else { columnInfo . setType ( column . getJavaType ( ) ) ; } columnInfo . setColumnName ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) ) ; if ( indexedColumn != null && indexedColumn . getName ( ) != null ) { columnInfo . setIndexable ( true ) ; IndexInfo indexInfo = new IndexInfo ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , indexedColumn . getMax ( ) , indexedColumn . getMin ( ) , indexedColumn . getIndexType ( ) , indexedColumn . getName ( ) ) ; tableInfo . addToIndexedColumnList ( indexInfo ) ; } return columnInfo ; } | getColumn method return ColumnInfo for the given column |
36,017 | private String getOrderByColumn ( String [ ] orderByColumns , Attribute column ) { if ( orderByColumns != null ) { for ( String orderColumn : orderByColumns ) { String [ ] orderValue = orderColumn . split ( "\\s" ) ; String orderColumnName = orderValue [ 0 ] . substring ( orderValue [ 0 ] . lastIndexOf ( '.' ) + 1 ) ; String orderColumnValue = orderValue [ 1 ] ; if ( orderColumnName . equals ( ( ( AbstractAttribute ) column ) . getName ( ) ) || orderColumnName . equals ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) ) ) { return orderColumnValue ; } } } return null ; } | getOrderByColumn method return order by value of the column |
36,018 | private ColumnInfo getJoinColumn ( TableInfo tableInfo , String joinColumnName , Class columnType ) { ColumnInfo columnInfo = new ColumnInfo ( ) ; columnInfo . setColumnName ( joinColumnName ) ; columnInfo . setIndexable ( true ) ; IndexInfo indexInfo = new IndexInfo ( joinColumnName ) ; tableInfo . addToIndexedColumnList ( indexInfo ) ; columnInfo . setType ( columnType ) ; return columnInfo ; } | getJoinColumn method return ColumnInfo for the join column |
36,019 | private String getSchemaProperty ( String persistenceUnit , Map < String , Object > externalProperties ) { PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata . getApplicationMetadata ( ) . getPersistenceUnitMetadata ( persistenceUnit ) ; String autoDdlOption = externalProperties != null ? ( String ) externalProperties . get ( PersistenceProperties . KUNDERA_DDL_AUTO_PREPARE ) : null ; if ( autoDdlOption == null ) { autoDdlOption = persistenceUnitMetadata != null ? persistenceUnitMetadata . getProperty ( PersistenceProperties . KUNDERA_DDL_AUTO_PREPARE ) : null ; } return autoDdlOption ; } | getKunderaProperty method return auto schema generation property for give persistence unit . |
36,020 | @ SuppressWarnings ( "unchecked" ) public static PropertyAccessor getPropertyAccessor ( Class < ? > clazz ) { PropertyAccessor < ? > accessor ; if ( clazz . isEnum ( ) ) { accessor = new EnumAccessor ( ) ; } else { accessor = map . get ( clazz ) ; } if ( null == accessor ) { if ( Enum . class . isAssignableFrom ( clazz ) ) { accessor = map . get ( Enum . class ) ; } else { accessor = map . get ( Object . class ) ; } } return accessor ; } | Gets the property accessor . |
36,021 | public HashMap < TranslationType , Map < String , StringBuilder > > prepareColumnOrColumnValues ( final Object record , final EntityMetadata entityMetadata , TranslationType type , Map < String , Object > externalProperties , final KunderaMetadata kunderaMetadata ) { HashMap < TranslationType , Map < String , StringBuilder > > parsedColumnOrColumnValue = new HashMap < CQLTranslator . TranslationType , Map < String , StringBuilder > > ( ) ; if ( type == null ) { throw new TranslationException ( "Please specify TranslationType: either COLUMN or VALUE" ) ; } MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) ; Class entityClazz = entityMetadata . getEntityClazz ( ) ; EntityType entityType = metaModel . entity ( entityClazz ) ; Map < String , StringBuilder > builders = new HashMap < String , StringBuilder > ( ) ; Map < String , StringBuilder > columnBuilders = new HashMap < String , StringBuilder > ( ) ; onTranslation ( record , entityMetadata , type , metaModel , entityClazz , entityType , builders , columnBuilders , externalProperties , kunderaMetadata ) ; for ( String tableName : columnBuilders . keySet ( ) ) { StringBuilder builder = builders . get ( tableName ) ; StringBuilder columnBuilder = columnBuilders . get ( tableName ) ; if ( type . equals ( TranslationType . ALL ) || type . equals ( TranslationType . VALUE ) ) { builder . deleteCharAt ( builder . length ( ) - 1 ) ; } if ( type . equals ( TranslationType . ALL ) || type . equals ( TranslationType . COLUMN ) ) { columnBuilder . deleteCharAt ( columnBuilder . length ( ) - 1 ) ; } } parsedColumnOrColumnValue . put ( TranslationType . COLUMN , columnBuilders ) ; parsedColumnOrColumnValue . put ( TranslationType . VALUE , builders ) ; return parsedColumnOrColumnValue ; } | Prepares column name or column values . |
36,022 | private void buildEmbeddedValue ( final Object record , MetamodelImpl metaModel , StringBuilder embeddedValueBuilder , SingularAttribute attribute ) { Field field = ( Field ) attribute . getJavaMember ( ) ; EmbeddableType embeddableKey = metaModel . embeddable ( field . getType ( ) ) ; Object embeddableKeyObj = PropertyAccessorHelper . getObject ( record , field ) ; if ( embeddableKeyObj != null ) { StringBuilder tempBuilder = new StringBuilder ( ) ; tempBuilder . append ( Constants . OPEN_CURLY_BRACKET ) ; for ( Field embeddableColumn : field . getType ( ) . getDeclaredFields ( ) ) { if ( ! ReflectUtils . isTransientOrStatic ( embeddableColumn ) ) { Attribute subAttribute = ( SingularAttribute ) embeddableKey . getAttribute ( embeddableColumn . getName ( ) ) ; if ( metaModel . isEmbeddable ( ( ( AbstractAttribute ) subAttribute ) . getBindableJavaType ( ) ) ) { buildEmbeddedValue ( embeddableKeyObj , metaModel , tempBuilder , ( SingularAttribute ) subAttribute ) ; } else { appendColumnName ( tempBuilder , ( ( AbstractAttribute ) ( embeddableKey . getAttribute ( embeddableColumn . getName ( ) ) ) ) . getJPAColumnName ( ) ) ; tempBuilder . append ( Constants . COLON ) ; appendColumnValue ( tempBuilder , embeddableKeyObj , embeddableColumn ) ; } tempBuilder . append ( Constants . COMMA ) ; } } tempBuilder . deleteCharAt ( tempBuilder . length ( ) - 1 ) ; tempBuilder . append ( Constants . CLOSE_CURLY_BRACKET ) ; appendColumnName ( embeddedValueBuilder , ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ) ; embeddedValueBuilder . append ( Constants . COLON ) ; embeddedValueBuilder . append ( tempBuilder ) ; } else { embeddedValueBuilder . deleteCharAt ( embeddedValueBuilder . length ( ) - 1 ) ; } } | Builds the embedded value . |
36,023 | private void translateCompositeId ( final Object record , final EntityMetadata m , TranslationType type , MetamodelImpl metaModel , Map < String , StringBuilder > builders , Map < String , StringBuilder > columnBuilders , Map < String , Object > externalProperties , final KunderaMetadata kunderaMetadata , String tableName , SingularAttribute attribute ) { StringBuilder builder = builders . get ( tableName ) ; StringBuilder columnBuilder = columnBuilders . get ( tableName ) ; Field field = ( Field ) attribute . getJavaMember ( ) ; if ( metaModel . isEmbeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { EmbeddableType compoundKey = metaModel . embeddable ( field . getType ( ) ) ; Object compoundKeyObj = PropertyAccessorHelper . getObject ( record , field ) ; for ( Field compositeColumn : field . getType ( ) . getDeclaredFields ( ) ) { if ( ! ReflectUtils . isTransientOrStatic ( compositeColumn ) ) { attribute = ( SingularAttribute ) compoundKey . getAttribute ( compositeColumn . getName ( ) ) ; if ( metaModel . isEmbeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { translateCompositeId ( compoundKeyObj , m , type , metaModel , builders , columnBuilders , externalProperties , kunderaMetadata , tableName , attribute ) ; } else { onTranslation ( type , builder , columnBuilder , ( ( AbstractAttribute ) ( compoundKey . getAttribute ( compositeColumn . getName ( ) ) ) ) . getJPAColumnName ( ) , compoundKeyObj , compositeColumn ) ; } } } } else if ( ! ReflectUtils . isTransientOrStatic ( field ) ) { onTranslation ( type , builder , columnBuilder , CassandraUtilities . getIdColumnName ( kunderaMetadata , m , externalProperties , true ) , record , field ) ; } } | Translate composite id . |
36,024 | public void buildSetClauseForCounters ( StringBuilder builder , String field , Object value ) { builder = ensureCase ( builder , field , false ) ; builder . append ( EQ_CLAUSE ) ; builder = ensureCase ( builder , field , false ) ; builder . append ( INCR_COUNTER ) ; appendValue ( builder , value . getClass ( ) , value , false , false ) ; builder . append ( COMMA_STR ) ; } | Builds set clause for a given counter field . |
36,025 | public void buildSetClause ( EntityMetadata m , StringBuilder builder , String property , Object value ) { builder = ensureCase ( builder , property , false ) ; builder . append ( EQ_CLAUSE ) ; if ( m . isCounterColumnType ( ) ) { builder = ensureCase ( builder , property , false ) ; builder . append ( INCR_COUNTER ) ; builder . append ( value ) ; } else { appendValue ( builder , value . getClass ( ) , value , false , false ) ; } builder . append ( COMMA_STR ) ; } | Builds set clause for a given field . |
36,026 | public StringBuilder ensureCase ( StringBuilder builder , String fieldName , boolean useToken ) { if ( useToken ) { builder . append ( TOKEN ) ; } builder . append ( Constants . ESCAPE_QUOTE ) ; builder . append ( fieldName ) ; builder . append ( Constants . ESCAPE_QUOTE ) ; if ( useToken ) { builder . append ( CLOSE_BRACKET ) ; } return builder ; } | Ensures case for corresponding column name . |
36,027 | private boolean appendColumnValue ( StringBuilder builder , Object valueObj , Field column ) { Object value = PropertyAccessorHelper . getObject ( valueObj , column ) ; boolean isPresent = false ; isPresent = appendValue ( builder , column . getType ( ) , value , isPresent , false ) ; return isPresent ; } | Appends column value with parametrised builder object . Returns true if value is present . |
36,028 | public boolean appendValue ( StringBuilder builder , Class fieldClazz , Object value , boolean isPresent , boolean useToken ) { if ( List . class . isAssignableFrom ( fieldClazz ) ) { isPresent = appendList ( builder , value != null ? value : new ArrayList ( ) ) ; } else if ( Set . class . isAssignableFrom ( fieldClazz ) ) { isPresent = appendSet ( builder , value != null ? value : new HashSet ( ) ) ; } else if ( Map . class . isAssignableFrom ( fieldClazz ) ) { isPresent = appendMap ( builder , value != null ? value : new HashMap ( ) ) ; } else { isPresent = true ; appendValue ( builder , fieldClazz , value , useToken ) ; } return isPresent ; } | Appends value to builder object for given class type . |
36,029 | public void appendColumnName ( StringBuilder builder , String columnName , String dataType ) { ensureCase ( builder , columnName , false ) ; builder . append ( " " ) ; builder . append ( dataType ) ; } | Appends column name and data type also ensures case sensitivity . |
36,030 | private boolean isDate ( Class clazz ) { return clazz . isAssignableFrom ( Date . class ) || clazz . isAssignableFrom ( java . sql . Date . class ) || clazz . isAssignableFrom ( Timestamp . class ) || clazz . isAssignableFrom ( Time . class ) || clazz . isAssignableFrom ( Calendar . class ) ; } | Validates if input class is of type input . |
36,031 | public void buildOrderByClause ( StringBuilder builder , String field , Object orderType , boolean useToken ) { builder . append ( SPACE_STRING ) ; builder . append ( SORT_CLAUSE ) ; builder = ensureCase ( builder , field , useToken ) ; builder . append ( SPACE_STRING ) ; builder . append ( orderType ) ; } | Builds the order by clause . |
36,032 | public StringBuilder buildSelectQuery ( TableGeneratorDiscriptor descriptor ) { StringBuilder builder = new StringBuilder ( "Select " ) ; ensureCase ( builder , descriptor . getValueColumnName ( ) , false ) . append ( " from " ) ; ensureCase ( builder , descriptor . getTable ( ) , false ) . append ( " where " ) ; ensureCase ( builder , descriptor . getPkColumnName ( ) , false ) . append ( " = '" ) . append ( descriptor . getPkColumnValue ( ) + "'" ) ; return builder ; } | Builds the select query . |
36,033 | @ SuppressWarnings ( "unchecked" ) private void addCallBackMethod ( EntityMetadata metadata , Class < ? > jpaAnnotation , CallbackMethod callbackMethod ) { Map < Class < ? > , List < ? extends CallbackMethod > > callBackMethodsMap = metadata . getCallbackMethodsMap ( ) ; List < CallbackMethod > list = ( List < CallbackMethod > ) callBackMethodsMap . get ( jpaAnnotation ) ; if ( null == list ) { list = new ArrayList < CallbackMethod > ( ) ; callBackMethodsMap . put ( jpaAnnotation , list ) ; } list . add ( callbackMethod ) ; } | Adds the call back method . |
36,034 | private List < Class < ? > > getValidJPAAnnotationsFromMethod ( Class < ? > clazz , Method method , int numberOfParams , Class < ? > entityClazz ) { List < Class < ? > > annotations = new ArrayList < Class < ? > > ( ) ; for ( Annotation methodAnnotation : method . getAnnotations ( ) ) { Class < ? > methodAnnotationType = methodAnnotation . annotationType ( ) ; if ( isValidJPAEntityListenerAnnotation ( methodAnnotationType ) ) { boolean hasUncheckedExceptions = false ; for ( Class < ? > exception : method . getExceptionTypes ( ) ) { if ( ! ReflectUtils . hasSuperClass ( RuntimeException . class , exception ) ) { hasUncheckedExceptions = true ; break ; } } if ( hasUncheckedExceptions ) { log . info ( "Skipped method(" + clazz . getName ( ) + "." + method . getName ( ) + ") Must not throw unchecked exceptions." ) ; continue ; } if ( ! method . getReturnType ( ) . getSimpleName ( ) . equals ( "void" ) ) { log . info ( "Skipped method(" + clazz . getName ( ) + "." + method . getName ( ) + ") Must have \"void\" return type." ) ; continue ; } Class < ? > [ ] paramTypes = method . getParameterTypes ( ) ; if ( paramTypes . length != numberOfParams ) { log . info ( "Skipped method(" + clazz . getName ( ) + "." + method . getName ( ) + ") Must have " + numberOfParams + " parameter." ) ; continue ; } if ( numberOfParams == 1 ) { Class < ? > parameter = paramTypes [ 0 ] ; if ( ! ( parameter != null && parameter . isAssignableFrom ( entityClazz ) ) ) { log . info ( "Skipped method(" + clazz . getName ( ) + "." + method . getName ( ) + ") Must have only 1 \"Object\" type parameter." ) ; continue ; } } annotations . add ( methodAnnotationType ) ; } } return annotations ; } | Gets the valid jpa annotations from method . |
36,035 | private ConnectionPool getPoolUsingPolicy ( ) { if ( ! hostPools . isEmpty ( ) ) { return ( ConnectionPool ) loadBalancingPolicy . getPool ( hostPools . values ( ) ) ; } throw new KunderaException ( "All hosts are down. please check servers manully." ) ; } | Gets the pool using policy . |
36,036 | private ConnectionPool getNewPool ( String host , int port ) { CassandraHost cassandraHost = ( ( CassandraHostConfiguration ) configuration ) . getCassandraHost ( host , port ) ; hostPools . remove ( cassandraHost ) ; if ( cassandraHost . isRetryHost ( ) ) { logger . warn ( "Scheduling node for future retry" ) ; ( ( CassandraRetryService ) hostRetryService ) . add ( ( CassandraHost ) cassandraHost ) ; } return getPoolUsingPolicy ( ) ; } | Gets the new pool . |
36,037 | void releaseConnection ( ConnectionPool pool , Cassandra . Client conn ) { if ( pool != null && conn != null ) { pool . release ( conn ) ; } } | Release connection . |
36,038 | private LoadBalancingPolicy getPolicyInstance ( BalancingPolicy policy , Properties conProperties ) { LoadBalancingPolicy loadBalancingPolicy = null ; String isTokenAware = ( String ) conProperties . get ( "isTokenAware" ) ; String isLatencyAware = ( String ) conProperties . get ( "isLatencyAware" ) ; String whiteList = ( String ) conProperties . get ( "whiteList" ) ; String hostFilterPolicy = ( String ) conProperties . get ( "hostFilterPolicy" ) ; switch ( policy ) { case DCAwareRoundRobinPolicy : String usedHostsPerRemoteDc = ( String ) conProperties . get ( "usedHostsPerRemoteDc" ) ; String localdc = ( String ) conProperties . get ( "localdc" ) ; String allowRemoteDCsForLocalConsistencyLevel = ( String ) conProperties . get ( "allowRemoteDCsForLocalConsistencyLevel" ) ; DCAwareRoundRobinPolicy . Builder policyBuilder = DCAwareRoundRobinPolicy . builder ( ) ; policyBuilder . withLocalDc ( localdc == null ? "DC1" : localdc ) ; policyBuilder . withUsedHostsPerRemoteDc ( usedHostsPerRemoteDc != null ? Integer . parseInt ( usedHostsPerRemoteDc ) : 0 ) ; if ( allowRemoteDCsForLocalConsistencyLevel != null && "true" . equalsIgnoreCase ( allowRemoteDCsForLocalConsistencyLevel ) ) { policyBuilder . allowRemoteDCsForLocalConsistencyLevel ( ) ; } loadBalancingPolicy = policyBuilder . build ( ) ; break ; default : loadBalancingPolicy = new RoundRobinPolicy ( ) ; break ; } if ( loadBalancingPolicy != null && Boolean . valueOf ( isTokenAware ) ) { loadBalancingPolicy = new TokenAwarePolicy ( loadBalancingPolicy ) ; } else if ( loadBalancingPolicy != null && Boolean . valueOf ( isLatencyAware ) ) { loadBalancingPolicy = LatencyAwarePolicy . builder ( loadBalancingPolicy ) . build ( ) ; } if ( loadBalancingPolicy != null && whiteList != null ) { Collection < InetSocketAddress > whiteListCollection = buildWhiteListCollection ( whiteList ) ; loadBalancingPolicy = new WhiteListPolicy ( loadBalancingPolicy , whiteListCollection ) ; } if ( loadBalancingPolicy != null && hostFilterPolicy != null ) { Predicate < com . datastax . driver . core . Host > predicate = getHostFilterPredicate ( hostFilterPolicy ) ; loadBalancingPolicy = new HostFilterPolicy ( loadBalancingPolicy , predicate ) ; } return loadBalancingPolicy ; } | Gets the policy instance . |
36,039 | private Predicate < com . datastax . driver . core . Host > getHostFilterPredicate ( String hostFilterPolicy ) { Predicate < com . datastax . driver . core . Host > predicate = null ; Method getter = null ; Class < ? > hostFilterClazz = null ; try { hostFilterClazz = Class . forName ( hostFilterPolicy ) ; getter = hostFilterClazz . getDeclaredMethod ( GET_INSTANCE ) ; predicate = ( Predicate < com . datastax . driver . core . Host > ) getter . invoke ( KunderaCoreUtils . createNewInstance ( hostFilterClazz ) ) ; } catch ( ClassNotFoundException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Please make sure class " + hostFilterPolicy + " set in property file exists in classpath " + e . getMessage ( ) ) ; } catch ( IllegalAccessException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Method " + getter . getName ( ) + " must be declared public " + e . getMessage ( ) ) ; } catch ( NoSuchMethodException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Please make sure getter method of " + hostFilterClazz . getSimpleName ( ) + " is named \"getInstance()\"" ) ; } catch ( InvocationTargetException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Error while executing \"getInstance()\" method of Class " + hostFilterClazz . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; } catch ( SecurityException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Encountered security exception while accessing the method: " + "\"getInstance()\"" + e . getMessage ( ) ) ; } return predicate ; } | Gets the host filter predicate . |
36,040 | private Collection < InetSocketAddress > buildWhiteListCollection ( String whiteList ) { String [ ] list = whiteList . split ( Constants . COMMA ) ; Collection < InetSocketAddress > whiteListCollection = new ArrayList < InetSocketAddress > ( ) ; PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata . getApplicationMetadata ( ) . getPersistenceUnitMetadata ( getPersistenceUnit ( ) ) ; Properties props = persistenceUnitMetadata . getProperties ( ) ; int defaultPort = 9042 ; if ( externalProperties != null && externalProperties . get ( PersistenceProperties . KUNDERA_PORT ) != null ) { try { defaultPort = Integer . parseInt ( ( String ) externalProperties . get ( PersistenceProperties . KUNDERA_PORT ) ) ; } catch ( NumberFormatException e ) { logger . error ( "Port in persistence.xml should be integer" ) ; } } else { try { defaultPort = Integer . parseInt ( ( String ) props . get ( PersistenceProperties . KUNDERA_PORT ) ) ; } catch ( NumberFormatException e ) { logger . error ( "Port in persistence.xml should be integer" ) ; } } for ( String node : list ) { if ( node . indexOf ( Constants . COLON ) > 0 ) { String [ ] parts = node . split ( Constants . COLON ) ; whiteListCollection . add ( new InetSocketAddress ( parts [ 0 ] , Integer . parseInt ( parts [ 1 ] ) ) ) ; } else { whiteListCollection . add ( new InetSocketAddress ( node , defaultPort ) ) ; } } return whiteListCollection ; } | Builds the white list collection . |
36,041 | private com . datastax . driver . core . policies . RetryPolicy getCustomRetryPolicy ( Properties props ) { String customRetryPolicy = ( String ) props . get ( CUSTOM_RETRY_POLICY ) ; Class < ? > clazz = null ; Method getter = null ; try { clazz = Class . forName ( customRetryPolicy ) ; com . datastax . driver . core . policies . RetryPolicy retryPolicy = ( com . datastax . driver . core . policies . RetryPolicy ) KunderaCoreUtils . createNewInstance ( clazz ) ; if ( retryPolicy != null ) { return retryPolicy ; } getter = clazz . getDeclaredMethod ( GET_INSTANCE ) ; return ( com . datastax . driver . core . policies . RetryPolicy ) getter . invoke ( null , ( Object [ ] ) null ) ; } catch ( ClassNotFoundException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Please make sure class " + customRetryPolicy + " set in property file exists in classpath " + e . getMessage ( ) ) ; } catch ( IllegalAccessException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Method " + getter . getName ( ) + " must be declared public " + e . getMessage ( ) ) ; } catch ( NoSuchMethodException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Please make sure getter method of " + clazz . getSimpleName ( ) + " is named \"getInstance()\"" ) ; } catch ( InvocationTargetException e ) { logger . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Error while executing \"getInstance()\" method of Class " + clazz . getSimpleName ( ) + ": " + e . getMessage ( ) ) ; } } | Gets the custom retry policy . |
36,042 | private SocketOptions getSocketOptions ( Properties connectionProperties ) { SocketOptions socketConfig = new SocketOptions ( ) ; String connectTimeoutMillis = connectionProperties . getProperty ( CassandraConstants . SOCKET_TIMEOUT ) ; String readTimeoutMillis = connectionProperties . getProperty ( "readTimeoutMillis" ) ; String keepAlive = connectionProperties . getProperty ( "keepAlive" ) ; String reuseAddress = connectionProperties . getProperty ( "reuseAddress" ) ; String soLinger = connectionProperties . getProperty ( "soLinger" ) ; String tcpNoDelay = connectionProperties . getProperty ( "tcpNoDelay" ) ; String receiveBufferSize = connectionProperties . getProperty ( "receiveBufferSize" ) ; String sendBufferSize = connectionProperties . getProperty ( "sendBufferSize" ) ; if ( ! StringUtils . isBlank ( connectTimeoutMillis ) ) { socketConfig . setConnectTimeoutMillis ( new Integer ( connectTimeoutMillis ) ) ; } if ( ! StringUtils . isBlank ( readTimeoutMillis ) ) { socketConfig . setReadTimeoutMillis ( new Integer ( readTimeoutMillis ) ) ; } if ( ! StringUtils . isBlank ( keepAlive ) ) { socketConfig . setKeepAlive ( new Boolean ( keepAlive ) ) ; } if ( ! StringUtils . isBlank ( reuseAddress ) ) { socketConfig . setReuseAddress ( new Boolean ( reuseAddress ) ) ; } if ( ! StringUtils . isBlank ( soLinger ) ) { socketConfig . setSoLinger ( new Integer ( soLinger ) ) ; } if ( ! StringUtils . isBlank ( tcpNoDelay ) ) { socketConfig . setTcpNoDelay ( new Boolean ( tcpNoDelay ) ) ; } if ( ! StringUtils . isBlank ( receiveBufferSize ) ) { socketConfig . setReceiveBufferSize ( new Integer ( receiveBufferSize ) ) ; } if ( ! StringUtils . isBlank ( sendBufferSize ) ) { socketConfig . setSendBufferSize ( new Integer ( sendBufferSize ) ) ; } return socketConfig ; } | Gets the socket options . |
36,043 | private PoolingOptions getPoolingOptions ( Properties connectionProperties ) { PoolingOptions options = new PoolingOptions ( ) ; String hostDistance = connectionProperties . getProperty ( "hostDistance" ) ; String maxConnectionsPerHost = connectionProperties . getProperty ( "maxConnectionsPerHost" ) ; String maxRequestsPerConnection = connectionProperties . getProperty ( "maxRequestsPerConnection" ) ; String coreConnections = connectionProperties . getProperty ( "coreConnections" ) ; if ( ! StringUtils . isBlank ( hostDistance ) ) { HostDistance hostDist = HostDistance . valueOf ( hostDistance . toUpperCase ( ) ) ; if ( ! StringUtils . isBlank ( coreConnections ) ) { options . setCoreConnectionsPerHost ( HostDistance . LOCAL , new Integer ( coreConnections ) ) ; } if ( ! StringUtils . isBlank ( maxConnectionsPerHost ) ) { options . setMaxConnectionsPerHost ( hostDist , new Integer ( maxConnectionsPerHost ) ) ; } if ( ! StringUtils . isBlank ( maxRequestsPerConnection ) ) { options . setMaxRequestsPerConnection ( hostDist , new Integer ( maxRequestsPerConnection ) ) ; } } return options ; } | Gets the pooling options . |
36,044 | private byte [ ] getBytes ( String jpaFieldName , EntityMetadata m , Object value ) { AbstractAttribute idCol = ( AbstractAttribute ) m . getIdAttribute ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entity = metaModel . entity ( m . getEntityClazz ( ) ) ; Class fieldClazz = null ; if ( idCol . getName ( ) . equals ( jpaFieldName ) ) { Field f = ( Field ) idCol . getJavaMember ( ) ; if ( metaModel . isEmbeddable ( idCol . getBindableJavaType ( ) ) ) { fieldClazz = String . class ; Map < Attribute , List < Object > > columnValues = new HashMap < Attribute , List < Object > > ( ) ; Field [ ] fields = m . getIdAttribute ( ) . getBindableJavaType ( ) . getDeclaredFields ( ) ; EmbeddableType embeddable = metaModel . embeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; StringBuilder compositeKey = new StringBuilder ( ) ; for ( Field field : fields ) { if ( ! ReflectUtils . isTransientOrStatic ( field ) ) { AbstractAttribute attrib = ( AbstractAttribute ) embeddable . getAttribute ( field . getName ( ) ) ; Object obj = PropertyAccessorHelper . getObject ( value , field ) ; compositeKey . append ( PropertyAccessorHelper . fromSourceToTargetClass ( String . class , attrib . getBindableJavaType ( ) , obj ) ) . append ( "\001" ) ; } } compositeKey . delete ( compositeKey . lastIndexOf ( "\001" ) , compositeKey . length ( ) ) ; value = compositeKey . toString ( ) ; } else { fieldClazz = f . getType ( ) ; } } else { StringTokenizer tokenizer = new StringTokenizer ( jpaFieldName , "." ) ; String embeddedFieldName = null ; if ( tokenizer . countTokens ( ) > 1 ) { embeddedFieldName = tokenizer . nextToken ( ) ; String fieldName = tokenizer . nextToken ( ) ; Attribute embeddableAttribute = entity . getAttribute ( embeddedFieldName ) ; EmbeddableType embeddableType = metaModel . embeddable ( embeddableAttribute . getJavaType ( ) ) ; Attribute embeddedAttribute = embeddableType . getAttribute ( fieldName ) ; jpaFieldName = ( ( AbstractAttribute ) embeddedAttribute ) . getJPAColumnName ( ) ; fieldClazz = ( ( AbstractAttribute ) embeddedAttribute ) . getBindableJavaType ( ) ; } else { String discriminatorColumn = ( ( AbstractManagedType ) entity ) . getDiscriminatorColumn ( ) ; if ( ! jpaFieldName . equals ( discriminatorColumn ) ) { String fieldName = m . getFieldName ( jpaFieldName ) ; Attribute col = entity . getAttribute ( fieldName ) ; fieldClazz = ( ( AbstractAttribute ) col ) . getBindableJavaType ( ) ; } } } if ( fieldClazz != null ) { return HBaseUtils . getBytes ( value , fieldClazz ) ; } else { return HBaseUtils . getBytes ( value , String . class ) ; } } | Returns bytes of value object . |
36,045 | public static Map < String , Object > getExternalProperties ( String pu , Map < String , Object > externalProperties , String ... persistenceUnits ) { Map < String , Object > puProperty ; if ( persistenceUnits != null && persistenceUnits . length > 1 && externalProperties != null ) { puProperty = ( Map < String , Object > ) externalProperties . get ( pu ) ; if ( puProperty != null ) { return fetchPropertyMap ( puProperty ) ; } return null ; } return externalProperties ; } | Retrun map of external properties for given pu ; |
36,046 | public static String prepareCompositeKey ( final EntityMetadata m , final Object compositeKey ) { Field [ ] fields = m . getIdAttribute ( ) . getBindableJavaType ( ) . getDeclaredFields ( ) ; StringBuilder stringBuilder = new StringBuilder ( ) ; for ( Field f : fields ) { if ( ! ReflectUtils . isTransientOrStatic ( f ) ) { try { String fieldValue = PropertyAccessorHelper . getString ( compositeKey , f ) ; stringBuilder . append ( fieldValue ) ; stringBuilder . append ( COMPOSITE_KEY_SEPERATOR ) ; } catch ( IllegalArgumentException e ) { logger . error ( "Error during prepare composite key, Caused by {}." , e ) ; throw new PersistenceException ( e ) ; } } } if ( stringBuilder . length ( ) > 0 ) { stringBuilder . deleteCharAt ( stringBuilder . lastIndexOf ( COMPOSITE_KEY_SEPERATOR ) ) ; } return stringBuilder . toString ( ) ; } | Prepares composite key . |
36,047 | public static String prepareCompositeKey ( final SingularAttribute attribute , final MetamodelImpl metaModel , final Object compositeKey ) { Field [ ] fields = attribute . getBindableJavaType ( ) . getDeclaredFields ( ) ; EmbeddableType embeddable = metaModel . embeddable ( attribute . getBindableJavaType ( ) ) ; StringBuilder stringBuilder = new StringBuilder ( ) ; try { for ( Field f : fields ) { if ( ! ReflectUtils . isTransientOrStatic ( f ) ) { if ( metaModel . isEmbeddable ( ( ( AbstractAttribute ) embeddable . getAttribute ( f . getName ( ) ) ) . getBindableJavaType ( ) ) ) { f . setAccessible ( true ) ; stringBuilder . append ( prepareCompositeKey ( ( SingularAttribute ) embeddable . getAttribute ( f . getName ( ) ) , metaModel , f . get ( compositeKey ) ) ) . append ( LUCENE_COMPOSITE_KEY_SEPERATOR ) ; } else { String fieldValue = PropertyAccessorHelper . getString ( compositeKey , f ) ; fieldValue = fieldValue . replaceAll ( "[^a-zA-Z0-9]" , "_" ) ; stringBuilder . append ( fieldValue ) ; stringBuilder . append ( LUCENE_COMPOSITE_KEY_SEPERATOR ) ; } } } } catch ( IllegalAccessException e ) { logger . error ( e . getMessage ( ) ) ; } catch ( IllegalArgumentException e ) { logger . error ( "Error during prepare composite key, Caused by {}." , e ) ; throw new PersistenceException ( e ) ; } if ( stringBuilder . length ( ) > 0 ) { stringBuilder . deleteCharAt ( stringBuilder . lastIndexOf ( LUCENE_COMPOSITE_KEY_SEPERATOR ) ) ; } return stringBuilder . toString ( ) ; } | Prepares composite key as a lucene key . |
36,048 | public static String resolvePath ( String input ) { if ( null == input ) { return input ; } Pattern pathPattern = Pattern . compile ( "\\$\\{(.+?)\\}" ) ; Matcher matcherPattern = pathPattern . matcher ( input ) ; StringBuffer sb = new StringBuffer ( ) ; EnvironmentConfiguration config = new EnvironmentConfiguration ( ) ; SystemConfiguration sysConfig = new SystemConfiguration ( ) ; while ( matcherPattern . find ( ) ) { String confVarName = matcherPattern . group ( 1 ) != null ? matcherPattern . group ( 1 ) : matcherPattern . group ( 2 ) ; String envConfVarValue = config . getString ( confVarName ) ; String sysVarValue = sysConfig . getString ( confVarName ) ; if ( envConfVarValue != null ) { matcherPattern . appendReplacement ( sb , envConfVarValue ) ; } else if ( sysVarValue != null ) { matcherPattern . appendReplacement ( sb , sysVarValue ) ; } else { matcherPattern . appendReplacement ( sb , "" ) ; } } matcherPattern . appendTail ( sb ) ; return sb . toString ( ) ; } | Resolves variable in path given as string |
36,049 | public static String getLuceneQueryFromJPAQuery ( final KunderaQuery kunderaQuery , final KunderaMetadata kunderaMetadata ) { LuceneQueryBuilder queryBuilder = new LuceneQueryBuilder ( ) ; EntityMetadata metadata = kunderaQuery . getEntityMetadata ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( metadata . getPersistenceUnit ( ) ) ; Class valueClazz = null ; EntityType entity = metaModel . entity ( metadata . getEntityClazz ( ) ) ; boolean partitionKeyCheck = true ; for ( Object object : kunderaQuery . getFilterClauseQueue ( ) ) { if ( object instanceof FilterClause ) { FilterClause filter = ( FilterClause ) object ; String property = filter . getProperty ( ) ; String condition = filter . getCondition ( ) ; String valueAsString = filter . getValue ( ) . get ( 0 ) . toString ( ) ; String fieldName = metadata . getFieldName ( property ) ; boolean isEmbeddedId = metaModel . isEmbeddable ( metadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ; String idColumn = ( ( AbstractAttribute ) metadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ; valueClazz = getValueType ( entity , fieldName ) ; if ( isEmbeddedId ) { if ( idColumn . equals ( property ) ) { valueAsString = prepareCompositeKey ( metadata . getIdAttribute ( ) , metaModel , filter . getValue ( ) . get ( 0 ) ) ; queryBuilder . appendIndexName ( metadata . getIndexName ( ) ) . appendPropertyName ( idColumn ) . buildQuery ( condition , valueAsString , valueClazz ) ; } else { valueClazz = metadata . getIdAttribute ( ) . getBindableJavaType ( ) ; if ( property . lastIndexOf ( '.' ) != property . indexOf ( '.' ) && partitionKeyCheck ) { isCompletePartitionKeyPresentInQuery ( kunderaQuery . getFilterClauseQueue ( ) , metaModel , metadata ) ; partitionKeyCheck = false ; } if ( metaModel . isEmbeddable ( filter . getValue ( ) . get ( 0 ) . getClass ( ) ) ) { prepareLuceneQueryForPartitionKey ( queryBuilder , filter . getValue ( ) . get ( 0 ) , metaModel , metadata . getIndexName ( ) , valueClazz ) ; } else { property = property . substring ( property . lastIndexOf ( "." ) + 1 ) ; queryBuilder . appendIndexName ( metadata . getIndexName ( ) ) . appendPropertyName ( getPropertyName ( metadata , property , kunderaMetadata ) ) . buildQuery ( condition , valueAsString , valueClazz ) ; } } } else { queryBuilder . appendIndexName ( metadata . getIndexName ( ) ) . appendPropertyName ( getPropertyName ( metadata , property , kunderaMetadata ) ) . buildQuery ( condition , valueAsString , valueClazz ) ; } } else { queryBuilder . buildQuery ( object . toString ( ) , object . toString ( ) , String . class ) ; } } queryBuilder . appendEntityName ( kunderaQuery . getEntityClass ( ) . getCanonicalName ( ) . toLowerCase ( ) ) ; return queryBuilder . getQuery ( ) ; } | Gets the lucene query from jpa query . |
36,050 | private static void isCompletePartitionKeyPresentInQuery ( Queue filterQueue , MetamodelImpl metaModel , EntityMetadata metadata ) { Set < String > partitionKeyFields = new HashSet < String > ( ) ; populateEmbeddedIdFields ( metaModel . embeddable ( metadata . getIdAttribute ( ) . getBindableJavaType ( ) ) . getAttributes ( ) , metaModel , partitionKeyFields ) ; Set < String > queryAttributes = new HashSet < String > ( ) ; for ( Object object : filterQueue ) { if ( object instanceof FilterClause ) { FilterClause filter = ( FilterClause ) object ; String property = filter . getProperty ( ) ; String filterAttr [ ] = property . split ( "\\." ) ; for ( String s : filterAttr ) { queryAttributes . add ( s ) ; } } } if ( ! queryAttributes . containsAll ( partitionKeyFields ) ) { throw new QueryHandlerException ( "Incomplete partition key fields in query" ) ; } } | cheking whether all the fields of partition key are present in the jpa query |
36,051 | private static void populateEmbeddedIdFields ( Set < Attribute > embeddedAttributes , MetamodelImpl metaModel , Set < String > embeddedIdFields ) { for ( Attribute attribute : embeddedAttributes ) { if ( ! ReflectUtils . isTransientOrStatic ( ( Field ) attribute . getJavaMember ( ) ) ) { if ( metaModel . isEmbeddable ( attribute . getJavaType ( ) ) ) { EmbeddableType embeddable = metaModel . embeddable ( attribute . getJavaType ( ) ) ; populateEmbeddedIdFieldsUtil ( embeddable . getAttributes ( ) , metaModel , embeddedIdFields ) ; } } } } | recursively populate all the fields present in partition key |
36,052 | public static String getJPAColumnName ( String field , EntityMetadata entityMetadata , MetamodelImpl metaModel ) { if ( field . indexOf ( '.' ) > 0 ) { return ( ( AbstractAttribute ) metaModel . entity ( entityMetadata . getEntityClazz ( ) ) . getAttribute ( field . substring ( field . indexOf ( '.' ) + 1 , field . indexOf ( ')' ) > 0 ? field . indexOf ( ')' ) : field . length ( ) ) ) ) . getJPAColumnName ( ) ; } else { return ( ( AbstractAttribute ) entityMetadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ; } } | Gets the JPA column name . |
36,053 | public static void addToRow ( PartialRow row , String jpaColumnName , Object value , Type type ) { if ( value == null ) { row . setNull ( jpaColumnName ) ; } else { switch ( type ) { case BINARY : row . addBinary ( jpaColumnName , ( byte [ ] ) value ) ; break ; case BOOL : row . addBoolean ( jpaColumnName , ( Boolean ) value ) ; break ; case DOUBLE : row . addDouble ( jpaColumnName , ( Double ) value ) ; break ; case FLOAT : row . addFloat ( jpaColumnName , ( Float ) value ) ; break ; case INT16 : row . addShort ( jpaColumnName , ( Short ) value ) ; break ; case INT32 : row . addInt ( jpaColumnName , ( Integer ) value ) ; break ; case INT64 : row . addLong ( jpaColumnName , ( Long ) value ) ; break ; case INT8 : row . addByte ( jpaColumnName , ( Byte ) value ) ; break ; case STRING : row . addString ( jpaColumnName , ( String ) value ) ; break ; case UNIXTIME_MICROS : default : logger . error ( type + " type is not supported by Kudu" ) ; throw new KunderaException ( type + " type is not supported by Kudu" ) ; } } } | Adds the to row . |
36,054 | public static KuduPredicate getPredicate ( ColumnSchema column , KuduPredicate . ComparisonOp operator , Type type , Object key ) { switch ( type ) { case BINARY : return KuduPredicate . newComparisonPredicate ( column , operator , ( byte [ ] ) key ) ; case BOOL : return KuduPredicate . newComparisonPredicate ( column , operator , ( Boolean ) key ) ; case DOUBLE : return KuduPredicate . newComparisonPredicate ( column , operator , ( Double ) key ) ; case FLOAT : return KuduPredicate . newComparisonPredicate ( column , operator , ( Float ) key ) ; case INT16 : return KuduPredicate . newComparisonPredicate ( column , operator , ( Short ) key ) ; case INT32 : return KuduPredicate . newComparisonPredicate ( column , operator , ( Integer ) key ) ; case INT64 : return KuduPredicate . newComparisonPredicate ( column , operator , ( Long ) key ) ; case INT8 : return KuduPredicate . newComparisonPredicate ( column , operator , ( Byte ) key ) ; case STRING : return KuduPredicate . newComparisonPredicate ( column , operator , ( String ) key ) ; case UNIXTIME_MICROS : default : logger . error ( type + " type is not supported by Kudu" ) ; throw new KunderaException ( type + " type is not supported by Kudu" ) ; } } | Gets the predicate . |
36,055 | public static KuduPredicate getEqualComparisonPredicate ( ColumnSchema column , Type type , Object key ) { return getPredicate ( column , KuduPredicate . ComparisonOp . EQUAL , type , key ) ; } | Gets the equal comparison predicate . |
36,056 | public static boolean hasColumn ( Schema schema , String columnName ) { try { schema . getColumn ( columnName ) ; return true ; } catch ( IllegalArgumentException e ) { return false ; } } | Checks for column . |
36,057 | private void onSuperClass ( Class < ? > clazz , List < Field > keys ) { Class < ? > superClass = clazz . getSuperclass ( ) ; if ( superClass != null && ( superClass . isAnnotationPresent ( MappedSuperclass . class ) || superClass . isAnnotationPresent ( Entity . class ) ) ) { while ( superClass != null && ( superClass . isAnnotationPresent ( MappedSuperclass . class ) || superClass . isAnnotationPresent ( Entity . class ) ) ) { for ( Field field : superClass . getDeclaredFields ( ) ) { onIdField ( field , superClass ) ; if ( field . isAnnotationPresent ( Id . class ) ) { keys . add ( field ) ; if ( field . isAnnotationPresent ( GeneratedValue . class ) ) { validateGeneratedValueAnnotation ( superClass , field ) ; } } else if ( field . isAnnotationPresent ( EmbeddedId . class ) ) { keys . add ( field ) ; } } if ( keys . size ( ) > 0 ) { onEntityKey ( keys , superClass ) ; break ; } superClass = superClass . getSuperclass ( ) ; } } onEntityKey ( keys , clazz ) ; } | Checks whether the defined class is a validone with an id field present either in class itself or its superclass |
36,058 | private void validateGeneratedValueAnnotation ( final Class < ? > clazz , Field field ) { Table table = clazz . getAnnotation ( Table . class ) ; if ( table != null ) { String schemaName = table . schema ( ) ; if ( schemaName != null && schemaName . indexOf ( '@' ) > 0 ) { schemaName = schemaName . substring ( 0 , schemaName . indexOf ( '@' ) ) ; GeneratedValue generatedValue = field . getAnnotation ( GeneratedValue . class ) ; if ( generatedValue != null && generatedValue . generator ( ) != null && ! generatedValue . generator ( ) . isEmpty ( ) ) { if ( ! ( field . isAnnotationPresent ( TableGenerator . class ) || field . isAnnotationPresent ( SequenceGenerator . class ) || clazz . isAnnotationPresent ( TableGenerator . class ) || clazz . isAnnotationPresent ( SequenceGenerator . class ) ) ) { throw new IllegalArgumentException ( "Unknown Id.generator: " + generatedValue . generator ( ) ) ; } else { checkForGenerator ( clazz , field , generatedValue , schemaName ) ; } } } } } | validate generated value annotation if given . |
36,059 | private void checkForGenerator ( final Class < ? > clazz , Field field , GeneratedValue generatedValue , String schemaName ) { TableGenerator tableGenerator = field . getAnnotation ( TableGenerator . class ) ; SequenceGenerator sequenceGenerator = field . getAnnotation ( SequenceGenerator . class ) ; if ( tableGenerator == null || ! tableGenerator . name ( ) . equals ( generatedValue . generator ( ) ) ) { tableGenerator = clazz . getAnnotation ( TableGenerator . class ) ; } if ( sequenceGenerator == null || ! sequenceGenerator . name ( ) . equals ( generatedValue . generator ( ) ) ) { sequenceGenerator = clazz . getAnnotation ( SequenceGenerator . class ) ; } if ( ( tableGenerator == null && sequenceGenerator == null ) || ( tableGenerator != null && ! tableGenerator . name ( ) . equals ( generatedValue . generator ( ) ) ) || ( sequenceGenerator != null && ! sequenceGenerator . name ( ) . equals ( generatedValue . generator ( ) ) ) ) { throw new RuleValidationException ( "Unknown Id.generator: " + generatedValue . generator ( ) ) ; } else if ( ( tableGenerator != null && ! tableGenerator . schema ( ) . isEmpty ( ) && ! tableGenerator . schema ( ) . equals ( schemaName ) ) || ( sequenceGenerator != null && ! sequenceGenerator . schema ( ) . isEmpty ( ) && ! sequenceGenerator . schema ( ) . equals ( schemaName ) ) ) { throw new RuleValidationException ( "Generator " + generatedValue . generator ( ) + " in entity : " + clazz . getName ( ) + " has different schema name ,it should be same as entity have" ) ; } } | Validate for generator . |
36,060 | private void setTTLPerRequest ( Object value ) { if ( value instanceof String ) { if ( Boolean . valueOf ( ( String ) value ) . booleanValue ( ) ) { this . cassandraClientBase . setTtlPerSession ( false ) ; } this . cassandraClientBase . setTtlPerRequest ( Boolean . valueOf ( ( String ) value ) ) ; } else if ( value instanceof Boolean ) { if ( ( ( Boolean ) value ) . booleanValue ( ) ) { this . cassandraClientBase . setTtlPerSession ( false ) ; } this . cassandraClientBase . setTtlPerRequest ( ( Boolean ) value ) ; } } | set ttl per request . |
36,061 | private void setConsistencylevel ( Object value ) { if ( value instanceof String ) { this . cassandraClientBase . setConsistencyLevel ( ConsistencyLevel . valueOf ( ( String ) value ) ) ; } else if ( value instanceof ConsistencyLevel ) { this . cassandraClientBase . setConsistencyLevel ( ( ConsistencyLevel ) value ) ; } } | set consistency level . |
36,062 | private Object populateEntityFromSlice ( EntityMetadata m , List < String > relationNames , boolean isWrapReq , Object e , Map < ByteBuffer , List < ColumnOrSuperColumn > > columnOrSuperColumnsFromRow ) throws CharacterCodingException { ThriftDataResultHelper dataGenerator = new ThriftDataResultHelper ( ) ; for ( ByteBuffer key : columnOrSuperColumnsFromRow . keySet ( ) ) { Object id = PropertyAccessorHelper . getObject ( m . getIdAttribute ( ) . getJavaType ( ) , key . array ( ) ) ; ThriftRow tr = new ThriftRow ( ) ; tr . setColumnFamilyName ( m . getTableName ( ) ) ; tr . setId ( id ) ; tr = dataGenerator . translateToThriftRow ( columnOrSuperColumnsFromRow , m . isCounterColumnType ( ) , m . getType ( ) , tr ) ; e = populateEntity ( tr , m , e , relationNames , isWrapReq ) ; } return e ; } | Populate entity from slice . |
36,063 | public static String getValidType ( String type ) { return ( validationClassMapper . get ( type ) == null ) ? "binary" : validationClassMapper . get ( type ) ; } | Gets the valid type . |
36,064 | public static String getValidIdType ( String type ) { if ( validationClassMapperforId . get ( type ) == null ) { throw new KunderaException ( "ID of type: " + type + " is not supported for Kundera Oracle NOSQL." ) ; } return validationClassMapperforId . get ( type ) ; } | Gets the valid Id type . |
36,065 | public static WhereClause getWhereClause ( JPQLExpression jpqlExpression ) { WhereClause whereClause = null ; if ( hasWhereClause ( jpqlExpression ) ) { if ( isSelectStatement ( jpqlExpression ) ) { whereClause = ( WhereClause ) ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . getWhereClause ( ) ; } else if ( isUpdateStatement ( jpqlExpression ) ) { whereClause = ( WhereClause ) ( ( UpdateStatement ) jpqlExpression . getQueryStatement ( ) ) . getWhereClause ( ) ; } if ( isDeleteStatement ( jpqlExpression ) ) { whereClause = ( WhereClause ) ( ( DeleteStatement ) jpqlExpression . getQueryStatement ( ) ) . getWhereClause ( ) ; } } return whereClause ; } | Gets the where clause . |
36,066 | public static OrderByClause getOrderByClause ( JPQLExpression jpqlExpression ) { OrderByClause orderByClause = null ; if ( hasOrderBy ( jpqlExpression ) ) { orderByClause = ( OrderByClause ) ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . getOrderByClause ( ) ; } return orderByClause ; } | Gets the order by clause . |
36,067 | public static boolean hasWhereClause ( JPQLExpression jpqlExpression ) { if ( isSelectStatement ( jpqlExpression ) ) { return ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . hasWhereClause ( ) ; } else if ( isUpdateStatement ( jpqlExpression ) ) { return ( ( UpdateStatement ) jpqlExpression . getQueryStatement ( ) ) . hasWhereClause ( ) ; } if ( isDeleteStatement ( jpqlExpression ) ) { return ( ( DeleteStatement ) jpqlExpression . getQueryStatement ( ) ) . hasWhereClause ( ) ; } return false ; } | Checks for where clause . |
36,068 | public static boolean hasGroupBy ( JPQLExpression jpqlExpression ) { if ( isSelectStatement ( jpqlExpression ) ) { return ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . hasGroupByClause ( ) ; } return false ; } | Checks for group by . |
36,069 | public static boolean hasHaving ( JPQLExpression jpqlExpression ) { if ( isSelectStatement ( jpqlExpression ) ) { return ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . hasHavingClause ( ) ; } return false ; } | Checks for having . |
36,070 | public static boolean hasOrderBy ( JPQLExpression jpqlExpression ) { if ( isSelectStatement ( jpqlExpression ) ) { return ( ( SelectStatement ) jpqlExpression . getQueryStatement ( ) ) . hasOrderByClause ( ) ; } return false ; } | Checks for order by . |
36,071 | private static void addToOutputColumns ( Expression selectExpression , EntityMetadata m , List < Map < String , Object > > columnsToOutput , KunderaMetadata kunderaMetadata ) { Map < String , Object > map = setFieldClazzAndColumnFamily ( selectExpression , m , kunderaMetadata ) ; columnsToOutput . add ( map ) ; } | Adds the to output columns . |
36,072 | public static List < Map < String , Object > > readSelectClause ( Expression selectExpression , EntityMetadata m , Boolean useLuceneOrES , KunderaMetadata kunderaMetadata ) { List < Map < String , Object > > columnsToOutput = new ArrayList < Map < String , Object > > ( ) ; if ( StateFieldPathExpression . class . isAssignableFrom ( selectExpression . getClass ( ) ) ) { Expression sfpExp = selectExpression ; addToOutputColumns ( selectExpression , m , columnsToOutput , kunderaMetadata ) ; } else if ( CollectionExpression . class . isAssignableFrom ( selectExpression . getClass ( ) ) ) { CollectionExpression collExp = ( CollectionExpression ) selectExpression ; ListIterator < Expression > itr = collExp . children ( ) . iterator ( ) ; while ( itr . hasNext ( ) ) { Expression exp = itr . next ( ) ; if ( StateFieldPathExpression . class . isAssignableFrom ( exp . getClass ( ) ) ) { addToOutputColumns ( exp , m , columnsToOutput , kunderaMetadata ) ; } } } return columnsToOutput ; } | Read select clause . |
36,073 | public static Map < String , Object > onRegExpression ( Expression expression , EntityMetadata m , KunderaMetadata kunderaMetadata , KunderaQuery kunderaQuery ) { RegexpExpression regExp = ( RegexpExpression ) expression ; Expression sfpExp = regExp . getStringExpression ( ) ; Map < String , Object > map = KunderaQueryUtils . setFieldClazzAndColumnFamily ( sfpExp , m , kunderaMetadata ) ; kunderaQuery . addFilterClause ( ( String ) map . get ( Constants . COL_NAME ) , regExp . getActualRegexpIdentifier ( ) . toUpperCase ( ) , regExp . getPatternValue ( ) . toActualText ( ) , ( String ) map . get ( Constants . FIELD_NAME ) , ( Boolean ) map . get ( Constants . IGNORE_CASE ) ) ; return map ; } | On reg expression . |
36,074 | public static void onLogicalExpression ( Expression expression , EntityMetadata m , KunderaMetadata kunderaMetadata , KunderaQuery kunderaQuery ) { if ( expression instanceof OrExpression ) { kunderaQuery . addFilterClause ( "(" ) ; } traverse ( ( ( LogicalExpression ) expression ) . getLeftExpression ( ) , m , kunderaMetadata , kunderaQuery , false ) ; if ( expression instanceof OrExpression ) { kunderaQuery . addFilterClause ( ")" ) ; } kunderaQuery . addFilterClause ( ( ( LogicalExpression ) expression ) . getIdentifier ( ) ) ; if ( expression instanceof OrExpression ) { kunderaQuery . addFilterClause ( "(" ) ; } traverse ( ( ( LogicalExpression ) expression ) . getRightExpression ( ) , m , kunderaMetadata , kunderaQuery , false ) ; if ( expression instanceof OrExpression ) { kunderaQuery . addFilterClause ( ")" ) ; } } | On logical expression . |
36,075 | public static Map < String , Object > onInExpression ( Expression expression , EntityMetadata m , KunderaMetadata kunderaMetadata , KunderaQuery kunderaQuery ) { InExpression inExp = ( InExpression ) expression ; Expression sfpExp = inExp . getExpression ( ) ; Map < String , Object > map = KunderaQueryUtils . setFieldClazzAndColumnFamily ( sfpExp , m , kunderaMetadata ) ; kunderaQuery . addFilterClause ( ( String ) map . get ( Constants . COL_NAME ) , inExp . getIdentifier ( ) , inExp . getInItems ( ) , ( String ) map . get ( Constants . FIELD_NAME ) , ( Boolean ) map . get ( Constants . IGNORE_CASE ) ) ; return map ; } | On in expression . |
36,076 | public static Map < String , Object > onComparisonExpression ( Expression expression , EntityMetadata m , KunderaMetadata kunderaMetadata , KunderaQuery kunderaQuery ) { ComparisonExpression compExp = ( ComparisonExpression ) expression ; String condition = compExp . getIdentifier ( ) ; Expression sfpExp = compExp . getLeftExpression ( ) ; Map < String , Object > map = KunderaQueryUtils . setFieldClazzAndColumnFamily ( sfpExp , m , kunderaMetadata ) ; Object value = KunderaQueryUtils . getValue ( compExp . getRightExpression ( ) , ( Class ) map . get ( Constants . FIELD_CLAZZ ) , kunderaQuery ) ; kunderaQuery . addFilterClause ( ( String ) map . get ( Constants . COL_NAME ) , condition , value , ( String ) map . get ( Constants . FIELD_NAME ) , ( Boolean ) map . get ( Constants . IGNORE_CASE ) ) ; return map ; } | On comparison expression . |
36,077 | public static Map < String , Object > onNullComparisonExpression ( Expression expression , EntityMetadata m , KunderaMetadata kunderaMetadata , KunderaQuery kunderaQuery ) { NullComparisonExpression compExp = ( NullComparisonExpression ) expression ; String condition = compExp . getIdentifier ( ) ; Expression sfpExp = compExp . getExpression ( ) ; Map < String , Object > map = KunderaQueryUtils . setFieldClazzAndColumnFamily ( sfpExp , m , kunderaMetadata ) ; kunderaQuery . addFilterClause ( ( String ) map . get ( Constants . COL_NAME ) , condition , null , ( String ) map . get ( Constants . FIELD_NAME ) , ( Boolean ) map . get ( Constants . IGNORE_CASE ) ) ; return map ; } | On null - comparison expression . |
36,078 | public static List < OrderByItem > getOrderByItems ( JPQLExpression jpqlExpression ) { List < OrderByItem > orderList = new LinkedList < > ( ) ; if ( hasOrderBy ( jpqlExpression ) ) { Expression orderByItems = getOrderByClause ( jpqlExpression ) . getOrderByItems ( ) ; if ( orderByItems instanceof CollectionExpression ) { ListIterator < Expression > iterator = orderByItems . children ( ) . iterator ( ) ; while ( iterator . hasNext ( ) ) { OrderByItem orderByItem = ( OrderByItem ) iterator . next ( ) ; orderList . add ( orderByItem ) ; } } else { orderList . add ( ( OrderByItem ) orderByItems ) ; } } return orderList ; } | Gets the order by items . |
36,079 | public static StringBuilder appendColumns ( StringBuilder builder , List < String > columns , String selectQuery , CQLTranslator translator ) { if ( columns != null ) { for ( String column : columns ) { translator . appendColumnName ( builder , column ) ; builder . append ( "," ) ; } } if ( builder . lastIndexOf ( "," ) != - 1 ) { builder . deleteCharAt ( builder . length ( ) - 1 ) ; selectQuery = StringUtils . replace ( selectQuery , CQLTranslator . COLUMNS , builder . toString ( ) ) ; } builder = new StringBuilder ( selectQuery ) ; return builder ; } | Append columns . |
36,080 | public List handleFindByRange ( EntityMetadata m , Client client , List result , Map < Boolean , List < IndexClause > > ixClause , boolean isRowKeyQuery , List < String > columns , int maxResults ) { List < IndexExpression > expressions = ixClause . get ( isRowKeyQuery ) . get ( 0 ) . getExpressions ( ) ; if ( expressions == null ) { return null ; } Map < String , byte [ ] > rowKeys = getRowKeyValue ( expressions , ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getJPAColumnName ( ) ) ; byte [ ] minValue = rowKeys . get ( MIN_ ) ; byte [ ] maxVal = rowKeys . get ( MAX_ ) ; try { result = ( ( CassandraClientBase ) client ) . findByRange ( minValue , maxVal , m , m . getRelationNames ( ) != null && ! m . getRelationNames ( ) . isEmpty ( ) , m . getRelationNames ( ) , columns , expressions , maxResults ) ; } catch ( Exception e ) { log . error ( "Error while executing find by range, Caused by: " , e ) ; throw new QueryHandlerException ( e ) ; } return result ; } | Handle find by range . |
36,081 | public List < EnhanceEntity > readFromIndexTable ( EntityMetadata m , Client client , Map < Boolean , List < IndexClause > > indexClauseMap ) { List < SearchResult > searchResults = new ArrayList < SearchResult > ( ) ; List < Object > primaryKeys = new ArrayList < Object > ( ) ; String columnFamilyName = m . getTableName ( ) + Constants . INDEX_TABLE_SUFFIX ; searchResults = ( ( CassandraClientBase ) client ) . searchInInvertedIndex ( columnFamilyName , m , indexClauseMap ) ; Map < String , String > embeddedColumns = new HashMap < String , String > ( ) ; for ( SearchResult searchResult : searchResults ) { if ( searchResult . getEmbeddedColumnValues ( ) != null ) { for ( String embeddedColVal : searchResult . getEmbeddedColumnValues ( ) ) { if ( embeddedColVal != null ) { StringBuilder strBuilder = new StringBuilder ( embeddedColVal ) ; strBuilder . append ( "|" ) ; strBuilder . append ( searchResult . getPrimaryKey ( ) . toString ( ) ) ; embeddedColumns . put ( strBuilder . toString ( ) , searchResult . getPrimaryKey ( ) . toString ( ) ) ; } } } } List < EnhanceEntity > enhanceEntityList = new ArrayList < EnhanceEntity > ( ) ; if ( embeddedColumns != null && ! embeddedColumns . isEmpty ( ) ) { enhanceEntityList = client . find ( m . getEntityClazz ( ) , embeddedColumns ) ; } else { for ( SearchResult searchResult : searchResults ) { primaryKeys . add ( searchResult . getPrimaryKey ( ) ) ; } enhanceEntityList = ( List < EnhanceEntity > ) ( ( CassandraClientBase ) client ) . find ( m . getEntityClazz ( ) , m . getRelationNames ( ) , true , m , primaryKeys . toArray ( new String [ ] { } ) ) ; } return enhanceEntityList ; } | Read from index table . |
36,082 | Map < String , byte [ ] > getRowKeyValue ( List < IndexExpression > expressions , String primaryKeyName ) { Map < String , byte [ ] > rowKeys = new HashMap < String , byte [ ] > ( ) ; List < IndexExpression > rowExpressions = new ArrayList < IndexExpression > ( ) ; if ( expressions != null ) { for ( IndexExpression e : expressions ) { if ( primaryKeyName . equals ( new String ( e . getColumn_name ( ) ) ) ) { IndexOperator operator = e . op ; if ( operator . equals ( IndexOperator . LTE ) || operator . equals ( IndexOperator . LT ) ) { rowKeys . put ( MAX_ , e . getValue ( ) ) ; rowExpressions . add ( e ) ; } else if ( operator . equals ( IndexOperator . GTE ) || operator . equals ( IndexOperator . GT ) ) { rowKeys . put ( MIN_ , e . getValue ( ) ) ; rowExpressions . add ( e ) ; } else if ( operator . equals ( IndexOperator . EQ ) ) { rowKeys . put ( MAX_ , e . getValue ( ) ) ; rowKeys . put ( MIN_ , e . getValue ( ) ) ; rowExpressions . add ( e ) ; } } } expressions . removeAll ( rowExpressions ) ; } return rowKeys ; } | Returns list of row keys . First element will be min value and second will be major value . |
36,083 | public void addIdAttribute ( SingularAttribute < ? super X , ? > idAttribute , boolean isIdClass , Set < SingularAttribute < ? super X , ? > > idClassAttributes ) { this . idAttribute = idAttribute ; this . isIdClass = isIdClass ; this . idClassAttributes = idClassAttributes ; if ( MetadataUtils . onCheckValidationConstraints ( ( Field ) idAttribute . getJavaMember ( ) ) ) { this . hasValidationConstraints = true ; } } | Adds the id attribute . |
36,084 | public < E > List < E > findByRange ( Class < E > entityClass , EntityMetadata metadata , byte [ ] startRow , byte [ ] endRow , String [ ] columns , Filter f , Queue filterClausequeue ) { EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , entityClass ) ; String tableName = entityMetadata . getSchema ( ) ; List results = new ArrayList ( ) ; FilterList filter = new FilterList ( ) ; if ( f != null ) { filter . addFilter ( f ) ; } if ( isFindKeyOnly ( metadata , columns ) ) { columns = null ; filter . addFilter ( new KeyOnlyFilter ( ) ) ; } try { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( entityClass ) ; List < AbstractManagedType > subManagedType = ( ( AbstractManagedType ) entityType ) . getSubManagedType ( ) ; if ( ! subManagedType . isEmpty ( ) ) { for ( AbstractManagedType subEntity : subManagedType ) { EntityMetadata subEntityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , subEntity . getJavaType ( ) ) ; List found = handler . readDataByRange ( tableName , subEntityMetadata . getEntityClazz ( ) , subEntityMetadata , startRow , endRow , columns , filter ) ; results . addAll ( found ) ; } } else { results = handler . readDataByRange ( tableName , entityClass , metadata , startRow , endRow , columns , filter ) ; } if ( showQuery && filterClausequeue . size ( ) > 0 ) { KunderaCoreUtils . printQueryWithFilterClause ( filterClausequeue , entityMetadata . getTableName ( ) ) ; } } catch ( IOException ioex ) { log . error ( "Error during find by range, Caused by: ." , ioex ) ; throw new KunderaException ( ioex ) ; } return results ; } | Handles find by range query for given start and end row key range values . |
36,085 | private void addRecords ( HBaseDataWrapper columnWrapper , List < HBaseDataWrapper > embeddableData , List < HBaseDataWrapper > dataSet ) { dataSet . add ( columnWrapper ) ; if ( ! embeddableData . isEmpty ( ) ) { dataSet . addAll ( embeddableData ) ; } } | Add records to data wrapper . |
36,086 | private List fetchEntity ( Class entityClass , Object rowId , EntityMetadata entityMetadata , List < String > relationNames , String tableName , List results , FilterList filter , Queue filterClausequeue , String ... columns ) throws IOException { results = new ArrayList ( ) ; List < AbstractManagedType > subManagedType = getSubManagedType ( entityClass , entityMetadata ) ; if ( ! subManagedType . isEmpty ( ) ) { for ( AbstractManagedType subEntity : subManagedType ) { EntityMetadata subEntityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , subEntity . getJavaType ( ) ) ; List tempResults = handler . readData ( tableName , subEntityMetadata . getEntityClazz ( ) , subEntityMetadata , rowId , subEntityMetadata . getRelationNames ( ) , filter , columns ) ; if ( tempResults != null && ! tempResults . isEmpty ( ) ) { results . addAll ( tempResults ) ; } } } else { results = handler . readData ( tableName , entityMetadata . getEntityClazz ( ) , entityMetadata , rowId , relationNames , filter , columns ) ; } if ( rowId != null ) { KunderaCoreUtils . printQuery ( "Fetch data from " + entityMetadata . getTableName ( ) + " for PK " + rowId , showQuery ) ; } else if ( showQuery && filterClausequeue . size ( ) > 0 ) { KunderaCoreUtils . printQueryWithFilterClause ( filterClausequeue , entityMetadata . getTableName ( ) ) ; } return results ; } | Fetch entity . |
36,087 | private List < AbstractManagedType > getSubManagedType ( Class entityClass , EntityMetadata entityMetadata ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( entityClass ) ; List < AbstractManagedType > subManagedType = ( ( AbstractManagedType ) entityType ) . getSubManagedType ( ) ; return subManagedType ; } | Gets the sub managed type . |
36,088 | public ThriftRow translateToThriftRow ( Map < ByteBuffer , List < ColumnOrSuperColumn > > coscResultMap , boolean isCounterType , Type columnFamilyType , ThriftRow row ) { ColumnFamilyType columnType = ColumnFamilyType . COLUMN ; if ( isCounterType ) { if ( columnFamilyType . equals ( Type . SUPER_COLUMN_FAMILY ) ) { columnType = ColumnFamilyType . COUNTER_SUPER_COLUMN ; } else { columnType = ColumnFamilyType . COUNTER_COLUMN ; } } else if ( columnFamilyType . equals ( Type . SUPER_COLUMN_FAMILY ) ) { columnType = ColumnFamilyType . SUPER_COLUMN ; } transformThriftResultAndAddToList ( coscResultMap , columnType , row ) ; return row ; } | Translates into thrift row . |
36,089 | private void addInPredicateToBuilder ( KuduScannerBuilder scannerBuilder , ListIterator < Expression > inIter , Attribute attribute ) { List < Object > finalVals = new ArrayList < > ( ) ; Type type = KuduDBValidationClassMapper . getValidTypeForClass ( ( ( Field ) attribute . getJavaMember ( ) ) . getType ( ) ) ; ColumnSchema column = new ColumnSchema . ColumnSchemaBuilder ( ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) , type ) . build ( ) ; while ( inIter . hasNext ( ) ) { String val = inIter . next ( ) . toActualText ( ) ; finalVals . add ( KuduDBDataHandler . parse ( type , val ) ) ; } scannerBuilder . addPredicate ( KuduDBDataHandler . getInPredicate ( column , finalVals ) ) ; } | Adds the in predicate to builder . |
36,090 | private void addColumnRangePredicateToBuilder ( Field field , KuduScannerBuilder scannerBuilder , String columnName , String value , String identifier ) { Type type = KuduDBValidationClassMapper . getValidTypeForClass ( field . getType ( ) ) ; ColumnSchema column = new ColumnSchema . ColumnSchemaBuilder ( columnName , type ) . build ( ) ; KuduPredicate predicate ; Object valueObject = KuduDBDataHandler . parse ( type , value ) ; switch ( identifier ) { case ">=" : predicate = KuduDBDataHandler . getPredicate ( column , KuduPredicate . ComparisonOp . GREATER_EQUAL , type , valueObject ) ; break ; case ">" : predicate = KuduDBDataHandler . getPredicate ( column , KuduPredicate . ComparisonOp . GREATER , type , valueObject ) ; break ; case "<" : predicate = KuduDBDataHandler . getPredicate ( column , KuduPredicate . ComparisonOp . LESS , type , valueObject ) ; break ; case "<=" : predicate = KuduDBDataHandler . getPredicate ( column , KuduPredicate . ComparisonOp . LESS_EQUAL , type , valueObject ) ; break ; case "=" : predicate = KuduDBDataHandler . getPredicate ( column , KuduPredicate . ComparisonOp . EQUAL , type , valueObject ) ; break ; default : logger . error ( "Operation not supported" ) ; throw new KunderaException ( "Operation not supported" ) ; } scannerBuilder . addPredicate ( predicate ) ; } | Adds the column range predicate to builder . |
36,091 | private static Object setIntValue ( Field member , Object retVal ) { if ( member != null ) { if ( member . getType ( ) . isAssignableFrom ( byte . class ) ) { retVal = ( ( Integer ) retVal ) . byteValue ( ) ; } else if ( member . getType ( ) . isAssignableFrom ( short . class ) ) { retVal = ( ( Integer ) retVal ) . shortValue ( ) ; } } return retVal ; } | Sets the int value . |
36,092 | private static Object setTextValue ( Object entity , Field member , Object retVal ) { if ( member != null && member . getType ( ) . isEnum ( ) ) { EnumAccessor accessor = new EnumAccessor ( ) ; if ( member != null ) { retVal = accessor . fromString ( member . getType ( ) , ( String ) retVal ) ; } } else if ( member != null && ( member . getType ( ) . isAssignableFrom ( char . class ) || member . getType ( ) . isAssignableFrom ( Character . class ) ) ) { retVal = new CharAccessor ( ) . fromString ( member . getType ( ) , ( String ) retVal ) ; } return retVal ; } | Sets the text value . |
36,093 | private Object populateEmbeddedObject ( SuperColumn sc , EntityMetadata m ) throws Exception { Field embeddedCollectionField = null ; Object embeddedObject = null ; String scName = PropertyAccessorFactory . STRING . fromBytes ( String . class , sc . getName ( ) ) ; String scNamePrefix = null ; Map < String , Field > columnNameToFieldMap = new HashMap < String , Field > ( ) ; Map < String , Field > superColumnNameToFieldMap = new HashMap < String , Field > ( ) ; MetadataUtils . populateColumnAndSuperColumnMaps ( m , columnNameToFieldMap , superColumnNameToFieldMap , kunderaMetadata ) ; if ( scName . indexOf ( Constants . EMBEDDED_COLUMN_NAME_DELIMITER ) != - 1 ) { StringTokenizer st = new StringTokenizer ( scName , Constants . EMBEDDED_COLUMN_NAME_DELIMITER ) ; if ( st . hasMoreTokens ( ) ) { scNamePrefix = st . nextToken ( ) ; } embeddedCollectionField = superColumnNameToFieldMap . get ( scNamePrefix ) ; Class < ? > embeddedClass = PropertyAccessorHelper . getGenericClass ( embeddedCollectionField ) ; try { embeddedClass . getConstructor ( ) ; } catch ( NoSuchMethodException nsme ) { throw new PersistenceException ( embeddedClass . getName ( ) + " is @Embeddable and must have a default no-argument constructor." ) ; } embeddedObject = embeddedClass . newInstance ( ) ; for ( Column column : sc . getColumns ( ) ) { String name = PropertyAccessorFactory . STRING . fromBytes ( String . class , column . getName ( ) ) ; byte [ ] value = column . getValue ( ) ; if ( value == null ) { continue ; } Field columnField = columnNameToFieldMap . get ( name ) ; PropertyAccessorHelper . set ( embeddedObject , columnField , value ) ; } } else { Field superColumnField = superColumnNameToFieldMap . get ( scName ) ; Class superColumnClass = superColumnField . getType ( ) ; embeddedObject = superColumnClass . newInstance ( ) ; for ( Column column : sc . getColumns ( ) ) { String name = PropertyAccessorFactory . STRING . fromBytes ( String . class , column . getName ( ) ) ; byte [ ] value = column . getValue ( ) ; if ( value == null ) { continue ; } Field columnField = columnNameToFieldMap . get ( name ) ; PropertyAccessorHelper . set ( embeddedObject , columnField , value ) ; } } return embeddedObject ; } | Populate embedded object . |
36,094 | private ThriftRow getThriftRow ( Object id , String columnFamily , Map < String , ThriftRow > thriftRows ) { ThriftRow tr = thriftRows . get ( columnFamily ) ; if ( tr == null ) { tr = new ThriftRow ( ) ; tr . setColumnFamilyName ( columnFamily ) ; tr . setId ( id ) ; thriftRows . put ( columnFamily , tr ) ; } return tr ; } | Gets the thrift row . |
36,095 | public List < ThriftRow > toIndexThriftRow ( Object e , EntityMetadata m , String columnFamily ) { List < ThriftRow > indexThriftRows = new ArrayList < ThriftRow > ( ) ; byte [ ] rowKey = getThriftColumnValue ( e , m . getIdAttribute ( ) ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; Map < String , EmbeddableType > embeddables = metaModel . getEmbeddables ( m . getEntityClazz ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; for ( String embeddedFieldName : embeddables . keySet ( ) ) { EmbeddableType embeddedColumn = embeddables . get ( embeddedFieldName ) ; Field embeddedField = ( Field ) entityType . getAttribute ( embeddedFieldName ) . getJavaMember ( ) ; if ( ! MetadataUtils . isEmbeddedAtributeIndexable ( embeddedField ) ) { continue ; } Object embeddedObject = PropertyAccessorHelper . getObject ( e , ( Field ) entityType . getAttribute ( embeddedFieldName ) . getJavaMember ( ) ) ; if ( embeddedObject == null ) { continue ; } if ( embeddedObject instanceof Collection ) { ElementCollectionCacheManager ecCacheHandler = ElementCollectionCacheManager . getInstance ( ) ; for ( Object obj : ( Collection ) embeddedObject ) { for ( Object column : embeddedColumn . getAttributes ( ) ) { Attribute columnAttribute = ( Attribute ) column ; String columnName = columnAttribute . getName ( ) ; if ( ! MetadataUtils . isColumnInEmbeddableIndexable ( embeddedField , columnName ) ) { continue ; } String id = ( String ) CassandraDataTranslator . decompose ( ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getBindableJavaType ( ) , rowKey , false ) ; String superColumnName = ecCacheHandler . getElementCollectionObjectName ( id , obj ) ; ThriftRow tr = constructIndexTableThriftRow ( columnFamily , embeddedFieldName , obj , columnAttribute , rowKey , superColumnName ) ; if ( tr != null ) { indexThriftRows . add ( tr ) ; } } } } else { for ( Object column : embeddedColumn . getAttributes ( ) ) { Attribute columnAttribute = ( Attribute ) column ; String columnName = columnAttribute . getName ( ) ; Class < ? > columnClass = ( ( AbstractAttribute ) columnAttribute ) . getBindableJavaType ( ) ; if ( ! MetadataUtils . isColumnInEmbeddableIndexable ( embeddedField , columnName ) || columnClass . equals ( byte [ ] . class ) ) { continue ; } ThriftRow tr = constructIndexTableThriftRow ( columnFamily , embeddedFieldName , embeddedObject , ( Attribute ) column , rowKey , "" ) ; if ( tr != null ) { indexThriftRows . add ( tr ) ; } } } } return indexThriftRows ; } | To index thrift row . |
36,096 | public < E > List < Object > getForeignKeysFromJoinTable ( String inverseJoinColumnName , List < Column > columns , Class columnJavaType ) { List < Object > foreignKeys = new ArrayList < Object > ( ) ; if ( columns == null || columns . isEmpty ( ) ) { return foreignKeys ; } for ( Column c : columns ) { try { String thriftColumnName = PropertyAccessorFactory . STRING . fromBytes ( String . class , c . getName ( ) ) ; byte [ ] thriftColumnValue = c . getValue ( ) ; if ( null == thriftColumnValue ) { continue ; } if ( thriftColumnName != null && thriftColumnName . startsWith ( inverseJoinColumnName ) ) { Object val = PropertyAccessorHelper . getObject ( columnJavaType , thriftColumnValue ) ; foreignKeys . add ( val ) ; } } catch ( PropertyAccessException e ) { continue ; } } return foreignKeys ; } | Gets the foreign keys from join table . |
36,097 | private void setId ( EntityMetadata m , Object entity , Object columnValue , boolean isCql3Enabled ) { if ( isCql3Enabled && ! m . getType ( ) . equals ( Type . SUPER_COLUMN_FAMILY ) ) { setFieldValueViaCQL ( entity , columnValue , m . getIdAttribute ( ) ) ; } else { setFieldValue ( entity , columnValue , m . getIdAttribute ( ) ) ; } } | Sets the id . |
36,098 | private boolean isAggregate ( String thriftColumnName ) { if ( thriftColumnName . startsWith ( SYS_COUNT ) || thriftColumnName . startsWith ( SYS_MIN ) || thriftColumnName . startsWith ( SYS_MAX ) || thriftColumnName . startsWith ( SYS_AVG ) || thriftColumnName . startsWith ( SYS_SUM ) ) { return true ; } else if ( thriftColumnName . startsWith ( COUNT ) || thriftColumnName . startsWith ( MIN ) || thriftColumnName . startsWith ( MAX ) || thriftColumnName . startsWith ( AVG ) || thriftColumnName . startsWith ( SUM ) ) { return true ; } return false ; } | Checks if is aggregate . |
36,099 | private void composeAndAdd ( HashMap entity , CqlMetadata cqlMetadata , Object thriftColumnValue , String thriftColumnName ) { byte [ ] columnName = thriftColumnName . getBytes ( ) ; Map < ByteBuffer , String > schemaTypes = this . clientBase . getCqlMetadata ( ) . getValue_types ( ) ; AbstractType < ? > type = null ; try { type = TypeParser . parse ( schemaTypes . get ( ByteBuffer . wrap ( ( byte [ ] ) columnName ) ) ) ; } catch ( SyntaxException | ConfigurationException e ) { log . error ( e . getMessage ( ) ) ; throw new KunderaException ( "Error while parsing CQL Type " + e ) ; } entity . put ( thriftColumnName , type . compose ( ByteBuffer . wrap ( ( byte [ ] ) thriftColumnValue ) ) ) ; } | Compose and add . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.