idx int64 0 41.2k | question stringlengths 73 5.81k | target stringlengths 5 918 |
|---|---|---|
35,800 | private static void onPrintTweets ( final List < Tweets > tweets ) { for ( Iterator < Tweets > iterator = tweets . iterator ( ) ; iterator . hasNext ( ) ; ) { int counter = 1 ; while ( iterator . hasNext ( ) ) { logger . info ( "\n" ) ; logger . info ( "\t\t Tweet No:#" + counter ++ ) ; Tweets rec = ( Tweets ) iterator . next ( ) ; logger . info ( "\t\t tweet is ->" + rec . getBody ( ) ) ; logger . info ( "\t\t Tweeted at ->" + rec . getTweetDate ( ) ) ; if ( rec . getVideos ( ) != null ) { logger . info ( "\t\t Tweeted Contains Video ->" + rec . getVideos ( ) . size ( ) ) ; for ( Iterator < Video > iteratorVideo = rec . getVideos ( ) . iterator ( ) ; iteratorVideo . hasNext ( ) ; ) { Video video = ( Video ) iteratorVideo . next ( ) ; logger . info ( video ) ; } } } } } | On print tweets event . |
35,801 | public void addElementCollectionMetadata ( CollectionColumnInfo elementCollectionMetadata ) { if ( this . elementCollectionMetadatas == null ) { this . elementCollectionMetadatas = new ArrayList < CollectionColumnInfo > ( ) ; } if ( ! elementCollectionMetadatas . contains ( elementCollectionMetadata ) ) { elementCollectionMetadatas . add ( elementCollectionMetadata ) ; } } | Adds the element collection metadata . |
35,802 | public void addColumnInfo ( ColumnInfo columnInfo ) { if ( this . columnMetadatas == null ) { this . columnMetadatas = new ArrayList < ColumnInfo > ( ) ; } if ( ! columnMetadatas . contains ( columnInfo ) && ! this . getIdColumnName ( ) . equals ( columnInfo . getColumnName ( ) ) ) { columnMetadatas . add ( columnInfo ) ; } } | Adds the column info . |
35,803 | public void addEmbeddedColumnInfo ( EmbeddedColumnInfo embdColumnInfo ) { if ( this . embeddedColumnMetadatas == null ) { this . embeddedColumnMetadatas = new ArrayList < EmbeddedColumnInfo > ( ) ; } if ( ! embeddedColumnMetadatas . contains ( embdColumnInfo ) ) { embeddedColumnMetadatas . add ( embdColumnInfo ) ; } } | Adds the embedded column info . |
35,804 | public void addCollectionColumnMetadata ( CollectionColumnInfo collectionColumnMetadata ) { if ( this . collectionColumnMetadatas == null ) { this . collectionColumnMetadatas = new ArrayList < CollectionColumnInfo > ( ) ; } if ( ! collectionColumnMetadatas . contains ( collectionColumnMetadata ) ) { collectionColumnMetadatas . add ( collectionColumnMetadata ) ; } } | Adds the collection column metadata . |
35,805 | public IndexInfo getColumnToBeIndexed ( String columnName ) { IndexInfo idxInfo = new IndexInfo ( columnName ) ; if ( columnToBeIndexed . contains ( idxInfo ) ) { int index = columnToBeIndexed . indexOf ( idxInfo ) ; return getColumnsToBeIndexed ( ) . get ( index ) ; } return idxInfo ; } | Gets the column to be indexed . |
35,806 | public void addToIndexedColumnList ( IndexInfo indexInfo ) { ColumnInfo columnInfo = new ColumnInfo ( ) ; columnInfo . setColumnName ( indexInfo . getColumnName ( ) ) ; if ( getEmbeddedColumnMetadatas ( ) . isEmpty ( ) || ! getEmbeddedColumnMetadatas ( ) . get ( 0 ) . getColumns ( ) . contains ( columnInfo ) ) { if ( ! columnToBeIndexed . contains ( indexInfo ) ) { columnToBeIndexed . add ( indexInfo ) ; } } } | Adds the to indexed column list . |
35,807 | public final void close ( ) { if ( isOpen ( ) ) { closed = true ; if ( cacheProvider != null ) { cacheProvider . shutdown ( ) ; } for ( String pu : persistenceUnits ) { ( ( ClientLifeCycleManager ) clientFactories . get ( pu ) ) . destroy ( ) ; } this . persistenceUnits = null ; this . properties = null ; clientFactories . clear ( ) ; clientFactories = new ConcurrentHashMap < String , ClientFactory > ( ) ; } else { throw new IllegalStateException ( "Entity manager factory has been closed" ) ; } } | Close the factory releasing any resources that it holds . After a factory instance has been closed all methods invoked on it will throw the IllegalStateException except for isOpen which will return false . Once an EntityManagerFactory has been closed all its entity managers are considered to be in the closed state . |
35,808 | public final EntityManager createEntityManager ( Map map ) { if ( isOpen ( ) ) { return new EntityManagerImpl ( this , map , transactionType , PersistenceContextType . EXTENDED ) ; } throw new IllegalStateException ( "Entity manager factory has been closed." ) ; } | Create a new application - managed EntityManager with the specified Map of properties . This method returns a new EntityManager instance each time it is invoked . The isOpen method will return true on the returned instance . |
35,809 | public Metamodel getMetamodel ( ) { if ( isOpen ( ) ) { MetamodelImpl metamodel = null ; for ( String pu : persistenceUnits ) { metamodel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( pu ) ; if ( metamodel != null ) { return metamodel ; } } } throw new IllegalStateException ( "Entity manager factory has been closed." ) ; } | Return an instance of Metamodel interface for access to the metamodel of the persistence unit . |
35,810 | private void configureClientFactories ( ) { ClientMetadataBuilder builder = new ClientMetadataBuilder ( getProperties ( ) , kunderaMetadata , getPersistenceUnits ( ) ) ; builder . buildClientFactoryMetadata ( clientFactories , kunderaMetadata ) ; } | Initialize and load clientFactory for all persistenceUnit with external properties . |
35,811 | private CacheProvider initSecondLevelCache ( final PersistenceUnitMetadata puMetadata ) { String classResourceName = ( String ) getProperties ( ) . get ( PersistenceProperties . KUNDERA_CACHE_CONFIG_RESOURCE ) ; classResourceName = classResourceName != null ? classResourceName : puMetadata . getProperty ( PersistenceProperties . KUNDERA_CACHE_CONFIG_RESOURCE ) ; String cacheProviderClassName = ( String ) getProperties ( ) . get ( PersistenceProperties . KUNDERA_CACHE_PROVIDER_CLASS ) ; cacheProviderClassName = cacheProviderClassName != null ? cacheProviderClassName : puMetadata . getProperty ( PersistenceProperties . KUNDERA_CACHE_PROVIDER_CLASS ) ; CacheProvider cacheProvider = null ; if ( cacheProviderClassName != null ) { try { Class < CacheProvider > cacheProviderClass = ( Class < CacheProvider > ) Class . forName ( cacheProviderClassName ) ; cacheProvider = cacheProviderClass . newInstance ( ) ; cacheProvider . init ( classResourceName ) ; } catch ( ClassNotFoundException e ) { throw new CacheException ( "Could not find class " + cacheProviderClassName + ". Check whether you spelled it correctly in persistence.xml" , e ) ; } catch ( InstantiationException e ) { throw new CacheException ( "Could not instantiate " + cacheProviderClassName , e ) ; } catch ( IllegalAccessException e ) { throw new CacheException ( e ) ; } } if ( cacheProvider == null ) { cacheProvider = new NonOperationalCacheProvider ( ) ; } return cacheProvider ; } | Inits the second level cache . |
35,812 | public Block getBlockWithTransactions ( BigInteger blockNumber ) { return EtherObjectConverterUtil . convertEtherBlockToKunderaBlock ( client . getBlock ( blockNumber , true ) ) ; } | Gets the block with transactions . |
35,813 | private boolean ignoreScan ( String intf ) { for ( String ignored : ignoredPackages ) { if ( intf . startsWith ( ignored + "." ) ) { return true ; } } return false ; } | Ignore scan . |
35,814 | public Query getQueryImplementation ( String jpaQuery , PersistenceDelegator persistenceDelegator , Class mappedClass , boolean isNative , final KunderaMetadata kunderaMetadata ) { if ( jpaQuery == null ) { throw new QueryHandlerException ( "Query String should not be null " ) ; } if ( jpaQuery . trim ( ) . endsWith ( Constants . SEMI_COLON ) ) { throw new QueryHandlerException ( "unexpected char: ';' in query [ " + jpaQuery + " ]" ) ; } KunderaQuery kunderaQuery = null ; ApplicationMetadata appMetadata = kunderaMetadata . getApplicationMetadata ( ) ; String mappedQuery = appMetadata . getQuery ( jpaQuery ) ; isNative = mappedQuery != null ? appMetadata . isNative ( jpaQuery ) : isNative ; EntityMetadata m = null ; if ( ! isNative ) { kunderaQuery = new KunderaQuery ( mappedQuery != null ? mappedQuery : jpaQuery , kunderaMetadata ) ; KunderaQueryParser parser = new KunderaQueryParser ( kunderaQuery ) ; parser . parse ( ) ; kunderaQuery . postParsingInit ( ) ; m = kunderaQuery . getEntityMetadata ( ) ; } else { if ( appMetadata . isNative ( jpaQuery ) ) { mappedClass = appMetadata . getMappedClass ( jpaQuery ) ; } kunderaQuery = new KunderaQuery ( jpaQuery , kunderaMetadata ) ; kunderaQuery . isNativeQuery = true ; m = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , mappedClass ) ; Field entityClazzField = null ; try { entityClazzField = kunderaQuery . getClass ( ) . getDeclaredField ( "entityClass" ) ; if ( entityClazzField != null && ! entityClazzField . isAccessible ( ) ) { entityClazzField . setAccessible ( true ) ; } entityClazzField . set ( kunderaQuery , mappedClass ) ; } catch ( Exception e ) { log . error ( e . getMessage ( ) ) ; throw new QueryHandlerException ( e ) ; } } Query query = null ; try { query = getQuery ( jpaQuery , persistenceDelegator , m , kunderaQuery , kunderaMetadata ) ; } catch ( Exception e ) { log . error ( e . getMessage ( ) ) ; throw new QueryHandlerException ( e ) ; } return query ; } | Gets the query implementation . |
35,815 | private void addColumnFamilyToTable ( String tableName , String columnFamilyName ) throws IOException { HColumnDescriptor cfDesciptor = new HColumnDescriptor ( columnFamilyName ) ; try { if ( admin . tableExists ( tableName ) ) { if ( ! admin . isTableEnabled ( tableName ) ) { admin . enableTable ( tableName ) ; } HTableDescriptor descriptor = admin . getTableDescriptor ( tableName . getBytes ( ) ) ; boolean found = false ; for ( HColumnDescriptor hColumnDescriptor : descriptor . getColumnFamilies ( ) ) { if ( hColumnDescriptor . getNameAsString ( ) . equalsIgnoreCase ( columnFamilyName ) ) found = true ; } if ( ! found ) { if ( admin . isTableEnabled ( tableName ) ) { admin . disableTable ( tableName ) ; } admin . addColumn ( tableName , cfDesciptor ) ; admin . enableTable ( tableName ) ; } } else { log . warn ( "Table {} doesn't exist, so no question of adding column family {} to it!" , tableName , columnFamilyName ) ; } } catch ( IOException e ) { log . error ( "Error while adding column family {}, to table{} . " , columnFamilyName , tableName ) ; throw e ; } } | Adds the column family to table . |
35,816 | private void setHBaseDataIntoObject ( String columnName , byte [ ] columnValue , Map < String , Field > columnNameToFieldMap , Object columnFamilyObj , boolean isEmbeddeble ) throws PropertyAccessException { String qualifier = columnName . substring ( columnName . indexOf ( "#" ) + 1 , columnName . lastIndexOf ( "#" ) ) ; Field columnField = columnNameToFieldMap . get ( qualifier ) ; if ( columnField != null ) { if ( isEmbeddeble ) { PropertyAccessorHelper . set ( columnFamilyObj , columnField , columnValue ) ; } else { columnFamilyObj = HBaseUtils . fromBytes ( columnValue , columnFamilyObj . getClass ( ) ) ; } } } | Sets the h base data into object . |
35,817 | private void configureClientProperties ( PersistenceUnitMetadata puMetadata ) { SparkSchemaMetadata metadata = SparkPropertyReader . ssmd ; ClientProperties cp = metadata != null ? metadata . getClientProperties ( ) : null ; if ( cp != null ) { DataStore dataStore = metadata != null ? metadata . getDataStore ( puMetadata . getProperty ( "kundera.client" ) ) : null ; List < Server > servers = dataStore != null && dataStore . getConnection ( ) != null ? dataStore . getConnection ( ) . getServers ( ) : null ; if ( servers != null && ! servers . isEmpty ( ) ) { Server server = servers . get ( 0 ) ; sparkconf . set ( "hostname" , server . getHost ( ) ) ; sparkconf . set ( "portname" , server . getPort ( ) ) ; } Connection conn = dataStore . getConnection ( ) ; Properties props = conn . getProperties ( ) ; Enumeration e = props . propertyNames ( ) ; while ( e . hasMoreElements ( ) ) { String key = ( String ) e . nextElement ( ) ; sparkconf . set ( key , props . getProperty ( key ) ) ; } } } | Configure client properties . |
35,818 | public void setColumns ( List < Cell > columns ) { for ( Cell column : columns ) { putColumn ( CellUtil . cloneFamily ( column ) , CellUtil . cloneQualifier ( column ) , CellUtil . cloneValue ( column ) ) ; } } | Sets the columns . |
35,819 | private void putColumn ( byte [ ] family , byte [ ] qualifier , byte [ ] qualifierValue ) { this . columns . put ( Bytes . toString ( family ) + ":" + Bytes . toString ( qualifier ) , qualifierValue ) ; } | Put column . |
35,820 | public final Node buildNode ( Object entity , PersistenceDelegator pd , Object entityId , NodeState nodeState ) { String nodeId = ObjectGraphUtils . getNodeId ( entityId , entity . getClass ( ) ) ; Node node = this . graph . getNode ( nodeId ) ; if ( node != null ) { if ( this . generator . traversedNodes . contains ( node ) ) { return node ; } return null ; } node = new NodeBuilder ( ) . assignState ( nodeState ) . buildNode ( entity , pd , entityId , nodeId ) . node ; this . graph . addNode ( node . getNodeId ( ) , node ) ; return node ; } | On build node . |
35,821 | RelationBuilder getRelationBuilder ( Object target , Relation relation , Node source ) { RelationBuilder relationBuilder = new RelationBuilder ( target , relation , source ) ; relationBuilder . assignGraphGenerator ( this . generator ) ; return relationBuilder ; } | Returns relation builder instance . |
35,822 | public < E > List < E > findData ( EntityMetadata m , Object rowKey , byte [ ] startRow , byte [ ] endRow , List < Map < String , Object > > columnsToOutput , Filter filters ) { String tableName = HBaseUtils . getHTableName ( m . getSchema ( ) , m . getTableName ( ) ) ; FilterList filterList = getFilterList ( filters ) ; try { return handler . readData ( tableName , m , rowKey , startRow , endRow , columnsToOutput , filterList ) ; } catch ( IOException ioex ) { log . error ( "Error during find by range, Caused by: ." , ioex ) ; throw new KunderaException ( "Error during find by range, Caused by: ." , ioex ) ; } } | Find data . |
35,823 | private FilterList getFilterList ( Filter filters ) { FilterList filterList = null ; if ( filters != null ) { if ( FilterList . class . isAssignableFrom ( filters . getClass ( ) ) ) { filterList = ( FilterList ) filters ; } else { filterList = new FilterList ( ) ; filterList . addFilter ( filters ) ; } } return filterList ; } | Gets the filter list . |
35,824 | protected void addToRelationStack ( Map < Object , Object > relationStack , Object entity , EntityMetadata m ) { Object obj = entity ; if ( entity instanceof EnhanceEntity ) { obj = ( ( EnhanceEntity ) entity ) . getEntity ( ) ; } relationStack . put ( obj . getClass ( ) . getCanonicalName ( ) + "#" + PropertyAccessorHelper . getId ( obj , m ) , obj ) ; } | Adds the to relation stack . |
35,825 | private List < Object > populateEmbeddedIdUsingLucene ( EntityMetadata m , Client client , List < Object > result , Map < String , Object > searchFilter , MetamodelImpl metaModel ) { List < Object > compositeIds = new ArrayList < Object > ( ) ; for ( String compositeIdName : searchFilter . keySet ( ) ) { Object compositeId = null ; Map < String , String > uniquePKs = ( Map < String , String > ) searchFilter . get ( compositeIdName ) ; compositeId = KunderaCoreUtils . initialize ( m . getIdAttribute ( ) . getBindableJavaType ( ) , compositeId ) ; prepareCompositeIdObject ( m . getIdAttribute ( ) , compositeId , uniquePKs , metaModel ) ; compositeIds . add ( compositeId ) ; } return findUsingLucene ( m , client , compositeIds . toArray ( ) ) ; } | Populate using lucene for embeddeId . |
35,826 | private Object prepareCompositeIdObject ( final SingularAttribute attribute , Object compositeId , Map < String , String > uniquePKs , MetamodelImpl metaModel ) { Field [ ] fields = attribute . getBindableJavaType ( ) . getDeclaredFields ( ) ; EmbeddableType embeddable = metaModel . embeddable ( attribute . getBindableJavaType ( ) ) ; for ( Field field : attribute . getBindableJavaType ( ) . getDeclaredFields ( ) ) { if ( ! ReflectUtils . isTransientOrStatic ( field ) ) { if ( metaModel . isEmbeddable ( ( ( AbstractAttribute ) embeddable . getAttribute ( field . getName ( ) ) ) . getBindableJavaType ( ) ) ) { try { field . setAccessible ( true ) ; Object embeddedObject = prepareCompositeIdObject ( ( SingularAttribute ) embeddable . getAttribute ( field . getName ( ) ) , KunderaCoreUtils . initialize ( ( ( AbstractAttribute ) embeddable . getAttribute ( field . getName ( ) ) ) . getBindableJavaType ( ) , field . get ( compositeId ) ) , uniquePKs , metaModel ) ; PropertyAccessorHelper . set ( compositeId , field , embeddedObject ) ; } catch ( IllegalAccessException e ) { log . error ( e . getMessage ( ) ) ; } } else { PropertyAccessorHelper . set ( compositeId , field , PropertyAccessorHelper . fromSourceToTargetClass ( field . getType ( ) , String . class , uniquePKs . get ( field . getName ( ) ) ) ) ; } } } return compositeId ; } | Prepare composite id object . |
35,827 | private List < Object > findUsingLucene ( EntityMetadata m , Client client , Object [ ] primaryKeys ) { String idField = m . getIdAttribute ( ) . getName ( ) ; String equals = "=" ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; String columnName = ( ( AbstractAttribute ) entityType . getAttribute ( idField ) ) . getJPAColumnName ( ) ; List < Object > result = new ArrayList < Object > ( ) ; Queue queue = getKunderaQuery ( ) . getFilterClauseQueue ( ) ; KunderaQuery kunderaQuery = getKunderaQuery ( ) ; for ( Object primaryKey : primaryKeys ) { FilterClause filterClause = kunderaQuery . new FilterClause ( columnName , equals , primaryKey , idField ) ; kunderaQuery . setFilter ( kunderaQuery . getEntityAlias ( ) + "." + columnName + " = " + primaryKey ) ; queue . clear ( ) ; queue . add ( filterClause ) ; List < Object > object = findUsingLucene ( m , client ) ; if ( object != null && ! object . isEmpty ( ) ) result . add ( object . get ( 0 ) ) ; } return result ; } | find data using lucene . |
35,828 | protected List < Object > populateUsingLucene ( EntityMetadata m , Client client , List < Object > result , String [ ] columnsToSelect ) { Set < Object > uniquePKs = null ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; if ( client . getIndexManager ( ) . getIndexer ( ) . getClass ( ) . getName ( ) . equals ( IndexingConstants . LUCENE_INDEXER ) ) { String luceneQ = KunderaCoreUtils . getLuceneQueryFromJPAQuery ( kunderaQuery , kunderaMetadata ) ; Map < String , Object > searchFilter = client . getIndexManager ( ) . search ( m . getEntityClazz ( ) , luceneQ , Constants . INVALID , Constants . INVALID ) ; boolean isEmbeddedId = metaModel . isEmbeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; if ( isEmbeddedId ) { return populateEmbeddedIdUsingLucene ( m , client , result , searchFilter , metaModel ) ; } Object [ ] primaryKeys = searchFilter . values ( ) . toArray ( new Object [ ] { } ) ; uniquePKs = new HashSet < Object > ( Arrays . asList ( primaryKeys ) ) ; return findUsingLucene ( m , client , uniquePKs . toArray ( ) ) ; } else { return populateUsingElasticSearch ( client , m ) ; } } | Populate using lucene . |
35,829 | private List populateUsingElasticSearch ( Client client , EntityMetadata m ) { Map < String , Object > searchFilter = client . getIndexManager ( ) . search ( kunderaMetadata , kunderaQuery , persistenceDelegeator , m , this . firstResult , this . maxResult ) ; Object [ ] primaryKeys = ( ( Map < String , Object > ) searchFilter . get ( Constants . PRIMARY_KEYS ) ) . values ( ) . toArray ( new Object [ ] { } ) ; Map < String , Object > aggregations = ( Map < String , Object > ) searchFilter . get ( Constants . AGGREGATIONS ) ; Iterable < Expression > resultOrderIterable = ( Iterable < Expression > ) searchFilter . get ( Constants . SELECT_EXPRESSION_ORDER ) ; List < Object > results = new ArrayList < Object > ( ) ; if ( ! kunderaQuery . isAggregated ( ) ) { results . addAll ( findUsingLucene ( m , client , primaryKeys ) ) ; } else { if ( KunderaQueryUtils . hasGroupBy ( kunderaQuery . getJpqlExpression ( ) ) ) { populateGroupByResponse ( aggregations , resultOrderIterable , results , client , m ) ; } else { Iterator < Expression > resultOrder = resultOrderIterable . iterator ( ) ; while ( resultOrder . hasNext ( ) ) { Expression expression = ( Expression ) resultOrder . next ( ) ; if ( AggregateFunction . class . isAssignableFrom ( expression . getClass ( ) ) ) { if ( aggregations . get ( expression . toParsedText ( ) ) != null ) { results . add ( aggregations . get ( expression . toParsedText ( ) ) ) ; } } else { results . addAll ( findUsingLucene ( m , client , new Object [ ] { primaryKeys [ 0 ] } ) ) ; } } } } return results ; } | Populate using elastic search . |
35,830 | private void populateGroupByResponse ( Map < String , Object > aggregations , Iterable < Expression > resultOrderIterable , List < Object > results , Client client , EntityMetadata m ) { List temp ; Object entity = null ; for ( String entry : aggregations . keySet ( ) ) { entity = null ; Object obj = aggregations . get ( entry ) ; temp = new ArrayList < > ( ) ; Iterator < Expression > resultOrder = resultOrderIterable . iterator ( ) ; while ( resultOrder . hasNext ( ) ) { Expression expression = ( Expression ) resultOrder . next ( ) ; if ( AggregateFunction . class . isAssignableFrom ( expression . getClass ( ) ) ) { if ( ( ( Map ) obj ) . get ( expression . toParsedText ( ) ) != null ) { temp . add ( ( ( Map ) obj ) . get ( expression . toParsedText ( ) ) ) ; } } else { if ( entity == null ) { entity = findUsingLucene ( m , client , new Object [ ] { entry } ) . get ( 0 ) ; } temp . add ( getEntityFieldValue ( m , entity , expression . toParsedText ( ) ) ) ; } } results . add ( temp . size ( ) == 1 ? temp . get ( 0 ) : temp ) ; } } | Populate group by response . |
35,831 | private Object getEntityFieldValue ( EntityMetadata entityMetadata , Object entity , String field ) { Class clazz = entityMetadata . getEntityClazz ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( clazz ) ; if ( field . indexOf ( "." ) > 0 && entityMetadata . getEntityClazz ( ) . equals ( entity . getClass ( ) ) ) { String fieldName = field . substring ( field . indexOf ( "." ) + 1 , field . length ( ) ) ; Attribute attribute = entityType . getAttribute ( fieldName ) ; return PropertyAccessorHelper . getObject ( entity , ( Field ) attribute . getJavaMember ( ) ) ; } else { if ( entity instanceof ArrayList ) { Object element = ( ( ArrayList ) entity ) . get ( 0 ) ; ( ( ArrayList ) entity ) . remove ( 0 ) ; return element ; } else { return entity ; } } } | Gets the entity field value . |
35,832 | protected int onUpdateDeleteEvent ( ) { if ( kunderaQuery . isDeleteUpdate ( ) ) { List result = fetch ( ) ; onDeleteOrUpdate ( result ) ; return result != null ? result . size ( ) : 0 ; } return 0 ; } | On update delete event . |
35,833 | protected void onDeleteOrUpdate ( List results ) { if ( results != null ) { if ( ! kunderaQuery . isUpdateClause ( ) ) { for ( Object result : results ) { PersistenceCacheManager . addEntityToPersistenceCache ( result , persistenceDelegeator , PropertyAccessorHelper . getId ( result , this . getEntityMetadata ( ) ) ) ; persistenceDelegeator . remove ( result ) ; } } else { EntityMetadata entityMetadata = getEntityMetadata ( ) ; for ( Object result : results ) { PersistenceCacheManager . addEntityToPersistenceCache ( result , persistenceDelegeator , PropertyAccessorHelper . getId ( result , this . getEntityMetadata ( ) ) ) ; for ( UpdateClause c : kunderaQuery . getUpdateClauseQueue ( ) ) { String columnName = c . getProperty ( ) ; try { DefaultEntityType entityType = ( DefaultEntityType ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( entityMetadata . getPersistenceUnit ( ) ) . entity ( entityMetadata . getEntityClazz ( ) ) ; Attribute attribute = entityType . getAttribute ( columnName ) ; if ( c . getValue ( ) instanceof String ) { PropertyAccessorHelper . set ( result , ( Field ) attribute . getJavaMember ( ) , c . getValue ( ) . toString ( ) ) ; } else { PropertyAccessorHelper . set ( result , ( Field ) attribute . getJavaMember ( ) , c . getValue ( ) ) ; } persistenceDelegeator . merge ( result ) ; } catch ( IllegalArgumentException iax ) { log . error ( "Invalid column name: " + columnName + " for class : " + entityMetadata . getEntityClazz ( ) ) ; throw new QueryHandlerException ( "Error while executing query: " + iax ) ; } } } } } } | Performs delete or update based on query . |
35,834 | private Parameter getParameterByName ( String name ) { if ( getParameters ( ) != null ) { for ( Parameter p : parameters ) { if ( name . equals ( p . getName ( ) ) ) { return p ; } } } return null ; } | Returns specific parameter instance for given name . |
35,835 | private Parameter getParameterByOrdinal ( Integer position ) { for ( Parameter p : parameters ) { if ( position . equals ( p . getPosition ( ) ) ) { return p ; } } return null ; } | Returns parameter by ordinal . |
35,836 | private List < Object > onParameterValue ( String paramString ) { List < Object > value = kunderaQuery . getClauseValue ( paramString ) ; if ( value == null ) { throw new IllegalStateException ( "parameter has not been bound" + paramString ) ; } return value ; } | Returns parameter value . |
35,837 | protected void handlePostEvent ( ) { EntityMetadata metadata = getEntityMetadata ( ) ; if ( ! kunderaQuery . isDeleteUpdate ( ) ) { persistenceDelegeator . getEventDispatcher ( ) . fireEventListeners ( metadata , null , PostLoad . class ) ; } } | Handle post event callbacks . |
35,838 | protected List fetch ( ) { EntityMetadata metadata = getEntityMetadata ( ) ; Client client = persistenceDelegeator . getClient ( metadata ) ; List results = isRelational ( metadata ) ? recursivelyPopulateEntities ( metadata , client ) : populateEntities ( metadata , client ) ; return results ; } | Returns collection of fetched entities . |
35,839 | protected void onValidateSingleResult ( List results ) { if ( results == null || results . isEmpty ( ) ) { log . error ( "No result found for {} " , kunderaQuery . getJPAQuery ( ) ) ; throw new NoResultException ( "No result found!" ) ; } if ( results . size ( ) > 1 ) { log . error ( "Non unique results found for query {} " , kunderaQuery . getJPAQuery ( ) ) ; throw new NonUniqueResultException ( "Containing more than one result!" ) ; } } | On validate single result . |
35,840 | private void assignReferenceToProxy ( List results ) { if ( results != null ) { for ( Object obj : results ) { kunderaMetadata . getCoreMetadata ( ) . getLazyInitializerFactory ( ) . setProxyOwners ( getEntityMetadata ( ) , obj ) ; } } } | If returned collection of object holds a reference to . |
35,841 | public static Map < String , String > populatePersistenceUnitProperties ( PropertyReader reader ) { String dbType = reader . getProperty ( EthConstants . DATABASE_TYPE ) ; String host = reader . getProperty ( EthConstants . DATABASE_HOST ) ; String port = reader . getProperty ( EthConstants . DATABASE_PORT ) ; String dbName = reader . getProperty ( EthConstants . DATABASE_NAME ) ; propertyNullCheck ( dbType , host , port , dbName ) ; String username = reader . getProperty ( EthConstants . DATABASE_USERNAME ) ; String pswd = reader . getProperty ( EthConstants . DATABASE_PASSWORD ) ; Map < String , String > props = new HashMap < > ( ) ; props . put ( EthConstants . KUNDERA_CLIENT_LOOKUP_CLASS , getKunderaClientToLookupClass ( dbType ) ) ; props . put ( EthConstants . KUNDERA_NODES , host ) ; props . put ( EthConstants . KUNDERA_PORT , port ) ; props . put ( EthConstants . KUNDERA_KEYSPACE , dbName ) ; props . put ( EthConstants . KUNDERA_DIALECT , dbType ) ; if ( username != null && ! username . isEmpty ( ) && pswd != null ) { props . put ( EthConstants . KUNDERA_USERNAME , username ) ; props . put ( EthConstants . KUNDERA_PASSWORD , pswd ) ; } if ( dbType . equalsIgnoreCase ( CASSANDRA ) ) { props . put ( CQL_VERSION , _3_0_0 ) ; } boolean schemaAutoGen = Boolean . parseBoolean ( reader . getProperty ( EthConstants . SCHEMA_AUTO_GENERATE ) ) ; boolean schemaDropExisting = Boolean . parseBoolean ( reader . getProperty ( EthConstants . SCHEMA_DROP_EXISTING ) ) ; if ( schemaAutoGen ) { if ( schemaDropExisting ) { props . put ( EthConstants . KUNDERA_DDL_AUTO_PREPARE , "create" ) ; } else { props . put ( EthConstants . KUNDERA_DDL_AUTO_PREPARE , "update" ) ; } } LOGGER . info ( "Kundera properties : " + props ) ; return props ; } | Populate persistence unit properties . |
35,842 | private static void propertyNullCheck ( String dbType , String host , String port , String dbName ) { if ( dbType == null || dbType . isEmpty ( ) ) { LOGGER . error ( "Property '" + EthConstants . DATABASE_TYPE + "' can't be null or empty" ) ; throw new KunderaException ( "Property '" + EthConstants . DATABASE_TYPE + "' can't be null or empty" ) ; } if ( host == null || host . isEmpty ( ) ) { LOGGER . error ( "Property '" + EthConstants . DATABASE_HOST + "' can't be null or empty" ) ; throw new KunderaException ( "Property '" + EthConstants . DATABASE_HOST + "' can't be null or empty" ) ; } if ( port == null || port . isEmpty ( ) ) { LOGGER . error ( "Property '" + EthConstants . DATABASE_PORT + "' can't be null or empty" ) ; throw new KunderaException ( "Property '" + EthConstants . DATABASE_PORT + "' can't be null or empty" ) ; } if ( dbName == null || dbName . isEmpty ( ) ) { LOGGER . error ( "Property'" + EthConstants . DATABASE_NAME + "' can't be null or empty" ) ; throw new KunderaException ( "Property '" + EthConstants . DATABASE_NAME + "' can't be null or empty" ) ; } } | Property null check . |
35,843 | private static String getKunderaClientToLookupClass ( String client ) { Datasource datasource ; try { datasource = Datasource . valueOf ( client . toUpperCase ( ) ) ; } catch ( IllegalArgumentException ex ) { LOGGER . error ( client + " is not supported!" , ex ) ; throw new KunderaException ( client + " is not supported!" , ex ) ; } return clientNameToFactoryMap . get ( datasource ) ; } | Gets the kundera client to lookup class . |
35,844 | public static void set ( Object target , Field field , Object value ) { if ( target != null ) { if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } try { field . set ( target , value ) ; } catch ( IllegalArgumentException iarg ) { throw new PropertyAccessException ( iarg ) ; } catch ( IllegalAccessException iacc ) { throw new PropertyAccessException ( iacc ) ; } } } | Sets an object onto a field . |
35,845 | public static Object getObject ( Object from , Field field ) { if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } try { return field . get ( from ) ; } catch ( IllegalArgumentException iarg ) { throw new PropertyAccessException ( iarg ) ; } catch ( IllegalAccessException iacc ) { throw new PropertyAccessException ( iacc ) ; } } | Gets object from field . |
35,846 | public static Object getObjectCopy ( Object from , Field field ) { if ( ! field . isAccessible ( ) ) { field . setAccessible ( true ) ; } try { PropertyAccessor < ? > accessor = PropertyAccessorFactory . getPropertyAccessor ( field ) ; return accessor . getCopy ( field . get ( from ) ) ; } catch ( IllegalArgumentException iarg ) { throw new PropertyAccessException ( iarg ) ; } catch ( IllegalAccessException iacc ) { throw new PropertyAccessException ( iacc ) ; } } | Retutrns copy of object |
35,847 | public static byte [ ] get ( Object from , Field field ) { PropertyAccessor < ? > accessor = PropertyAccessorFactory . getPropertyAccessor ( field ) ; return accessor . toBytes ( getObject ( from , field ) ) ; } | Gets field value as byte - array . |
35,848 | @ SuppressWarnings ( "null" ) public static final Object getObject ( Object obj , String fieldName ) { Field embeddedField ; try { embeddedField = obj . getClass ( ) . getDeclaredField ( fieldName ) ; if ( embeddedField != null ) { if ( ! embeddedField . isAccessible ( ) ) { embeddedField . setAccessible ( true ) ; } Object embededObject = embeddedField . get ( obj ) ; if ( embededObject == null ) { Class embeddedObjectClass = embeddedField . getType ( ) ; if ( Collection . class . isAssignableFrom ( embeddedObjectClass ) ) { if ( embeddedObjectClass . equals ( List . class ) ) { return new ArrayList ( ) ; } else if ( embeddedObjectClass . equals ( Set . class ) ) { return new HashSet ( ) ; } } else { embededObject = embeddedField . getType ( ) . newInstance ( ) ; embeddedField . set ( obj , embededObject ) ; } } return embededObject ; } else { throw new PropertyAccessException ( "Embedded object not found: " + fieldName ) ; } } catch ( Exception e ) { throw new PropertyAccessException ( e ) ; } } | Gets the embedded object . |
35,849 | public static Field [ ] getDeclaredFields ( Field relationalField ) { Field [ ] fields ; if ( isCollection ( relationalField . getType ( ) ) ) { fields = PropertyAccessorHelper . getGenericClass ( relationalField ) . getDeclaredFields ( ) ; } else { fields = relationalField . getType ( ) . getDeclaredFields ( ) ; } return fields ; } | Gets the declared fields . |
35,850 | private static Class < ? > toClass ( Type o ) { if ( o instanceof GenericArrayType ) { Class clazz = Array . newInstance ( toClass ( ( ( GenericArrayType ) o ) . getGenericComponentType ( ) ) , 0 ) . getClass ( ) ; return clazz ; } return ( Class < ? > ) o ; } | Borrowed from java . lang . class |
35,851 | private static Class < ? > getTypedClass ( java . lang . reflect . Type type ) { if ( type instanceof Class ) { return ( ( Class ) type ) ; } else if ( type instanceof ParameterizedType ) { java . lang . reflect . Type rawParamterizedType = ( ( ParameterizedType ) type ) . getRawType ( ) ; return getTypedClass ( rawParamterizedType ) ; } else if ( type instanceof TypeVariable ) { java . lang . reflect . Type upperBound = ( ( TypeVariable ) type ) . getBounds ( ) [ 0 ] ; return getTypedClass ( upperBound ) ; } throw new IllegalArgumentException ( "Error while finding generic class for :" + type ) ; } | Gets the typed class . |
35,852 | public final void remove ( EntityMetadata metadata , Object entity , Object key ) { if ( indexer != null ) { if ( indexer . getClass ( ) . getName ( ) . equals ( IndexingConstants . LUCENE_INDEXER ) ) { ( ( com . impetus . kundera . index . lucene . Indexer ) indexer ) . unindex ( metadata , key , kunderaMetadata , null ) ; } else { indexer . unIndex ( metadata . getEntityClazz ( ) , entity , metadata , ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( metadata . getPersistenceUnit ( ) ) ) ; } } } | Removes an object from Index . |
35,853 | public final void write ( EntityMetadata metadata , Object entity ) { if ( indexer != null ) { MetamodelImpl metamodel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( metadata . getPersistenceUnit ( ) ) ; ( ( com . impetus . kundera . index . lucene . Indexer ) indexer ) . index ( metadata , metamodel , entity ) ; } } | Indexes an object . |
35,854 | private static boolean compareOrdered ( DualKey dualKey , LinkedList < DualKey > stack , Collection visited ) { Collection col1 = ( Collection ) dualKey . _key1 ; Collection col2 = ( Collection ) dualKey . _key2 ; if ( ProxyHelper . isProxyCollection ( col1 ) || ProxyHelper . isProxyCollection ( col2 ) ) { return false ; } if ( col1 . size ( ) != col2 . size ( ) ) { return false ; } Iterator i1 = col1 . iterator ( ) ; Iterator i2 = col2 . iterator ( ) ; while ( i1 . hasNext ( ) ) { DualKey dk = new DualKey ( i1 . next ( ) , i2 . next ( ) ) ; if ( ! visited . contains ( dk ) ) { stack . addFirst ( dk ) ; } } return true ; } | Compare two Collections that must be same length and in same order . |
35,855 | private static boolean compareUnordered ( Collection col1 , Collection col2 , Set visited ) { if ( ProxyHelper . isProxyCollection ( col1 ) || ProxyHelper . isProxyCollection ( col2 ) ) { return false ; } if ( col1 . size ( ) != col2 . size ( ) ) { return false ; } int h1 = deepHashCode ( col1 ) ; int h2 = deepHashCode ( col2 ) ; if ( h1 != h2 ) { return false ; } List copy = new ArrayList ( col2 ) ; for ( Object element1 : col1 ) { int len = copy . size ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( deepEquals ( element1 , copy . get ( i ) , visited ) ) { copy . remove ( i ) ; break ; } } if ( len == copy . size ( ) ) { return false ; } } return true ; } | Deeply compare the two sets referenced by dualKey . This method attempts to quickly determine inequality by length then hash and finally does a deepEquals on each element if the two Sets passed by the prior tests . |
35,856 | @ SuppressWarnings ( "unchecked" ) protected < T > T lookup ( Class < T > entityClass , Object id ) { String key = cacheKey ( entityClass , id ) ; LOG . debug ( "Reading from L1 >> " + key ) ; T o = ( T ) sessionCache . get ( key ) ; if ( o == null ) { LOG . debug ( "Reading from L2 >> " + key ) ; Cache c = ( Cache ) getL2Cache ( ) ; if ( c != null ) { o = ( T ) c . get ( key ) ; if ( o != null ) { LOG . debug ( "Found item in second level cache!" ) ; } } } return o ; } | Find in cache . |
35,857 | protected void store ( Object id , Object entity ) { store ( id , entity , Boolean . TRUE ) ; } | Store in L1 only . |
35,858 | protected void store ( Object id , Object entity , boolean spillOverToL2 ) { String key = cacheKey ( entity . getClass ( ) , id ) ; LOG . debug ( "Writing to L1 >> " + key ) ; sessionCache . put ( key , entity ) ; if ( spillOverToL2 ) { LOG . debug ( "Writing to L2 >>" + key ) ; Cache c = ( Cache ) getL2Cache ( ) ; if ( c != null ) { c . put ( key , entity ) ; } } } | Save to cache . |
35,859 | protected < T > void remove ( Class < T > entityClass , Object id , boolean spillOverToL2 ) { String key = cacheKey ( entityClass , id ) ; LOG . debug ( "Removing from L1 >> " + key ) ; Object o = sessionCache . remove ( key ) ; if ( spillOverToL2 ) { LOG . debug ( "Removing from L2 >> " + key ) ; Cache c = ( Cache ) getL2Cache ( ) ; if ( c != null ) { c . evict ( entityClass , key ) ; } } } | Removes the from cache . |
35,860 | public void persist ( Node node ) { Object entity = node . getData ( ) ; Object id = node . getEntityId ( ) ; EntityMetadata metadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , node . getDataClass ( ) ) ; isUpdate = node . isUpdate ( ) ; List < RelationHolder > relationHolders = getRelationHolders ( node ) ; onPersist ( metadata , entity , id , relationHolders ) ; id = PropertyAccessorHelper . getId ( entity , metadata ) ; node . setEntityId ( id ) ; indexNode ( node , metadata ) ; } | Method to handle |
35,861 | private void buildEntityFromCursor ( Object entity , HashMap obj , EntityType entityType ) { Iterator < Attribute > iter = entityType . getAttributes ( ) . iterator ( ) ; while ( iter . hasNext ( ) ) { Attribute attribute = iter . next ( ) ; Field field = ( Field ) attribute . getJavaMember ( ) ; if ( field . isAnnotationPresent ( Id . class ) ) { PropertyAccessorHelper . set ( entity , field , obj . get ( ID ) ) ; } else { PropertyAccessorHelper . set ( entity , field , obj . get ( ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ) ) ; } } } | Builds the entity from cursor . |
35,862 | public static ReqlFunction1 buildFunction ( final String colName , final Object obj , final String identifier ) { return new ReqlFunction1 ( ) { public Object apply ( ReqlExpr row ) { switch ( identifier ) { case "<" : return row . g ( colName ) . lt ( obj ) ; case "<=" : return row . g ( colName ) . le ( obj ) ; case ">" : return row . g ( colName ) . gt ( obj ) ; case ">=" : return row . g ( colName ) . ge ( obj ) ; case "=" : return row . g ( colName ) . eq ( obj ) ; default : logger . error ( "Operation not supported" ) ; throw new KunderaException ( "Operation not supported" ) ; } } } ; } | Builds the function . |
35,863 | public static final boolean checkIfZero ( String value , Class valueClazz ) { boolean returnValue = false ; if ( value != null && NumberUtils . isNumber ( value ) && numberTypes . get ( valueClazz ) != null ) { switch ( numberTypes . get ( valueClazz ) ) { case INTEGER : returnValue = Integer . parseInt ( value ) == ( NumberUtils . INTEGER_ZERO ) ; break ; case FLOAT : returnValue = Float . parseFloat ( value ) == ( NumberUtils . FLOAT_ZERO ) ; break ; case LONG : returnValue = Long . parseLong ( value ) == ( NumberUtils . LONG_ZERO ) ; break ; case BIGDECIMAL : returnValue = ( new BigDecimal ( value ) ) . compareTo ( BigDecimal . ZERO ) == 0 ; break ; case BIGINTEGER : returnValue = ( new BigInteger ( value ) ) . equals ( BigInteger . ZERO ) ; break ; case SHORT : returnValue = ( new Short ( value ) ) . shortValue ( ) == NumberUtils . SHORT_ZERO . shortValue ( ) ; break ; } } return returnValue ; } | Check if zero |
35,864 | static Map < String , DBObject > getDocumentFromObject ( Metamodel metaModel , Object obj , Set < Attribute > columns , String tableName ) throws PropertyAccessException { Map < String , DBObject > embeddedObjects = new HashMap < String , DBObject > ( ) ; for ( Attribute column : columns ) { String collectionName = ( ( AbstractAttribute ) column ) . getTableName ( ) != null ? ( ( AbstractAttribute ) column ) . getTableName ( ) : tableName ; DBObject dbObject = embeddedObjects . get ( collectionName ) ; if ( dbObject == null ) { dbObject = new BasicDBObject ( ) ; embeddedObjects . put ( collectionName , dbObject ) ; } if ( ( ( MetamodelImpl ) metaModel ) . isEmbeddable ( ( ( AbstractAttribute ) column ) . getBindableJavaType ( ) ) ) { DefaultMongoDBDataHandler handler = new DefaultMongoDBDataHandler ( ) ; handler . onEmbeddable ( column , obj , metaModel , dbObject , collectionName ) ; } else { extractFieldValue ( obj , dbObject , column ) ; } } return embeddedObjects ; } | Creates a MongoDB document object wrt a given Java object . columns in the document correspond Columns provided as List . |
35,865 | static BasicDBObject [ ] getDocumentListFromCollection ( Metamodel metaModel , Collection coll , Set < Attribute > columns , String tableName ) throws PropertyAccessException { BasicDBObject [ ] dBObjects = new BasicDBObject [ coll . size ( ) ] ; int count = 0 ; for ( Object o : coll ) { dBObjects [ count ] = ( BasicDBObject ) getDocumentFromObject ( metaModel , o , columns , tableName ) . values ( ) . toArray ( ) [ 0 ] ; count ++ ; } return dBObjects ; } | Creates a MongoDB document list from a given java collection . columns in the document correspond Columns provided as List . |
35,866 | static void extractFieldValue ( Object entity , DBObject dbObj , Attribute column ) throws PropertyAccessException { try { Object valueObject = PropertyAccessorHelper . getObject ( entity , ( Field ) column . getJavaMember ( ) ) ; if ( valueObject != null ) { Class javaType = column . getJavaType ( ) ; switch ( AttributeType . getType ( javaType ) ) { case MAP : Map mapObj = ( Map ) valueObject ; BasicDBObjectBuilder b = new BasicDBObjectBuilder ( ) ; Iterator i = mapObj . entrySet ( ) . iterator ( ) ; while ( i . hasNext ( ) ) { Map . Entry entry = ( Map . Entry ) i . next ( ) ; b . add ( entry . getKey ( ) . toString ( ) , MongoDBUtils . populateValue ( entry . getValue ( ) , entry . getValue ( ) . getClass ( ) ) ) ; } dbObj . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , b . get ( ) ) ; break ; case SET : case LIST : Collection collection = ( Collection ) valueObject ; BasicDBList basicDBList = new BasicDBList ( ) ; for ( Object o : collection ) { basicDBList . add ( o ) ; } dbObj . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , basicDBList ) ; break ; case POINT : Point p = ( Point ) valueObject ; double [ ] coordinate = new double [ ] { p . getX ( ) , p . getY ( ) } ; dbObj . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , coordinate ) ; break ; case ENUM : case PRIMITIVE : dbObj . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , MongoDBUtils . populateValue ( valueObject , javaType ) ) ; break ; } } } catch ( PropertyAccessException paex ) { log . error ( "Error while getting column {} value, caused by : ." , ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , paex ) ; throw new PersistenceException ( paex ) ; } } | Extract entity field . |
35,867 | private JsonObject iterateAndPopulateJsonObject ( Object entity , Iterator < Attribute > iterator , String tableName ) { JsonObject obj = JsonObject . create ( ) ; while ( iterator . hasNext ( ) ) { Attribute attribute = iterator . next ( ) ; Field field = ( Field ) attribute . getJavaMember ( ) ; Object value = PropertyAccessorHelper . getObject ( entity , field ) ; obj . put ( ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) , value ) ; } obj . put ( CouchbaseConstants . KUNDERA_ENTITY , tableName ) ; return obj ; } | Iterate and populate json object . |
35,868 | public static boolean hasInterface ( Class < ? > has , Class < ? > in ) { if ( has . equals ( in ) ) { return true ; } boolean match = false ; for ( Class < ? > intrface : in . getInterfaces ( ) ) { if ( intrface . getInterfaces ( ) . length > 0 ) { match = hasInterface ( has , intrface ) ; } else { match = intrface . equals ( has ) ; } if ( match ) { return true ; } } return false ; } | Checks for interface has in class in . |
35,869 | public static Type [ ] getTypeArguments ( Field property ) { Type type = property . getGenericType ( ) ; if ( type instanceof ParameterizedType ) { return ( ( ParameterizedType ) type ) . getActualTypeArguments ( ) ; } return null ; } | Gets the type arguments . |
35,870 | public static boolean hasSuperClass ( Class < ? > has , Class < ? > in ) { if ( in . equals ( has ) ) { return true ; } boolean match = false ; if ( in . getSuperclass ( ) != null && in . getSuperclass ( ) . equals ( Object . class ) ) { return match ; } match = in . getSuperclass ( ) != null ? hasSuperClass ( has , in . getSuperclass ( ) ) : false ; return match ; } | Checks for super has in class in . |
35,871 | public static Class < ? > classForName ( String className , ClassLoader classLoader ) { try { Class < ? > c = null ; try { c = Class . forName ( className , true , ReflectUtils . class . getClassLoader ( ) ) ; } catch ( ClassNotFoundException e ) { try { c = Class . forName ( className ) ; } catch ( ClassNotFoundException e1 ) { if ( classLoader == null ) { throw e1 ; } else { c = classLoader . loadClass ( className ) ; } } } return c ; } catch ( ClassNotFoundException e ) { throw new KunderaException ( e ) ; } } | Loads class with className using classLoader . |
35,872 | public static Class < ? > stripEnhancerClass ( Class < ? > c ) { String className = c . getName ( ) ; int enhancedIndex = className . indexOf ( "$$EnhancerByCGLIB" ) ; if ( enhancedIndex != - 1 ) { className = className . substring ( 0 , enhancedIndex ) ; } if ( className . equals ( c . getName ( ) ) ) { return c ; } else { c = classForName ( className , c . getClassLoader ( ) ) ; } return c ; } | Strip enhancer class . |
35,873 | public void saveLOBFile ( Key key , File lobFile ) { try { FileInputStream fis = new FileInputStream ( lobFile ) ; Version version = kvStore . putLOB ( key , fis , client . getDurability ( ) , client . getTimeout ( ) , client . getTimeUnit ( ) ) ; } catch ( FileNotFoundException e ) { log . warn ( "Unable to find file " + lobFile + ". This is being omitted, Caused by:" + e + "." ) ; } catch ( IOException e ) { log . warn ( "IOException while writing file " + lobFile + ". This is being omitted. Caused by:" + e + "." ) ; } } | Saves LOB file to Oracle KV Store |
35,874 | public Map < Object , Map < Object , String > > getElementCollectionCache ( ) { if ( this . elementCollectionCache == null ) { this . elementCollectionCache = new HashMap < Object , Map < Object , String > > ( ) ; } return this . elementCollectionCache ; } | Gets the element collection cache . |
35,875 | public void addElementCollectionCacheMapping ( Object rowKey , Object elementCollectionObject , String elementCollObjectName ) { Map embeddedObjectMap = new HashMap < Object , String > ( ) ; if ( getElementCollectionCache ( ) . get ( rowKey ) == null ) { embeddedObjectMap . put ( elementCollectionObject , elementCollObjectName ) ; getElementCollectionCache ( ) . put ( rowKey , embeddedObjectMap ) ; } else { getElementCollectionCache ( ) . get ( rowKey ) . put ( elementCollectionObject , elementCollObjectName ) ; } } | Adds the element collection cache mapping . |
35,876 | public String getElementCollectionObjectName ( Object rowKey , Object elementCollectionObject ) { if ( getElementCollectionCache ( ) . isEmpty ( ) || getElementCollectionCache ( ) . get ( rowKey ) == null ) { log . debug ( "No element collection object map found in cache for Row key " + rowKey ) ; return null ; } else { Map < Object , String > elementCollectionObjectMap = getElementCollectionCache ( ) . get ( rowKey ) ; String elementCollectionObjectName = elementCollectionObjectMap . get ( elementCollectionObject ) ; if ( elementCollectionObjectName == null ) { for ( Object obj : elementCollectionObjectMap . keySet ( ) ) { if ( DeepEquals . deepEquals ( elementCollectionObject , obj ) ) { elementCollectionObjectName = elementCollectionObjectMap . get ( obj ) ; break ; } } } if ( elementCollectionObjectName == null ) { log . debug ( "No element collection object name found in cache for object:" + elementCollectionObject ) ; return null ; } else { return elementCollectionObjectName ; } } } | Gets the element collection object name . |
35,877 | public int getLastElementCollectionObjectCount ( Object rowKey ) { if ( getElementCollectionCache ( ) . get ( rowKey ) == null ) { log . debug ( "No element collection object map found in cache for Row key " + rowKey ) ; return - 1 ; } else { Map < Object , String > elementCollectionMap = getElementCollectionCache ( ) . get ( rowKey ) ; Collection < String > elementCollectionObjectNames = elementCollectionMap . values ( ) ; int max = 0 ; for ( String s : elementCollectionObjectNames ) { String elementCollectionCountStr = s . substring ( s . indexOf ( Constants . EMBEDDED_COLUMN_NAME_DELIMITER ) + 1 ) ; int elementCollectionCount = 0 ; try { elementCollectionCount = Integer . parseInt ( elementCollectionCountStr ) ; } catch ( NumberFormatException e ) { log . error ( "Invalid element collection Object name " + s ) ; throw new CacheException ( "Invalid element collection Object name " + s , e ) ; } if ( elementCollectionCount > max ) { max = elementCollectionCount ; } } return max ; } } | Gets the last element collection object count . |
35,878 | public List < GridFSDBFile > find ( final DBObject query , final DBObject sort , final int firstResult , final int maxResult ) { List < GridFSDBFile > files = new ArrayList < GridFSDBFile > ( ) ; DBCursor c = null ; try { c = getFilesCollection ( ) . find ( query ) ; if ( sort != null ) { c . sort ( sort ) ; } c . skip ( firstResult ) . limit ( maxResult ) ; while ( c . hasNext ( ) ) { files . add ( findOne ( c . next ( ) ) ) ; } } finally { if ( c != null ) { c . close ( ) ; } } return files ; } | Finds a list of files matching the given query . |
35,879 | public static ClientFactory getClientFactory ( String persistenceUnit , Map < String , Object > puProperties , final KunderaMetadata kunderaMetadata ) { ClientFactory clientFactory = instantiateClientFactory ( persistenceUnit , puProperties , kunderaMetadata ) ; clientFactories . put ( persistenceUnit , clientFactory ) ; return clientFactory ; } | Gets the client factory . |
35,880 | private static ClientFactory instantiateClientFactory ( String persistenceUnit , Map < String , Object > puProperties , final KunderaMetadata kunderaMetadata ) { ClientFactory clientFactory = null ; logger . info ( "Initializing client factory for: " + persistenceUnit ) ; PersistenceUnitMetadata persistenceUnitMetadata = kunderaMetadata . getApplicationMetadata ( ) . getPersistenceUnitMetadata ( persistenceUnit ) ; String kunderaClientFactory = puProperties != null ? ( String ) puProperties . get ( PersistenceProperties . KUNDERA_CLIENT_FACTORY ) : null ; if ( kunderaClientFactory == null ) { kunderaClientFactory = persistenceUnitMetadata . getProperties ( ) . getProperty ( PersistenceProperties . KUNDERA_CLIENT_FACTORY ) ; } if ( kunderaClientFactory == null ) { throw new ClientResolverException ( "<kundera.client.lookup.class> is missing from persistence.xml, please provide specific client factory. e.g., <property name=\"kundera.client.lookup.class\" value=\"com.impetus.client.cassandra.pelops.PelopsClientFactory\" />" ) ; } try { clientFactory = ( ClientFactory ) Class . forName ( kunderaClientFactory ) . newInstance ( ) ; Method m = GenericClientFactory . class . getDeclaredMethod ( "setPersistenceUnit" , String . class ) ; if ( ! m . isAccessible ( ) ) { m . setAccessible ( true ) ; } m . invoke ( clientFactory , persistenceUnit ) ; m = GenericClientFactory . class . getDeclaredMethod ( "setExternalProperties" , Map . class ) ; if ( ! m . isAccessible ( ) ) { m . setAccessible ( true ) ; } m . invoke ( clientFactory , puProperties ) ; m = GenericClientFactory . class . getDeclaredMethod ( "setKunderaMetadata" , KunderaMetadata . class ) ; if ( ! m . isAccessible ( ) ) { m . setAccessible ( true ) ; } m . invoke ( clientFactory , kunderaMetadata ) ; } catch ( InstantiationException e ) { onError ( e ) ; } catch ( IllegalAccessException e ) { onError ( e ) ; } catch ( ClassNotFoundException e ) { onError ( e ) ; } catch ( SecurityException e ) { onError ( e ) ; } catch ( NoSuchMethodException e ) { onError ( e ) ; } catch ( IllegalArgumentException e ) { onError ( e ) ; } catch ( InvocationTargetException e ) { onError ( e ) ; } if ( clientFactory == null ) { logger . error ( "Client Factory Not Configured For Specified Client Type : " ) ; throw new ClientResolverException ( "Client Factory Not Configured For Specified Client Type." ) ; } logger . info ( "Finishing factory initialization" ) ; return clientFactory ; } | Creates new instance of client factory for given persistence unit . |
35,881 | protected boolean isCappedCollection ( TableInfo tableInfo ) { return MongoDBPropertyReader . msmd != null ? MongoDBPropertyReader . msmd . isCappedCollection ( databaseName , tableInfo . getTableName ( ) ) : false ; } | Checks whether the given table is a capped collection |
35,882 | private void onValidateEmbeddable ( Object embeddedObject , EmbeddableType embeddedColumn ) { if ( embeddedObject instanceof Collection ) { for ( Object obj : ( Collection ) embeddedObject ) { for ( Object column : embeddedColumn . getAttributes ( ) ) { Attribute columnAttribute = ( Attribute ) column ; Field f = ( Field ) columnAttribute . getJavaMember ( ) ; this . factory . validate ( f , embeddedObject , new AttributeConstraintRule ( ) ) ; } } } else { for ( Object column : embeddedColumn . getAttributes ( ) ) { Attribute columnAttribute = ( Attribute ) column ; Field f = ( Field ) ( ( Field ) columnAttribute . getJavaMember ( ) ) ; this . factory . validate ( f , embeddedObject , new AttributeConstraintRule ( ) ) ; } } } | Checks constraints present on embeddable attributes |
35,883 | public static SparkDataClient getDataClient ( String clientName ) { if ( clientPool . get ( clientName ) != null ) { return clientPool . get ( clientName ) ; } try { SparkDataClient dataClient = ( SparkDataClient ) KunderaCoreUtils . createNewInstance ( Class . forName ( clientNameToClass . get ( clientName ) ) ) ; clientPool . put ( clientName , dataClient ) ; return dataClient ; } catch ( Exception e ) { logger . error ( clientName + " client is invalid/not supported. Please check kundera.client in persistence properties." ) ; throw new KunderaException ( clientName + " client is invalid/not supported. Please check kundera.client in persistence properties." ) ; } } | Gets the data client . |
35,884 | private boolean validateSize ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } int objectSize = 0 ; int minSize = ( ( Size ) annotate ) . min ( ) ; int maxSize = ( ( Size ) annotate ) . max ( ) ; if ( validationObject != null ) { if ( String . class . isAssignableFrom ( validationObject . getClass ( ) ) ) { objectSize = ( ( String ) validationObject ) . length ( ) ; } else if ( Collection . class . isAssignableFrom ( validationObject . getClass ( ) ) ) { objectSize = ( ( Collection ) validationObject ) . size ( ) ; } else if ( Map . class . isAssignableFrom ( validationObject . getClass ( ) ) ) { objectSize = ( ( Map ) validationObject ) . size ( ) ; } else if ( ArrayList . class . isAssignableFrom ( validationObject . getClass ( ) ) ) { objectSize = ( ( ArrayList ) validationObject ) . size ( ) ; } else { throwValidationException ( ( ( Size ) annotate ) . message ( ) ) ; } } return objectSize <= maxSize && objectSize >= minSize ; } | Checks whether the given attribute s value is within specified limit |
35,885 | private boolean validatePattern ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } java . util . regex . Pattern pattern = java . util . regex . Pattern . compile ( ( ( Pattern ) annotate ) . regexp ( ) , ( ( Pattern ) annotate ) . flags ( ) . length ) ; Matcher matcherPattern = pattern . matcher ( ( String ) validationObject ) ; if ( ! matcherPattern . matches ( ) ) { throwValidationException ( ( ( Pattern ) annotate ) . message ( ) ) ; } return true ; } | Checks whether the given string is a valid pattern or not |
35,886 | private boolean validatePast ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } int res = 0 ; if ( validationObject . getClass ( ) . isAssignableFrom ( java . util . Date . class ) ) { Date today = new Date ( ) ; Date pastDate = ( Date ) validationObject ; res = pastDate . compareTo ( today ) ; } else if ( validationObject . getClass ( ) . isAssignableFrom ( java . util . Calendar . class ) ) { Calendar cal = Calendar . getInstance ( ) ; Calendar pastDate = ( Calendar ) validationObject ; res = pastDate . compareTo ( cal ) ; } if ( res >= 0 ) { throwValidationException ( ( ( Past ) annotate ) . message ( ) ) ; } return true ; } | Checks whether the object is null or not |
35,887 | private boolean validateFuture ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } int res = 0 ; if ( validationObject . getClass ( ) . isAssignableFrom ( java . util . Date . class ) ) { Date today = new Date ( ) ; Date futureDate = ( Date ) validationObject ; res = futureDate . compareTo ( today ) ; } else if ( validationObject . getClass ( ) . isAssignableFrom ( java . util . Calendar . class ) ) { Calendar cal = Calendar . getInstance ( ) ; Calendar futureDate = ( Calendar ) validationObject ; res = futureDate . compareTo ( cal ) ; } if ( res <= 0 ) { throwValidationException ( ( ( Future ) annotate ) . message ( ) ) ; } return true ; } | Checks whether a given date is that in future or not |
35,888 | private boolean validateNull ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } if ( ! validationObject . equals ( null ) || validationObject != null ) { throwValidationException ( ( ( Null ) annotate ) . message ( ) ) ; } return true ; } | Checks whether a given date is that in past or not |
35,889 | private boolean validateMinValue ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } Long minValue = ( ( Min ) annotate ) . value ( ) ; if ( checkvalidDigitTypes ( validationObject . getClass ( ) ) ) { if ( ( NumberUtils . toLong ( toString ( validationObject ) ) ) < minValue ) { throwValidationException ( ( ( Min ) annotate ) . message ( ) ) ; } } return true ; } | Checks whether a given value is greater than given min value or not |
35,890 | private boolean validateMaxValue ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } Long maxValue = ( ( Max ) annotate ) . value ( ) ; if ( checkvalidDigitTypes ( validationObject . getClass ( ) ) ) { if ( ( NumberUtils . toLong ( toString ( validationObject ) ) ) > maxValue ) { throwValidationException ( ( ( Max ) annotate ) . message ( ) ) ; } } return true ; } | Checks whether a given value is lesser than given max value or not |
35,891 | private boolean validateDigits ( Object validationObject , Annotation annotate ) { if ( checkNullObject ( validationObject ) ) { return true ; } if ( checkvalidDigitTypes ( validationObject . getClass ( ) ) ) { if ( ! NumberUtils . isDigits ( toString ( validationObject ) ) ) { throwValidationException ( ( ( Digits ) annotate ) . message ( ) ) ; } } return true ; } | Checks whether a given value is is a number or not |
35,892 | private boolean validateMinDecimal ( Object validationObject , Annotation annotate ) { if ( validationObject != null ) { try { if ( checkvalidDeciDigitTypes ( validationObject . getClass ( ) ) ) { BigDecimal minValue = NumberUtils . createBigDecimal ( ( ( DecimalMin ) annotate ) . value ( ) ) ; BigDecimal actualValue = NumberUtils . createBigDecimal ( toString ( validationObject ) ) ; int res = actualValue . compareTo ( minValue ) ; if ( res < 0 ) { throwValidationException ( ( ( DecimalMin ) annotate ) . message ( ) ) ; } } } catch ( NumberFormatException nfe ) { throw new RuleValidationException ( nfe . getMessage ( ) ) ; } } return true ; } | Checks whether a given value is a valid minimum decimal digit when compared to given value or not |
35,893 | private boolean validateMaxDecimal ( Object validationObject , Annotation annotate ) { if ( validationObject != null ) { try { if ( checkvalidDeciDigitTypes ( validationObject . getClass ( ) ) ) { BigDecimal maxValue = NumberUtils . createBigDecimal ( ( ( DecimalMax ) annotate ) . value ( ) ) ; BigDecimal actualValue = NumberUtils . createBigDecimal ( toString ( validationObject ) ) ; int res = actualValue . compareTo ( maxValue ) ; if ( res > 0 ) { throwValidationException ( ( ( DecimalMax ) annotate ) . message ( ) ) ; } } } catch ( NumberFormatException nfe ) { throw new RuleValidationException ( nfe . getMessage ( ) ) ; } } return true ; } | Checks whether a given value is a valid maximum decimal digit when compared to given value or not |
35,894 | public static Date getDateByPattern ( String date ) { if ( StringUtils . isNumeric ( date ) ) { return new Date ( Long . parseLong ( date ) ) ; } for ( String p : patterns ) { try { DateFormat formatter = new SimpleDateFormat ( p ) ; Date dt = formatter . parse ( date ) ; return dt ; } catch ( IllegalArgumentException iae ) { } catch ( ParseException e ) { } } log . error ( "Required Date format is not supported!" + date ) ; throw new PropertyAccessException ( "Required Date format is not supported!" + date ) ; } | Get Date from given below formats . |
35,895 | public static String getFormattedObect ( String date ) { return date != null ? getDateByPattern ( date ) . toString ( ) : null ; } | Just to verify with supported types of date pattern . Get Date from given below formats |
35,896 | public Map < String , Object > getRelations ( ) { return relations != null ? Collections . unmodifiableMap ( relations ) : null ; } | Gets the relations . |
35,897 | private HostFailoverPolicy getFailoverPolicy ( String failoverOption ) { if ( failoverOption != null ) { if ( Constants . FAIL_FAST . equals ( failoverOption ) ) { return HostFailoverPolicy . FAIL_FAST ; } else if ( Constants . ON_FAIL_TRY_ALL_AVAILABLE . equals ( failoverOption ) ) { return HostFailoverPolicy . ON_FAIL_TRY_ALL_AVAILABLE ; } else if ( Constants . ON_FAIL_TRY_ONE_NEXT_AVAILABLE . equals ( failoverOption ) ) { return HostFailoverPolicy . ON_FAIL_TRY_ONE_NEXT_AVAILABLE ; } else { logger . warn ( "Invalid failover policy {}, using default {} " , failoverOption , HostFailoverPolicy . ON_FAIL_TRY_ALL_AVAILABLE . name ( ) ) ; return HostFailoverPolicy . ON_FAIL_TRY_ALL_AVAILABLE ; } } return HostFailoverPolicy . ON_FAIL_TRY_ALL_AVAILABLE ; } | Resolve failover policy for Cassandra thrift . |
35,898 | public static String generatePoolName ( String node , int port , String keyspace ) { return node + ":" + port + ":" + keyspace ; } | Generate pool name . |
35,899 | public static SimpleConnectionAuthenticator getAuthenticationRequest ( String userName , String password ) { SimpleConnectionAuthenticator authenticator = null ; if ( userName != null || password != null ) { authenticator = new SimpleConnectionAuthenticator ( userName , password ) ; } return authenticator ; } | If userName and password provided Method prepares for AuthenticationRequest . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.