Ignite 2.14.0 Exception with Date column (java.sql.BatchUpdateException: Failed to marshal object with optimized marshaller) JDK 17 - ignite

Running Sample Code Ignite standalone application Exception been thrown while on Insert and Select query statment. Code snippet is given below.
Exception
Caused by: java.sql.BatchUpdateException: Failed to marshal object with optimized marshaller: 2023-02-06
at org.apache.ignite.internal.jdbc.thin.JdbcThinConnection$StreamState.readResponses(JdbcThinConnection.java:1580)
at java.base/java.lang.Thread.run(Thread.java:833) Here is below attached the query for reference... Solution expecting is Date field storage
Maven Depenedency
<properties>
<ignite.version>2.14.0</ignite.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-core</artifactId>
<version>${ignite.version}</version>
</dependency>
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-spring</artifactId>
<version>${ignite.version}</version>
</dependency>
</dependencies>
DDL
CREATE TABLE PUBLIC.COLL_6_2_23_4 (
PRIMARY_ID INTEGER,
COLLECTION_ID VARCHAR(20),
CLIENT_ID VARCHAR(20),
TRADE_DATE DATE,
CONSTRAINT PRIMARY_ID PRIMARY KEY (PRIMARY_ID)
);
JAVA CODE
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import org.apache.ignite.Ignite;
import org.apache.ignite.Ignition;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.internal.processors.query.IgniteSQLException;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder;
public class Test {
public static void main(String[] args) throws Exception {
Test objTest = new Test();
objTest.execute();
}
public void execute() throws SQLException {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true);
cfg.setPeerClassLoadingEnabled(false);
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
String[] serverIp = "127.0.0.1:48510".split(";");
ipFinder.setAddresses(Arrays.asList(serverIp));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
Ignite ignite = Ignition.start(cfg);
Connection conn = null;
try {
conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1,10801/");
} catch (SQLException e) {
}
try {
try (Statement stmt1 = conn.createStatement()) {
ResultSet rs = stmt1.executeQuery(
"select * from PUBLIC.COLL_6_2_23_2");
System.out.println(rs.next());
rs.close();
} catch (SQLException e) {
throw new IgniteSQLException(
e);
}
} catch (Exception e) {
conn.close();
}
ignite.close();
}
}

Related

Problem when executing report ".jasper" in Apache ISIS

The execution of the method "ReporteListadoVehiculos()" only displays up to the line "JasperPrint j = JasperFillManager.fillReport(report, null, conectar());", and apparently there's an error that avoids continuing the execution.
How can I find the error that is avoiding the execution of the report, and which are the steps I should follow to fix this tipe of problems?
This is the code I'm using to execute the report:
package domainapp.modules.simple.dominio.reportes;
import java.io.File;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
import javax.swing.JOptionPane;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.util.JRLoader;
import net.sf.jasperreports.view.JasperViewer;
public class EjecutarReportes {
public static Connection conectar() {
Connection con = null;
try {
String url = "jdbc:postgresql://127.0.0.1:5432/adet?user=adetuser&password=Passw0rd";
con = DriverManager.getConnection(url);
if (con != null) {
System.out.println("Conexion Satisfactoria");
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return con;
}
public void ReporteListadoVehiculos(){
try {
File ruta = new File("C:\\Users\\4G\\Desktop\\Proyecto_Final\\Codigo\\AdeT\\module-simple\\src\\main\\java\\domainapp\\modules\\simple\\dominio\\reportes\\ListadoVehiculos.jasper");
JasperReport report = (JasperReport) JRLoader.loadObject(ruta);
JasperPrint j = JasperFillManager.fillReport(report, null, conectar());
JasperViewer jv = new JasperViewer(j,false);
jv.setTitle("Listado de Vehiculos");
jv.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error al mostrar el Reporte: "+e);
}
}
}
AFAIK JOptionPane is part of swing. By default Apache Isis comes with a WicketViewer.
Try using a logger (eg. log4j) or even System.out.println() to get closer to the problem.

Refreshing RedisTemplate

I am using spring quartz job to connect to Redis to perform a operation. I have configured the RedisTemplate to connect to only the master node.
When failover happens in Redis and new master is elected I am notified via client-reconfig-script in sentinel.conf. After this I am trying to rewire my RedisTemplate to talk to the new master. This rewire part is not working.
Spring boot config for quartz job and RedisTemplate:
package com.XXX.XXX;
import org.quartz.JobDetail;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.ClassPathResource;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.quartz.JobDetailFactoryBean;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.scheduling.quartz.SimpleTriggerFactoryBean;
import org.springframework.scheduling.quartz.SpringBeanJobFactory;
import de.chandre.quartz.spring.AutowiringSpringBeanJobFactory;
import de.chandre.quartz.spring.QuartzSchedulerAutoConfiguration;
#SpringBootApplication(exclude = { QuartzSchedulerAutoConfiguration.class })
public class OrderProcessorApplication {
public static void main(String[] args) {
SpringApplication.run(OrderProcessorApplication.class, args);
}
#Bean
public JobDetailFactoryBean jobDetail() {
JobDetailFactoryBean jobDetailFactory = new JobDetailFactoryBean();
jobDetailFactory.setJobClass(OrderProcessorJob.class);
jobDetailFactory.setDurability(true);
return jobDetailFactory;
}
#Value("${job.interval}")
private int interval;
#Bean
public SimpleTriggerFactoryBean trigger(JobDetail job) {
SimpleTriggerFactoryBean trigger = new SimpleTriggerFactoryBean();
trigger.setJobDetail(job);
trigger.setRepeatInterval(interval);
trigger.setRepeatCount(SimpleTrigger.REPEAT_INDEFINITELY);
return trigger;
}
#Bean
public SchedulerFactoryBean scheduler(Trigger trigger, JobDetail job) {
SchedulerFactoryBean schedulerFactory = new SchedulerFactoryBean();
schedulerFactory.setConfigLocation(new ClassPathResource("quartz.properties"));
schedulerFactory.setJobFactory(springBeanJobFactory());
schedulerFactory.setJobDetails(job);
schedulerFactory.setTriggers(trigger);
return schedulerFactory;
}
#Autowired
private ApplicationContext ap;
#Bean
#Primary
public SpringBeanJobFactory springBeanJobFactory() {
AutowiringSpringBeanJobFactory jobFactory = new AutowiringSpringBeanJobFactory();
jobFactory.setApplicationContext(ap);
return jobFactory;
}
// #Bean
// #Qualifier("sentinel")
// public RedisTemplate<String, Object> createRedisTemplate() {
// RedisSentinelConfiguration sc = new RedisSentinelConfiguration()
// .master("redis-cluster")
// .sentinel("127.0.0.1", 26179)
// .sentinel("127.0.0.1", 26381);
//
// JedisConnectionFactory jcf = new JedisConnectionFactory(sc);
// jcf.setUsePool(true);
// jcf.afterPropertiesSet();
//
// RedisTemplate rt = new RedisTemplate();
// rt.setConnectionFactory(jcf);
// rt.afterPropertiesSet();
// return rt;
// }
#Bean
#Primary
public RedisTemplate<String, Object> createMasterOnlyRedisTemplate() {
JedisConnectionFactory jcf = new JedisConnectionFactory();
jcf.setHostName("127.0.0.1");
jcf.setPort(6379);
jcf.setUsePool(true);
jcf.afterPropertiesSet();
RedisTemplate rt = new RedisTemplate();
rt.setConnectionFactory(jcf);
rt.afterPropertiesSet();
return rt;
}
}
Refresh REST service invoked by sentinel:
package com.store.platform;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.kohls.store.platform.common.model.ui.UpdateRedisMaster;
#RestController
#RequestMapping(path = "/refresh", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public class Test {
#Autowired
private RedisTemplate<String, Object> rt;
#RequestMapping(method = RequestMethod.POST)
public void refresh(#RequestBody UpdateRedisMaster um) {
JedisConnectionFactory jcf = (JedisConnectionFactory) rt.getConnectionFactory();
jcf.setHostName(um.getIp());
jcf.setPort(um.getPort());
jcf.setShardInfo(null);
jcf.afterPropertiesSet();
}
}
After successfully invoking refresh, next the quartz job tries to connect to Redis I get following exception:
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:204) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:92) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:194) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at org.springframework.data.redis.core.DefaultValueOperations.set(DefaultValueOperations.java:182) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
at com.XXX.platform.OrderProcessorJob.execute(OrderProcessorJob.java:32) ~[classes/:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.0.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [quartz-2.3.0.jar:na]
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
at redis.clients.util.Pool.getResource(Pool.java:53) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16) ~[jedis-2.9.0.jar:na]
at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194) ~[spring-data-redis-1.8.4.RELEASE.jar:na]
... 11 common frames omitted
Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused (Connection refused)
at redis.clients.jedis.Connection.connect(Connection.java:207) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.BinaryJedis.connect(BinaryJedis.java:1767) ~[jedis-2.9.0.jar:na]
at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:106) ~[jedis-2.9.0.jar:na]
at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) ~[commons-pool2-2.4.2.jar:2.4.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) ~[commons-pool2-2.4.2.jar:2.4.2]
at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[commons-pool2-2.4.2.jar:2.4.2]
at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.0.jar:na]
... 14 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_121]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_121]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_121]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_121]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_121]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_121]
at redis.clients.jedis.Connection.connect(Connection.java:184) ~[jedis-2.9.0.jar:na]
... 21 common frames omitted
I want to get consistent data, thats why I want to use master for read and write, and slave for redundancy and failover.
I am struck on this issue for two days. Any help is highly appreciated.
I was able to resolve my issue by creating my own RedisConnectionFactory.
public class SPRedisConnectionFactory implements InitializingBean, RedisConnectionFactory, DisposableBean {
private Jedis jedis;
private String[] nodes;
private Map<String, String[]> nodeMap;
#Value("${master.node}")
private String masterNode;
#Override
public void afterPropertiesSet() throws Exception {
nodeMap = Arrays.stream(this.nodes)
.map(n -> n.split(":"))
.collect(toMap(n -> n[0] + ":" + n[1], n -> n));
System.out.println(nodeMap);
}
#Override
public RedisConnection getConnection() {
String[] master = nodeMap.get(masterNode);
jedis = new Jedis(master[0], parseInt(master[1]), 2000);
jedis.connect();
JedisConnection c = new JedisConnection(jedis);
return c;
}
#Override
public RedisClusterConnection getClusterConnection() {
throw new UnsupportedOperationException();
}
#Override
public boolean getConvertPipelineAndTxResults() {
return false;
}
#Override
public RedisSentinelConnection getSentinelConnection() {
throw new UnsupportedOperationException();
}
#Override
public DataAccessException translateExceptionIfPossible(RuntimeException e) {
return null;
}
#Override
public void destroy() throws Exception {
jedis.disconnect();
}
}
Got this idea from Connections to multiple Redis servers with Spring Data Redis.

