Migrate to mousetech - part IA

This commit is contained in:
Tim Holloway 2021-12-28 12:24:58 -05:00
parent a2f7b9a290
commit 4f0ccdd3a2
8 changed files with 195 additions and 0 deletions

13
application.properties Normal file
View File

@ -0,0 +1,13 @@
joinfaces.jsf.project-stage=development
joinfaces.primefaces.theme=omega
spring.thymeleaf.enabled=false
spring.datasource.url=jdbc:sqlite:/home/timh/foo/bazz/recipes.db
#spring.datasource.username=dbuser
#pring.datasource.password=dbpass
spring.datasource.driverClassName=org.sqlite.JDBC
#spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
spring.jpa.database-platform=org.sqlite.hibernate.dialect.SQLiteDialect
#spring.jpa.show-sql: true

View File

@ -0,0 +1,10 @@
package com.mousetech.gourmetj;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.mousetech.gourmetj.persistence.model.Category;
@Repository
public interface CategoryRepository extends JpaRepository<Category, Long> {
}

View File

@ -0,0 +1,24 @@
package com.mousetech.gourmetj;
import java.io.Serializable;
import java.util.List;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import com.mousetech.gourmetj.persistence.model.Category;
@Named
@ApplicationScoped
public class CategoryService implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private CategoryRepository categoryRepository;
public List<Category> findAll() {
return categoryRepository.findAll();
}
}

View File

@ -0,0 +1,31 @@
package com.mousetech.gourmetj;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import com.mousetech.gourmetj.persistence.model.Category;
@Named
@ViewScoped
public class CategoryView implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private CategoryService categoryRepository;
private List<Category> categories;
@PostConstruct
public void init() {
categories = categoryRepository.findAll();
}
public List<Category> getCategories() {
return categories;
}
}

View File

@ -0,0 +1,15 @@
package com.mousetech.gourmetj;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EntityScan(value = {"com.mousetech.gourmetj.persistence.model", "com.codenotfound.primefaces"})
public class SpringPrimeFacesApplication {
public static void main(String[] args) {
SpringApplication.run(SpringPrimeFacesApplication.class, args);
}
}

View File

@ -0,0 +1,68 @@
package com.mousetech.gourmetj.persistence.model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the "categories" database table.
* Generally only one category gets assigned per recipe, but the
* schema allows for more. There is no master category name
* table.
*/
@Entity
@Table(name="categories")
@NamedQuery(name="Category.findAll", query="SELECT c FROM Category c")
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
@Column(name="category")
private String category;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Long id;
// @ManyToOne(fetch=FetchType.EAGER, optional = false)
// @JoinColumn(name="recipe_id")
// private Recipe recipe;
//
// /**
// * @return the parent recipe
// */
// public Recipe getRecipe() {
// return recipe;
// }
//
// /**
// * @param recipe the parent recipe to set
// */
// public void setRecipe(Recipe recipe) {
// this.recipe = recipe;
// }
public Category() {
}
public String getCategory() {
return this.category;
}
public void setCategory(String category) {
this.category = category;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
@Override
public String toString() {
return this.getCategory();
}
}

View File

@ -0,0 +1,11 @@
server:
context-path: /codenotfound
port: 9090
spring:
datasource:
url: jdbc:sqlite:/home/timh/foo/bazz/recipes.db
jpa:
hibernate:
ddl-auto: none
database-platform: org.sqlite.hibernate.dialect.SQLiteDialect

View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>PrimeFaces DataTable Example Foo</title>
</h:head>
<h:body>
<p:dataTable var="car" value="#{categoryView.categories}">
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Category">
<h:outputText value="#{car.category}" />
</p:column>
</p:dataTable>
</h:body>
</html>