I have following code.
String orientDBPath = "memory:visdb";
ODatabaseObjectPool objectPool;
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
objectPool = new ODatabaseObjectPool(orientDBPath, username, password, dbConfig);
When I'm acquiring ODatabaseObject with objectPool.acquire(), I receive following ODatabaseException.
Caused by: com.orientechnologies.orient.core.exception.ODatabaseException: OrientDB instanced created without physical path, only memory databases are allowed
DB name="visdb"
at com.orientechnologies.orient.core.db.OrientDBEmbedded.buildName(OrientDBEmbedded.java:186)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.getOrInitStorage(OrientDBEmbedded.java:173)
at com.orientechnologies.orient.core.db.OrientDBEmbedded.poolOpen(OrientDBEmbedded.java:159)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl$1.createNewResource(ODatabasePoolImpl.java:40)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl$1.createNewResource(ODatabasePoolImpl.java:37)
at com.orientechnologies.common.concur.resource.OResourcePool.getResource(OResourcePool.java:95)
at com.orientechnologies.orient.core.db.ODatabasePoolImpl.acquire(ODatabasePoolImpl.java:59)
at com.orientechnologies.orient.core.db.ODatabasePool.acquire(ODatabasePool.java:132)
at com.orientechnologies.orient.object.db.ODatabaseObjectPool.acquire(ODatabaseObjectPool.java:40)
What is the correct way to initialize ODatabaseObjectPool and ODatabasePool for memory DB?
I do use in-memory graph in my unit tests. Here is how I create the pool
String orientDBPath = "memory:visdb";
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
OrientDB orientDB = new OrientDB(orientDBPath, dbConfig);
orientDB.createIfNotExists(orientDBPath, ODatabaseType.MEMORY);
ODatabasePool pool = new ODatabasePool(orientDB, orientDBPath, "admin",
"admin");
ODatabaseSession session = pool.acquire();
// later
session.close();
pool.close();
orientDB.close();
Depentency:
<dependency>
<groupId>com.orientechnologies</groupId>
<artifactId>orientdb-client</artifactId>
<version>3.0.4</version>
</dependency>
Hope it helps.
I found another solution which worked for me.
OrientDBConfig dbConfig = OrientDBConfig.defaultConfig();
ODatabasePoolInternal documentPoolInternal;
OrientDBEmbedded orientDBEmbedded = new OrientDBEmbedded("", dbConfig, Orient.instance());
orientDBEmbedded.create(orientDBName, username, password, ODatabaseType.MEMORY, dbConfig);
documentPoolInternal = orientDBEmbedded.openPool(orientDBName, username, password);
ODatabaseSession session = documentPoolInternal.acquire();
Related
I'm connecting to my postgres instance in springboot and I've implemented Hikari CP for connection pooling . I see after a few days of deployment , my code seems to break I seem to get the following error message in my logs
java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 60000ms.
at com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:602)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:195)
at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:145)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:85)
atcom.dell.it.daas.apibuilder.submitrequestservice.Services.PostgresConnectionServiceImpl.connectToPostgresDatabase(PostgresConnectionServiceImpl.java:103)
at com.dell.it.daas.apibuilder.submitrequestservice.Services.PostgresConnectionServiceImpl.getRequestDetailsByRequestId(PostgresConnectionServiceImpl.java:114)
Here's my Hikari CP connection parameters
public static Connection connectToPostgresDatabase(String connectionString, String userName, String
password)
throws SQLException {
if (config == null) {
config = new HikariConfig();
config.setJdbcUrl(connectionString);
config.setUsername(userName);
config.setPassword(password);
config.addDataSourceProperty("cachePrepStmts", "true");
config.addDataSourceProperty("prepStmtCacheSize", "256");
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
config.setConnectionTimeout(60000);
config.setMinimumIdle(10);
config.setMaximumPoolSize(30);
config.setLeakDetectionThreshold(60000);
config.setConnectionTestQuery("SELECT 1");
config.setInitializationFailTimeout(20000);
config.addDataSourceProperty("prepareThreshold", 0);
config.addDataSourceProperty("useServerPrepStmts", true);
ds = new HikariDataSource(config);
}
return ds.getConnection();
}
SO whenever I need to execute any Query I get the connection to database as
try(Connection con =
PostgresConnectionServiceImpl.connectToPostgresDatabase(apibuilderConnectionString,
apibuilderUserName, apibuilderPassword))
{
if(getSchema()!=null)
con.setSchema(getSchema());
try(PreparedStatement st = con.prepareStatement(queryToRetrieveRequestDetails);
ResultSet requestDetailsSet = st.executeQuery();)
I'm using try with resources to do all my database related operations
PostgresConnectionServiceImpl.connectToPostgresDatabase(apibuilderConnectionString,
apibuilderUserName, apibuilderPassword)
This is the the line which is failing .
Been struggling with this for some time now appreciate any help . Thanks
I want to create an abstract repository to a federated store in AllegroGraph.
I can connect to the repositories stored on different server. But when I try to combine them using federate function, it throws an error that it cannot find the repository on the second server.
I found the same question in this link but it doesn't help. Any hints?
This is my code:
AGServer server = new AGServer(SERVER_URL, USERNAME, PASSWORD);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
println("Available catalogs: " + server.listCatalogs());
AGRepositoryConnection custCon = server.createRepositoryConnection("repo1", CATALOG_ID, false);
AGRepositoryConnection supCon = server2.createRepositoryConnection("repo2", CATALOG_ID, false);
AGAbstractRepository rainbowRepo = server2.federate(custCon.getRepository(), supCon.getRepository());
rainbowRepo.initialize();
AGRepositoryConnection rainbowConn = rainbowRepo.getConnection();
SailRepository class implements FederatedServiceResolverClient for the federation context, so u can use the class SailRepository to add a federated store with different repositories :
AGServer server = new AGServer(SERVER_URL, USERNAME, PASSWORD);
AGServer server2 = new AGServer(SERVER_URL2, USERNAME2, PASSWORD2);
AGRepository repo1 = server.getCatalog(CATALOG_ID).openRepository("repo1");
AGRepository repo2 = server2.getCatalog(CATALOG_ID).openRepository("repo2");
Federation federation = new Federation();
federation.addMember(repo1);
federation.addMember(repo2);
federation.setReadOnly(true);
SailRepository rainbowRepo = new SailRepository(federation);
rainbowRepo .initialize();
SailRepositoryConnection rainbowConn = rainbowRepo .getConnection(); //for querying and updating the contents of the repository.
I am trying to configure and read data from existing Oracle tables
However, I get error message while calling cache.loadCache(); this line.
It shows error message as
Message as
session:javax.cache.integration.CacheWriterException: Failed to start store
session [tx=null]Caused by: java.sql.SQLException: No suitable driver found
for jdbc:oracle:thin:#192.168.2.218:1521:xe at
org.h2.jdbcx.JdbcDataSource.getJdbcConnection(JdbcDataSource.java:190) at
org.h2.jdbcx.JdbcDataSource.getXAConnection(JdbcDataSource.java:351) at
org.h2.jdbcx.JdbcDataSource.getPooledConnection(JdbcDataSource.java:383) at
org.h2.jdbcx.JdbcConnectionPool.getConnectionNow(JdbcConnectionPool.java:226)
at
org.h2.jdbcx.JdbcConnectionPool.getConnection(JdbcConnectionPool.java:198)
at
CacheConfiguration<String, TempClass> cacheCfg = new CacheConfiguration<String, TempClass>();
cacheCfg.setName("Test_CacheConfig");
IgniteConfiguration igniteConfig = new IgniteConfiguration();
Factory<TempClassCacheStore> factory = FactoryBuilder.factoryOf(TempClassCacheStore.class);
cacheCfg.setReadThrough(true);
cacheCfg.setWriteThrough(true);
cacheCfg.setIndexedTypes(String.class, TempClass.class);
cacheCfg.setCacheStoreFactory(factory);
cacheCfg.setCacheStoreSessionListenerFactories(new Factory<CacheStoreSessionListener>() {
#Override
public CacheStoreSessionListener create() {
CacheJdbcStoreSessionListener lsnr = new CacheJdbcStoreSessionListener();
lsnr.setDataSource(JdbcConnectionPool.create("jdbc:oracle:thin:#192.168.2.218:1521:xe", "test", "test"));
return lsnr;
}
});
Ignite ignite = Ignition.start(igniteConfig);
IgniteCache<String, TempClass> cache = ignite.getOrCreateCache(cacheCfg);
cache.loadCache(null);
SqlFieldsQuery sql = new SqlFieldsQuery("SELECT ID_, NAME_ FROM TEST_TABLE");
QueryCursor<List<?>> cursor = cache.query(sql);
I have configured CacheStore for TempClass also as shown in
https://apacheignite.readme.io/docs/persistent-store#cachestore
Any help will be highly appreciated
As you're trying to load data from oracle to Ignite, you need to have Oracle JDBC Driver in classpath. Just put the driver JAR into IGNITE_HOME/libs folder prior to starting the nodes and run loading again.
I have installed Websphere Network deployment server 7.0.0.0
I have configured a cluster on it.
I have configured a data source on it say ORA_DS this data source using "JAAS - J2C authentication data"
When i test the ORA_DS by clicking on "Test connection" button, the test connection is success.
The issue comes when i try to access this data source using my java code.
Here is my code to access data source and create a connection:
public class DSTester
{
/**
* Return the data source.
* #return the data source
*/
private DataSource getDataSource()
{
DataSource dataSource = null;
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, "iiop://localhost:9811");
// Retrieve datasource name
String dataSourceName = "EPLA1";
if (dataSource == null)
{
try
{
Context initialContext = new InitialContext(env);
dataSource = (DataSource) initialContext.lookup(dataSourceName);
}
catch (NamingException e1)
{
e1.printStackTrace();
return null;
}
}
return dataSource;
}
public static void main(String[] args)
throws Exception
{
DSTester dsTester = new DSTester();
DataSource ds = dsTester.getDataSource();
System.out.println(ds);
System.out.println(ds.getConnection());
}
}
Here is the output:
com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource#17e40be6
Exception in thread "P=792041:O=0:CT" java.sql.SQLException: ORA-01017: invalid username/password; logon denied
DSRA0010E: SQL State = 72000, Error Code = 1,017
at oracle.jdbc.driver.SQLStateMapping.newSQLException(SQLStateMapping.java:70)
at oracle.jdbc.driver.DatabaseError.newSQLException(DatabaseError.java:133)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:206)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:455)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:406)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:399)
at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:799)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:368)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:508)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:203)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:33)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:510)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:275)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:206)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:139)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:88)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPooledConnection(OracleConnectionPoolDataSource.java:70)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper$1.run(InternalGenericDataStoreHelper.java:1175)
at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
at com.ibm.ws.rsadapter.spi.InternalGenericDataStoreHelper.getPooledConnection(InternalGenericDataStoreHelper.java:1212)
at com.ibm.ws.rsadapter.spi.WSRdbDataSource.getPooledConnection(WSRdbDataSource.java:2019)
at com.ibm.ws.rsadapter.spi.WSManagedConnectionFactoryImpl.createManagedConnection(WSManagedConnectionFactoryImpl.java:1422)
at com.ibm.ws.rsadapter.spi.WSDefaultConnectionManagerImpl.allocateConnection(WSDefaultConnectionManagerImpl.java:81)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:646)
at com.ibm.ws.rsadapter.jdbc.WSJdbcDataSource.getConnection(WSJdbcDataSource.java:613)
at com.test.DSTester.main(DSTester.java:70)
The code works fine if i replace
ds.getConnection()
with
ds.getConnection("ora_user", "ora_password")
My issue is i need to get the connection without specifying login details for Oracle.
Please help me on this issue.
Any clue will be appreciated.
Thanks
I'd guess it would work if you retrieved the datasource from an application running on the WAS.
Try creating a servlet.
Context initialContext = new InitialContext();
DataSource dataSource = (DataSource) initialContext.lookup("EPLA1");
Connection con = dataSource.getConnection();
As within a servlet it is running within WAS it should be fine, if the "Test Connection" works. Running it outside is probably a different context.
I think you need to check all your configuration:
1) Is it application deplyed on cluster or into only one of cluster member?
2) JAAS - J2C authentication data - what is the scope?
Sometimes you need restar all your WAS environment. It depends on resource configuration scope
I'd recomend to you add resource refences for better configuration options.
SeeIBM Tech note
I am running a java app (java 1.7) with hibernate 4.2.0 and I need to implement a schema based multi tenancy setup. I used this exampleto do that.
my problem is that I was unable to figure out how to create the connection providers. the example uses:
acmeProvider = ConnectionProviderBuilder.buildConnectionProvider( "acme" );
jbossProvider = ConnectionProviderBuilder.buildConnectionProvider( "jboss" );
but ConnectionProviderBuilder is for testing use.
I tried to use the following:
C3P0ConnectionProvider connectionProvider = new C3P0ConnectionProvider()
{
public boolean supportsAggressiveRelease()
{
return allowAggressiveRelease;
}
};
connectionProvider.configure(props);
the problem here was that the C3P0ConnectionProvider has a null serviceRegistry which crush the with NPE.
does anyone have an idea on how to create ConnectionProvider for each tenant?
Thanks,
Ronen
Try suggestion using Properties to add data source properties:
DatasourceConnectionProviderImpl cp = new DatasourceConnectionProviderImpl();
cp.setDataSource(ds);
Properties p = new Properties();
// ...
cp.configure(p);
Or with DriverManagerConnectionProviderImpl:
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl() {
public boolean supportsAggressiveRelease() {
return allowAggressiveRelease;
}
};
connectionProvider.configure( props );