Package org.hibernate.ogm.datastore.couchdb.dialect.backend.json.impl

Examples of org.hibernate.ogm.datastore.couchdb.dialect.backend.json.impl.EntityDocument


  @Override
  public Map<String, Object> extractEntityTuple(SessionFactory sessionFactory, EntityKey key) {
    Map<String, Object> tupleMap = new HashMap<String, Object>();
    CouchDBDatastore dataStore = getDataStore( sessionFactory );
    EntityDocument entity = dataStore.getEntity( Identifier.createEntityId( key ) );
    CouchDBTupleSnapshot snapshot = new CouchDBTupleSnapshot( entity.getProperties() );
    Set<String> columnNames = snapshot.getColumnNames();
    for ( String columnName : columnNames ) {
      tupleMap.put( columnName, snapshot.get( columnName ) );
    }
    return tupleMap;
View Full Code Here


    return null;
  }

  @Override
  public Tuple getTuple(EntityKey key, TupleContext tupleContext) {
    EntityDocument entity = getDataStore().getEntity( Identifier.createEntityId( key ) );
    if ( entity != null ) {
      return new Tuple( new CouchDBTupleSnapshot( entity.getProperties() ) );
    }

    return null;
  }
View Full Code Here

    if ( revision == null && !snapshot.isCreatedOnInsert() ) {
      revision = getDataStore().getCurrentRevision( Identifier.createEntityId( key ), false );
    }

    // this will raise an optimistic locking exception if the revision is either null or not the current one
    getDataStore().saveDocument( new EntityDocument( key, revision, tuple ) );
  }
View Full Code Here

  @Override
  public Association getAssociation(AssociationKey key, AssociationContext associationContext) {
    CouchDBAssociation couchDBAssociation = null;

    if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) {
      EntityDocument owningEntity = getDataStore().getEntity( Identifier.createEntityId( key.getEntityKey() ) );
      if ( owningEntity != null && owningEntity.getProperties().containsKey( key.getMetadata().getCollectionRole() ) ) {
        couchDBAssociation = CouchDBAssociation.fromEmbeddedAssociation( owningEntity, key.getMetadata().getCollectionRole() );
      }
    }
    else {
      AssociationDocument association = getDataStore().getAssociation( Identifier.createAssociationId( key ) );
View Full Code Here

  @Override
  public Association createAssociation(AssociationKey key, AssociationContext associationContext) {
    CouchDBAssociation couchDBAssociation = null;

    if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) {
      EntityDocument owningEntity = getDataStore().getEntity( Identifier.createEntityId( key.getEntityKey() ) );
      if ( owningEntity == null ) {
        owningEntity = (EntityDocument) getDataStore().saveDocument( new EntityDocument( key.getEntityKey() ) );
      }

      couchDBAssociation = CouchDBAssociation.fromEmbeddedAssociation( owningEntity, key.getMetadata().getCollectionRole() );
    }
    else {
View Full Code Here

  }

  @Override
  public void removeAssociation(AssociationKey key, AssociationContext associationContext) {
    if ( isStoredInEntityStructure( key.getMetadata(), associationContext.getAssociationTypeContext() ) ) {
      EntityDocument owningEntity = getDataStore().getEntity( Identifier.createEntityId( key.getEntityKey() ) );
      if ( owningEntity != null ) {
        owningEntity.removeAssociation( key.getMetadata().getCollectionRole() );
        getDataStore().saveDocument( owningEntity );
      }
    }
    else {
      removeDocumentIfPresent( Identifier.createAssociationId( key ) );
View Full Code Here

  public void testDeleteADocument() {
    Document createdDocument = dataStore.saveDocument( createEntity() );
    String createdDocumentId = createdDocument.getId();
    dataStore.deleteDocument( createdDocument.getId(), createdDocument.getRevision() );

    EntityDocument entity = dataStore.getEntity( createdDocumentId );

    assertThat( entity, nullValue() );
  }
View Full Code Here

  }

  @Test
  public void testGetEntity() {
    Document createdDocument = dataStore.saveDocument( createEntity() );
    EntityDocument entity = dataStore.getEntity( createdDocument.getId() );
    assertThat( entity, notNullValue() );
  }
View Full Code Here

  }

  @Test
  public void testGetEntityWithWrongIdReturnNullValue() {
    Document createdDocument = dataStore.saveDocument( createEntity() );
    EntityDocument entity = dataStore.getEntity( createdDocument.getId() + "_1" );
    assertThat( entity, nullValue() );
  }
View Full Code Here

      return LOCALHOST;
    }
  }

  private EntityDocument createEntity() {
    return new EntityDocument( createEntityKey( "tableName", new String[] { "id", "name" }, new String[] { "1",
        "Andrea" } ) );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.couchdb.dialect.backend.json.impl.EntityDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.