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 ( ) ) ; // Populate Row Key Object id = PropertyAccessorHelper . getId ( entity , m ) ; DBObject dbObj = MongoDBUtils . getDBObject ( m , m . getTableName ( ) , dbObjects , metaModel , id ) ; // dbObjects.put(m.getTableName(), dbObj); // Populate columns Set < Attribute > columns = entityType . getAttributes ( ) ; for ( Attribute column : columns ) { // String tableName = ((AbstractAttribute) column).getTableName() != // null ? ((AbstractAttribute) column) // .getTableName() : m.getTableName(); // dbObj = MongoDBUtils.getDBObject(m, tableName, dbObjects, // metaModel, id); 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 ( ) ) ; } } // dbObjects.put(tableName, dbObj); } if ( relations != null ) { dbObj = dbObjects . get ( m . getTableName ( ) ) ; for ( RelationHolder rh : relations ) { dbObj . put ( rh . getRelationName ( ) , MongoDBUtils . populateValue ( rh . getRelationValue ( ) , rh . getRelationValue ( ) . getClass ( ) ) ) ; } // dbObjects.put(m.getTableName(), dbObj); } if ( ( ( AbstractManagedType ) entityType ) . isInherited ( ) ) { dbObj = dbObjects . get ( m . getTableName ( ) ) ; String discrColumn = ( ( AbstractManagedType ) entityType ) . getDiscriminatorColumn ( ) ; String discrValue = ( ( AbstractManagedType ) entityType ) . getDiscriminatorValue ( ) ; // No need to check for empty or blank, as considering it as valid // name for nosql! if ( discrColumn != null && discrValue != null ) { dbObj . put ( discrColumn , discrValue ) ; } // dbObjects.put(m.getTableName(), dbObj); } return dbObjects ; }
Gets the document from entity .