Skip to content

Commit

Permalink
Clean
Browse files Browse the repository at this point in the history
Signed-off-by: yichen88 <[email protected]>
  • Loading branch information
yichen88 committed Jan 20, 2021
1 parent 6e8f106 commit 58e6982
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 24 deletions.
38 changes: 25 additions & 13 deletions afs-postgres/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,33 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>powsybl-afs-postgres</artifactId>
<name>AFS Postgres filesystem implementation</name>
<description>An AFS filesystem implementation based on Postgres</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Automatic-Module-Name>com.powsybl.afs.postgres</Automatic-Module-Name>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- TO REMOVE-->
<!-- TO REMOVE-->
<dependency>
<groupId>com.powsybl</groupId>
<artifactId>powsybl-config-classic</artifactId>
<version>${powsyblcore.version}</version>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-afs-core</artifactId>
Expand All @@ -27,43 +45,37 @@
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.8</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>

<!-- Test dependencies -->
<!-- <dependency>-->
<!-- <groupId>com.powsybl</groupId>-->
<!-- <artifactId>powsybl-config-test</artifactId>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>powsybl-afs-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/
package com.powsybl.afs.postgres;

import com.google.common.collect.Lists;
import com.google.common.primitives.Doubles;
import com.powsybl.afs.postgres.jpa.*;
import com.powsybl.timeseries.*;
Expand Down Expand Up @@ -291,6 +290,12 @@ void addStringTimeSeriesData(String nodeId, int version, String timeSeriesName,
}

void clearTimeSeries(String nodeId) {
// TODO jpa relationship delete
final List<TimeSeriesMetadataEntity> allByNodeId = metaRepo.findAllByNodeId(nodeId);
for (TimeSeriesMetadataEntity metadataEntity : allByNodeId) {
regTsiRepo.deleteByMetadataEntity(metadataEntity);
tagRepo.deleteByMetadataEntity(metadataEntity);
}
metaRepo.deleteAllByNodeId(nodeId);
doubleDataRepo.deleteAllByNodeId(nodeId);
stringDataRepo.deleteAllByNodeId(nodeId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Embeddable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.Table;
import java.util.Objects;

/**
* @author Yichen TANG <yichen.tang at rte-france.com>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.powsybl.afs.postgres.jpa;

import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.persistence.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
*/
package com.powsybl.afs.postgres.jpa;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface RegularTimeSeriesIndexRepository extends CrudRepository<RegularTimeSeriesIndexEntity, Long> {

RegularTimeSeriesIndexEntity findByMetadataEntity(TimeSeriesMetadataEntity metadataEntity);

@Transactional
@Modifying
void deleteByMetadataEntity(TimeSeriesMetadataEntity metadataEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Repository
Expand All @@ -20,6 +21,8 @@ public interface TimeSeriesMetadataRepository extends CrudRepository<TimeSeriesM
@Query(value = "select t.name from meta_ts t where t.node_id = ?1", nativeQuery = true)
Set<String> getTimeSeriesNames(String nodeId);

List<TimeSeriesMetadataEntity> findAllByNodeId(String nodeId);

boolean existsByNodeIdAndName(String nodeId, String name);

Iterable<TimeSeriesMetadataEntity> findAllByNodeIdAndName(String nodeId, Iterable<String> names);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
*/
package com.powsybl.afs.postgres.jpa;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface TsTagRepository extends CrudRepository<TsTagEntity, Long> {

Iterable<TsTagEntity> findAllByMetadataEntity(TimeSeriesMetadataEntity entity);

@Transactional
@Modifying
void deleteByMetadataEntity(TimeSeriesMetadataEntity metadataEntity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ public abstract class AbstractAppStorageTest {

protected BlockingQueue<NodeEvent> eventStack;

protected AppStorageListener l = eventList -> {
eventStack.addAll(eventList.getEvents());
};
protected AppStorageListener l = eventList -> eventStack.addAll(eventList.getEvents());

protected abstract AppStorage createStorage();

Expand All @@ -65,7 +63,7 @@ public void tearDown() {

private void assertEventStack(NodeEvent... events) throws InterruptedException {
for (NodeEvent event : events) {
assertEquals(event, eventStack.poll(200, TimeUnit.MILLISECONDS));
assertEquals(event, eventStack.take());
}

// assert all events have been checked
Expand Down
31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@
<cassandraunit.version>3.1.3.2</cassandraunit.version>
<groovy.version>2.5.8</groovy.version>
<guava.version>20.0</guava.version>
<h2.version>1.4.200</h2.version>
<jackson.jaxrs.version>2.8.11</jackson.jaxrs.version>
<javaeeapi.version>7.0</javaeeapi.version>
<jimfs.version>1.1</jimfs.version>
<jjwt.version>0.9.0</jjwt.version>
<junit.version>4.12</junit.version>
<lombok.version>1.18.10</lombok.version>
<mapdb.version>3.0.6</mapdb.version>
<maven.core.version>3.3.9</maven.core.version>
<mockito.version>3.3.3</mockito.version>
<postgres.version>42.2.8</postgres.version>
<resteasy.version>3.1.4.Final</resteasy.version>
<shrinkwrap-resolver.version>2.2.6</shrinkwrap-resolver.version>
<slf4j.version>1.7.22</slf4j.version>
<spring.version>2.2.1.RELEASE</spring.version>
<swaggerjaxrs.version>1.5.16</swaggerjaxrs.version>
<tyrus.version>1.13.1</tyrus.version>
<wildfly.dist.version>11.0.0.Final</wildfly.dist.version>
Expand Down Expand Up @@ -260,11 +264,26 @@
<artifactId>mapdb</artifactId>
<version>${mapdb.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
Expand Down Expand Up @@ -296,6 +315,12 @@
<artifactId>jimfs</artifactId>
<version>${jimfs.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -320,6 +345,12 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
Expand Down

0 comments on commit 58e6982

Please sign in to comment.