idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
36,100
private void setFieldValueViaCQL ( Object entity , Object thriftColumnValue , Attribute attribute ) { if ( attribute != null ) { try { if ( attribute . isCollection ( ) ) { setCollectionValue ( entity , thriftColumnValue , attribute ) ; } else if ( CassandraDataTranslator . isCassandraDataTypeClass ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { PropertyAccessorHelper . set ( entity , ( Field ) attribute . getJavaMember ( ) , CassandraDataTranslator . decompose ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) , thriftColumnValue , true ) ) ; } else { PropertyAccessorHelper . set ( entity , ( Field ) attribute . getJavaMember ( ) , ( byte [ ] ) thriftColumnValue ) ; } } catch ( PropertyAccessException pae ) { log . warn ( "Error while setting field{} value via CQL, Caused by: ." , attribute . getName ( ) , pae ) ; } } }
Sets the field value via cql .
36,101
private Object setElementCollectionMap ( MapType mapType , ByteBuffer thriftColumnValue , Object entity , Field field , MetamodelImpl metaModel , Class embeddedClass , boolean useNativeProtocol2 ) { Map result = new HashMap ( ) ; MapSerializer mapSerializer = mapType . getSerializer ( ) ; Map outputCollection = new HashMap ( ) ; if ( useNativeProtocol2 ) { outputCollection . putAll ( mapSerializer . deserializeForNativeProtocol ( thriftColumnValue , ProtocolVersion . V2 ) ) ; } else { outputCollection . putAll ( ( Map ) mapSerializer . deserialize ( thriftColumnValue ) ) ; } UserType usertype = ( UserType ) mapType . getValuesType ( ) ; for ( Object key : outputCollection . keySet ( ) ) { Object embeddedObject = KunderaCoreUtils . createNewInstance ( embeddedClass ) ; Object value = populateEmbeddedRecursive ( ( ByteBuffer ) outputCollection . get ( key ) , usertype . allTypes ( ) , usertype . fieldNames ( ) , embeddedObject , metaModel ) ; result . put ( key , value ) ; } PropertyAccessorHelper . set ( entity , field , result ) ; return entity ; }
Sets the element collection map .
36,102
private Object setElementCollectionSet ( SetType setType , ByteBuffer thriftColumnValue , Object entity , Field field , MetamodelImpl metaModel , Class embeddedClass , boolean useNativeProtocol2 ) { SetSerializer setSerializer = setType . getSerializer ( ) ; Collection outputCollection = new ArrayList ( ) ; if ( useNativeProtocol2 ) { outputCollection . addAll ( ( Collection ) setSerializer . deserializeForNativeProtocol ( thriftColumnValue , ProtocolVersion . V2 ) ) ; } else { outputCollection . addAll ( ( Collection ) setSerializer . deserialize ( thriftColumnValue ) ) ; } UserType usertype = ( UserType ) setType . getElementsType ( ) ; Collection result = new HashSet ( ) ; Iterator collectionItems = outputCollection . iterator ( ) ; while ( collectionItems . hasNext ( ) ) { Object embeddedObject = KunderaCoreUtils . createNewInstance ( embeddedClass ) ; Object value = populateEmbeddedRecursive ( ( ByteBuffer ) collectionItems . next ( ) , usertype . allTypes ( ) , usertype . fieldNames ( ) , embeddedObject , metaModel ) ; result . add ( value ) ; } PropertyAccessorHelper . set ( entity , field , result ) ; return entity ; }
Sets the element collection set .
36,103
private Object setElementCollectionList ( ListType listType , ByteBuffer thriftColumnValue , Object entity , Field field , MetamodelImpl metaModel , Class embeddedClass , boolean useNativeProtocol2 ) { ListSerializer listSerializer = listType . getSerializer ( ) ; Collection outputCollection = new ArrayList ( ) ; if ( useNativeProtocol2 ) { outputCollection . addAll ( ( Collection ) listSerializer . deserializeForNativeProtocol ( thriftColumnValue , ProtocolVersion . V2 ) ) ; } else { outputCollection . addAll ( ( Collection ) listSerializer . deserialize ( thriftColumnValue ) ) ; } UserType usertype = ( UserType ) listType . getElementsType ( ) ; Collection result = new ArrayList ( ) ; Iterator collectionItems = outputCollection . iterator ( ) ; while ( collectionItems . hasNext ( ) ) { Object embeddedObject = KunderaCoreUtils . createNewInstance ( embeddedClass ) ; Object value = populateEmbeddedRecursive ( ( ByteBuffer ) collectionItems . next ( ) , usertype . allTypes ( ) , usertype . fieldNames ( ) , embeddedObject , metaModel ) ; result . add ( value ) ; } PropertyAccessorHelper . set ( entity , field , result ) ; return entity ; }
Sets the element collection list .
36,104
private Object getFieldValueViaCQL ( Object thriftColumnValue , Attribute attribute ) { PropertyAccessor < ? > accessor = PropertyAccessorFactory . getPropertyAccessor ( ( Field ) attribute . getJavaMember ( ) ) ; Object objValue ; try { if ( CassandraDataTranslator . isCassandraDataTypeClass ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { objValue = CassandraDataTranslator . decompose ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) , thriftColumnValue , true ) ; return objValue ; } else { objValue = accessor . fromBytes ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) , ( byte [ ] ) thriftColumnValue ) ; return objValue ; } } catch ( PropertyAccessException pae ) { log . warn ( "Error while setting field{} value via CQL, Caused by: ." , attribute . getName ( ) , pae ) ; } return null ; }
Gets the field value via cql .
36,105
private Collection < ThriftRow > onColumnOrSuperColumnThriftRow ( EntityMetadata m , Object e , Object id , long timestamp , Object columnTTLs ) { Map < String , ThriftRow > thriftRows = new HashMap < String , ThriftRow > ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; Set < Attribute > attributes = entityType . getAttributes ( ) ; for ( Attribute attribute : attributes ) { String tableName = ( ( AbstractAttribute ) attribute ) . getTableName ( ) != null ? ( ( AbstractAttribute ) attribute ) . getTableName ( ) : m . getTableName ( ) ; ThriftRow tr = getThriftRow ( id , tableName , thriftRows ) ; if ( ! attribute . getName ( ) . equals ( m . getIdAttribute ( ) . getName ( ) ) && ! attribute . isAssociation ( ) ) { Field field = ( Field ) ( ( Attribute ) attribute ) . getJavaMember ( ) ; byte [ ] name = ByteBufferUtil . bytes ( ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ) . array ( ) ; if ( metaModel . isEmbeddable ( attribute . isCollection ( ) ? ( ( PluralAttribute ) attribute ) . getBindableJavaType ( ) : attribute . getJavaType ( ) ) ) { Map < String , Object > thriftSuperColumns = onEmbeddable ( timestamp , tr , m , e , id , attribute ) ; if ( thriftSuperColumns != null ) { for ( String columnFamilyName : thriftSuperColumns . keySet ( ) ) { ThriftRow thriftRow = getThriftRow ( id , columnFamilyName , thriftRows ) ; if ( m . isCounterColumnType ( ) ) { thriftRow . addCounterSuperColumn ( ( CounterSuperColumn ) thriftSuperColumns . get ( columnFamilyName ) ) ; } else { thriftRow . addSuperColumn ( ( SuperColumn ) thriftSuperColumns . get ( columnFamilyName ) ) ; } } } } else { Object value = getColumnValue ( m , e , attribute ) ; if ( m . getType ( ) . equals ( Type . SUPER_COLUMN_FAMILY ) ) { prepareSuperColumn ( tr , m , value , name , timestamp ) ; } else { int ttl = getTTLForColumn ( columnTTLs , attribute ) ; prepareColumn ( tr , m , value , name , timestamp , ttl ) ; } } } } onDiscriminatorColumn ( thriftRows . get ( m . getTableName ( ) ) , timestamp , entityType ) ; return thriftRows . values ( ) ; }
On column or super column thrift row .
36,106
private int getTTLForColumn ( Object columnTTLs , Attribute attribute ) { Integer ttl = null ; if ( columnTTLs != null ) { if ( columnTTLs instanceof Map ) { ttl = ( Integer ) ( columnTTLs == null ? 0 : ( ( Map ) columnTTLs ) . get ( ( ( AbstractAttribute ) attribute ) . getJPAColumnName ( ) ) ) ; } else if ( columnTTLs instanceof Integer ) { ttl = ( Integer ) columnTTLs ; } } return ttl == null ? 0 : ttl ; }
Determined TTL for a given column .
36,107
protected byte [ ] getThriftColumnValue ( Object e , Attribute attribute ) { byte [ ] value = null ; Field field = ( Field ) ( ( Attribute ) attribute ) . getJavaMember ( ) ; try { if ( attribute != null && field . get ( e ) != null ) { if ( CassandraDataTranslator . isCassandraDataTypeClass ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { value = CassandraDataTranslator . compose ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) , field . get ( e ) , false ) ; } else { value = PropertyAccessorHelper . get ( e , field ) ; } } } catch ( IllegalArgumentException iae ) { log . error ( "Error while persisting data, Caused by: ." , iae ) ; throw new IllegalArgumentException ( iae ) ; } catch ( IllegalAccessException iace ) { log . error ( "Error while persisting data, Caused by: ." , iace ) ; } return value ; }
Gets the thrift column value .
36,108
private void prepareSuperColumn ( ThriftRow tr , EntityMetadata m , Object value , byte [ ] name , long timestamp ) { if ( value != null ) { if ( m . isCounterColumnType ( ) ) { CounterSuperColumn counterSuper = new CounterSuperColumn ( ) ; counterSuper . setName ( name ) ; CounterColumn counterColumn = prepareCounterColumn ( ( String ) value , name ) ; List < CounterColumn > subCounterColumn = new ArrayList < CounterColumn > ( ) ; subCounterColumn . add ( counterColumn ) ; counterSuper . setColumns ( subCounterColumn ) ; tr . addCounterSuperColumn ( counterSuper ) ; } else { SuperColumn superCol = new SuperColumn ( ) ; superCol . setName ( name ) ; Column column = prepareColumn ( ( byte [ ] ) value , name , timestamp , 0 ) ; List < Column > subColumn = new ArrayList < Column > ( ) ; subColumn . add ( column ) ; superCol . setColumns ( subColumn ) ; tr . addSuperColumn ( superCol ) ; } } }
Prepare super column .
36,109
private CounterColumn prepareCounterColumn ( String value , byte [ ] name ) { CounterColumn counterColumn = new CounterColumn ( ) ; counterColumn . setName ( name ) ; LongAccessor accessor = new LongAccessor ( ) ; counterColumn . setValue ( accessor . fromString ( LongAccessor . class , value ) ) ; return counterColumn ; }
Prepare counter column .
36,110
private Map < String , Object > buildThriftCounterSuperColumn ( String tableName , String superColumnName , EmbeddableType superColumn , Object counterSuperColumnObject ) { Map < String , Object > thriftCounterSuperColumns = new HashMap < String , Object > ( ) ; Iterator < Attribute > iter = superColumn . getAttributes ( ) . iterator ( ) ; List < CounterColumn > thriftColumns = new ArrayList < CounterColumn > ( ) ; while ( iter . hasNext ( ) ) { Attribute column = iter . next ( ) ; Field field = ( Field ) column . getJavaMember ( ) ; String name = ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) ; String value = null ; try { value = PropertyAccessorHelper . getString ( counterSuperColumnObject , field ) ; } catch ( PropertyAccessException exp ) { if ( log . isInfoEnabled ( ) ) { log . info ( exp . getMessage ( ) + ". Possible case of entity column in a super column family. Will be treated as a super column." ) ; } value = counterSuperColumnObject . toString ( ) ; } if ( null != value ) { try { CounterColumn thriftColumn = new CounterColumn ( ) ; thriftColumn . setName ( PropertyAccessorFactory . STRING . toBytes ( name ) ) ; thriftColumn . setValue ( Long . parseLong ( value ) ) ; thriftColumns . add ( thriftColumn ) ; tableName = ( ( AbstractAttribute ) column ) . getTableName ( ) != null ? ( ( AbstractAttribute ) column ) . getTableName ( ) : tableName ; CounterSuperColumn thriftSuperColumn = ( CounterSuperColumn ) thriftCounterSuperColumns . get ( tableName ) ; if ( thriftSuperColumn == null ) { thriftSuperColumn = new CounterSuperColumn ( ) ; thriftSuperColumn . setName ( PropertyAccessorFactory . STRING . toBytes ( superColumnName ) ) ; thriftCounterSuperColumns . put ( tableName , thriftSuperColumn ) ; } thriftSuperColumn . addToColumns ( thriftColumn ) ; } catch ( NumberFormatException nfe ) { log . error ( "For counter column arguments should be numeric type, Caused by: ." , nfe ) ; throw new KunderaException ( nfe ) ; } } } return thriftCounterSuperColumns ; }
Builds the thrift counter super column .
36,111
private Object find ( Class entityClass , Object key , List < String > columnsToSelect ) { EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , entityClass ) ; MetamodelImpl metamodel = ( MetamodelImpl ) KunderaMetadataManager . getMetamodel ( kunderaMetadata , entityMetadata . getPersistenceUnit ( ) ) ; String idColumnName = ( ( AbstractAttribute ) entityMetadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ; Table schemaTable = tableAPI . getTable ( entityMetadata . getTableName ( ) ) ; PrimaryKey rowKey = schemaTable . createPrimaryKey ( ) ; if ( metamodel . isEmbeddable ( entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { readEmbeddable ( key , columnsToSelect , entityMetadata , metamodel , schemaTable , rowKey , entityMetadata . getIdAttribute ( ) ) ; } else { if ( eligibleToFetch ( columnsToSelect , idColumnName ) ) { NoSqlDBUtils . add ( schemaTable . getField ( idColumnName ) , rowKey , key , idColumnName ) ; } } KunderaCoreUtils . printQuery ( "Fetch data from " + entityMetadata . getTableName ( ) + " for PK " + key , showQuery ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Fetching data from " + entityMetadata . getTableName ( ) + " for PK " + key ) ; } List entities = new ArrayList ( ) ; Map < String , Object > relationMap = initialize ( entityMetadata ) ; try { Iterator < Row > rowsIter = tableAPI . tableIterator ( rowKey , null , null ) ; entities = scrollAndPopulate ( key , entityMetadata , metamodel , schemaTable , rowsIter , relationMap , columnsToSelect ) ; } catch ( Exception e ) { log . error ( "Error while finding data for Key " + key + ", Caused By :" + e + "." ) ; throw new PersistenceException ( e ) ; } return entities . isEmpty ( ) ? null : entities . get ( 0 ) ; }
Find by id .
36,112
private void readEmbeddable ( Object key , List < String > columnsToSelect , EntityMetadata entityMetadata , MetamodelImpl metamodel , Table schemaTable , RecordValue value , Attribute attribute ) { EmbeddableType embeddableId = metamodel . embeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddableId . getAttributes ( ) ; for ( Attribute embeddedAttrib : embeddedAttributes ) { String columnName = ( ( AbstractAttribute ) embeddedAttrib ) . getJPAColumnName ( ) ; Object embeddedColumn = PropertyAccessorHelper . getObject ( key , ( Field ) embeddedAttrib . getJavaMember ( ) ) ; if ( eligibleToFetch ( columnsToSelect , columnName ) ) { NoSqlDBUtils . add ( schemaTable . getField ( columnName ) , value , embeddedColumn , columnName ) ; } } }
Read embeddable .
36,113
public void delete ( Object entity , Object pKey ) { EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , entity . getClass ( ) ) ; MetamodelImpl metamodel = ( MetamodelImpl ) KunderaMetadataManager . getMetamodel ( kunderaMetadata , entityMetadata . getPersistenceUnit ( ) ) ; String idColumnName = ( ( AbstractAttribute ) entityMetadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ; Table schemaTable = tableAPI . getTable ( entityMetadata . getTableName ( ) ) ; PrimaryKey key = schemaTable . createPrimaryKey ( ) ; if ( metamodel . isEmbeddable ( entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { EmbeddableType embeddableId = metamodel . embeddable ( entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddableId . getAttributes ( ) ; for ( Attribute embeddedAttrib : embeddedAttributes ) { String columnName = ( ( AbstractAttribute ) embeddedAttrib ) . getJPAColumnName ( ) ; Object embeddedColumn = PropertyAccessorHelper . getObject ( pKey , ( Field ) embeddedAttrib . getJavaMember ( ) ) ; NoSqlDBUtils . add ( schemaTable . getField ( columnName ) , key , embeddedColumn , columnName ) ; } } else { NoSqlDBUtils . add ( schemaTable . getField ( idColumnName ) , key , pKey , idColumnName ) ; } tableAPI . delete ( key , null , null ) ; KunderaCoreUtils . printQuery ( "Delete data from " + entityMetadata . getTableName ( ) + " for PK " + pKey , showQuery ) ; }
Delete by primary key .
36,114
private void addOps ( Map < Key , List < TableOperation > > operations , Table schemaTable , Row row ) { Key key = ( ( TableImpl ) schemaTable ) . createKey ( row , false ) ; TableOperation ops = tableAPI . getTableOperationFactory ( ) . createPut ( row , Choice . NONE , true ) ; if ( operations . containsKey ( key ) ) { operations . get ( key ) . add ( ops ) ; } else { List < TableOperation > operation = new ArrayList < TableOperation > ( ) ; operation . add ( ops ) ; operations . put ( key , operation ) ; } }
Adds the ops .
36,115
public < E > List < E > executeQuery ( Class < E > entityClass , OracleNoSQLQueryInterpreter interpreter , Set < Object > primaryKeys ) { EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , entityClass ) ; MetamodelImpl metamodel = ( MetamodelImpl ) KunderaMetadataManager . getMetamodel ( kunderaMetadata , entityMetadata . getPersistenceUnit ( ) ) ; EntityType entityType = metamodel . entity ( entityMetadata . getEntityClazz ( ) ) ; List < E > results = new ArrayList < E > ( ) ; if ( interpreter . getClauseQueue ( ) . isEmpty ( ) ) { return findAll ( entityClass , interpreter . getSelectColumns ( ) , null ) ; } else if ( interpreter . isFindById ( ) && interpreter . getClauseQueue ( ) . size ( ) == 1 ) { Object value = null ; Object clause = interpreter . getClauseQueue ( ) . peek ( ) ; if ( clause . getClass ( ) . isAssignableFrom ( FilterClause . class ) ) { value = interpreter . getRowKey ( ) ; } else { throw new QueryHandlerException ( "Query with multiple AND/OR clause is not supported with oracle nosql db" ) ; } if ( value != null ) { Object output = find ( entityClass , value , Arrays . asList ( interpreter . getSelectColumns ( ) ) ) ; if ( output != null ) { results . add ( ( E ) output ) ; } } } else if ( interpreter . getClauseQueue ( ) . size ( ) >= 1 ) { return onIndexSearch ( interpreter , entityMetadata , metamodel , results , Arrays . asList ( interpreter . getSelectColumns ( ) ) ) ; } return results ; }
On JPQL query execution .
36,116
public List < Object > findByRelation ( String colName , Object colValue , Class entityClazz ) { EntityMetadata entityMetadata = KunderaMetadataManager . getEntityMetadata ( kunderaMetadata , entityClazz ) ; MetamodelImpl metamodel = ( MetamodelImpl ) KunderaMetadataManager . getMetamodel ( kunderaMetadata , entityMetadata . getPersistenceUnit ( ) ) ; EntityType entityType = metamodel . entity ( entityMetadata . getEntityClazz ( ) ) ; Table schemaTable = tableAPI . getTable ( entityMetadata . getTableName ( ) ) ; Iterator < Row > rowsIter = null ; if ( schemaTable . getPrimaryKey ( ) . contains ( colName ) ) { PrimaryKey rowKey = schemaTable . createPrimaryKey ( ) ; NoSqlDBUtils . add ( schemaTable . getField ( colName ) , rowKey , colValue , colName ) ; rowsIter = tableAPI . tableIterator ( rowKey , null , null ) ; } else { Index index = schemaTable . getIndex ( colName ) ; IndexKey indexKey = index . createIndexKey ( ) ; NoSqlDBUtils . add ( schemaTable . getField ( colName ) , indexKey , colValue , colName ) ; rowsIter = tableAPI . tableIterator ( indexKey , null , null ) ; } try { Map < String , Object > relationMap = initialize ( entityMetadata ) ; return scrollAndPopulate ( null , entityMetadata , metamodel , schemaTable , rowsIter , relationMap , null ) ; } catch ( Exception e ) { log . error ( "Error while finding data for Key " + colName + ", Caused By :" + e + "." ) ; throw new PersistenceException ( e ) ; } }
Find by relational column name and value .
36,117
private void process ( Object entity , MetamodelImpl metamodel , Row row , Set < Attribute > attributes , Table schemaTable , EntityMetadata metadata ) { for ( Attribute attribute : attributes ) { if ( ! attribute . isAssociation ( ) ) { if ( attribute . equals ( metadata . getIdAttribute ( ) ) && metamodel . isEmbeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { processEmbeddableAttribute ( entity , metamodel , row , schemaTable , metadata , attribute ) ; } else { if ( metamodel . isEmbeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ) { processEmbeddableAttribute ( entity , metamodel , row , schemaTable , metadata , attribute ) ; } else { setField ( row , schemaTable , entity , attribute ) ; } } } } }
Iterate and store attributes .
36,118
private void processEmbeddableAttribute ( Object entity , MetamodelImpl metamodel , Row row , Table schemaTable , EntityMetadata metadata , Attribute attribute ) { EmbeddableType embeddable = metamodel . embeddable ( ( ( AbstractAttribute ) attribute ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddable . getAttributes ( ) ; Object embeddedObject = PropertyAccessorHelper . getObject ( entity , ( Field ) attribute . getJavaMember ( ) ) ; for ( Attribute embeddedAttrib : embeddedAttributes ) { setField ( row , schemaTable , embeddedObject , embeddedAttrib ) ; } }
Process embeddable attribute .
36,119
private void onRelationalAttributes ( List < RelationHolder > rlHolders , Row row , Table schemaTable ) { if ( rlHolders != null && ! rlHolders . isEmpty ( ) ) { for ( RelationHolder rh : rlHolders ) { String relationName = rh . getRelationName ( ) ; Object valueObj = rh . getRelationValue ( ) ; if ( ! StringUtils . isEmpty ( relationName ) && valueObj != null ) { if ( valueObj != null ) { NoSqlDBUtils . add ( schemaTable . getField ( relationName ) , row , valueObj , relationName ) ; KunderaCoreUtils . printQuery ( "Add relation: relation name:" + relationName + "relation value:" + valueObj , showQuery ) ; } } } } }
Process relational attributes .
36,120
private void addDiscriminatorColumn ( Row row , EntityType entityType , Table schemaTable ) { String discrColumn = ( ( AbstractManagedType ) entityType ) . getDiscriminatorColumn ( ) ; String discrValue = ( ( AbstractManagedType ) entityType ) . getDiscriminatorValue ( ) ; if ( discrColumn != null && discrValue != null ) { byte [ ] valueInBytes = PropertyAccessorHelper . getBytes ( discrValue ) ; NoSqlDBUtils . add ( schemaTable . getField ( discrColumn ) , row , discrValue , discrColumn ) ; } }
Process discriminator columns .
36,121
private void setField ( Row row , Table schemaTable , Object embeddedObject , Attribute embeddedAttrib ) { Field field = ( Field ) embeddedAttrib . getJavaMember ( ) ; FieldDef fieldDef = schemaTable . getField ( ( ( AbstractAttribute ) embeddedAttrib ) . getJPAColumnName ( ) ) ; Object valueObj = PropertyAccessorHelper . getObject ( embeddedObject , field ) ; if ( valueObj != null ) NoSqlDBUtils . add ( fieldDef , row , valueObj , ( ( AbstractAttribute ) embeddedAttrib ) . getJPAColumnName ( ) ) ; }
setter field .
36,122
private void populateId ( EntityMetadata entityMetadata , Table schemaTable , Object entity , Row row ) { FieldDef fieldMetadata ; FieldValue value ; String idColumnName = ( ( AbstractAttribute ) entityMetadata . getIdAttribute ( ) ) . getJPAColumnName ( ) ; fieldMetadata = schemaTable . getField ( idColumnName ) ; value = row . get ( idColumnName ) ; NoSqlDBUtils . get ( fieldMetadata , value , entity , ( Field ) entityMetadata . getIdAttribute ( ) . getJavaMember ( ) ) ; }
Populate id .
36,123
private void onEmbeddableId ( EntityMetadata entityMetadata , MetamodelImpl metaModel , Table schemaTable , Object entity , Row row ) throws InstantiationException , IllegalAccessException { FieldDef fieldMetadata ; FieldValue value ; EmbeddableType embeddableType = metaModel . embeddable ( entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddableType . getAttributes ( ) ; Object embeddedObject = entityMetadata . getIdAttribute ( ) . getBindableJavaType ( ) . newInstance ( ) ; for ( Attribute attrib : embeddedAttributes ) { String columnName = ( ( AbstractAttribute ) attrib ) . getJPAColumnName ( ) ; fieldMetadata = schemaTable . getField ( columnName ) ; value = row . get ( columnName ) ; NoSqlDBUtils . get ( fieldMetadata , value , embeddedObject , ( Field ) attrib . getJavaMember ( ) ) ; } PropertyAccessorHelper . set ( entity , ( Field ) entityMetadata . getIdAttribute ( ) . getJavaMember ( ) , embeddedObject ) ; }
On embeddable id .
36,124
private Object initializeEntity ( Object key , EntityMetadata entityMetadata ) throws InstantiationException , IllegalAccessException { Object entity = null ; entity = entityMetadata . getEntityClazz ( ) . newInstance ( ) ; if ( key != null ) { PropertyAccessorHelper . setId ( entity , entityMetadata , key ) ; } return entity ; }
Initialize entity .
36,125
private < E > List < E > onIndexSearch ( OracleNoSQLQueryInterpreter interpreter , EntityMetadata entityMetadata , MetamodelImpl metamodel , List < E > results , List < String > columnsToSelect ) { Map < String , List > indexes = new HashMap < String , List > ( ) ; StringBuilder indexNamebuilder = new StringBuilder ( ) ; for ( Object clause : interpreter . getClauseQueue ( ) ) { if ( clause . getClass ( ) . isAssignableFrom ( FilterClause . class ) ) { String fieldName = null ; String clauseName = ( ( FilterClause ) clause ) . getProperty ( ) ; StringTokenizer stringTokenizer = new StringTokenizer ( clauseName , "." ) ; if ( stringTokenizer . countTokens ( ) > 1 ) { fieldName = stringTokenizer . nextToken ( ) ; } fieldName = stringTokenizer . nextToken ( ) ; Object value = ( ( FilterClause ) clause ) . getValue ( ) ; if ( ! indexes . containsKey ( fieldName ) ) { indexNamebuilder . append ( fieldName ) ; indexNamebuilder . append ( "," ) ; } indexes . put ( fieldName , ( List ) value ) ; } else { if ( clause . toString ( ) . equalsIgnoreCase ( "OR" ) ) { throw new QueryHandlerException ( "OR clause is not supported with oracle nosql db" ) ; } } } Table schemaTable = tableAPI . getTable ( entityMetadata . getTableName ( ) ) ; String indexKeyName = indexNamebuilder . deleteCharAt ( indexNamebuilder . length ( ) - 1 ) . toString ( ) ; Index index = schemaTable . getIndex ( entityMetadata . getIndexProperties ( ) . get ( indexKeyName ) . getName ( ) ) ; IndexKey indexKey = index . createIndexKey ( ) ; for ( String indexName : indexes . keySet ( ) ) { NoSqlDBUtils . add ( schemaTable . getField ( indexName ) , indexKey , indexes . get ( indexName ) . get ( 0 ) , indexName ) ; } Iterator < Row > rowsIter = tableAPI . tableIterator ( indexKey , null , null ) ; Map < String , Object > relationMap = initialize ( entityMetadata ) ; try { results = scrollAndPopulate ( null , entityMetadata , metamodel , schemaTable , rowsIter , relationMap , columnsToSelect ) ; KunderaCoreUtils . printQueryWithFilterClause ( interpreter . getClauseQueue ( ) , entityMetadata . getTableName ( ) ) ; } catch ( Exception e ) { log . error ( "Error while finding records , Caused By :" + e + "." ) ; throw new PersistenceException ( e ) ; } return results ; }
On index search .
36,126
private Row createRow ( EntityMetadata entityMetadata , Object entity , Object id , List < RelationHolder > rlHolders ) { String schema = entityMetadata . getSchema ( ) ; String table = entityMetadata . getTableName ( ) ; MetamodelImpl metamodel = ( MetamodelImpl ) KunderaMetadataManager . getMetamodel ( kunderaMetadata , entityMetadata . getPersistenceUnit ( ) ) ; Table schemaTable = null ; try { schemaTable = tableAPI . getTable ( table ) ; if ( schemaTable == null ) { log . error ( "No table found for " + table ) ; throw new KunderaException ( "No table found for " + table ) ; } } catch ( FaultException ex ) { log . error ( "Error while getting table " + table + ". Caused By: " , ex ) ; throw new KunderaException ( "Error while getting table " + table + ". Caused By: " , ex ) ; } Row row = schemaTable . createRow ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Persisting data into " + schema + "." + table + " for " + id ) ; } EntityType entityType = metamodel . entity ( entityMetadata . getEntityClazz ( ) ) ; Set < Attribute > attributes = entityType . getAttributes ( ) ; process ( entity , metamodel , row , attributes , schemaTable , entityMetadata ) ; onRelationalAttributes ( rlHolders , row , schemaTable ) ; addDiscriminatorColumn ( row , entityType , schemaTable ) ; return row ; }
Creates the row .
36,127
private boolean eligibleToFetch ( List < String > columnsToSelect , String columnName ) { return ( columnsToSelect != null && ! columnsToSelect . isEmpty ( ) && columnsToSelect . contains ( columnName ) ) || ( columnsToSelect == null || columnsToSelect . isEmpty ( ) ) ; }
Eligible to fetch .
36,128
List createAndExecuteQuery ( CouchDBQueryInterpreter interpreter ) { EntityMetadata m = interpreter . getMetadata ( ) ; List results = new ArrayList ( ) ; try { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; StringBuilder q = new StringBuilder ( ) ; String _id = CouchDBConstants . URL_SEPARATOR + m . getSchema ( ) . toLowerCase ( ) + CouchDBConstants . URL_SEPARATOR + CouchDBConstants . DESIGN + m . getTableName ( ) + CouchDBConstants . VIEW ; if ( ( interpreter . isIdQuery ( ) && ! interpreter . isRangeQuery ( ) && interpreter . getOperator ( ) == null ) || interpreter . isQueryOnCompositeKey ( ) ) { Object object = null ; if ( metaModel . isEmbeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ) { EmbeddableType embeddableType = metaModel . embeddable ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) ; if ( KunderaCoreUtils . countNonSyntheticFields ( m . getIdAttribute ( ) . getBindableJavaType ( ) ) == interpreter . getKeyValues ( ) . size ( ) ) { Object key = CouchDBObjectMapper . getObjectFromJson ( gson . toJsonTree ( interpreter . getKeyValues ( ) ) . getAsJsonObject ( ) , m . getIdAttribute ( ) . getBindableJavaType ( ) , embeddableType . getAttributes ( ) ) ; object = find ( m . getEntityClazz ( ) , key ) ; if ( object != null ) { results . add ( object ) ; } return results ; } else if ( m . getIdAttribute ( ) . getName ( ) . equals ( interpreter . getKeyName ( ) ) && interpreter . getKeyValues ( ) . size ( ) == 1 ) { object = find ( m . getEntityClazz ( ) , interpreter . getKeyValue ( ) ) ; if ( object != null ) { results . add ( object ) ; } return results ; } else { log . error ( "There should be each and every field of composite key." ) ; throw new QueryHandlerException ( "There should be each and every field of composite key." ) ; } } object = find ( m . getEntityClazz ( ) , interpreter . getKeyValue ( ) ) ; if ( object != null ) { results . add ( object ) ; } return results ; } _id = createQuery ( interpreter , m , q , _id ) ; if ( interpreter . getLimit ( ) > 0 ) { q . append ( "&limit=" + interpreter . getLimit ( ) ) ; } if ( interpreter . isDescending ( ) ) { q . append ( "&descending=" + false ) ; } executeQueryAndGetResults ( q , _id , m , results , interpreter ) ; } catch ( Exception e ) { log . error ( "Error while executing query, Caused by {}." , e ) ; throw new KunderaException ( e ) ; } return results ; }
Creates the and execute query .
36,129
void executeQueryAndGetResults ( StringBuilder q , String _id , EntityMetadata m , List results , CouchDBQueryInterpreter interpreter ) throws IOException , URISyntaxException , ClientProtocolException { HttpResponse response = null ; try { response = getResponse ( q , _id ) ; JsonArray array = getJsonFromResponse ( response ) ; if ( interpreter != null && interpreter . isAggregation ( ) ) { setAggregatedValuesInResult ( results , interpreter , array ) ; } else if ( interpreter != null && interpreter . getColumns ( ) != null && interpreter . getColumns ( ) . length != 0 ) { setSpecificFieldsInResult ( interpreter . getColumnsToOutput ( ) , m , results , array ) ; } else { setEntitiesInResult ( m , results , array ) ; } } finally { CouchDBUtils . closeContent ( response ) ; } }
Execute query and get results .
36,130
private void setAggregatedValuesInResult ( List results , CouchDBQueryInterpreter interpreter , JsonArray array ) { for ( JsonElement json : array ) { JsonElement value = json . getAsJsonObject ( ) . get ( "value" ) ; if ( interpreter . getAggregationType ( ) . equals ( CouchDBConstants . COUNT ) ) results . add ( value . getAsInt ( ) ) ; else results . add ( value . getAsDouble ( ) ) ; } }
Sets the aggregated values in result .
36,131
private void setSpecificFieldsInResult ( List < Map < String , Object > > columnsToOutput , EntityMetadata m , List results , JsonArray array ) { Map < String , Class > colNameToJavaType = new HashMap < String , Class > ( ) ; for ( Map < String , Object > map : columnsToOutput ) { colNameToJavaType . put ( ( String ) map . get ( Constants . COL_NAME ) , ( Class ) map . get ( Constants . FIELD_CLAZZ ) ) ; } Map < String , List < Object > > outputResults = new HashMap < String , List < Object > > ( ) ; for ( JsonElement element : array ) { String column = element . getAsJsonObject ( ) . get ( "key" ) . getAsString ( ) ; String value = element . getAsJsonObject ( ) . get ( "value" ) . getAsString ( ) ; String id = element . getAsJsonObject ( ) . get ( "id" ) . getAsString ( ) ; Object obj = PropertyAccessorHelper . fromSourceToTargetClass ( colNameToJavaType . get ( column ) , String . class , value ) ; if ( colNameToJavaType . size ( ) > 1 ) { if ( ! outputResults . containsKey ( id ) ) { outputResults . put ( id , new ArrayList < Object > ( ) ) ; } outputResults . get ( id ) . add ( obj ) ; } else { results . add ( obj ) ; } } if ( colNameToJavaType . size ( ) > 1 ) { results . addAll ( outputResults . values ( ) ) ; } }
Sets the specific fields in result .
36,132
private void setEntitiesInResult ( EntityMetadata m , List results , JsonArray array ) { for ( JsonElement element : array ) { String id = element . getAsJsonObject ( ) . get ( "value" ) . getAsJsonObject ( ) . get ( ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getJPAColumnName ( ) ) . getAsString ( ) ; Object entityFromJson = CouchDBObjectMapper . getEntityFromJson ( m . getEntityClazz ( ) , m , element . getAsJsonObject ( ) . get ( "value" ) . getAsJsonObject ( ) , m . getRelationNames ( ) , kunderaMetadata ) ; if ( entityFromJson != null && ( m . getTableName ( ) . concat ( id ) ) . equals ( element . getAsJsonObject ( ) . get ( "id" ) . getAsString ( ) ) ) { results . add ( entityFromJson ) ; } } }
Sets the entities in result .
36,133
private JsonArray getJsonFromResponse ( HttpResponse response ) throws IOException { InputStream content = response . getEntity ( ) . getContent ( ) ; Reader reader = new InputStreamReader ( content ) ; JsonObject json = gson . fromJson ( reader , JsonObject . class ) ; JsonElement jsonElement = json . get ( "rows" ) ; return jsonElement == null ? null : jsonElement . getAsJsonArray ( ) ; }
Gets the json from response .
36,134
public static synchronized LuceneIndexer getInstance ( String lucDirPath ) { if ( indexer == null && lucDirPath != null ) { indexer = new LuceneIndexer ( lucDirPath ) ; } return indexer ; }
Gets the single instance of LuceneIndexer .
36,135
private IndexReader getIndexReader ( ) { if ( reader == null ) { try { if ( ! isInitialized ) { Directory sourceDir = FSDirectory . open ( getIndexDirectory ( ) . toPath ( ) ) ; copy ( sourceDir , index ) ; isInitialized = true ; } reader = DirectoryReader . open ( index ) ; } catch ( IndexNotFoundException infex ) { log . warn ( "No index found in given directory, caused by:" , infex . getMessage ( ) ) ; } catch ( Exception e ) { log . error ( "Error while instantiating LuceneIndexer, Caused by :." , e ) ; throw new LuceneIndexingException ( e ) ; } } return reader ; }
Returns default index reader .
36,136
private File getIndexDirectory ( ) { File file = new File ( luceneDirPath ) ; if ( ! file . isDirectory ( ) ) { file . mkdir ( ) ; } return file ; }
Creates a Lucene index directory if it does not exist .
36,137
public void prepareEmbeddedId ( TopDocs docs , Map < String , Object > indexCol , IndexSearcher searcher , EntityMetadata metadata , MetamodelImpl metaModel ) { try { for ( ScoreDoc sc : docs . scoreDocs ) { Document doc = searcher . doc ( sc . doc ) ; Map < String , Object > embeddedIdFields = new HashMap < String , Object > ( ) ; EmbeddableType embeddableId = metaModel . embeddable ( metadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddableId . getAttributes ( ) ; prepareEmbeddedIdFields ( embeddedAttributes , metaModel , embeddedIdFields , doc , metadata ) ; String entityId = doc . get ( IndexingConstants . ENTITY_ID_FIELD ) ; indexCol . put ( entityId , embeddedIdFields ) ; } } catch ( Exception e ) { log . error ( "Error while parsing Lucene Query {} " , e ) ; throw new LuceneIndexingException ( e ) ; } }
search the data from lucene for embeddedid
36,138
private void flushInternal ( ) { try { if ( w != null && readyForCommit ) { w . commit ( ) ; copy ( index , FSDirectory . open ( getIndexDirectory ( ) . toPath ( ) ) ) ; readyForCommit = false ; reader = null ; isInitialized = false ; } } catch ( Exception e ) { log . error ( "Error while Flushing Lucene Indexes, Caused by: " , e ) ; throw new LuceneIndexingException ( "Error while Flushing Lucene Indexes" , e ) ; } }
Flush internal .
36,139
public void close ( ) { try { if ( w != null && readyForCommit ) { w . commit ( ) ; copy ( index , FSDirectory . open ( getIndexDirectory ( ) . toPath ( ) ) ) ; } } catch ( Exception e ) { log . error ( "Error while closing lucene indexes, Caused by: " , e ) ; throw new LuceneIndexingException ( "Error while closing lucene indexes." , e ) ; } }
Close of transaction .
36,140
private Document indexDocument ( EntityMetadata metadata , final MetamodelImpl metaModel , Object object , String parentId , Class < ? > clazz ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Indexing @Entity[{}],{} " , metadata . getEntityClazz ( ) . getName ( ) , object ) ; } Document currentDoc = updateOrCreateIndex ( metadata , metaModel , object , parentId , clazz , false ) ; return currentDoc ; }
Index document .
36,141
private Document updateOrCreateIndexNonSuperColumnFamily ( EntityMetadata metadata , final MetamodelImpl metaModel , Object entity , String parentId , Class < ? > clazz , boolean isUpdate , boolean isEmbeddedId , Object rowKey ) { Document document = new Document ( ) ; addEntityClassToDocument ( metadata , entity , document , metaModel ) ; addEntityFieldsToDocument ( metadata , entity , document , metaModel ) ; addAssociatedEntitiesToDocument ( metadata , entity , document , metaModel ) ; addParentKeyToDocument ( parentId , document , clazz ) ; if ( isUpdate ) { if ( isEmbeddedId ) { String compositeId = KunderaCoreUtils . prepareCompositeKey ( metadata . getIdAttribute ( ) , metaModel , rowKey ) ; updateDocument ( compositeId , document , null ) ; EmbeddableType embeddableId = metaModel . embeddable ( metadata . getIdAttribute ( ) . getBindableJavaType ( ) ) ; Set < Attribute > embeddedAttributes = embeddableId . getAttributes ( ) ; updateOrCreateIndexEmbeddedIdFields ( embeddedAttributes , metaModel , document , metadata , rowKey ) ; } else { updateDocument ( rowKey . toString ( ) , document , null ) ; } } else { indexDocument ( metadata , document ) ; } return document ; }
update or Create Index for non super columnfamily
36,142
private Document updateOrCreateIndexCollectionTypeEmbeddedObject ( EntityMetadata metadata , final MetamodelImpl metaModel , Object entity , String parentId , Class < ? > clazz , boolean isUpdate , Document document , Object embeddedObject , Object rowKey , String attributeName , EmbeddableType embeddableAttribute ) { ElementCollectionCacheManager ecCacheHandler = ElementCollectionCacheManager . getInstance ( ) ; if ( ecCacheHandler . isCacheEmpty ( ) ) { int count = 0 ; for ( Object obj : ( Collection < ? > ) embeddedObject ) { String elementCollectionObjectName = attributeName + Constants . EMBEDDED_COLUMN_NAME_DELIMITER + count ; document = prepareDocumentForSuperColumn ( metadata , entity , elementCollectionObjectName , parentId , clazz ) ; createSuperColumnDocument ( metadata , entity , document , obj , embeddableAttribute , metaModel ) ; if ( isUpdate ) { updateDocument ( parentId , document , null ) ; } else { indexDocument ( metadata , document ) ; } count ++ ; } } else { int lastEmbeddedObjectCount = ecCacheHandler . getLastElementCollectionObjectCount ( rowKey ) ; for ( Object obj : ( Collection < ? > ) embeddedObject ) { document = indexCollectionObject ( metadata , entity , parentId , clazz , isUpdate , rowKey , attributeName , embeddableAttribute , ecCacheHandler , lastEmbeddedObjectCount , obj , metaModel ) ; } } return document ; }
update or create indexes when embedded object is of collection type
36,143
private void updateDocument ( EntityMetadata metadata , final MetamodelImpl metaModel , Object entity , String parentId , Class < ? extends Object > class1 , boolean b ) { updateOrCreateIndex ( metadata , metaModel , entity , parentId , entity . getClass ( ) , true ) ; onCommit ( ) ; }
Updates document .
36,144
private String appendRange ( final String value , final boolean inclusive , final boolean isGreaterThan , final Class clazz ) { String appender = " " ; StringBuilder sb = new StringBuilder ( ) ; sb . append ( ":" ) ; sb . append ( inclusive ? "[" : "{" ) ; sb . append ( isGreaterThan ? value : "*" ) ; sb . append ( appender ) ; sb . append ( "TO" ) ; sb . append ( appender ) ; if ( clazz != null && ( clazz . isAssignableFrom ( int . class ) || clazz . isAssignableFrom ( Integer . class ) || clazz . isAssignableFrom ( short . class ) || clazz . isAssignableFrom ( long . class ) || clazz . isAssignableFrom ( Timestamp . class ) || clazz . isAssignableFrom ( Long . class ) || clazz . isAssignableFrom ( float . class ) || clazz . isAssignableFrom ( Float . class ) || clazz . isAssignableFrom ( BigDecimal . class ) || clazz . isAssignableFrom ( Double . class ) || clazz . isAssignableFrom ( double . class ) ) ) { sb . append ( isGreaterThan ? "*" : value ) ; } else { sb . append ( isGreaterThan ? "null" : value ) ; } sb . append ( inclusive ? "]" : "}" ) ; return sb . toString ( ) ; }
Append range .
36,145
public static final Object deepCopy ( Object source , final KunderaMetadata kunderaMetadata ) { Map < Object , Object > copiedObjectMap = new HashMap < Object , Object > ( ) ; Object target = deepCopyUsingMetadata ( source , copiedObjectMap , kunderaMetadata ) ; copiedObjectMap . clear ( ) ; copiedObjectMap = null ; return target ; }
Deep copy .
36,146
private static Object searchInCacheThenCopy ( Map < Object , Object > copiedObjectMap , Object sourceObject , final KunderaMetadata kunderaMetadata ) { Object copyTargetRelObj = null ; copyTargetRelObj = deepCopyUsingMetadata ( sourceObject , copiedObjectMap , kunderaMetadata ) ; return copyTargetRelObj ; }
Search in cache then copy .
36,147
public static Object getFieldInstance ( List chids , Field f ) { if ( Set . class . isAssignableFrom ( f . getType ( ) ) ) { Set col = new HashSet ( chids ) ; return col ; } return chids ; }
Gets the field instance .
36,148
public Object getEntityFromGFSDBFile ( Class < ? > entityClazz , Object entity , EntityMetadata m , GridFSDBFile outputFile , KunderaMetadata kunderaMetadata ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; String id = ( ( AbstractAttribute ) m . getIdAttribute ( ) ) . getJPAColumnName ( ) ; Object rowKey = ( ( DBObject ) outputFile . get ( MongoDBUtils . METADATA ) ) . get ( id ) ; Class < ? > rowKeyValueClass = rowKey . getClass ( ) ; Class < ? > idClass = m . getIdAttribute ( ) . getJavaType ( ) ; rowKey = MongoDBUtils . populateValue ( rowKey , idClass ) ; rowKey = MongoDBUtils . getTranslatedObject ( rowKey , rowKeyValueClass , idClass ) ; PropertyAccessorHelper . setId ( entity , m , rowKey ) ; EntityType entityType = metaModel . entity ( entityClazz ) ; Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { boolean isLob = ( ( Field ) column . getJavaMember ( ) ) . getAnnotation ( Lob . class ) != null ; if ( isLob ) { if ( column . getJavaType ( ) . isAssignableFrom ( byte [ ] . class ) ) { InputStream is = outputFile . getInputStream ( ) ; try { PropertyAccessorHelper . set ( entity , ( Field ) column . getJavaMember ( ) , ByteStreams . toByteArray ( is ) ) ; } catch ( IOException e ) { log . error ( "Error while converting inputstream from GridFSDBFile to byte array, Caused by: " , e ) ; throw new KunderaException ( "Error while converting inputstream from GridFSDBFile to byte array, Caused by: " , e ) ; } } } else if ( ! column . equals ( m . getIdAttribute ( ) ) ) DocumentObjectMapper . setFieldValue ( outputFile , entity , column , true ) ; } return entity ; }
Gets the entity from GFSDBFile .
36,149
public Map < String , DBObject > getDocumentFromEntity ( EntityMetadata m , Object entity , List < RelationHolder > relations , final KunderaMetadata kunderaMetadata ) throws PropertyAccessException { Map < String , DBObject > dbObjects = new HashMap < String , DBObject > ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; Object id = PropertyAccessorHelper . getId ( entity , m ) ; DBObject dbObj = MongoDBUtils . getDBObject ( m , m . getTableName ( ) , dbObjects , metaModel , id ) ; Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { if ( ! column . equals ( m . getIdAttribute ( ) ) ) { try { Class javaType = ( ( AbstractAttribute ) column ) . getBindableJavaType ( ) ; if ( metaModel . isEmbeddable ( javaType ) ) { Map < String , DBObject > embeddedObjects = onEmbeddable ( column , entity , metaModel , dbObj , m . getTableName ( ) ) ; for ( String documentName : embeddedObjects . keySet ( ) ) { DBObject db = dbObjects . get ( documentName ) ; if ( db == null ) { db = MongoDBUtils . getDBObject ( m , documentName , dbObjects , metaModel , id ) ; } db . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , embeddedObjects . get ( documentName ) ) ; dbObjects . put ( documentName , db ) ; } } else if ( ! column . isAssociation ( ) ) { DocumentObjectMapper . extractFieldValue ( entity , dbObj , column ) ; } } catch ( PropertyAccessException paex ) { log . error ( "Can't access property " + column . getName ( ) ) ; } } } if ( relations != null ) { dbObj = dbObjects . get ( m . getTableName ( ) ) ; for ( RelationHolder rh : relations ) { dbObj . put ( rh . getRelationName ( ) , MongoDBUtils . populateValue ( rh . getRelationValue ( ) , rh . getRelationValue ( ) . getClass ( ) ) ) ; } } if ( ( ( AbstractManagedType ) entityType ) . isInherited ( ) ) { dbObj = dbObjects . get ( m . getTableName ( ) ) ; String discrColumn = ( ( AbstractManagedType ) entityType ) . getDiscriminatorColumn ( ) ; String discrValue = ( ( AbstractManagedType ) entityType ) . getDiscriminatorValue ( ) ; if ( discrColumn != null && discrValue != null ) { dbObj . put ( discrColumn , discrValue ) ; } } return dbObjects ; }
Gets the document from entity .
36,150
public GridFSInputFile getGFSInputFileFromEntity ( GridFS gfs , EntityMetadata m , Object entity , KunderaMetadata kunderaMetadata , boolean isUpdate ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; GridFSInputFile gridFSInputFile = null ; DBObject gfsMetadata = new BasicDBObject ( ) ; Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { boolean isLob = ( ( Field ) column . getJavaMember ( ) ) . getAnnotation ( Lob . class ) != null ; if ( isLob ) { gridFSInputFile = createGFSInputFile ( gfs , entity , ( Field ) column . getJavaMember ( ) ) ; gridFSInputFile . setFilename ( column . getName ( ) ) ; } else { if ( isUpdate && column . getName ( ) . equals ( m . getIdAttribute ( ) . getName ( ) ) ) { gfsMetadata . put ( ( ( AbstractAttribute ) column ) . getJPAColumnName ( ) , new ObjectId ( ) ) ; } else DocumentObjectMapper . extractFieldValue ( entity , gfsMetadata , column ) ; } } gridFSInputFile . setMetaData ( gfsMetadata ) ; return gridFSInputFile ; }
Gets the GFSInputFile from entity .
36,151
private GridFSInputFile createGFSInputFile ( GridFS gfs , Object entity , Field f ) { Object obj = PropertyAccessorHelper . getObject ( entity , f ) ; GridFSInputFile gridFSInputFile = null ; if ( f . getType ( ) . isAssignableFrom ( byte [ ] . class ) ) gridFSInputFile = gfs . createFile ( ( byte [ ] ) obj ) ; else if ( f . getType ( ) . isAssignableFrom ( File . class ) ) { try { gridFSInputFile = gfs . createFile ( ( File ) obj ) ; } catch ( IOException e ) { log . error ( "Error while creating GridFS file for \"" + f . getName ( ) + "\". Caused by: " , e ) ; throw new KunderaException ( "Error while creating GridFS file for \"" + f . getName ( ) + "\". Caused by: " , e ) ; } } else new UnsupportedOperationException ( f . getType ( ) . getSimpleName ( ) + " is unsupported Lob object" ) ; return gridFSInputFile ; }
Creates the GFS Input file .
36,152
public Object getLobFromGFSEntity ( GridFS gfs , EntityMetadata m , Object entity , KunderaMetadata kunderaMetadata ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { boolean isLob = ( ( Field ) column . getJavaMember ( ) ) . getAnnotation ( Lob . class ) != null ; if ( isLob ) { return PropertyAccessorHelper . getObject ( entity , ( Field ) column . getJavaMember ( ) ) ; } } return null ; }
Gets the lob from GFS entity .
36,153
public DBObject getMetadataFromGFSEntity ( GridFS gfs , EntityMetadata m , Object entity , KunderaMetadata kunderaMetadata ) { MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entityType = metaModel . entity ( m . getEntityClazz ( ) ) ; DBObject gfsMetadata = new BasicDBObject ( ) ; Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { boolean isLob = ( ( Field ) column . getJavaMember ( ) ) . getAnnotation ( Lob . class ) != null ; if ( ! isLob ) { DocumentObjectMapper . extractFieldValue ( entity , gfsMetadata , column ) ; } } return gfsMetadata ; }
Gets the metadata from GFS entity .
36,154
@ SuppressWarnings ( { "UnusedReturnValue" , "WeakerAccess" } ) public PagerFragment addFragment ( String title , Fragment fragment ) { this . mFragmentTitles . add ( title ) ; this . mFragments . add ( fragment ) ; return this ; }
Add a Fragment to this PagerFragment .
36,155
public static Style red ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_RED ) ; return style ; }
Default material red transparent style for SuperToasts .
36,156
public static Style pink ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_PINK ) ; return style ; }
Default material pink transparent style for SuperToasts .
36,157
public static Style purple ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_PURPLE ) ; return style ; }
Default material purple transparent style for SuperToasts .
36,158
public static Style deepPurple ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_DEEP_PURPLE ) ; return style ; }
Default material deep purple transparent style for SuperToasts .
36,159
public static Style indigo ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_INDIGO ) ; return style ; }
Default material indigo transparent style for SuperToasts .
36,160
public static Style blue ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BLUE ) ; return style ; }
Default material blue transparent style for SuperToasts .
36,161
public static Style lightBlue ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_LIGHT_BLUE ) ; return style ; }
Default material light blue transparent style for SuperToasts .
36,162
public static Style cyan ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_CYAN ) ; return style ; }
Default material cyan transparent style for SuperToasts .
36,163
public static Style teal ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_TEAL ) ; return style ; }
Default material teal transparent style for SuperToasts .
36,164
public static Style green ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_GREEN ) ; return style ; }
Default material green transparent style for SuperToasts .
36,165
public static Style lightGreen ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_LIGHT_GREEN ) ; return style ; }
Default material light green transparent style for SuperToasts .
36,166
public static Style lime ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_LIME ) ; style . messageTextColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; style . buttonDividerColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; style . buttonTextColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; return style ; }
Default material lime transparent style for SuperToasts .
36,167
public static Style yellow ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_YELLOW ) ; style . messageTextColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; style . buttonDividerColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; style . buttonTextColor = PaletteUtils . getSolidColor ( PaletteUtils . DARK_GREY ) ; return style ; }
Default material yellow transparent style for SuperToasts .
36,168
public static Style amber ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_AMBER ) ; return style ; }
Default material amber transparent style for SuperToasts .
36,169
public static Style orange ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_ORANGE ) ; return style ; }
Default material orange transparent style for SuperToasts .
36,170
public static Style deepOrange ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_DEEP_ORANGE ) ; return style ; }
Default material deep orange transparent style for SuperToasts .
36,171
public static Style brown ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BROWN ) ; return style ; }
Default material brown transparent style for SuperToasts .
36,172
public static Style grey ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_GREY ) ; return style ; }
Default material grey transparent style for SuperToasts .
36,173
public static Style blueGrey ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BLUE_GREY ) ; return style ; }
Default material blue - grey transparent style for SuperToasts .
36,174
public static Style rottenBanana ( ) { final Style style = new Style ( ) ; style . color = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_YELLOW ) ; style . frame = FRAME_LOLLIPOP ; style . messageTextColor = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BROWN ) ; style . buttonDividerColor = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BROWN ) ; style . buttonTextColor = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BROWN ) ; style . priorityColor = PaletteUtils . getSolidColor ( PaletteUtils . MATERIAL_BROWN ) ; return style ; }
Default material rotten banana transparent style for SuperToasts .
36,175
public SuperActivityToast setProgress ( int progress ) { if ( this . mProgressBar == null ) { Log . e ( getClass ( ) . getName ( ) , "Could not set SuperActivityToast " + "progress, are you sure you set the type to TYPE_PROGRESS_CIRCLE " + "or TYPE_PROGRESS_BAR?" ) ; return this ; } this . mStyle . progress = progress ; this . mProgressBar . setProgress ( progress ) ; return this ; }
Set the progress of the ProgressBar in a TYPE_PROGRESS_BAR SuperActivityToast . This can be called multiple times after the SuperActivityToast is showing .
36,176
@ SuppressLint ( "InflateParams" ) protected View onCreateView ( Context context , LayoutInflater layoutInflater , int type ) { return layoutInflater . inflate ( R . layout . supertoast , null ) ; }
Protected View that is overridden by the SuperActivityToast class .
36,177
public static int convertToDIP ( int pixels ) { return Math . round ( TypedValue . applyDimension ( TypedValue . COMPLEX_UNIT_DIP , pixels , Resources . getSystem ( ) . getDisplayMetrics ( ) ) ) ; }
Returns a density independent pixel value rounded to the nearest integer for the desired dimension .
36,178
private void showNextSuperToast ( ) { if ( superToastPriorityQueue . isEmpty ( ) ) return ; final SuperToast superToast = superToastPriorityQueue . peek ( ) ; if ( ! superToast . isShowing ( ) ) { final Message message = obtainMessage ( Messages . DISPLAY_SUPERTOAST ) ; message . obj = superToast ; sendMessage ( message ) ; } }
Show the next SuperToast in the current queue . If a SuperToast is currently showing do nothing . The currently showing SuperToast will call this method when it dismisses .
36,179
private void sendDelayedMessage ( SuperToast superToast , int messageId , long delay ) { Message message = obtainMessage ( messageId ) ; message . obj = superToast ; sendMessageDelayed ( message , delay ) ; }
Send a message at a later time . This is used to dismiss a SuperToast .
36,180
private void displaySuperToast ( SuperToast superToast ) { if ( superToast . isShowing ( ) ) return ; if ( superToast instanceof SuperActivityToast ) { if ( ( ( SuperActivityToast ) superToast ) . getViewGroup ( ) == null ) { Log . e ( getClass ( ) . getName ( ) , ERROR_SAT_VIEWGROUP_NULL ) ; return ; } try { ( ( SuperActivityToast ) superToast ) . getViewGroup ( ) . addView ( superToast . getView ( ) ) ; if ( ! ( ( SuperActivityToast ) superToast ) . isFromOrientationChange ( ) ) { AnimationUtils . getShowAnimation ( ( SuperActivityToast ) superToast ) . start ( ) ; } } catch ( IllegalStateException illegalStateException ) { Log . e ( getClass ( ) . getName ( ) , illegalStateException . toString ( ) ) ; } if ( ! ( ( SuperActivityToast ) superToast ) . isIndeterminate ( ) ) { sendDelayedMessage ( superToast , Messages . REMOVE_SUPERTOAST , superToast . getDuration ( ) + AnimationUtils . SHOW_DURATION ) ; } } else { final WindowManager windowManager = ( WindowManager ) superToast . getContext ( ) . getApplicationContext ( ) . getSystemService ( Context . WINDOW_SERVICE ) ; if ( windowManager != null ) { windowManager . addView ( superToast . getView ( ) , superToast . getWindowManagerParams ( ) ) ; } sendDelayedMessage ( superToast , Messages . REMOVE_SUPERTOAST , superToast . getDuration ( ) + AnimationUtils . SHOW_DURATION ) ; } }
Try to show the SuperToast . SuperToasts will be shown using the WindowManager while SuperActivityToasts will be shown using their supplied ViewGroup .
36,181
void removeSuperToast ( final SuperToast superToast ) { if ( superToast instanceof SuperActivityToast ) { if ( ! superToast . isShowing ( ) ) { this . superToastPriorityQueue . remove ( superToast ) ; return ; } final Animator animator = AnimationUtils . getHideAnimation ( ( SuperActivityToast ) superToast ) ; animator . addListener ( new Animator . AnimatorListener ( ) { public void onAnimationStart ( Animator animation ) { } public void onAnimationEnd ( Animator animation ) { if ( superToast . getOnDismissListener ( ) != null ) { superToast . getOnDismissListener ( ) . onDismiss ( superToast . getView ( ) , superToast . getStyle ( ) . dismissToken ) ; } ( ( SuperActivityToast ) superToast ) . getViewGroup ( ) . removeView ( superToast . getView ( ) ) ; Toaster . this . showNextSuperToast ( ) ; } public void onAnimationCancel ( Animator animation ) { } public void onAnimationRepeat ( Animator animation ) { } } ) ; animator . start ( ) ; } else { final WindowManager windowManager = ( WindowManager ) superToast . getContext ( ) . getSystemService ( Context . WINDOW_SERVICE ) ; if ( windowManager == null ) throw new IllegalStateException ( ERROR_ST_WINDOWMANAGER_NULL ) ; try { windowManager . removeView ( superToast . getView ( ) ) ; } catch ( IllegalArgumentException illegalArgumentException ) { Log . e ( getClass ( ) . getName ( ) , illegalArgumentException . toString ( ) ) ; } if ( superToast . getOnDismissListener ( ) != null ) { superToast . getOnDismissListener ( ) . onDismiss ( superToast . getView ( ) , superToast . getStyle ( ) . dismissToken ) ; } this . sendDelayedMessage ( superToast , Messages . SHOW_NEXT , AnimationUtils . HIDE_DURATION ) ; } superToastPriorityQueue . poll ( ) ; }
Removes a showing SuperToast . This method will poll the Queue as well as try to show the next SuperToast if one exists in the Queue .
36,182
public void create ( final T value ) throws SQLException { transactionTemplate . doInTransaction ( new SQLFunction < Connection , Object > ( ) { public Object apply ( Connection connection ) throws SQLException { delegate . create ( connection , value ) ; return null ; } } ) ; }
insert value into the db through the specified connection .
36,183
public void delete ( final Collection < K > keys ) throws SQLException { transactionTemplate . doInTransaction ( new SQLFunction < Connection , Object > ( ) { public Object apply ( Connection connection ) throws SQLException { delegate . delete ( connection , keys ) ; return null ; } } ) ; }
delete the objects with the specified keys .
36,184
public CsvWriter < T > append ( T value ) throws IOException { try { mapper . mapTo ( value , appendable , mappingContext ) ; } catch ( Exception e ) { ErrorHelper . rethrow ( e ) ; } return this ; }
write the specified value to the underlying appendable .
36,185
public final B addKey ( String column ) { return addMapping ( column , calculatedIndex ++ , FieldMapperColumnDefinition . < K > key ( ) ) ; }
add a new mapping to the specified property with a key property definition and an undefined type . The index is incremented for each non indexed property mapping .
36,186
@ SuppressWarnings ( "unchecked" ) public final B addMapper ( FieldMapper < ROW , T > mapper ) { setRowMapperBuilder . addMapper ( mapper ) ; return ( B ) this ; }
append a FieldMapper to the mapping list .
36,187
public JdbcMapperFactory getterFactory ( final GetterFactory < ResultSet , JdbcColumnKey > getterFactory ) { return addGetterFactory ( new ContextualGetterFactoryAdapter < ResultSet , JdbcColumnKey > ( getterFactory ) ) ; }
Override the default implementation of the GetterFactory used to get access to value from the ResultSet .
36,188
public JdbcMapperFactory addCustomFieldMapper ( String key , FieldMapper < ResultSet , ? > fieldMapper ) { return addColumnDefinition ( key , FieldMapperColumnDefinition . < JdbcColumnKey > customFieldMapperDefinition ( fieldMapper ) ) ; }
Associate the specified FieldMapper for the specified property .
36,189
public JdbcMapperFactory addCustomGetter ( String key , Getter < ResultSet , ? > getter ) { return addColumnDefinition ( key , FieldMapperColumnDefinition . < JdbcColumnKey > customGetter ( getter ) ) ; }
Associate the specified Getter for the specified property .
36,190
public < T > JdbcMapper < T > newMapper ( final Class < T > target , final ResultSetMetaData metaData ) throws SQLException { JdbcMapperBuilder < T > builder = newBuilder ( target ) ; builder . addMapping ( metaData ) ; return builder . mapper ( ) ; }
Will create a newInstance of JdbcMapper based on the specified metadata and the target class .
36,191
public < T > JdbcMapperBuilder < T > newBuilder ( final Class < T > target ) { return newBuilder ( ( Type ) target ) ; }
Will create a newInstance of JdbcMapperBuilder on the specified target class .
36,192
public < T > JdbcMapperBuilder < T > newBuilder ( final TypeReference < T > target ) { return newBuilder ( target . getType ( ) ) ; }
Will create a newInstance of JdbcMapperBuilder on the type T specified by the typeReference .
36,193
public < T > JdbcMapperBuilder < T > newBuilder ( final Type target ) { ClassMeta < T > classMeta = getClassMeta ( target ) ; return newBuilder ( classMeta ) ; }
Will create a newInstance of JdbcMapperBuilder on the specified type .
36,194
public < T > DynamicJdbcMapper < T > newMapper ( final Class < T > target ) { return newMapper ( ( Type ) target ) ; }
Will create a DynamicMapper on the specified target class .
36,195
public < T > DynamicJdbcMapper < T > newMapper ( final TypeReference < T > target ) { return newMapper ( target . getType ( ) ) ; }
Will create a DynamicMapper on the type specified by the TypeReference .
36,196
public < T > DynamicJdbcMapper < T > newMapper ( final Type target ) { final ClassMeta < T > classMeta = getClassMeta ( target ) ; return new DynamicJdbcSetRowMapper < T > ( new SetRowMapperFactory < T > ( classMeta ) , new MapperKeyFactory ( ) , new MapperKeyFactory ( ) ) ; }
Will create a DynamicMapper on the specified type .
36,197
public < T > DiscriminatorJdbcBuilder < T > newDiscriminator ( String column ) { ignorePropertyNotFound ( ) ; addColumnDefinition ( column , FieldMapperColumnDefinition . < JdbcColumnKey > ignoreDefinition ( ) ) ; return new DiscriminatorJdbcBuilder < T > ( column , this ) ; }
Create a discriminator builder based on the specified property
36,198
protected < P > void addMapping ( K columnKey , ColumnDefinition < K , ? > columnDefinition , PropertyMeta < T , P > prop ) { propertyMappingsBuilder . addProperty ( columnKey , columnDefinition , prop ) ; }
the keys are initialised
36,199
public DiscriminatorJdbcSubBuilder when ( String value , Type type ) { return when ( new DiscriminatorPredicate ( value ) , type ) ; }
Add a discriminator value with its associated type .