Implement DefaultListener (1.3.2)
This commit is contained in:
parent
0887b15614
commit
733bf50f91
@ -1,44 +1,71 @@
|
|||||||
package dst.ass1.jpa.listener;
|
package dst.ass1.jpa.listener;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
public class DefaultListener {
|
public class DefaultListener {
|
||||||
|
private static final AtomicInteger countLoad = new AtomicInteger(0);
|
||||||
|
private static final AtomicInteger countUpdate = new AtomicInteger(0);
|
||||||
|
private static final AtomicInteger countRemove = new AtomicInteger(0);
|
||||||
|
private static final AtomicInteger countPersist = new AtomicInteger(0);
|
||||||
|
private static final AtomicLong overallTime = new AtomicLong(0);
|
||||||
|
private static final List<Date> persistDateStart = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
private static final List<Date> persistDateEnd = Collections.synchronizedList(new ArrayList<>());
|
||||||
|
|
||||||
// TODO
|
@PostLoad
|
||||||
|
|
||||||
public static int getLoadOperations() {
|
public static int getLoadOperations() {
|
||||||
// TODO
|
return countLoad.incrementAndGet();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostUpdate
|
||||||
public static int getUpdateOperations() {
|
public static int getUpdateOperations() {
|
||||||
// TODO
|
return countUpdate.incrementAndGet();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostRemove
|
||||||
public static int getRemoveOperations() {
|
public static int getRemoveOperations() {
|
||||||
// TODO
|
return countRemove.incrementAndGet();
|
||||||
return -1;
|
}
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
private void prePersist() {
|
||||||
|
persistDateStart.add(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostPersist
|
||||||
|
private void postPersist() {
|
||||||
|
persistDateEnd.add(new Date());
|
||||||
|
long delta = persistDateEnd.get(persistDateEnd.size() - 1).getTime()
|
||||||
|
- persistDateStart.get(persistDateStart.size() - 1).getTime();
|
||||||
|
overallTime.getAndAdd(delta);
|
||||||
|
countPersist.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getPersistOperations() {
|
public static int getPersistOperations() {
|
||||||
// TODO
|
return countPersist.incrementAndGet();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getOverallTimeToPersist() {
|
public static long getOverallTimeToPersist() {
|
||||||
// TODO
|
return overallTime.get();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getAverageTimeToPersist() {
|
public static double getAverageTimeToPersist() {
|
||||||
// TODO
|
return (double) getOverallTimeToPersist() / countPersist.get();
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the internal data structures that are used for storing the operations.
|
* Clears the internal data structures that are used for storing the operations.
|
||||||
*/
|
*/
|
||||||
public static void clear() {
|
public static void clear() {
|
||||||
// TODO
|
countLoad.set(0);
|
||||||
|
countUpdate.set(0);
|
||||||
|
countRemove.set(0);
|
||||||
|
countPersist.set(0);
|
||||||
|
overallTime.set(0);
|
||||||
|
persistDateStart.clear();
|
||||||
|
persistDateEnd.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user