Monthly Archives: February 2014

Spring3.x with Mybatis 3.x insert시에 generated key 받아오기

스프링4.x 이 나왔지만 아직까지 제대로 검토를 못해봐서… 3.x까지만.. 확인.

롬복사용한 도메인포조DomainPOJO with lombok

@Data
public class EventLog {
	private Long eventLogId;
	private String eventResultStatusCode;
	private Timestamp createdAt;
	private String description;
	private Long eventInfoId;
	//OCCURRENCE, CONFIRM, RESOVED
	private String eventStatus;
}

매퍼인터페이스 Mapper interface

public interface LogMapper {
	int insertEventLog(EventLog eventLog);
}

매퍼xml Mapper xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="mapper.LogMapper">
	<cache />

    <!-- <insert id="insertEventLog" parameterType="EventLog" > -->
    <insert id="insertEventLog" parameterType="EventLog"  useGeneratedKeys="true" keyProperty="eventLogId">
		INSERT INTO event_log(
			event_result_status_code,
			description,
			event_info_id
		)VALUES(
			#{eventResultStatusCode},
			#{description},
			#{eventInfoId}
		)
	</insert>
</mapper>

테스트코드 Junit TestCode

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(
		locations = {
				"classpath*:spring-context.xml"
		}
)
public class LogInsertTest {

	@Autowired
	LogMapper logMapper;
	
	@Test
	public void test(){
		EventLog eventLog = new EventLog();
		eventLog.setEventResultStatusCode("200");
		eventLog.setDescription("desc");
		eventLog.setEventInfoId(54L);
		
		int result = logMapper.insertEventLog(eventLog);
		System.out.println(result);
		System.out.println(eventLog);
	}
}

리턴값은 적용된 쿼리의 로우수

call by reference로 값을 확인할 수 있다.

기존 코드에서 몇 라인정도만 수정해주면 된다.

 

 

 

 

Ubuntu12.04 postgresql with postgis

현재 우분투 버전 13.04 postgis설치시에 apt-get 기본패키지로 postgresql 9.1과 그에 딸린  postgis설치하면 제대로 동작을 하지않는다.

정확한 패키지명.. postgresql-9.1-postgis

 

2.x버전을 설치해야 제대로 동작한다고한다.

관련 페이지.

http://trac.osgeo.org/postgis/wiki/UsersWikiPostGIS20Ubuntu1210src

http://docs.geonode.org/en/latest/tutorials/admin/install/install_postgis.html

http://postgis.net/docs/postgis_installation.html#make_install_postgis_extensions

삭제되는경우를 대비하여 복사.

How to install PostGIS 2.0 on Ubuntu 12.10 (quantal) from source
Prerequisites

Several components are needed, which can either be built from source or installed from pre-built packages, as shown below.

Install prerequisite packages using:

sudo apt-get install build-essential postgresql-9.1 postgresql-server-dev-9.1 libgeos-c1 libxml2-dev libproj-dev libjson0-dev xsltproc docbook-xsl docbook-mathml
Optional package for raster support (this is required if you want to build the PostgreSQL extensions):

sudo apt-get install libgdal1-dev
Build PostGIS

wget http://download.osgeo.org/postgis/source/postgis-2.0.4.tar.gz
tar xfz postgis-2.0.4.tar.gz
cd postgis-2.0.4
PostGIS 2.0 can be configured to disable topology or raster components, using the configure flags --without-raster and/or --without-topology. The default is to build both. Note that raster is required for the extension installation method for PostgreSQL.

./configure
make
sudo make install
sudo ldconfig
sudo make comments-install
Lastly, enable the command-line tools to work from your shell:

sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/shp2pgsql
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/pgsql2shp
sudo ln -sf /usr/share/postgresql-common/pg_wrapper /usr/local/bin/raster2pgsql
Spatially enabling a database

With PostgreSQL 9.1, there are two methods to add PostGIS functionality to a database: using extensions, or using enabler scripts.

PostGIS Extension for PostgreSQL

Spatially enabling a database using extensions is a new feature of PostgreSQL 9.1.

Connect to your database using pgAdmin or psql, and run the following commands. To add postgis with raster support:

CREATE EXTENSION postgis;
To add topology support, a second extension can be created on the database:

CREATE EXTENSION postgis_topology;
Enabler Scripts / Template

Enabler scripts can be used to either build a template, or directly spatially enable a database. This method is older than the extension method, but is required if the raster support is not built.

The following example creates a template, which can be re-used for creating multiple spatially-enabled databases. Or if you just want to make one spatially enabled database, you can modify the commands for your needs.

PostGIS:

sudo -u postgres createdb template_postgis
sudo -u postgres psql -d template_postgis -c "UPDATE pg_database SET datistemplate=true WHERE datname='template_postgis'"
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/spatial_ref_sys.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/postgis_comments.sql
with raster support:

sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/rtpostgis.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/raster_comments.sql
with topology support:

sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology.sql
sudo -u postgres psql -d template_postgis -f /usr/share/postgresql/9.1/contrib/postgis-2.0/topology_comments.sql
See also

 https://help.ubuntu.com/community/PostgreSQL