Implement DefaultListener (1.3.2)
This commit is contained in:
parent
0887b15614
commit
733bf50f91
@ -1,44 +1,71 @@
|
||||
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 {
|
||||
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() {
|
||||
// TODO
|
||||
return -1;
|
||||
return countLoad.incrementAndGet();
|
||||
}
|
||||
|
||||
@PostUpdate
|
||||
public static int getUpdateOperations() {
|
||||
// TODO
|
||||
return -1;
|
||||
return countUpdate.incrementAndGet();
|
||||
}
|
||||
|
||||
@PostRemove
|
||||
public static int getRemoveOperations() {
|
||||
// TODO
|
||||
return -1;
|
||||
return countRemove.incrementAndGet();
|
||||
}
|
||||
|
||||
@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() {
|
||||
// TODO
|
||||
return -1;
|
||||
return countPersist.incrementAndGet();
|
||||
}
|
||||
|
||||
public static long getOverallTimeToPersist() {
|
||||
// TODO
|
||||
return -1;
|
||||
return overallTime.get();
|
||||
}
|
||||
|
||||
public static double getAverageTimeToPersist() {
|
||||
// TODO
|
||||
return -1;
|
||||
return (double) getOverallTimeToPersist() / countPersist.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the internal data structures that are used for storing the operations.
|
||||
*/
|
||||
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