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 applicat...


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

  • Java 8
  • MySQL or MariaDB
  • Maven
  • Installing
  • Clone the repository and let it download all the dependencies.

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
  • startDate - the lower data boundary when a line was created on the log file
  • duration - either hourly (1hour) or daily (24hours)
  • threshold - the minimum ip count given the date range
  • accesslog - path to log file

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:
  • Reads the log file
  • Saves the request log into a MySQL table
  • Filter the MySQL table given a date range and a minimum grouping count base on IP
  • Insert the IP that exceeds the request count on a given date range on another table

COMMENTS

mas template
Name

amazon,1,angular,8,bigdata,2,business,1,course-spring,27,courses,6,database,4,docker,3,java,50,kafka,1,keycloak,4,microservices,5,mysql,1,neworking,1,nosql,2,php,1,pinned,2,react,3,server management,7,shared drive,1,spring,7,synology,1,troubleshooting,2,web,1,wordpress,1,
ltr
item
toztech: Java Standalone Persistence using JPA
Java Standalone Persistence using JPA
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7wpdahjjFR0qn2uJbnNcz63T3Wh67IZHbvNpkQT2bPynwUFdtsWRAef5yQlUoo6lUSGBGyP05Wi3DKA4MxEt4oKcr_uoWw52djO0-w0s_7lh6qMTutHJKJALeb3VCLJYwP7PGoiQVe8Q/s400/bc_parser.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7wpdahjjFR0qn2uJbnNcz63T3Wh67IZHbvNpkQT2bPynwUFdtsWRAef5yQlUoo6lUSGBGyP05Wi3DKA4MxEt4oKcr_uoWw52djO0-w0s_7lh6qMTutHJKJALeb3VCLJYwP7PGoiQVe8Q/s72-c/bc_parser.png
toztech
https://toztech.blogspot.com/2019/07/java-standalone-persistence-using-jpa.html
https://toztech.blogspot.com/
https://toztech.blogspot.com/
https://toztech.blogspot.com/2019/07/java-standalone-persistence-using-jpa.html
true
2554149350007112447
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content