Skip to content

Commit

Permalink
[orient, session, factory] autoinitialize the transaction/session fro…
Browse files Browse the repository at this point in the history
…m the configuration if requested
  • Loading branch information
sleroy committed Dec 9, 2014
1 parent 8357246 commit c38fd0d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TDatabase db() {

/*
* (non-Javadoc)
*
*
* @see
* org.springframework.orm.orient.AbstractOrientDatabaseFactory#openDatabase
* ()
Expand All @@ -79,6 +79,10 @@ public void init(final DatabaseConfiguration _configuration) {
this.createDatabase(createdDB, _configuration);
LOGGER.debug("Creation of the connexion pool {} ", _configuration.getUrl());
this.createPool(_configuration);
if (_configuration.isAutoInitializeCurrentThreadTransaction()) {
LOGGER.warn("Autoinitialize the database for the current thread");
this.getOrCreateDatabaseSession();
}
}

public void setPool(final ODatabaseDocumentPool pool) {
Expand Down Expand Up @@ -114,9 +118,9 @@ private final void createDatabase(final ODatabase _database, final DatabaseConfi
*/
private final void createPool(final DatabaseConfiguration _configuration) {
LOGGER.debug("Configuration of the connexion pool min={}, max={}", _configuration.getMinPoolSize(),
_configuration.getMaxPoolSize());
_configuration.getMaxPoolSize());
this.pool = new ODatabaseDocumentPool(_configuration.getUrl(), _configuration.getUsername(),
_configuration.getPassword());
_configuration.getPassword());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public class DatabaseConfiguration {
private String url;

/** Default minimum pool size. */
public static final int DEFAULT_MIN_POOL_SIZE = 1;
public static final int DEFAULT_MIN_POOL_SIZE = 1;

/** Default maximum pool size. */
public static final int DEFAULT_MAX_POOL_SIZE = 20;
public static final int DEFAULT_MAX_POOL_SIZE = 20;

/** The username. */
private String username;
Expand All @@ -29,12 +29,14 @@ public class DatabaseConfiguration {
private String password;

/** The min pool size. */
private int minPoolSize = DEFAULT_MIN_POOL_SIZE;
private int minPoolSize = DEFAULT_MIN_POOL_SIZE;

/** The max pool size. */
private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;
private int maxPoolSize = DEFAULT_MAX_POOL_SIZE;

private Map<String, Object> extraConfiguration = Collections.emptyMap();
private boolean autoInitializeCurrentThreadTransaction = false;

private Map<String, Object> extraConfiguration = Collections.emptyMap();

public DatabaseConfiguration() {
super();
Expand Down Expand Up @@ -64,6 +66,14 @@ public String getUsername() {
return this.username;
}

public boolean isAutoInitializeCurrentThreadTransaction() {
return this.autoInitializeCurrentThreadTransaction;
}

public void setAutoInitializeCurrentThreadTransaction(final boolean _autoInitializeCurrentThreadTransaction) {
this.autoInitializeCurrentThreadTransaction = _autoInitializeCurrentThreadTransaction;
}

public void setExtraConfiguration(final Map<String, Object> _extraConfiguration) {
this.extraConfiguration = _extraConfiguration;
}
Expand Down Expand Up @@ -91,6 +101,6 @@ public void setUsername(final String _username) {
@Override
public String toString() {
return "DatabaseConfiguration [url=" + this.url + ", username=" + this.username + ", minPoolSize="
+ this.minPoolSize + ", maxPoolSize=" + this.maxPoolSize + "]";
+ this.minPoolSize + ", maxPoolSize=" + this.maxPoolSize + "]";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class TestDatabaseConfiguration extends MemoryDatabaseConfiguration {

public TestDatabaseConfiguration() {
super("database" + Long.toString(new Date().getTime()) + new Random().nextInt());
this.setAutoInitializeCurrentThreadTransaction(true);
}

}

0 comments on commit c38fd0d

Please sign in to comment.