ByteBuffer getBytesValue ( String jpaFieldName , EntityMetadata m , Object value ) { Attribute idCol = m . getIdAttribute ( ) ; MetamodelImpl metaModel = ( MetamodelImpl ) kunderaMetadata . getApplicationMetadata ( ) . getMetamodel ( m . getPersistenceUnit ( ) ) ; EntityType entity = metaModel . entity ( m . getEntityClazz ( ) ) ; Field f = null ; boolean isId = false ; if ( ( ( AbstractAttribute ) idCol ) . getJPAColumnName ( ) . equals ( jpaFieldName ) ) { f = ( Field ) idCol . getJavaMember ( ) ; isId = true ; } else { if ( jpaFieldName != null && jpaFieldName . indexOf ( Constants . INDEX_TABLE_ROW_KEY_DELIMITER ) > 0 ) { String embeddedFieldName = jpaFieldName . substring ( 0 , jpaFieldName . indexOf ( Constants . INDEX_TABLE_ROW_KEY_DELIMITER ) ) ; String columnFieldName = jpaFieldName . substring ( jpaFieldName . indexOf ( Constants . INDEX_TABLE_ROW_KEY_DELIMITER ) + 1 , jpaFieldName . length ( ) ) ; Attribute embeddedAttr = entity . getAttribute ( embeddedFieldName ) ; try { Class < ? > embeddedClass = embeddedAttr . getJavaType ( ) ; if ( Collection . class . isAssignableFrom ( embeddedClass ) ) { Class < ? > genericClass = PropertyAccessorHelper . getGenericClass ( ( Field ) embeddedAttr . getJavaMember ( ) ) ; f = genericClass . getDeclaredField ( columnFieldName ) ; } else { f = embeddedClass . getDeclaredField ( columnFieldName ) ; } } catch ( SecurityException e ) { log . error ( "Error while extrating " + jpaFieldName + ", Caused by: " , e ) ; throw new QueryHandlerException ( "Error while extrating " + jpaFieldName + "." ) ; } catch ( NoSuchFieldException e ) { log . error ( "Error while extrating " + jpaFieldName + ", Caused by: " , e ) ; throw new QueryHandlerException ( "Error while extrating " + jpaFieldName + "." ) ; } } else { String discriminatorColumn = ( ( AbstractManagedType ) entity ) . getDiscriminatorColumn ( ) ; if ( ! jpaFieldName . equals ( discriminatorColumn ) ) { String fieldName = m . getFieldName ( jpaFieldName ) ; Attribute col = entity . getAttribute ( fieldName ) ; if ( col == null ) { throw new QueryHandlerException ( "column type is null for: " + jpaFieldName ) ; } f = ( Field ) col . getJavaMember ( ) ; } } } // need to do integer.parseInt..as value will be string in case of // create query. if ( f != null && f . getType ( ) != null ) { return CassandraUtilities . toBytes ( value , f ) ; } else { // default is String type return CassandraUtilities . toBytes ( value , String . class ) ; } }
Returns bytes value for given value .