Hi,
I am trying to connect to Oracle DB and pull the data to cache. But when i
am trying to connect it is throwing me an exception. How can i connect to
Oracle DB. Is the dataSource i am declaring correct.
package org.apache.ignite.examples.algofusion;
import java.sql.SQLException;
import java.util.List;
import javax.cache.Cache.Entry;
import javax.cache.configuration.Factory;
import javax.cache.integration.CacheLoaderException;
import javax.cache.integration.CacheWriterException;
import oracle.jdbc.pool.OracleDataSource;
import org.apache.commons.logging.Log;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.query.SqlFieldsQuery;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreAdapter;
import org.apache.ignite.cache.store.jdbc.CacheJdbcPojoStore;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
public class AlgoDB extends
CacheStoreAdapter<ExceptionMasterKey, ExceptionMaster> {
@SuppressWarnings("unchecked")
public static void main(String args[]) throws InterruptedException {
CacheConfiguration<ExceptionMasterKey, ExceptionMaster> ccfg =
CacheConfig
.cache("AlgoCache",
new
Factory<CacheStore<ExceptionMasterKey, ExceptionMaster>>() {
/**
*
*/
private static final
long serialVersionUID = -4108832625530307161L;
public
CacheStore<ExceptionMasterKey, ExceptionMaster> create() {
CacheJdbcPojoStore<ExceptionMasterKey, ExceptionMaster> store = new
CacheJdbcPojoStore<>();
OracleDataSource dataSource = null;
try {
dataSource = new OracleDataSource();
dataSource
.setURL("jdbc:oracle:thin:@192.168.1.12:1521:AFTDB");
dataSource.setUser("algoreconutil_dev");
dataSource.setPassword("algorecon");
System.out.println(dataSource.getDatabaseName());
} catch
(SQLException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
}
store.setDataSource(dataSource);
System.out.println("the datasource is created");
return store;
}
});
ccfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(false); // from config
/*
OptimizedMarshaller opm = new OptimizedMarshaller();
opm.setRequireSerializable(true);
cfg.setMarshaller(opm);*/
System.out.println("start ignite");
Ignite ignite = Ignition.start(cfg);
System.out.println("started ignite");
IgniteCache<ExceptionMasterKey, ExceptionMaster> bob = ignite
.getOrCreateCache(ccfg);
//bob.loadCache(null);
// System.out.println("" + ccfg.getName());
// Select top 10 words.
/* SqlFieldsQuery excepQuery = new SqlFieldsQuery(
"select EXCEPTION_ID from EXCEPTION_MASTER"
);
System.out.println("loading cache");
IgniteBiInClosure<ExceptionMasterKey, ExceptionMaster> p = new
IgniteBiInClosure<ExceptionMasterKey, ExceptionMaster>() {
*//**
*
*//*
private static final long serialVersionUID =
4383013082688304684L;
@Override
public void apply(ExceptionMasterKey e1,
ExceptionMaster e2) {
// TODO Auto-generated method stub
}
};
//bob.loadCache((IgniteBiPredicate<ExceptionMasterKey,
ExceptionMaster>)
p, null);
System.out.println("loaded cache");
for (Cache.Entry<ExceptionMasterKey, ExceptionMaster> entry :
bob) {
System.out.println("############################");
System.out.println("KEY: " + entry.getKey().toString());
if (entry.getValue() != null) {
System.out.println("not null");
} else {
System.out.println("null value");
}
System.out.println("############################");
}*/
while (true) {
// Execute queries.
List<List<?>> top10 = bob.query(excepQuery).getAll();
// Print average count.
System.out.println("this is the result "+top10.size());
Thread.sleep(5000);
}
}
@Override
public ExceptionMaster load(ExceptionMasterKey arg0)
throws CacheLoaderException {
// TODO Auto-generated method stub
return null;
}
@Override
public void delete(Object arg0) throws CacheWriterException {
// TODO Auto-generated method stub
}
@Override
public void write(
Entry<? extends ExceptionMasterKey, ? extends
ExceptionMaster> arg0)
throws CacheWriterException {
// TODO Auto-generated method stub
}
}
The Exception is as follows
23:19:42] __________ ________________
[23:19:42] / _/ ___/ |/ / _/_ __/ __/
[23:19:42] _/ // (7 7 // / / / / _/
[23:19:42] /___/\___/_/|_/___/ /_/ /___/
[23:19:42]
[23:19:42] ver. 1.3.0-incubating#20150710-sha1:2ade6d00
[23:19:42] 2015 Copyright(C) Apache Software Foundation
[23:19:42]
[23:19:42] Ignite documentation: http://ignite.incubator.apache.org
[23:19:42]
[23:19:42] Quiet mode.
[23:19:42] ^-- Logging to file
'/home/hadoop/Downloads/apache-ignite-fabric-1.2.0-incubating-bin/work/log/ignite-1dcf44ea.log'
[23:19:42] ^-- To see **FULL** console log here add -DIGNITE_QUIET=false
or "-v" to ignite.{sh|bat}
[23:19:42]
[23:19:42] Initial heap size is 89MB (should be no less than 512MB, use
-Xms512m -Xmx512m).
[23:19:42] Configured plugins:
[23:19:42] ^-- None
[23:19:42]
null
the datasource is created
[23:19:46] Performance suggestions for grid (fix if possible)
[23:19:46] To disable, set -DIGNITE_PERFORMANCE_SUGGESTIONS_DISABLED=true
[23:19:46] ^-- Enable ATOMIC mode if not using transactions (set
'atomicityMode' to ATOMIC)
[23:19:46] ^-- Enable write-behind to persistent store (set
'writeBehindEnabled' to true)
[23:19:46]
[23:19:46] To start Console Management & Monitoring run
ignitevisorcmd.{sh|bat}
[23:19:46]
[23:19:46] Ignite node started OK (id=1dcf44ea)
[23:19:46] Topology snapshot [ver=10, server nodes=4, client nodes=0,
CPUs=8, heap=5.0GB]
started ignite
Exception in thread "main" javax.cache.CacheException: class
org.apache.ignite.IgniteException: Failed to parse query: select
EXCEPTION_ID from EXCEPTION_MASTER
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:581)
at org.apache.ignite.examples.algofusion.AlgoDB.main(AlgoDB.java:123)
Caused by: class org.apache.ignite.IgniteException: Failed to parse query:
select EXCEPTION_ID from EXCEPTION_MASTER
at
org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:598)
at
org.apache.ignite.internal.processors.cache.IgniteCacheProxy.query(IgniteCacheProxy.java:572)
... 1 more
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to parse
query: select EXCEPTION_ID from EXCEPTION_MASTER
at
org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1459)
at
org.apache.ignite.internal.processors.query.GridQueryProcessor.queryTwoStep(GridQueryProcessor.java:591)
... 2 more
Caused by: javax.cache.CacheException: Failed to parse query: select
EXCEPTION_ID from EXCEPTION_MASTER
at
org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:852)
at
org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:593)
at
org.apache.ignite.internal.processors.query.GridQueryProcessor$4.applyx(GridQueryProcessor.java:591)
at
org.apache.ignite.internal.util.lang.IgniteOutClosureX.apply(IgniteOutClosureX.java:36)
at
org.apache.ignite.internal.processors.query.GridQueryProcessor.executeQuery(GridQueryProcessor.java:1447)
... 3 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "EXCEPTION_MASTER" not found;
SQL statement:
select EXCEPTION_ID from EXCEPTION_MASTER [42102-175]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:332)
at org.h2.message.DbException.get(DbException.java:172)
at org.h2.message.DbException.get(DbException.java:149)
at org.h2.command.Parser.readTableOrView(Parser.java:5071)
at org.h2.command.Parser.readTableFilter(Parser.java:1188)
at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1813)
at org.h2.command.Parser.parseSelectSimple(Parser.java:1921)
at org.h2.command.Parser.parseSelectSub(Parser.java:1807)
at org.h2.command.Parser.parseSelectUnion(Parser.java:1631)
at org.h2.command.Parser.parseSelect(Parser.java:1619)
at org.h2.command.Parser.parsePrepared(Parser.java:426)
at org.h2.command.Parser.parse(Parser.java:298)
at org.h2.command.Parser.parse(Parser.java:270)
at org.h2.command.Parser.prepareCommand(Parser.java:235)
at org.h2.engine.Session.prepareLocal(Session.java:436)
at org.h2.engine.Session.prepareCommand(Session.java:379)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1138)
at
org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:70)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:267)
at
org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.queryTwoStep(IgniteH2Indexing.java:849)
... 7 more
Thanks and Regards
Krishna
--
View this message in context:
http://apache-ignite-users.70518.x6.nabble.com/Connecting-to-Oracle-DB-tp719.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.