Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Wicket 8 and Hibernate 5 and add Flyway. #6

Merged
merged 1 commit into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ Now validate that all your properties are correct and confirm. Your project is n

### Create database schema

Just run the following command to create the database and corresponding schema:
```bash
cd <project dir>
bash share/scripts/apply_sql.sh
```
If the database doesn't exist, you will be prompted for permission to create it. Following this, all SQL scripts are executed, setting up your database automatically.
Create the database manually. The archetype includes Flyway and will create the schema automatically when it runs.

### Run it

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.premiumminds.persistence.utils.HibernateDDL"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--update app-data-unit jdbc:postgresql://localhost/${databaseName} postgres postgres"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="--update app-data-unit-ddl jdbc:postgresql://localhost/${databaseName} postgres postgres"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="${artifactId}"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
</launchConfiguration>
53 changes: 35 additions & 18 deletions src/main/resources/archetype-resources/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<url>http://www.premium-minds.com</url>

<properties>
<wicket.version>7.6.0</wicket.version>
<guice.version>4.1.0</guice.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<wicket.version>8.0.0</wicket.version>
<guice.version>4.2.0</guice.version>
<hibernate.version>5.3.5.Final</hibernate.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
Expand All @@ -27,23 +27,23 @@
<!-- IN HOUSE DEPENDENCIES -->
<dependency>
<groupId>com.premiumminds</groupId>
<artifactId>pm-persistence-utils</artifactId>
<version>1.1</version>
<artifactId>pm-webapp-utils</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>com.premiumminds</groupId>
<artifactId>pm-webapp-utils</artifactId>
<version>1.4</version>
<artifactId>pm-persistence-utils</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.premiumminds</groupId>
<artifactId>pm-wicket-utils</artifactId>
<version>3.0</version>
<version>4.1</version>
</dependency>
<dependency>
<groupId>com.premiumminds</groupId>
<artifactId>wicket-crudifier</artifactId>
<version>3.0</version>
<version>4.0</version>
</dependency>

<!-- WICKET DEPENDENCIES -->
Expand Down Expand Up @@ -77,7 +77,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>me.moocar</groupId>
Expand All @@ -88,16 +88,22 @@
<!-- PERSISTENCE -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
<version>1.4.197</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.1.4</version>
</dependency>

<!-- GUICE -->
<dependency>
<groupId>com.google.inject</groupId>
Expand All @@ -114,26 +120,26 @@
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
<version>0.4</version>
</dependency>

<!-- MAIL -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.6</version>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.5.6</version>
<version>1.6.2</version>
</dependency>

<!-- JODA -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
<version>2.10</version>
</dependency>

<!-- TESTS -->
Expand All @@ -147,14 +153,14 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<version>3.6</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<version>4.0.0</version>
<scope>test</scope>
</dependency>

Expand Down Expand Up @@ -215,4 +221,15 @@
</plugin>
</plugins>
</build>

<repositories>
<repository>
<id>premiumminds-nexus-snapshots</id>
<name>premiumminds-nexus-snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots </url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
64 changes: 0 additions & 64 deletions src/main/resources/archetype-resources/share/scripts/apply_sql.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import javax.inject.Inject;

import org.flywaydb.core.Flyway;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -23,26 +24,31 @@ public class Application extends WebApplication {
@Override
protected void init() {
try {
Flyway flyway = new Flyway();
flyway.setDataSource("jdbc:postgresql://localhost/udifar-mvp", "postgres", "postgres");
flyway.setLocations("filesystem:src/main/sql/migrations");
flyway.migrate();

persistService.start();

getRequestCycleListeners().add(new TransactionalRequestCycleListener(persistenceTransaction));

super.init();
} catch(Throwable t){
log.error("error starting application", t);
throw t;
}
}

@Override
protected void finalize() throws Throwable {
try {
super.finalize();

persistService.stop();
} catch(Throwable t){
log.error("error ending application", t);
throw t;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.validation.constraints.Email;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.hibernate.validator.constraints.NotEmpty;
import org.hibernate.validator.constraints.Email;

@SuppressWarnings("serial")
@Entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import java.io.Serializable;
import java.util.Set;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

import org.hibernate.validator.constraints.NotEmpty;

@SuppressWarnings("serial")
@Entity
public class UserProfile implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void onClick() {
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(JQueryResourceReference.get())));
response.render(new PriorityHeaderItem(JavaScriptHeaderItem.forReference(getApplication().getJavaScriptLibrarySettings()
.getJQueryReference())));
}

/*
Expand Down Expand Up @@ -92,10 +93,8 @@ public void onComponentTag(Component component, ComponentTag tag) {
}

private boolean isActive(){
boolean ret = false;
for(Component submenu : visitChildren(Menu.class)){
ret |= ((Menu) submenu).isActive();
}
boolean ret = streamChildren().filter(c -> c instanceof Menu).anyMatch(c -> ((Menu)c).isActive());

return ret || TemplatePage.this.getClass().equals(pageClass);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public ChangePasswordPage(){

form.add(new AjaxSubmitLink("submit") {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
target.add(form);
protected void onSubmit(AjaxRequestTarget target) {
target.add(getForm());

try {
service.changePassword(getLoggedInUser(), currentPassword.getModelObject(), newPassword.getModelObject());
Expand All @@ -57,8 +57,8 @@ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
}

@Override
protected void onError(AjaxRequestTarget target, Form<?> form) {
target.add(form);
protected void onError(AjaxRequestTarget target) {
target.add(getForm());
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- A JPA Persistence Unit -->
<persistence-unit name="app-data-unit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/appDatasource</non-jta-data-source>

<mapping-file>META-INF/ormapping.xml</mapping-file>
Expand All @@ -19,10 +19,21 @@
<property name="hibernate.hbm2ddl.auto" value="validate"/>
</properties>
</persistence-unit>


<!-- A JPA Persistence Unit for DDL generation -->
<persistence-unit name="app-data-unit-ddl" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

<mapping-file>META-INF/ormapping.xml</mapping-file>

<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
</properties>
</persistence-unit>

<!-- A JPA Persistence Unit for testing-->
<persistence-unit name="app-data-unit-test" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

<mapping-file>META-INF/ormapping.xml</mapping-file>

Expand All @@ -34,4 +45,4 @@
</properties>
</persistence-unit>

</persistence>
</persistence>

This file was deleted.

Loading