ORM

개요

ORM Service 를 적용해서 (egovframework-ormcivilappealsample)으로 별도 구현되어 있다.

설명

Configuration

resources\META-INF\persistence.xml

<persistence-unit name="HSQLMUnit" transaction-type="RESOURCE_LOCAL">
 
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
 
    <class>egovframework.rte.cvpl.service.CvplUser</class>
    <exclude-unlisted-classes/>
 
    <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
    </properties>
</persistence-unit>

resources\spring\context-jpa.xml

<tx:annotation-driven />
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>  
 
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="HSQLMUnit"/>
    <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
    <property name="dataSource" ref="dataSource"/>
</bean> 
 
<context:component-scan base-package="egovframework"/>

resources\spring\context-datasource.xml

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
	<property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
	<property name="url" value="jdbc:log4jdbc:hsqldb:hsql://localhost/cvpldb"/>
	<property name="username" value="sa"/>
</bean>

resources\spring\context-transaction.xml

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="*" propagation="REQUIRES_NEW"
            rollback-for="Exception" />
    </tx:attributes>
</tx:advice>
 
<aop:config>
	<aop:pointcut id="requiredTx"
		expression="execution(* egovframework.rte.cvpl..impl.*Impl.*(..))"/>
	<aop:advisor advice-ref="txAdvice"
		pointcut-ref="requiredTx" />
</aop:config>

Source

egovframework\rte\cvpl\service\CvplUser.java

@Entity
@SqlResultSetMapping(name="setMap",
		 columns = { @ColumnResult(name = "totCnt") })
@Table(name="RTETNORMUSER")
@NamedQueries({
	@NamedQuery(name = "selectCvplUserList", 
	    query = "FROM CvplUser cvplUser"),
	@NamedQuery(name = "selectCvplUserId", 
	    query = "FROM CvplUser cvplUser 
	                WHERE cvplUser.userId = :searchKeyword ORDER BY cvplUser.userId"),
	@NamedQuery(name = "selectCvplUserName", 
	    query = "FROM CvplUser cvplUser 
	                WHERE cvplUser.userName like :searchKeyword ORDER BY cvplUser.userName")
})
public class CvplUser implements Serializable {
 
	private static final long serialVersionUID = 1L;
 
	@Id
	@Column(name = "USER_ID", length=20)
	private String userId;
 
	@Column(name = "USER_NAME", length=20)
	private String userName;
	.
	.
	.

egovframework\rte\cvpl\service\impl\CvplUserDAO.java

@Repository("cvplUserDAO")
public class CvplUserDAO {
 
	@PersistenceContext
	private EntityManager em;
        .
        .
        .
 
    	String strQl = "selectCvplUserList";
    	String searchCondition = searchVO.getSearchCondition();
    	String searchKeyword = searchVO.getSearchKeyword();
 
    	if( "0".equals(searchCondition) ) {
    		strQl = "selectCvplUserId";
    	} else {
    		strQl = "selectCvplUserName";
    		searchKeyword = "%" + searchKeyword + "%";
    	}
 
    	Query qlQuery = em.createNamedQuery(strQl);
    	qlQuery.setParameter("searchKeyword", searchKeyword);
    	qlQuery.setFirstResult(searchVO.getFirstIndex());
    	qlQuery.setMaxResults(searchVO.getRecordCountPerPage());
 
    	return qlQuery.getResultList();
 
        .
        .
        .
 
egovframework/rte/sample/cvpl/orm.txt · 마지막 수정: 2023/12/21 05:21 (외부 편집기)
 
이 위키의 내용은 다음의 라이센스에 따릅니다 :CC Attribution-Noncommercial-Share Alike 3.0 Unported
전자정부 표준프레임워크 라이센스(바로가기)

전자정부 표준프레임워크 활용의 안정성 보장을 위해 위험성을 지속적으로 모니터링하고 있으나, 오픈소스의 특성상 문제가 발생할 수 있습니다.
전자정부 표준프레임워크는 Apache 2.0 라이선스를 따르고 있는 오픈소스 프로그램입니다. Apache 2.0 라이선스에 따라 표준프레임워크를 활용하여 발생된 업무중단, 컴퓨터 고장 또는 오동작으로 인한 손해 등에 대해서 책임이 없습니다.
Recent changes RSS feed CC Attribution-Noncommercial-Share Alike 3.0 Unported Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki