Skip to content

Instantly share code, notes, and snippets.

public class CartRepository {
private static Properties dbConnProps;
public static List<Cart> getCartItems(String userId) throws SQLException {
List<Cart> records = new ArrayList<>();
Connection connection = DriverManager.getConnection(dbConnProps.getProperty("url"),
dbConnProps.getProperty("user"),
dbConnProps.getProperty("password"));
"""
config.json
{
"stats_key1": {
"name": "Stats Key1",
"compute": {
"function": "calc_stats_key1",
"args": {"name": "test1", "age": 1}
}
},
@abhilater
abhilater / gist:cbc4f9c404bd14cb2ef5c5e198bfae02
Created September 20, 2020 12:09 — forked from aspyker/gist:2a9ecaed1a2c79f1b0d6
running jmxterm from command line to force gc
wget http://downloads.sourceforge.net/project/cyclops-group/jmxterm/0.2/jmxterm-0.2-uber.jar
a@a:~$ java -jar jmxterm-0.2-uber.jar
Welcome to JMX terminal. Type "help" for available commands.
?$ open localhost:8076
Connection to localhost:8076 is opened
>$ bean java.lang:type=Memory
bean is set to java.lang:type=Memory
>$ run gc
calling operation gc of mbean java.lang:type=Memory
/**
* Maps the {@link ResultSet} object from SQL query result to ORM Entity class.
* <p>
* For reflection cost optimization it uses the entity class fields list from
* {@link orm.cache.EntityFieldsCache} cache object.
* <p>
* It maps SQL data types to the Java data types as defined in the {@link ColumnField} annotations.
*/
public final class ResultSetToEntityMapper {
DROP TABLE IF EXISTS issue_metrics_table;
CREATE TABLE IF NOT EXISTS issue_metrics_table (
domain TEXT NOT NULL,
issue_id TEXT NOT NULL,
created_at BIGINT NOT NULL,
inbound_count BIGINT,
outbound_count BIGINT,
csat INT
);
/**
* Data accessor class to access paginated entity objects {@link T}.
* These entity objects are mapped from {@link ResultSet} objects obtained from querying the
* table for the specified objects {@link T} for which {@link DataAccessor} class is defined
* <p>
* Created by abhishek on 21/06/19.
*/
public class DataAccessor<T> {
private final Class<T> entityClass;
public class DataAccessorTest {
@Test
public void issueMetricsPaginateTest() throws Exception {
DataAccessor<IssueMetrics> da = new DataAccessor<IssueMetrics>(IssueMetrics.class)
.withFilter(new String[]{"domain", "eq"}, "hscustomer")
.withFilter(new String[]{"created_at", "gte"}, 1001)
.withFilter(new String[]{"created_at", "lt"}, 1003)
.build();
Assert.assertNotNull(da.getGeneratedQuery());
/**
* ORM Entity class for 'agent_metrics_table' table.
*
* @ColumnField annotation injects the table schema information on each entity fields like
* i) the column name,
* ii) column alias to be used for aggregate function queries,
* iii) data type to which the table column data is to casted during data mapping to entity class
* iv) if this field corresponds to PK column and its position in the PK composite column and
* v) if this column is to be used as group-by field for an aggregated query
* vi) the aggregate function/UDF to applied on the column during query
/**
* ORM Entity class for 'issue_metrics_table' table.
*/
@Table(name = "issue_metrics_table")
public class IssueMetrics {
@ColumnField(type = ColumnField.FieldType.STRING,
name = "domain",
pk = true,
pkPosition = 0)
public String domain;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Table {
/**
* name of the table corresponding to this entity
*/
String name() default "";
}