The constructor ReportBuilder(List<String>, Configuration) is undefined

I'm getting an error in my Report Generator script as "The constructor ReportBuilder(List, Configuration) is undefined" on the below line of code.
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
Please refer my complete set of code:
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.junit.Cucumber;
import net.masterthought.cucumber.Configuration;
import net.masterthought.cucumber.ReportBuilder;
import net.masterthought.cucumber.ReportParser;
public class GenerateReport {
public static void GenerateMasterthoughtReport(){
try{
//String RootDir = System.getProperty("user.dir");
File reportOutputDirectory = new File("target/Masterthought");
List<String> jsonFiles = new ArrayList<String>();
jsonFiles.add("target/cucumber.json");
//list.add("target/cucumber2.json");
String jenkinsBasePath = "";
String buildNumber = "1";
String projectName = "cucumber-jvm";
boolean skippedFails = true;
boolean pendingFails = false;
boolean undefinedFails = true;
boolean missingFails = true;
boolean runWithJenkins = false;
boolean parallelTesting = false;
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
// optionally only if you need
configuration.setStatusFlags(skippedFails, pendingFails, undefinedFails, missingFails);
configuration.setParallelTesting(parallelTesting);
configuration.setJenkinsBasePath(jenkinsBasePath);
configuration.setRunWithJenkins(runWithJenkins);
configuration.setBuildNumber(buildNumber);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}catch(Exception e){
e.printStackTrace();
}
}
}
Please provide your valuable suggestions to make my script work.
As per the latest version of cucumber-reports viz
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>3.2.0</version>
</dependency>
the constructor public ReportBuilder(List<String> jsonFiles, Configuration configuration) exists. Please check your dependencies/CLASSPATH and make sure you are using the correct version.
Please refer here

Java txt to sqlite database data transfer how can be faster

I wrote a java program about transfering a txt file to a sqlite db but it takes really more time there are about 83000 data (200 data takes about 1 minute).
how can i increase transfering speed. İ tried adding arraylist than get but its not change
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.Statement;
public class NewMain {
public static Connection connect() {
Connection conn = null;
try {
String url1 = "jdbc:sqlite:c:/Users/sozdemir/Desktop/sozluk.db";
conn = DriverManager.getConnection(url1);
String sql1 = "CREATE TABLE IF NOT EXISTS KELIMELER (Kelime PRIMARYKEY NOT NULL);";
Statement s = conn.createStatement();
s.execute(sql1);
} catch (Exception e) {
System.out.println(e.getMessage());
}
return conn;
}
public void Verigir(String kelime){
String sql = "INSERT INTO KELIMELER (kelime) VALUES(?)";
try (Connection conn = this.connect();
PreparedStatement statement = conn.prepareStatement(sql)
){
statement.setString(1, kelime);
statement.executeUpdate();
} catch (Exception e) {
}
}
public static void main(String[] args) throws IOException {
/* connect();*/
NewMain app = new NewMain();
String kelime = null;
BufferedReader in = null;
int adet;
adet= 0;
in = new BufferedReader(new FileReader("C://Users//sozdemir//Desktop//ozluk.txt"));
while ((kelime=in.readLine()) !=null) {
app.Verigir(kelime);
adet +=1;
System.out.println(81742 - adet);
}
}
}
Some hints:
Use a single prepareStatement
Put everything inside a transaction
Use PRAGMA synchronous = OFF and PRAGMA journal_mode = OFF
This will give you very fast inserts.

How should we handle SQL exceptions in the DAO layer?

How should we handle SQLExceptions in the DAO layer using Hibernate?
Create the class EmployeeDaoImpl.java
package com.mypro.module.emp.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.apache.commons.dbutils.DbUtils;
import com.mypro.module.emp.exception.EmployeeException;
import com.mypro.module.emp.model.Employee;
public class EmployeeDaoImpl extends JdbcDaoSupportImpl implements EmployeeDao {
#Override
public int save(Employee employee) throws EmployeeException {
// TODO Auto-generated method stub
String sql = "INSERT INTO EMPLOYEE VALUES(?,?,?)";
Connection conToUse = null;
PreparedStatement ps = null;
int status = 0;
try {
conToUse = getConnection();
ps = conToUse.prepareStatement(sql);
ps.setInt(1, employee.getEmpNo());
ps.setString(2, employee.getEmpName());
ps.setLong(3, employee.getEmpSal());
status = ps.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
throw new EmployeeException(
"%%% Exception occured in EmployeeDao save() %%% " + e);
} finally {
DbUtils.closeQuietly(ps);
}
return status;
}
}