Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
f63920a6
Commit
f63920a6
authored
Apr 15, 2015
by
Matija Obreza
Browse files
updateAccessionCount called from outside transaction (causes too many locks)
parent
98cfb73b
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/server/model/genesys/SelfCopy.java
View file @
f63920a6
...
...
@@ -2,15 +2,18 @@ package org.genesys2.server.model.genesys;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
public
class
SelfCopy
{
private
static
Log
LOG
=
LogFactory
.
getLog
(
SelfCopy
.
class
);
private
static
Map
<
Method
,
Method
>
gettersSetters
=
new
HashMap
<
Method
,
Method
>();
public
static
void
copy
(
AccessionData
source
,
AccessionData
target
)
{
Method
[]
allMethods
=
source
.
getC
lass
()
.
getMethods
();
static
{
Method
[]
allMethods
=
AccessionData
.
c
lass
.
getMethods
();
for
(
Method
getter
:
allMethods
)
{
String
name
=
getter
.
getName
();
boolean
isGet
=
false
;
...
...
@@ -23,33 +26,27 @@ public class SelfCopy {
name
=
name
.
substring
(
2
);
}
LOG
.
debug
(
"Getter coreName="
+
name
);
if
(
isGet
)
{
LOG
.
info
(
"Using getter "
+
name
);
LOG
.
info
(
"Using getter "
+
getter
);
try
{
Object
val
=
getter
.
invoke
(
source
);
set
(
target
,
name
,
getter
.
getReturnType
(),
val
);
}
catch
(
IllegalAccessException
|
IllegalArgumentException
|
InvocationTargetException
|
NoSuchMethodException
|
SecurityException
e
)
{
LOG
.
warn
(
e
.
getMessage
(),
e
);
Method
setter
=
AccessionData
.
class
.
getMethod
(
"set"
+
name
,
getter
.
getReturnType
());
gettersSetters
.
put
(
getter
,
setter
);
LOG
.
info
(
"Using setter "
+
setter
);
}
catch
(
NoSuchMethodException
|
SecurityException
e
)
{
LOG
.
error
(
"No setter for "
+
name
);
}
}
}
}
private
static
void
set
(
AccessionData
target
,
String
name
,
Class
<?>
type
,
Object
val
)
throws
NoSuchMethodException
,
SecurityException
,
IllegalAccessException
,
IllegalArgumentException
,
InvocationTargetException
{
LOG
.
info
(
"Using setter 'get"
+
name
+
"' to apply type "
+
type
+
" val="
+
val
);
try
{
Method
setter
=
target
.
getClass
().
getMethod
(
"set"
+
name
,
type
);
if
(
setter
==
null
)
{
LOG
.
error
(
"No setter for "
+
name
);
return
;
public
static
void
copy
(
AccessionData
source
,
AccessionData
target
)
{
for
(
Method
getter
:
gettersSetters
.
keySet
())
{
try
{
Object
val
=
getter
.
invoke
(
source
);
gettersSetters
.
get
(
getter
).
invoke
(
target
,
val
);
}
catch
(
IllegalAccessException
|
IllegalArgumentException
|
InvocationTargetException
e
)
{
LOG
.
error
(
e
.
getMessage
(),
e
);
}
LOG
.
info
(
"Setting property "
+
name
);
setter
.
invoke
(
target
,
val
);
}
catch
(
NoSuchMethodException
e
)
{
LOG
.
debug
(
"No setter for "
+
name
);
}
}
...
...
src/main/java/org/genesys2/server/service/impl/GenesysServiceImpl.java
View file @
f63920a6
...
...
@@ -689,7 +689,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
}
else
{
res
=
accessionRepository
.
save
((
Accession
)
accession
);
}
updateAccessionCount
(
accession
.
getInstitute
());
return
res
;
}
...
...
@@ -735,8 +734,6 @@ public class GenesysServiceImpl implements GenesysService, DatasetService {
for
(
Accession
a
:
toDelete
)
{
accessionRepository
.
deleteActive
(
a
.
getId
());
}
updateAccessionCount
(
institute
);
}
return
deleted
;
...
...
src/main/java/org/genesys2/server/service/impl/RESTApiException.java
View file @
f63920a6
...
...
@@ -16,6 +16,8 @@
package
org.genesys2.server.service.impl
;
import
org.springframework.dao.CannotAcquireLockException
;
public
class
RESTApiException
extends
Exception
{
/**
...
...
@@ -27,4 +29,8 @@ public class RESTApiException extends Exception {
super
(
message
);
}
public
RESTApiException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
src/main/java/org/genesys2/server/servlet/controller/rest/AccessionController.java
View file @
f63920a6
...
...
@@ -50,6 +50,7 @@ import org.genesys2.server.servlet.controller.rest.model.AccessionHeaderJson;
import
org.genesys2.server.servlet.controller.rest.model.AccessionNamesJson
;
import
org.genesys2.spring.ResourceNotFoundException
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.dao.CannotAcquireLockException
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
...
...
@@ -224,10 +225,9 @@ public class AccessionController extends RestController {
}
batch
.
put
(
dataJson
,
(
ObjectNode
)
json
);
}
// Step 1: Ensure all taxonomic data provided by client is persisted
batchRESTService
.
ensureTaxonomies
(
institute
,
batch
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
try
{
...
...
@@ -292,9 +292,14 @@ public class AccessionController extends RestController {
throw
new
ResourceNotFoundException
();
}
final
int
deleted
=
batchRESTService
.
deleteAccessions
(
institute
,
batch
);
LOG
.
info
(
"Deleted "
+
deleted
+
" accessions from "
+
instCode
);
return
new
JsonDeleteResult
(
deleted
);
try
{
final
int
deleted
=
batchRESTService
.
deleteAccessions
(
institute
,
batch
);
LOG
.
info
(
"Deleted "
+
deleted
+
" accessions from "
+
instCode
);
genesysService
.
updateAccessionCount
(
institute
);
return
new
JsonDeleteResult
(
deleted
);
}
catch
(
CannotAcquireLockException
e
)
{
throw
new
PleaseRetryException
(
"Operation failed, please retry."
,
e
);
}
}
/**
...
...
@@ -317,6 +322,7 @@ public class AccessionController extends RestController {
final
int
deleted
=
batchRESTService
.
deleteAccessionsById
(
institute
,
batch
);
LOG
.
info
(
"Deleted "
+
deleted
+
" accessions from "
+
instCode
);
genesysService
.
updateAccessionCount
(
institute
);
return
new
JsonDeleteResult
(
deleted
);
}
...
...
src/main/java/org/genesys2/server/servlet/controller/rest/PleaseRetryException.java
0 → 100644
View file @
f63920a6
package
org.genesys2.server.servlet.controller.rest
;
import
org.genesys2.server.service.impl.RESTApiException
;
import
org.springframework.dao.CannotAcquireLockException
;
public
class
PleaseRetryException
extends
RESTApiException
{
public
PleaseRetryException
(
String
message
,
Throwable
cause
)
{
super
(
message
,
cause
);
}
}
src/main/resources/spring/spring.properties
View file @
f63920a6
...
...
@@ -25,7 +25,7 @@ db.url=jdbc:mysql://localhost/genesys?useUnicode=true&characterEncoding=UTF-8&us
db.driverClassName
=
com.mysql.jdbc.Driver
db.username
=
root
db.password
=
db.showSql
=
tru
e
db.showSql
=
fals
e
db.hbm2ddl
=
false
hibernate.dialect
=
org.hibernate.dialect.MySQL5InnoDBDialect
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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