Package org.hibernate.ogm.datastore.mongodb.impl

Examples of org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider


    Map<String, String> cfg = TestHelper.getEnvironmentProperties();
    cfg.put( OgmProperties.DATABASE, "test" );
    cfg.put( OgmProperties.USERNAME, "notauser" );
    cfg.put( OgmProperties.PASSWORD, "test" );

    MongoDBDatastoreProvider provider = new MongoDBDatastoreProvider();
    provider.injectServices( getServiceRegistry( cfg ) );
    provider.configure( cfg );

    error.expect( HibernateException.class );
    error.expectMessage( "OGM001213" );

    provider.start();
  }
View Full Code Here


  @Test
  public void testConnectionErrorWrappedInHibernateException() throws Exception {
    Map<String, String> cfg = TestHelper.getEnvironmentProperties();
    cfg.put( OgmProperties.HOST, NON_EXISTENT_IP );

    MongoDBDatastoreProvider provider = new MongoDBDatastoreProvider();
    provider.injectServices( getServiceRegistry( cfg ) );
    provider.configure( cfg );

    error.expect( HibernateException.class );
    error.expectMessage( "OGM001214" );

    provider.start();
  }
View Full Code Here

    Map<String, Object> cfg = new HashMap<String, Object>();
    cfg.put( MongoDBProperties.TIMEOUT, "30" );
    cfg.put( OgmProperties.HOST, NON_EXISTENT_IP );
    cfg.put( OgmProperties.DATABASE, "ogm_test_database" );

    MongoDBDatastoreProvider provider = new MongoDBDatastoreProvider();

    /*
     * To be sure, the test passes on slow / busy machines the hole
     * operation should not take more than 3 seconds.
      */
    final long estimateSpentTime = 3L * 1000L * 1000L * 1000L;
    provider.injectServices( getServiceRegistry( cfg ) );
    provider.configure( cfg );

    Exception exception = null;
    final long start = System.nanoTime();
    try {
      provider.start();
    }
    catch ( Exception e ) {
      exception = e;
      assertThat( System.nanoTime() - start ).isLessThanOrEqualTo( estimateSpentTime );
    }
View Full Code Here

    return mongoHostName != null && mongoHostName.length() > 0 && ! "null".equals( mongoHostName );
  }

  @Override
  public long getNumberOfEntities(SessionFactory sessionFactory) {
    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DB db = provider.getDatabase();
    int count = 0;

    for ( String collectionName : getEntityCollections( sessionFactory ) ) {
      count += db.getCollection( collectionName ).count();
    }
View Full Code Here

  }

  @Override
  @SuppressWarnings("unchecked")
  public Map<String, Object> extractEntityTuple(SessionFactory sessionFactory, EntityKey key) {
    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DBObject finder = new BasicDBObject( MongoDBDialect.ID_FIELDNAME, key.getColumnValues()[0] );
    DBObject result = provider.getDatabase().getCollection( key.getTable() ).findOne( finder );
    replaceIdentifierColumnName( result, key );
    return result.toMap();
  }
View Full Code Here

    return MongoDBDatastoreProvider.class.cast( provider );
  }

  @Override
  public void dropSchemaAndDatabase(SessionFactory sessionFactory) {
    MongoDBDatastoreProvider provider = getProvider( sessionFactory );
    try {
      provider.getDatabase().dropDatabase();
    }
    catch ( MongoException ex ) {
      throw log.unableToDropDatabase( ex, provider.getDatabase().getName() );
    }
  }
View Full Code Here

  public static void assertDbObject(OgmSessionFactory sessionFactory, String collection, String queryDbObject, String expectedDbObject) {
    DBObject finder = (DBObject) JSON.parse( queryDbObject );
    DBObject expected = (DBObject) JSON.parse( expectedDbObject );

    MongoDBDatastoreProvider provider = MongoDBTestHelper.getProvider( sessionFactory );
    DBObject actual = provider.getDatabase().getCollection( collection ).findOne( finder );

    assertThat( actual ).isEqualTo( expected );
  }
View Full Code Here

  @Test
  public void testLoadSelectedColumns() {
    final String collectionName = "Drink";

    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) this.getService( DatastoreProvider.class );

    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( collectionName );
    BasicDBObject water = new BasicDBObject();
    water.put( "_id", "1234" );
    water.put( "name", "Water" );
    water.put( "volume", "1L" );
View Full Code Here

  /**
   * To be sure the datastoreProvider retrieves only the columns we want,
   * an extra column is manually added to the association document
   */
  protected void addExtraColumn() {
    MongoDBDatastoreProvider provider = (MongoDBDatastoreProvider) this.getService( DatastoreProvider.class );
    DB database = provider.getDatabase();
    DBCollection collection = database.getCollection( "associations_Project_Module" );
    BasicDBObject query = new BasicDBObject( 1 );
    query.put( "_id", new BasicDBObject( "Project_id", "projectID" ) );

    BasicDBObject updater = new BasicDBObject( 1 );
View Full Code Here

  @Test
  public void shouldApplyConfiguredReadPreferenceForGettingTuple() {
    // given an empty database
    MockMongoClient mockClient = mockClient().build();
    setupSessionFactory( new MongoDBDatastoreProvider( mockClient.getClient() ) );

    final Session session = sessions.openSession();
    Transaction transaction = session.beginTransaction();

    // when getting a golf player
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.datastore.mongodb.impl.MongoDBDatastoreProvider

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.