Java Standalone Persistence using JPA
Tech-Today

Java Standalone Persistence using JPA



This application demonstrates the use of JPA in a standalone Java application.

I. Getting Started

This project is a standalone Java application that reads a server log file, parses and saves to a MySQL table access_log.

It also executes a named query that groups and filter the access log table via IP and threshold. It logs the grouped and filtered records in the console and another MySQL table named block_ip.

The project is created using maven and uses an entity manager to manage the entities. It compiles a project with all the dependencies and creates a jar named parser-jar-with-dependencies.jar in the target folder.

*Note that you must set your timezone to UTC.

II. Prerequisites

III. Running the tests

Before running the command the database must be reset first. Execute "sql/1 - schema.sql".

You must be inside the target folder before you execute the following commands.

java -jar parser-jar-with-dependencies.jar --startDate=2017-01-01.15:00:00 --duration=hourly --threshold=200 --accesslog=D:\Downloads\exercise\parser\src\main\resources\access.log
>The output will have 192.168.11.231 which has 200 or more requests between 2017-01-01.15:00:00 and 2017-01-01.15:59:59

java -jar parser-jar-with-dependencies.jar --startDate=2017-01-01.00:00:00 --duration=daily --threshold=500 --accesslog=D:\Downloads\exercise\\parser\src\main\resources\access.log
>The output will have 192.168.102.136 which has 500 or more requests between 2017-01-01.00:00:00 and 2017-01-01.23:59:59

The SQL used to create the schema and test the queries are stored in exercise/parser/sql folder.

Where

IV. Codes

AccessLog entity. This is where we will install the logs.
Notice that we have created a named query that we will use to filter a request given a date range and number of request for a given IP.

The PersistenceManager that we use to create a local entity manager factory resource with a given persistence.xml. And finally, here is the service class that:




- How To Create A Modularized Ear Project In Maven
This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api). How it looks like (assuming our top project is named ipiel): +ipiel  +ipiel-ear...

- Create A Simple Javaee6 Web App With Maven, Glassfish And Postgresql
This tutorial creates a simple javaee6 project using eclipse with maven. The application has 1 xhtml page that has a create button, and as you guest it when press will create an Employee record in the database. We use postgresql as the database and glassfish...

- A Maven Project That Have Multiple Property Files Via Maven Antrun Plugin
This tutorial will answer several questions (below) within a maven project that has several configuration files (dataset, property, persistence). 1.) How to have multiple persistence, datasource and property files depending on the profile or environment...

- Create A New Seam Web Project In Eclipse-helios
In this exercise we will be building seam web project in eclipse. It's long so stay focus :-D. What you need (The following should be installed correctly): Note: in parentheses is where I installed mine. 1.) Jboss seam 2.2.1 (C:\jboss-seam-2.2.1)...

- Mysql Engine: Myisam Vs Innodb
MyISAM (http://dev.mysql.com/doc/refman/5.0/en/myisam-storage-engine.html) -to create a MyISAM table, add ENGINE = MYISAM; at the end of create table script -supports table locking (this is an issue when you need to backup the whole database) -fast execution...



Tech-Today








.