diff --git a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageHandlerImpl.java b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageHandlerImpl.java index 98df88fc..a534d899 100644 --- a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageHandlerImpl.java +++ b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageHandlerImpl.java @@ -304,7 +304,7 @@ public ChannelEntity createChannel ( final String name, final String description return channel; } - public void setProvidedMetaData ( final ChannelEntity channel, final Map providedMetaData ) + protected void setProvidedMetaData ( final ChannelEntity channel, final Map providedMetaData ) { if ( providedMetaData == null ) { @@ -329,20 +329,22 @@ public void setProvidedMetaData ( final ChannelEntity channel, final Map { + final ChannelEntity channel = getCheckedChannel ( channelId ); - if ( "".equals ( name ) ) - { - channel.setName ( null ); - } - else - { - channel.setName ( name ); - } + if ( "".equals ( name ) ) + { + channel.setName ( null ); + } + else + { + channel.setName ( name ); + } - channel.setDescription ( description ); + channel.setDescription ( description ); - this.em.persist ( channel ); + this.em.persist ( channel ); + } ); } @Override @@ -698,8 +700,10 @@ public void generateArtifact ( final String id ) testLocked ( ae.getChannel () ); - regenerateArtifact ( (GeneratorArtifactEntity)ae, false ); - runChannelAggregators ( ae.getChannel () ); + this.lockManager.modifyRun ( ae.getChannel ().getId (), () -> { + regenerateArtifact ( (GeneratorArtifactEntity)ae, false ); + runChannelAggregators ( ae.getChannel () ); + } ); } catch ( final Exception e ) { @@ -719,28 +723,32 @@ public ArtifactInformation deleteArtifact ( final String artifactId ) testLocked ( ae.getChannel () ); - if ( !isDeleteable ( ae ) ) - { - throw new IllegalStateException ( String.format ( "Unable to delete artifact %s (%s). Artifact might be virtual or generated.", ae.getName (), ae.getId () ) ); - } + return this.lockManager.modifyCall ( ae.getChannel ().getId (), () -> { - final SortedMap md = convertMetaData ( ae ); + if ( !isDeleteable ( ae ) ) + { + throw new IllegalStateException ( String.format ( "Unable to delete artifact %s (%s). Artifact might be virtual or generated.", ae.getName (), ae.getId () ) ); + } - this.em.remove ( ae ); - this.em.flush (); + final SortedMap md = convertMetaData ( ae ); - logger.info ( "Artifact deleted: {}", artifactId ); + this.em.remove ( ae ); + this.em.flush (); - final ChannelEntity channel = ae.getChannel (); + logger.info ( "Artifact deleted: {}", artifactId ); - final RegenerateTracker tracker = new RegenerateTracker (); - runGeneratorTriggers ( tracker, channel, new RemovedEvent ( ae.getId (), md ) ); - tracker.process ( this ); + final ChannelEntity channel = ae.getChannel (); - // now run the channel aggregator - runChannelAggregators ( channel ); + final RegenerateTracker tracker = new RegenerateTracker (); + runGeneratorTriggers ( tracker, channel, new RemovedEvent ( ae.getId (), md ) ); + tracker.process ( this ); + + // now run the channel aggregator + runChannelAggregators ( channel ); + + return convert ( ae, null ); - return convert ( ae, null ); + } ); } private void runGeneratorTriggers ( final RegenerateTracker tracker, final ChannelEntity channel, final Object event ) @@ -1366,16 +1374,18 @@ public SortedMap getChannelProvidedMetaData ( final String chan public void clearChannel ( final String channelId ) { - final ChannelEntity channel = getCheckedChannel ( channelId ); + this.lockManager.modifyRun ( channelId, () -> { + final ChannelEntity channel = getCheckedChannel ( channelId ); - testLocked ( channel ); + testLocked ( channel ); - // processing by "clear" triggers the entity listeners + // processing by "clear" triggers the entity listeners - channel.getArtifacts ().clear (); - this.em.persist ( channel ); + channel.getArtifacts ().clear (); + this.em.persist ( channel ); - runChannelAggregators ( channel ); + runChannelAggregators ( channel ); + } ); } private static Set expandDependencies ( final Set aspects ) diff --git a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java index 88d20dfb..7c3889cd 100644 --- a/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java +++ b/de.dentrassi.pm.storage.service.jpa/src/de/dentrassi/pm/storage/service/jpa/StorageServiceImpl.java @@ -557,40 +557,43 @@ public Map applyMetaData ( final String artifactId, final Map result = convert ( artifact.getProvidedProperties () ); + return this.lockManager.modifyCall ( artifact.getChannel ().getId (), () -> { - // merge + final Map result = convert ( artifact.getProvidedProperties () ); - mergeMetaData ( metadata, result ); + // merge - // first clear all + mergeMetaData ( metadata, result ); - artifact.getProvidedProperties ().clear (); + // first clear all - em.persist ( artifact ); - em.flush (); + artifact.getProvidedProperties ().clear (); - // now add the new set + em.persist ( artifact ); + em.flush (); - Helper.convertProvidedProperties ( result, artifact, artifact.getProvidedProperties () ); + // now add the new set - // store + Helper.convertProvidedProperties ( result, artifact, artifact.getProvidedProperties () ); - em.persist ( artifact ); - em.flush (); + // store - // recreate virtual artifacts + em.persist ( artifact ); + em.flush (); - hi.recreateVirtualArtifacts ( artifact ); + // recreate virtual artifacts - // recreate generated artifacts + hi.recreateVirtualArtifacts ( artifact ); - if ( artifact instanceof GeneratorArtifactEntity ) - { - hi.regenerateArtifact ( (GeneratorArtifactEntity)artifact, true ); - } + // recreate generated artifacts - return result; + if ( artifact instanceof GeneratorArtifactEntity ) + { + hi.regenerateArtifact ( (GeneratorArtifactEntity)artifact, true ); + } + + return result; + } ); } ); } @@ -700,9 +703,7 @@ public List findByName ( final String channelId, final String artifact public void clearChannel ( final String channelId ) { this.lockManager.modifyRun ( channelId, () -> { - doWithHandlerVoid ( hi -> hi.clearChannel ( channelId ) ); - } ); } @@ -753,30 +754,34 @@ public Collection getDeployGroups ( final String channelId ) public void addDeployGroup ( final String channelId, final String groupId ) { - doWithTransactionVoid ( ( em ) -> { - final ChannelEntity channel = getCheckedChannel ( em, channelId ); - final DeployGroupEntity group = DeployAuthServiceImpl.getGroupChecked ( em, groupId ); - channel.getDeployGroups ().add ( group ); - em.persist ( channel ); + this.lockManager.modifyRun ( channelId, () -> { + doWithTransactionVoid ( ( em ) -> { + final ChannelEntity channel = getCheckedChannel ( em, channelId ); + final DeployGroupEntity group = DeployAuthServiceImpl.getGroupChecked ( em, groupId ); + channel.getDeployGroups ().add ( group ); + em.persist ( channel ); + } ); } ); } public void removeDeployGroup ( final String channelId, final String groupId ) { - doWithTransactionVoid ( ( em ) -> { - final ChannelEntity channel = getCheckedChannel ( em, channelId ); + this.lockManager.modifyRun ( channelId, () -> { + doWithTransactionVoid ( ( em ) -> { + final ChannelEntity channel = getCheckedChannel ( em, channelId ); - final Iterator i = channel.getDeployGroups ().iterator (); - while ( i.hasNext () ) - { - final DeployGroupEntity dg = i.next (); - if ( dg.getId ().equals ( groupId ) ) + final Iterator i = channel.getDeployGroups ().iterator (); + while ( i.hasNext () ) { - i.remove (); + final DeployGroupEntity dg = i.next (); + if ( dg.getId ().equals ( groupId ) ) + { + i.remove (); + } } - } - em.persist ( channel ); + em.persist ( channel ); + } ); } ); }