Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
4220f74d
Commit
4220f74d
authored
Dec 29, 2014
by
Matija Obreza
Browse files
Spring configuration, hibernate.properties
parent
eacc0568
Changes
9
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/persistence/domain/GenesysLowlevelRepositoryImpl.java
View file @
4220f74d
...
...
@@ -23,8 +23,6 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.util.List
;
import
javax.sql.DataSource
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.genesys2.server.model.genesys.Method
;
...
...
@@ -47,16 +45,12 @@ import org.springframework.transaction.annotation.Transactional;
public
class
GenesysLowlevelRepositoryImpl
implements
GenesysLowlevelRepository
{
public
static
final
Log
LOG
=
LogFactory
.
getLog
(
GenesysLowlevelRepositoryImpl
.
class
);
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
MethodRepository
methodRepository
;
@Autowired
public
void
setDataSource
(
final
DataSource
dataSource
)
{
this
.
jdbcTemplate
=
new
JdbcTemplate
(
dataSource
);
}
@Override
@PreAuthorize
(
"hasRole('ADMINISTRATOR')"
)
@Transactional
(
readOnly
=
false
)
...
...
src/main/java/org/genesys2/server/service/GenesysService.java
View file @
4220f74d
...
...
@@ -132,7 +132,8 @@ public interface GenesysService {
Set
<
Long
>
filterAvailableForDistribution
(
Set
<
Long
>
accessionIds
);
List
<
Accession
>
saveAccession
(
Accession
...
accession
);
Accession
saveAccession
(
Accession
accession
);
List
<
Accession
>
saveAccessions
(
Iterable
<
Accession
>
accession
);
void
updateAccessionCount
(
FaoInstitute
institute
);
...
...
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
4220f74d
...
...
@@ -441,7 +441,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
for
(
Accession
a
:
accessionRepository
.
findAll
(
accessionIds
))
{
AllStuff
all
=
map
.
get
(
a
.
getId
());
all
.
accession
=
a
;
a
.
getStoRage
().
size
();
// Can use a#getStorage() instead
// a.getStoRage().size();
all
.
names
=
new
ArrayList
<
AccessionAlias
>();
all
.
remarks
=
new
ArrayList
<
AccessionRemark
>();
}
...
...
@@ -630,6 +631,8 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Transactional
(
readOnly
=
false
)
@CacheEvict
(
value
=
"statistics"
,
allEntries
=
true
)
public
void
updateAccessionCount
(
FaoInstitute
institute
)
{
if
(
institute
==
null
)
return
;
long
accessionCount
=
accessionRepository
.
countByInstitute
(
institute
);
institute
.
setAccessionCount
(
accessionCount
);
instituteRepository
.
save
(
institute
);
...
...
@@ -670,15 +673,29 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
@Override
@Transactional
(
readOnly
=
false
)
@CacheEvict
(
value
=
"statistics"
,
allEntries
=
true
)
public
List
<
Accession
>
saveAccession
(
Accession
...
accession
)
{
List
<
Accession
>
list
=
new
ArrayList
<
Accession
>();
for
(
final
Accession
a
:
accession
)
{
public
Accession
saveAccession
(
Accession
accession
)
{
if
(
LOG
.
isDebugEnabled
())
LOG
.
debug
(
"Updating "
+
a
);
accessionRepository
.
save
(
a
);
list
.
add
(
a
);
LOG
.
debug
(
"Updating "
+
accession
);
System
.
err
.
println
(
"Saving "
+
accession
+
" ST="
+
accession
.
getStorage
());
Accession
res
=
accessionRepository
.
save
(
accession
);
updateAccessionCount
(
accession
.
getInstitute
());
return
res
;
}
@Override
@Transactional
(
readOnly
=
false
)
@CacheEvict
(
value
=
"statistics"
,
allEntries
=
true
)
public
List
<
Accession
>
saveAccessions
(
Iterable
<
Accession
>
accessions
)
{
Set
<
FaoInstitute
>
institutes
=
new
HashSet
<
FaoInstitute
>();
for
(
Accession
accession
:
accessions
)
{
System
.
out
.
println
(
"Saving "
+
accession
+
" STO="
+
accession
.
getStoRage
()
+
" ST="
+
accession
.
getStorage
());
institutes
.
add
(
accession
.
getInstitute
());
}
return
list
;
List
<
Accession
>
res
=
accessionRepository
.
save
(
accessions
);
for
(
FaoInstitute
institute
:
institutes
)
updateAccessionCount
(
institute
);
return
res
;
}
@Override
...
...
src/main/java/org/genesys2/spring/config/SpringDataBaseConfig.java
View file @
4220f74d
...
...
@@ -18,12 +18,18 @@ package org.genesys2.spring.config;
import
java.util.Properties
;
import
javax.persistence.EntityManagerFactory
;
import
org.apache.tomcat.jdbc.pool.DataSource
;
import
org.hibernate.jpa.HibernatePersistenceProvider
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.config.PropertiesFactoryBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.ImportResource
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.orm.jpa.JpaTransactionManager
;
import
org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
;
import
org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter
;
...
...
@@ -51,11 +57,8 @@ public class SpringDataBaseConfig {
@Value
(
"${db.showSql}"
)
private
boolean
dbShowSql
;
@Value
(
"${db.dialect}"
)
private
String
dbDialect
;
@Value
(
"${db.hbm2ddl}"
)
private
String
dbHbm2d
dl
;
private
boolean
dbGenerateD
dl
;
@Bean
public
DataSource
dataSource
()
{
...
...
@@ -70,14 +73,24 @@ public class SpringDataBaseConfig {
return
dataSource
;
}
@Bean
public
JdbcTemplate
jdbcTemplate
(
DataSource
dataSource
)
{
return
new
JdbcTemplate
(
dataSource
);
}
@Bean
(
name
=
"entityManagerFactory"
)
public
LocalContainerEntityManagerFactoryBean
entityManagerFactory
()
{
public
LocalContainerEntityManagerFactoryBean
entityManagerFactory
()
throws
Exception
{
final
LocalContainerEntityManagerFactoryBean
entityManager
=
new
LocalContainerEntityManagerFactoryBean
();
entityManager
.
setDataSource
(
dataSource
());
entityManager
.
setPersistenceUnitName
(
"spring-jpa"
);
entityManager
.
setJpaVendorAdapter
(
hibernateJpaVendorAdapter
());
entityManager
.
setJpaProperties
(
jpaProperties
());
entityManager
.
setPersistenceProvider
(
new
HibernatePersistenceProvider
());
Properties
jpaProperties
=
jpaProperties
();
for
(
Object
key
:
jpaProperties
.
keySet
())
{
System
.
err
.
println
(
"JPA: "
+
key
+
" = "
+
jpaProperties
.
get
(
key
));
}
entityManager
.
setJpaProperties
(
jpaProperties
);
entityManager
.
setPackagesToScan
(
"org.genesys2.server.model.acl"
,
"org.genesys2.server.model.impl"
,
"org.genesys2.server.model.genesys"
,
"org.genesys2.server.model.oauth"
,
"org.genesys2.server.model.kpi"
);
...
...
@@ -85,25 +98,23 @@ public class SpringDataBaseConfig {
}
@Bean
public
JpaTransactionManager
transactionManager
()
{
public
JpaTransactionManager
transactionManager
(
DataSource
dataSource
,
EntityManagerFactory
emf
)
{
final
JpaTransactionManager
transactionManager
=
new
JpaTransactionManager
();
transactionManager
.
setDataSource
(
dataSource
()
);
transactionManager
.
setEntityManagerFactory
(
e
ntityManagerFactory
().
getObject
()
);
transactionManager
.
setDataSource
(
dataSource
);
transactionManager
.
setEntityManagerFactory
(
e
mf
);
return
transactionManager
;
}
private
Properties
jpaProperties
()
{
final
Properties
properties
=
new
Properties
();
properties
.
setProperty
(
"hibernate.dialect"
,
dbDialect
);
properties
.
setProperty
(
"hibernate.connection.charSet"
,
"utf8"
);
properties
.
setProperty
(
"hibernate.connection.autocommit"
,
"false"
);
properties
.
setProperty
(
"hibernate.hbm2ddl.auto"
,
dbHbm2ddl
);
return
properties
;
private
Properties
jpaProperties
()
throws
Exception
{
Properties
jpaProp
=
new
Properties
();
jpaProp
.
load
(
getClass
().
getResourceAsStream
(
"/spring/hibernate.properties"
));
return
jpaProp
;
}
private
HibernateJpaVendorAdapter
hibernateJpaVendorAdapter
()
{
final
HibernateJpaVendorAdapter
jpaVendorAdapter
=
new
HibernateJpaVendorAdapter
();
jpaVendorAdapter
.
setShowSql
(
dbShowSql
);
jpaVendorAdapter
.
setGenerateDdl
(
dbGenerateDdl
);
return
jpaVendorAdapter
;
}
...
...
src/main/resources/spring/hibernate.properties
0 → 100644
View file @
4220f74d
#Hibernate specific properties
hibernate.dialect
=
org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.connection.charSet
=
utf8
hibernate.connection.autocommit
=
false
hibernate.jdbc.batch_size
=
50
hibernate.order_updates
=
true
hibernate.order_inserts
=
true
src/main/resources/spring/spring.properties
View file @
4220f74d
...
...
@@ -23,11 +23,10 @@ base.cookie-http-only=false
db.url
=
jdbc:mysql://localhost/genesyslive?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
db.driverClassName
=
com.mysql.jdbc.Driver
db.dialect
=
org.hibernate.dialect.MySQL5Dialect
db.username
=
root
db.password
=
db.showSql
=
false
db.hbm2ddl
=
do-nothing
db.hbm2ddl
=
false
c3p0.acquireIncrement
=
1
c3p0.minPoolSize
=
1
...
...
src/test/java/org/genesys2/server/service/worker/ElasticUpdaterTest.java
View file @
4220f74d
...
...
@@ -17,6 +17,8 @@
package
org.genesys2.server.service.worker
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
...
...
@@ -211,13 +213,14 @@ public class ElasticUpdaterTest {
@Test
public
void
testAspect2
()
throws
InterruptedException
{
Accession
[]
a
=
new
Accession
[
100
]
;
List
<
Accession
>
a
=
new
ArrayList
<
Accession
>()
;
for
(
int
i
=
0
;
i
<
100
;
i
++)
{
a
[
i
]
=
new
Accession
();
a
[
i
].
setAccessionName
(
"A-"
+
i
);
a
[
i
].
setInstituteCode
(
"INS000"
);
Accession
accn
;
a
.
add
(
accn
=
new
Accession
());
accn
.
setAccessionName
(
"A-"
+
i
);
accn
.
setInstituteCode
(
"INS000"
);
}
genesysService
.
saveAccession
(
a
);
genesysService
.
saveAccession
s
(
a
);
LOG
.
info
(
"Accessions saved"
);
Thread
.
sleep
(
5000
);
}
...
...
src/test/java/org/genesys2/server/test/JpaDataConfig.java
View file @
4220f74d
...
...
@@ -21,15 +21,13 @@ import java.util.Properties;
import
javax.persistence.EntityManagerFactory
;
import
javax.sql.DataSource
;
import
org.hibernate.jpa.HibernatePersistenceProvider
;
import
org.junit.Ignore
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.config.PropertiesFactoryBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.PropertySource
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ClassPathResource
;
import
org.springframework.dao.support.PersistenceExceptionTranslator
;
import
org.springframework.data.jpa.repository.config.EnableJpaRepositories
;
import
org.springframework.jdbc.datasource.DriverManagerDataSource
;
...
...
@@ -51,15 +49,6 @@ public class JpaDataConfig {
@Autowired
private
Environment
env
;
@Bean
(
name
=
"hibernateProperties"
)
public
PropertiesFactoryBean
hibernateProperties
()
throws
Exception
{
final
PropertiesFactoryBean
bean
=
new
PropertiesFactoryBean
();
bean
.
setLocation
(
new
ClassPathResource
(
"/spring/hibernate.properties"
));
return
bean
;
}
@Bean
(
name
=
"dataSource"
)
public
DataSource
dataSource
()
throws
Exception
{
final
DriverManagerDataSource
dataSource
=
new
DriverManagerDataSource
();
...
...
@@ -73,18 +62,19 @@ public class JpaDataConfig {
}
@Bean
(
name
=
"entityManagerFactory"
)
public
FactoryBean
<
EntityManagerFactory
>
entityManagerFactory
(
Properties
hibernateProperties
)
throws
Exception
{
public
LocalContainer
EntityManagerFactory
Bean
entityManagerFactory
()
throws
Exception
{
final
LocalContainerEntityManagerFactoryBean
bean
=
new
LocalContainerEntityManagerFactoryBean
();
bean
.
setDataSource
(
dataSource
());
bean
.
setPersistenceUnitName
(
"spring-jpa"
);
bean
.
setPackagesToScan
(
"org.genesys2.server.model"
);
bean
.
setPersistenceProvider
(
new
HibernatePersistenceProvider
());
final
HibernateJpaVendorAdapter
jpaVendorAdapter
=
new
HibernateJpaVendorAdapter
();
jpaVendorAdapter
.
setShowSql
(
env
.
getProperty
(
"db.show.sql"
,
Boolean
.
TYPE
,
true
));
jpaVendorAdapter
.
setGenerateDdl
(
env
.
getProperty
(
"db.generate.ddl"
,
Boolean
.
TYPE
,
true
));
bean
.
setJpaProperties
(
hibernate
Properties
);
bean
.
setJpaProperties
(
jpa
Properties
()
);
bean
.
setJpaVendorAdapter
(
jpaVendorAdapter
);
...
...
@@ -103,5 +93,10 @@ public class JpaDataConfig {
public
PersistenceExceptionTranslator
hibernateExceptionTranslator
()
{
return
new
HibernateExceptionTranslator
();
}
private
Properties
jpaProperties
()
throws
Exception
{
Properties
jpaProp
=
new
Properties
();
jpaProp
.
load
(
getClass
().
getResourceAsStream
(
"/spring/hibernate.properties"
));
return
jpaProp
;
}
}
src/test/resources/spring/hibernate.properties
View file @
4220f74d
#Hibernate specific properties
hibernate.dialect
=
org.hibernate.dialect.HSQLDialect
hibernate.connection.
autocommit
=
true
hibernate.
hbm2ddl.auto
=
updat
e
hibernate.
search.default.indexBase
=
./lucene/
hibernate.
search.default.exclusive_index_use
=
fals
e
hibernate.
search.default.worker.execution
=
async
hibernate.connection.
charSet
=
utf8
hibernate.
connection.autocommit
=
fals
e
hibernate.
jdbc.batch_size
=
50
hibernate.
order_updates
=
tru
e
hibernate.
order_inserts
=
true
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment