Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
App Blocks
Commits
88449b5c
Commit
88449b5c
authored
Sep 28, 2017
by
Andrey Lugovskiy
Committed by
Matija Obreza
Oct 04, 2017
Browse files
Create new classPk if it doesn't exist
parent
9a861ab5
Changes
2
Show whitespace changes
Inline
Side-by-side
auditlog/src/main/java/org/genesys/blocks/auditlog/service/ClassPKService.java
View file @
88449b5c
...
...
@@ -48,6 +48,6 @@ public interface ClassPKService {
* @param className
* @return
*/
Long
getClassPkId
(
String
className
);
Long
getClassPkId
(
String
className
)
throws
ClassNotFoundException
;
}
auditlog/src/main/java/org/genesys/blocks/auditlog/service/impl/ClassPKServiceImpl.java
View file @
88449b5c
...
...
@@ -53,15 +53,7 @@ public class ClassPKServiceImpl implements ClassPKService {
if
(
classPk
!=
null
)
{
return
classPk
;
}
classPk
=
new
ClassPK
();
classPk
.
setClassname
(
class1
.
getName
());
classPk
.
setShortName
(
generateShortPkName
(
class1
.
getSimpleName
().
toLowerCase
()));
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Persisting new ClassPK for classname={}"
,
classPk
.
getClassname
());
}
return
classPkRepository
.
save
(
classPk
);
return
createNewClassPkForClass
(
class1
);
}
private
String
generateShortPkName
(
String
shortName
)
{
...
...
@@ -84,7 +76,6 @@ public class ClassPKServiceImpl implements ClassPKService {
throw
new
PersistenceException
(
"Can't generate a shortName for ClassPK for "
+
shortName
);
}
@Override
@Transactional
(
isolation
=
Isolation
.
DEFAULT
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
String
getClassName
(
final
Long
id
)
{
...
...
@@ -98,7 +89,33 @@ public class ClassPKServiceImpl implements ClassPKService {
}
@Override
public
Long
getClassPkId
(
String
classname
)
{
return
classPkRepository
.
getClassPkId
(
classname
);
@Transactional
(
isolation
=
Isolation
.
DEFAULT
,
propagation
=
Propagation
.
REQUIRES_NEW
)
public
Long
getClassPkId
(
String
classname
)
throws
ClassNotFoundException
{
Long
id
=
null
;
try
{
id
=
classPkRepository
.
getClassPkId
(
classname
);
if
(
id
==
null
)
{
throw
new
Exception
();
}
}
catch
(
Exception
e
)
{
Class
aClass
=
Class
.
forName
(
classname
);
ClassPK
classPK
=
createNewClassPkForClass
(
aClass
);
id
=
classPK
.
getId
();
}
return
id
;
}
private
ClassPK
createNewClassPkForClass
(
Class
<?>
aClass
)
{
ClassPK
classPk
=
new
ClassPK
();
classPk
.
setClassname
(
aClass
.
getName
());
classPk
.
setShortName
(
generateShortPkName
(
aClass
.
getSimpleName
().
toLowerCase
()));
if
(
LOG
.
isTraceEnabled
())
{
LOG
.
trace
(
"Persisting new ClassPK for classname={}"
,
classPk
.
getClassname
());
}
return
classPkRepository
.
save
(
classPk
);
}
}
Write
Preview
Supports
Markdown
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