Skip to content

Commit

Permalink
Revises SessionFactoryBean
Browse files Browse the repository at this point in the history
  • Loading branch information
htr3n committed Jun 21, 2018
1 parent 6c74e7a commit da1f9a2
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 338 deletions.
422 changes: 130 additions & 292 deletions loan-approval-portal.iws

Large diffs are not rendered by default.

35 changes: 24 additions & 11 deletions src/main/java/com/westbank/db/PortalSessionFactoryBean.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.westbank.db;

import com.westbank.db.entity.*;
import com.westbank.db.entity.Agency;
import com.westbank.db.entity.Contract;
import com.westbank.db.entity.Customer;
import com.westbank.db.entity.LoanFile;
import com.westbank.db.entity.Role;
import com.westbank.db.entity.Staff;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
Expand All @@ -10,7 +15,6 @@
import org.hibernate.tool.schema.TargetType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
Expand Down Expand Up @@ -93,19 +97,28 @@ void initializeTestingData(SessionFactory sessionFactory) {

Agency agency = new Agency();

Customer alice = new Customer();
alice.setFirstName("Alice");
alice.setLastName("Power");
alice.setPin("abc123");
alice.setIncome(80000.0);
alice.setEmail("power@abc.com");


// start saving data to the database
final Session session = sessionFactory.openSession();
try {
final Transaction transaction = session.beginTransaction();
template.save(agency);
template.save(manager);
template.save(supervisor);
template.save(broker);
template.save(clerk);
template.save(staff1);
template.save(staff2);
template.save(staff3);
template.save(staff4);
session.save(alice);
session.save(agency);
session.save(manager);
session.save(supervisor);
session.save(broker);
session.save(clerk);
session.save(staff1);
session.save(staff2);
session.save(staff3);
session.save(staff4);
transaction.commit();
} finally {
session.close();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback.dev.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
<logger name="com.mchange" level="WARN" />
-->
<logger name="org.hibernate.cfg" level="INFO" />
<logger name="org.hibernate.connection" level="DEBUG" />
<logger name="org.hibernate.impl" level="DEBUG" />
<logger name="org.hibernate.connection" level="INFO" />
<logger name="org.hibernate.impl" level="INFO" />
</configuration>
29 changes: 29 additions & 0 deletions src/main/webapp/WEB-INF/dao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,34 @@
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<!--
<bean id="customerService" class="com.westbank.db.service.CustomerServiceImpl" >
<constructor-arg ref="customerDao"/>
</bean>
<bean id="loanFileService" class="com.westbank.db.service.LoanFileServiceImpl" />
<bean id="contractService" class="com.westbank.db.service.LoanContractServiceImpl" >
<constructor-arg ref="loanContractDao" />
</bean>
<bean id="staffService" class="com.westbank.db.service.StaffServiceImpl" >
<constructor-arg ref="staffDao"/>
</bean>
-->

<bean id="customerDao" class="com.westbank.db.dao.CustomerDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="loanFileDao" class="com.westbank.db.dao.LoanFileDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="loanContractDao" class="com.westbank.db.dao.LoanContractDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="agencyDao" class="com.westbank.db.dao.AgencyDaoImpl"/>

<bean id="staffDao" class="com.westbank.db.dao.StaffDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

</beans>
32 changes: 1 addition & 31 deletions src/main/webapp/WEB-INF/data-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
http://www.springframework.org/schema/beans/spring-beans.xsd">

<import resource="dao.xml" />
<import resource="test-beans.xml" />

<bean id="propertyPlaceholderConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
Expand Down Expand Up @@ -74,35 +75,4 @@
</property>
</bean>


<!--
<bean id="customerService" class="com.westbank.db.service.CustomerServiceImpl" >
<constructor-arg ref="customerDao"/>
</bean>
<bean id="loanFileService" class="com.westbank.db.service.LoanFileServiceImpl" />
<bean id="contractService" class="com.westbank.db.service.LoanContractServiceImpl" >
<constructor-arg ref="loanContractDao" />
</bean>
<bean id="staffService" class="com.westbank.db.service.StaffServiceImpl" >
<constructor-arg ref="staffDao"/>
</bean>
-->

<bean id="customerDao" class="com.westbank.db.dao.CustomerDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="loanFileDao" class="com.westbank.db.dao.LoanFileDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="loanContractDao" class="com.westbank.db.dao.LoanContractDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

<bean id="agencyDao" class="com.westbank.db.dao.AgencyDaoImpl" />

<bean id="staffDao" class="com.westbank.db.dao.StaffDaoImpl"
p:sessionFactory-ref="sessionFactory"/>

</beans>
1 change: 0 additions & 1 deletion src/main/webapp/WEB-INF/mvc-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</bean>

<import resource="resources.xml" />
<import resource="test-beans.xml" />

<mvc:annotation-driven />

Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/WEB-INF/test-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean
id="customerAliceMeyer"
id="exampleLoanForm"
class="com.westbank.mvc.customer.model.ApplicationForm"
p:loanAmount="100000"
p:loanReason="Home Mortgage"
Expand Down

0 comments on commit da1f9a2

Please # to comment.