Tuesday, April 12, 2016
Monday, April 11, 2016
TIL: Oracle BPEL Process Manager
BPEL is the standard for assembling a set of discrete services into an
end-to-end process flow, radically reducing the cost and complexity of
process integration initiatives. Oracle BPEL Process Manager offers a
comprehensive and easy-to-use infrastructure for creating, deploying and
managing BPEL business processes.
http://www.oracle.com/technetwork/middleware/bpel/overview/index.html
http://www.oracle.com/technetwork/middleware/bpel/overview/index.html
Sunday, April 10, 2016
Thursday, March 31, 2016
Monday, March 28, 2016
Windows wireless service is not running on this computer in Windows 10
Run the following commands in the command prompt as Administrator to fix the issue in Windows 10. A system restart will be required.
netsh winsock reset catalog
netsh int ip reset reset.log hit
netsh winsock reset catalog
netsh int ip reset reset.log hit
Sunday, March 27, 2016
BindingResult result follows validated object
BindingResult result has to follow the object show that it binds to properly validate the inputs. Otherwise, you'll get an exception similar to "field error in object on field rejected value codes".
@RequestMapping(value={"/addnewshow", "/editshow"}, method=RequestMethod.POST)
public String processShow(@Valid @ModelAttribute("show") Show show, BindingResult result,
@RequestParam(value="showid", required=false) Long showId)
{
if(result.hasErrors()){
return "myapp.editshow";
}
else{
show.setId(showId);
show = showService.save(show);
}
return "redirect:editshow.html?showid=" + show.getId();
}
@RequestMapping(value={"/addnewshow", "/editshow"}, method=RequestMethod.POST)
public String processShow(@Valid @ModelAttribute("show") Show show, BindingResult result,
@RequestParam(value="showid", required=false) Long showId)
{
if(result.hasErrors()){
return "myapp.editshow";
}
else{
show.setId(showId);
show = showService.save(show);
}
return "redirect:editshow.html?showid=" + show.getId();
}
Friday, March 25, 2016
Thursday, March 24, 2016
Wednesday, March 16, 2016
Querystring or Model values
<c:set var="showId" value="${param.showid}"/>
~
<c:set var="showId" value="${show.getId()}"/>
~
<c:set var="showId" value="${show.getId()}"/>
Monday, March 14, 2016
Java Config dataSourceInitializer
@Value("classpath:db/sql/insert-data.sql")
private org.springframework.core.io.Resource DATA_SCRIPT;
@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
final DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setDatabasePopulator(databasePopulator());
return initializer;
}
private DatabasePopulator databasePopulator() {
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(DATA_SCRIPT);
return populator;
}
OR
populator.addScript(new ClassPathResource("db/sql/insert-data.sql"));
private org.springframework.core.io.Resource DATA_SCRIPT;
@Bean
public DataSourceInitializer dataSourceInitializer(final DataSource dataSource) {
final DataSourceInitializer initializer = new DataSourceInitializer();
initializer.setDataSource(dataSource);
initializer.setDatabasePopulator(databasePopulator());
return initializer;
}
private DatabasePopulator databasePopulator() {
final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
populator.addScript(DATA_SCRIPT);
return populator;
}
OR
populator.addScript(new ClassPathResource("db/sql/insert-data.sql"));
Sunday, March 13, 2016
Saturday, February 27, 2016
JAVA JPA Goal Repository
JAVA JPA
//Repository
package com.thekhuc.repository;
import java.util.List;
import com.thekhuc.model.Goal;
import com.thekhuc.model.GoalReport;
public interface GoalRepository {
Goal save(Goal goal);
List<Goal> loadAll();
List<GoalReport> findAllGoalReports();
}
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Repository;
import com.thekhuc.model.Goal;
import com.thekhuc.model.GoalReport;
@Repository("goalRepository")
public class GoalRepositoryImpl implements GoalRepository {
@PersistenceContext
private EntityManager em;
@Override
public Goal save(Goal goal) {
if(goal.getId() == null){
em.persist(goal);
em.flush();
}
else{
goal = em.merge(goal);
}
return goal;
}
@Override
public List<Goal> loadAll() {
//Query query=em.createQuery("Select g from Goal g");
TypedQuery<Goal> query = em.createNamedQuery(Goal.FIND_ALL_GOALS, Goal.class);
return query.getResultList();
}
@Override
public List<GoalReport> findAllGoalReports() {
//Query query = em.createQuery("Select new com.thekhuc.model.GoalReport(g.minutes, e.minutes, e.activity) " +
// "from Goal g, Exercise e where g.id = e.goal.id");
TypedQuery<GoalReport> query = em.createNamedQuery(Goal.FIND_GOAL_REPORTS, GoalReport.class);
return query.getResultList();
}
}
//Repository
package com.thekhuc.repository;
import java.util.List;
import com.thekhuc.model.Goal;
import com.thekhuc.model.GoalReport;
public interface GoalRepository {
Goal save(Goal goal);
List<Goal> loadAll();
List<GoalReport> findAllGoalReports();
}
//Interface
package com.thekhuc.repository;import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Repository;
import com.thekhuc.model.Goal;
import com.thekhuc.model.GoalReport;
@Repository("goalRepository")
public class GoalRepositoryImpl implements GoalRepository {
@PersistenceContext
private EntityManager em;
@Override
public Goal save(Goal goal) {
if(goal.getId() == null){
em.persist(goal);
em.flush();
}
else{
goal = em.merge(goal);
}
return goal;
}
@Override
public List<Goal> loadAll() {
//Query query=em.createQuery("Select g from Goal g");
TypedQuery<Goal> query = em.createNamedQuery(Goal.FIND_ALL_GOALS, Goal.class);
return query.getResultList();
}
@Override
public List<GoalReport> findAllGoalReports() {
//Query query = em.createQuery("Select new com.thekhuc.model.GoalReport(g.minutes, e.minutes, e.activity) " +
// "from Goal g, Exercise e where g.id = e.goal.id");
TypedQuery<GoalReport> query = em.createNamedQuery(Goal.FIND_GOAL_REPORTS, GoalReport.class);
return query.getResultList();
}
}
Sunday, February 21, 2016
persistence.xml
/src/main/resources/META-INF/persistence.xml
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.or/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/XML/ns/persistence http://java.sun.com/xml/ns/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="punit"></persistence-unit>
</persistence>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.or/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/XML/ns/persistence http://java.sun.com/xml/ns/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="punit"></persistence-unit>
</persistence>
jpaContext.xml
/src/main/resources/jpaContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
<context:annotation-config/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="punit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<entry key="hibernate.hbm2ddl.auto" value="create"/>
<entry key="hibernate.format_sql" value="true"/>
</map>
</property>
</bean>
<bean id="transactionmanager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/fitnesstracker?autoReconnect=true"/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.2.xsd">
<context:annotation-config/>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="punit"/>
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
</bean>
</property>
<property name="jpaPropertyMap">
<map>
<entry key="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<entry key="hibernate.hbm2ddl.auto" value="create"/>
<entry key="hibernate.format_sql" value="true"/>
</map>
</property>
</bean>
<bean id="transactionmanager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/fitnesstracker?autoReconnect=true"/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
</beans>
Friday, February 19, 2016
Monday, January 18, 2016
Tuesday, December 8, 2015
Saturday, November 21, 2015
Sunday, November 15, 2015
Consuming a RESTful Web Service Video and Notes
mkdir src/main/java/hello
@JsonIgnoreProperties - any properties not bound in this type should be ignored.
gradle bootRun
or
gradle build
java -jar build/libs/gs-consuming-rest-0.1.0.jar
OR
gradle wrapper
./gradlew bootRun
or
./gradlew build
java -jar build/libs/gs-consuming-rest-0.1.0.jar
OR
mvn spring-boot:run
or
mvn clean package
java -jar target/gs-consuming-rest-0.1.0.jar
output:
2015-11-14 03:20:26.415 INFO 23613 --- [main] hello.Application : Quote{type='success', value=Value{id=12, quote='@springboot with @springframework is pure productivity! Who said in #java one has to write double the code than in other langs? #newFavLib'}}
@JsonIgnoreProperties - any properties not bound in this type should be ignored.
gradle bootRun
or
gradle build
java -jar build/libs/gs-consuming-rest-0.1.0.jar
OR
gradle wrapper
./gradlew bootRun
or
./gradlew build
java -jar build/libs/gs-consuming-rest-0.1.0.jar
OR
mvn spring-boot:run
or
mvn clean package
java -jar target/gs-consuming-rest-0.1.0.jar
output:
2015-11-14 03:20:26.415 INFO 23613 --- [main] hello.Application : Quote{type='success', value=Value{id=12, quote='@springboot with @springframework is pure productivity! Who said in #java one has to write double the code than in other langs? #newFavLib'}}
Thursday, November 12, 2015
Building Java Projects with Maven Video and Notes
mvn compile
mvn package
mvn install
Greeter.java
package hello;
public class Greeter{
public String sayHello(){
return "Hello world!";
}
}
HelloWorld.java
package hello;
import org.joda.time.LocalTime;
public class HelloWorld{
public static void main(String[] args){
LocalTime currentTime = new LocalTime();
System.out.println("The curent local time is " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
mvn package
mvn install
Greeter.java
package hello;
public class Greeter{
public String sayHello(){
return "Hello world!";
}
}
HelloWorld.java
package hello;
import org.joda.time.LocalTime;
public class HelloWorld{
public static void main(String[] args){
LocalTime currentTime = new LocalTime();
System.out.println("The curent local time is " + currentTime);
Greeter greeter = new Greeter();
System.out.println(greeter.sayHello());
}
}
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Monday, November 9, 2015
Subscribe to:
Posts (Atom)

