Skip to content

Instantly share code, notes, and snippets.

View ggdio's full-sized avatar
:octocat:
Learning something new

Guilherme Dio ggdio

:octocat:
Learning something new
View GitHub Profile
@ggdio
ggdio / application.properties
Created December 2, 2015 17:20
Spring Boot Application Properties FULL
# ===================================================================
# COMMON SPRING BOOT PROPERTIES
#
# This sample file is provided as a guideline. Do NOT copy it in its
# entirety to your own application. ^^^
# ===================================================================
# ----------------------------------------
# CORE PROPERTIES
@ggdio
ggdio / Controller.java
Created October 26, 2013 17:39
Controller for JPA
package br.com.ggdio.gist;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public abstract class Controller<T> {
@ggdio
ggdio / Service.java
Last active December 26, 2015 15:19
Service class for JPA
package br.com.ggdio.gist;
public abstract class Service<T> {
private final Dao<T> dao;
public Service(Dao<T> dao) {
super();
this.dao = dao;
}
@ggdio
ggdio / Dao.java
Last active December 26, 2015 15:19
Generic Dao for JPA
package br.com.ggdio.gist;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityNotFoundException;
@ggdio
ggdio / persistence.xml
Created October 25, 2013 19:16
Persistence.xml file for datasource
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="user-unit">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/jdbc/ExampleDS</jta-data-source>
@ggdio
ggdio / persistence.xml
Created October 11, 2013 12:11
Persistence XML for hibernate
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="<PERSISTENCE UNIT NAME>">
<properties>
<!--
@ggdio
ggdio / Hibernate Reverse Engineering
Last active December 24, 2015 10:59
HIBERNATE - Entity classes generation
1 - Download Hibernate Tools. [1] and extract content to root folder of Eclipse (should merge plugins and features folders).
2 - Start eclipse.
3 - Click on [File -> New -> Other -> Hibernate -> Hibernate Configuration File] and create a cfg file. The following properties should be specified : jdbc url , username, password, DB schema, driver class and dialect.
4 - Click on [File -> New -> Other -> Hibernate -> Hibernate Console Configuration ] and create a new console configuration. Add the jar file that contains your DB driver in the classpath section at the bottom.
5 - Enter the name of the console configuration. Click Browse button against the Configuration file and select the cfg.xml file created in step 3.
6 - Click on [File -> New -> Other -> Hibernate -> Hibernate Reverse Engineering File(reveng.xml) ] and select the location of the file.
7 - Select the cfg.xml file created in step 3 as the Console Configuration. Click on include button and specify the schema and table name(s) to reverse engineer. Mult
@ggdio
ggdio / UploadServlet.java
Created October 1, 2013 10:49
A file upload demonstration using HttpServlet
// Import required java libraries
import java.io.*;
import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ggdio
ggdio / JBoss Deploy - Maven
Last active December 24, 2015 08:39
POM.xml configuration to auto-deploy war, using maven, to JBoss AS Run Command: jboss-as:deploy
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<!-- Java EE 6 doesnt require web.xml -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
@ggdio
ggdio / DaoTestExample.java
Created September 30, 2013 16:08
Integration TEST for DAOs and SQLs - JUnit
//Imports
public class DaoTestExample {
//The class fields to be used
private Session session;
private MyDao dao;
//Before each test
@Before
public void before(){