Skip to content

Commit

Permalink
refactor: storage module
Browse files Browse the repository at this point in the history
  • Loading branch information
akardapolov committed Aug 22, 2019
1 parent 81d50b7 commit 1007d49
Show file tree
Hide file tree
Showing 26 changed files with 265 additions and 413 deletions.
19 changes: 7 additions & 12 deletions ashv/src/main/java/core/processing/GetFromRemoteAndStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@
import profile.OracleEE;
import profile.Postgres;
import remote.RemoteDBManager;
import store.ConvertManager;
import store.OlapCacheManager;
import store.RawStoreManager;
import store.StoreManager;
import store.dao.olap.AggrDAO;
import store.*;
import store.entity.database.SqlPlan;
import store.entity.olap.AshAggrMinData;
import store.entity.olap.AshUser;
Expand Down Expand Up @@ -117,7 +113,6 @@ public void loadSqlsMetadata() {
this.storeManager.getDatabaseDAO().setConvertManager(this.convertManager);

this.olapCacheManager.setOlapDAO(storeManager.getDatabaseDAO().getOlapDAO());
this.olapCacheManager.setAggrDao(storeManager.getDatabaseDAO().getOlapDAO().getAggrDao());
this.loadMetadata();

this.rawStoreManager.setSqlColMetadata(metadataMap.get(modNameAshSql));
Expand Down Expand Up @@ -201,9 +196,9 @@ private void loadToMainStackedChart(){
continue;
}

AggrDAO aggrDAO = this.storeManager.getDatabaseDAO().getOlapDAO().getAggrDao();
OlapDAO olapDAO = storeManager.getDatabaseDAO().getOlapDAO();

EntityCursor<AshAggrMinData> cursor = aggrDAO.getAshAggrMinDataDAO().getAshAggrEntityCursorRangeQuery(d, (d + range));
EntityCursor<AshAggrMinData> cursor = olapDAO.getAshAggrMinDataDAO().getAshAggrEntityCursorRangeQuery(d, (d + range));
Iterator<AshAggrMinData> iterator = cursor.iterator();

hashMap.putIfAbsent(d, new long[waitClassCount]);
Expand All @@ -228,7 +223,7 @@ private void loadToMainStackedChart(){
sl.getSum(this.getIProfile().getWaitClassId(k))); //mtrx[2]::sum;

allWaitId1.entrySet().stream().forEach(s -> {
out.merge(aggrDAO.getEventStrValueForWaitEventId(s.getKey()), s.getValue(), Integer::sum);
out.merge(olapDAO.getEventStrValueForWaitEventId(s.getKey()), s.getValue(), Integer::sum);
});

});
Expand Down Expand Up @@ -435,7 +430,7 @@ private void loadDataToOlap() {
.sorted(Map.Entry.comparingByKey()).forEach(e -> sqlAddParam[e.getKey()] = e.getValue());

/** Additional dimension for sql detail **/
storeManager.getDatabaseDAO().getOlapDAO().getAggrDao().getCheckOrLoadParameter(sqlId, sqlAddParam);
storeManager.getDatabaseDAO().getOlapDAO().getCheckOrLoadParameter(sqlId, sqlAddParam);
}

// Sqltext (for postgres db only)
Expand All @@ -458,7 +453,7 @@ private void loadDataToOlap() {
addParamSqlSess, waitEvent, iProfile.getWaitClassId(waitClass));

/** Additional dimension for session detail **/
storeManager.getDatabaseDAO().getOlapDAO().getAggrDao().getCheckOrLoadParameter(sessionId + "_" + seriailId, sessAddParam);
storeManager.getDatabaseDAO().getOlapDAO().getCheckOrLoadParameter(sessionId + "_" + seriailId, sessAddParam);

sampleTimeG = sampleTime;

Expand Down Expand Up @@ -633,7 +628,7 @@ private void loadUserIdUsernameToLocalDB(String statement){
s = connection.prepareStatement(statement);
rs = s.executeQuery();
while (rs.next()) {
storeManager.getDatabaseDAO().getOlapDAO().getAggrDao()
storeManager.getDatabaseDAO().getOlapDAO()
.putUserIdUsername(new AshUser(rs.getInt(1), rs.getString(2)));
}

Expand Down
36 changes: 18 additions & 18 deletions ashv/src/main/java/gui/gantt/GanttDataById2.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import lombok.Setter;
import org.jfree.chart.util.GanttParam;
import profile.IProfile;
import store.OlapDAO;
import store.StoreManager;
import store.cache.CompositeKeyCache2;
import store.cache.TripleValueCache;
import store.dao.olap.AggrDAO;
import store.entity.olap.AshAggrMinData15Sec;
import utility.Utils;

Expand All @@ -27,7 +27,7 @@

public class GanttDataById2 {
private StoreManager storeManager;
private AggrDAO dao;
private OlapDAO olapDAO;

private final byte parameterGroupId;

Expand All @@ -43,7 +43,7 @@ public class GanttDataById2 {

public GanttDataById2(StoreManager storeManager, byte parameterGroupId){
this.storeManager = storeManager;
this.dao = storeManager.getDatabaseDAO().getOlapDAO().getAggrDao();
this.olapDAO = storeManager.getDatabaseDAO().getOlapDAO();
this.parameterGroupId = parameterGroupId;
}

Expand Down Expand Up @@ -81,7 +81,7 @@ public void computeGanttDataFromBDB(GanttParam ganttParameter){
long start1 = begin.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();

EntityCursor<AshAggrMinData15Sec> cursor =
this.dao.getAshAggrMinData15SecDAO().getAshAggrEntityCursorRangeQuery(start1, end0 + ConstantManager.CURRENT_WINDOW / ConstantManager.MAX_POINT_PER_GRAPH);
this.olapDAO.getAshAggrMinData15SecDAO().getAshAggrEntityCursorRangeQuery(start1, end0 + ConstantManager.CURRENT_WINDOW / ConstantManager.MAX_POINT_PER_GRAPH);
Iterator<AshAggrMinData15Sec> iterator = cursor.iterator();

/////////////////////////////////////////////
Expand All @@ -90,7 +90,7 @@ public void computeGanttDataFromBDB(GanttParam ganttParameter){
boolean needToProcess;

if (this.parameterGroupId == 0
& !this.dao.getStrParameterValueById(sl.getCompositeKey().getParamId()).contains(
& !this.olapDAO.getStrParameterValueById(sl.getCompositeKey().getParamId()).contains(
ConstantManager.NULL_VALUE)){ // SQL_ID
needToProcess = true;
} else if (this.parameterGroupId == 1 ){ // SessionId + SerialId
Expand All @@ -111,14 +111,14 @@ public void loadAshRowAggrData(AshAggrMinData15Sec ashAggrMinData){

/** !!! Refactor it !!! **/
int paramId = ashAggrMinData.getCompositeKey().getParamId();
String[] outputParam = this.dao.getStrParameterValueById(ashAggrMinData.getCompositeKey().getParamId()).split("_");
String[] outputParam = this.olapDAO.getStrParameterValueById(ashAggrMinData.getCompositeKey().getParamId()).split("_");

if (this.parameterGroupId == 0 & !outputParam[0].equalsIgnoreCase(ConstantManager.NULL_VALUE)){
paramId = this.dao.getParameterIdByStrValue(outputParam[0]);
paramId = this.olapDAO.getParameterIdByStrValue(outputParam[0]);
} else {
if (!outputParam[0].equalsIgnoreCase(ConstantManager.NULL_VALUE)){
int paramId0 = dao.getCheckOrLoadParameter(ConstantManager.NULL_VALUE + "_" + outputParam[1] + "_" + outputParam[2],
this.dao.getAdditStrArrayParameters(paramId)); // 1 sec
int paramId0 = olapDAO.getCheckOrLoadParameter(ConstantManager.NULL_VALUE + "_" + outputParam[1] + "_" + outputParam[2],
this.olapDAO.getAdditStrArrayParameters(paramId)); // 1 sec

paramId = paramId0;
}
Expand Down Expand Up @@ -149,12 +149,12 @@ public void loadAshRowAggrData(AshAggrMinData15Sec ashAggrMinData){
.findAny().get().setSum(e.getValue());
} else {
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
}
} else {
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
}
});
Expand All @@ -165,7 +165,7 @@ public void loadAshRowAggrData(AshAggrMinData15Sec ashAggrMinData){

allWaitId1.entrySet().forEach(e ->{
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
});
}
Expand Down Expand Up @@ -212,8 +212,8 @@ public Object[][] getDataToGantt(int columnCnt) {
}

private void loadDataByRow(Object[][] data, int rowNumber, AtomicInteger atomicIntegerInter, CompositeKeyCache2 key){
String[] outputParam = this.dao.getStrParameterValueById(key.getParamId()).split("_");
String[] addParam = this.dao.getAdditStrArrayParameters(key.getParamId());
String[] outputParam = this.olapDAO.getStrParameterValueById(key.getParamId()).split("_");
String[] addParam = this.olapDAO.getAdditStrArrayParameters(key.getParamId());

if (this.parameterGroupId == 0){ // SqlId
data[rowNumber][atomicIntegerInter.getAndIncrement()] = outputParam[0];
Expand All @@ -230,7 +230,7 @@ private void loadDataByRow(Object[][] data, int rowNumber, AtomicInteger atomicI
}

data[rowNumber][atomicIntegerInter.getAndIncrement()] =
storeManager.getDatabaseDAO().getOlapDAO().getAggrDao().getUsername(userId);
storeManager.getDatabaseDAO().getOlapDAO().getUsername(userId);
data[rowNumber][atomicIntegerInter.getAndIncrement()] =
addParam[2].equalsIgnoreCase(ConstantManager.NULL_VALUE) ? "" : addParam[2];

Expand Down Expand Up @@ -302,7 +302,7 @@ private DrawingState createDrawingState(GanttDrawingPartHelper helper,

String keyString = waitClassId == -1
? iProfile.getWaitClass(key0.byteValue())
: this.dao.getEventStrValueForWaitEventId(key0);
: this.olapDAO.getEventStrValueForWaitEventId(key0);
double value = value0;

// Show only not zero activities.
Expand Down Expand Up @@ -372,9 +372,9 @@ public List<String> getListClassAndEvents(){
iProfile.getWaitClass(k.getWaitClassId()));
}
} else {
if (!arrayList.contains(this.dao.getEventStrValueForWaitEventId(k.getWaitEventId()))) {
if (!arrayList.contains(this.olapDAO.getEventStrValueForWaitEventId(k.getWaitEventId()))) {
arrayList.add(
this.dao.getEventStrValueForWaitEventId(k.getWaitEventId()));
this.olapDAO.getEventStrValueForWaitEventId(k.getWaitEventId()));
}
}
});
Expand Down
36 changes: 18 additions & 18 deletions ashv/src/main/java/gui/gantt/GanttDataById3.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import ext.egantt.swing.GanttDrawingPartHelper;
import lombok.extern.slf4j.Slf4j;
import org.jfree.chart.util.GanttParam;
import store.OlapDAO;
import store.StoreManager;
import store.cache.CompositeKeyCache2;
import store.cache.TripleValueCache;
import store.dao.olap.AggrDAO;
import store.entity.olap.AshAggrMinData15Sec;
import utility.Utils;

Expand All @@ -26,7 +26,7 @@
@Slf4j
public class GanttDataById3 {
private StoreManager storeManager;
private AggrDAO dao;
private OlapDAO olapDAO;

private final byte parameterGroupId;

Expand All @@ -42,7 +42,7 @@ public class GanttDataById3 {

public GanttDataById3(StoreManager storeManager, byte parameterGroupId){
this.storeManager = storeManager;
this.dao = storeManager.getDatabaseDAO().getOlapDAO().getAggrDao();
this.olapDAO = storeManager.getDatabaseDAO().getOlapDAO();
this.parameterGroupId = parameterGroupId;
}

Expand Down Expand Up @@ -71,7 +71,7 @@ public void computeGanttDataFromBDB(GanttParam ganttParamTo){
long start1 = begin.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();

EntityCursor<AshAggrMinData15Sec> cursor =
this.dao.getAshAggrMinData15SecDAO().getAshAggrEntityCursorRangeQuery(start1, end0);
this.olapDAO.getAshAggrMinData15SecDAO().getAshAggrEntityCursorRangeQuery(start1, end0);
Iterator<AshAggrMinData15Sec> iterator = cursor.iterator();

/////////////////////////////////////////////
Expand All @@ -81,30 +81,30 @@ public void computeGanttDataFromBDB(GanttParam ganttParamTo){
//byte parameterGrpId = (byte) this.dao.getParameterGrp(sl.getCompositeKey().getParamId());

//if (parameterGrpId == 2) {
String[] output = this.dao.getStrParameterValueById(sl.getCompositeKey().getParamId()).split("_");
String[] output = this.olapDAO.getStrParameterValueById(sl.getCompositeKey().getParamId()).split("_");

if (!this.ganttParamTo.getSqlId().isEmpty() &
this.parameterGroupId == 0){ // SQL_ID for Sql chart
if (this.ganttParamTo.getSqlId().equalsIgnoreCase(output[0])){
loadAshRowAggrData(sl, this.dao.getParameterIdByStrValue(output[0]), (byte) 2);
loadAshRowAggrData(sl, this.olapDAO.getParameterIdByStrValue(output[0]), (byte) 2);
}
} else if (!this.ganttParamTo.getSqlId().isEmpty() &
this.parameterGroupId == 1) { // SQL_ID for for Session chart
if (this.ganttParamTo.getSqlId().equalsIgnoreCase(output[0])) {
loadAshRowAggrData(sl, this.dao.getParameterIdByStrValue(output[1]+"_"+output[2]), (byte) 2);
loadAshRowAggrData(sl, this.olapDAO.getParameterIdByStrValue(output[1]+"_"+output[2]), (byte) 2);
}
} else if (!this.ganttParamTo.getSessionId().isEmpty() &
this.parameterGroupId == 1) { // SessionId + SerialId for Session chart
if (this.ganttParamTo.getSessionId().equalsIgnoreCase(output[1]) &
this.ganttParamTo.getSerial().equalsIgnoreCase(output[2])) {
loadAshRowAggrData(sl, this.dao.getParameterIdByStrValue(output[1]+"_"+output[2]), (byte) 2);
loadAshRowAggrData(sl, this.olapDAO.getParameterIdByStrValue(output[1]+"_"+output[2]), (byte) 2);
}
} else if (!this.ganttParamTo.getSessionId().isEmpty() &
this.parameterGroupId == 0) { // SessionId + SerialId for Sql chart
if (!output[0].equalsIgnoreCase("Null") &
this.ganttParamTo.getSessionId().equalsIgnoreCase(output[1]) &
this.ganttParamTo.getSerial().equalsIgnoreCase(output[2])){
loadAshRowAggrData(sl, this.dao.getParameterIdByStrValue(output[0]), (byte) 2);
loadAshRowAggrData(sl, this.olapDAO.getParameterIdByStrValue(output[0]), (byte) 2);
}
}

Expand Down Expand Up @@ -138,12 +138,12 @@ public void loadAshRowAggrData(AshAggrMinData15Sec ashAggrMinData, int paramIdIn
.findAny().get().setSum(e.getValue());
} else {
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
}
} else {
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
}
});
Expand All @@ -154,7 +154,7 @@ public void loadAshRowAggrData(AshAggrMinData15Sec ashAggrMinData, int paramIdIn

allWaitId1.entrySet().forEach(e ->{
tripleValueCache.add(new TripleValueCache(e.getKey(),
(byte) this.dao.getEventGrp(e.getKey()),
(byte) this.olapDAO.getEventGrp(e.getKey()),
e.getValue()));
});
}
Expand Down Expand Up @@ -199,8 +199,8 @@ public Object[][] getDataToGantt(int columnCnt) {
}

private void loadDataByRow(Object[][] data, int rowNumber, AtomicInteger atomicIntegerInter, CompositeKeyCache2 key){
String[] outputParam = this.dao.getStrParameterValueById(key.getParamId()).split("_");
String[] addParam = this.dao.getAdditStrArrayParameters(key.getParamId());
String[] outputParam = this.olapDAO.getStrParameterValueById(key.getParamId()).split("_");
String[] addParam = this.olapDAO.getAdditStrArrayParameters(key.getParamId());

if (this.parameterGroupId == 0){ // SqlId
data[rowNumber][atomicIntegerInter.getAndIncrement()] = outputParam[0];
Expand All @@ -223,7 +223,7 @@ private void loadDataByRow(Object[][] data, int rowNumber, AtomicInteger atomicI
}

data[rowNumber][atomicIntegerInter.getAndIncrement()] =
storeManager.getDatabaseDAO().getOlapDAO().getAggrDao().getUsername(userId);
storeManager.getDatabaseDAO().getOlapDAO().getUsername(userId);
data[rowNumber][atomicIntegerInter.getAndIncrement()] =
addParam[1].equalsIgnoreCase(ConstantManager.NULL_VALUE) ? "" : addParam[1];

Expand Down Expand Up @@ -290,7 +290,7 @@ private DrawingState createDrawingState(GanttDrawingPartHelper helper,
Integer key0 = entry.getKey();
Integer value0 = entry.getValue();

String keyString = this.dao.getEventStrValueForWaitEventId(key0);
String keyString = this.olapDAO.getEventStrValueForWaitEventId(key0);
double value = value0;

// Show only not zero activities.
Expand Down Expand Up @@ -354,9 +354,9 @@ public List<String> getListClassAndEvents(){
e.getValue()
.stream()
.forEach(k -> {
if(!arrayList.contains(this.dao.getEventStrValueForWaitEventId(k.getWaitEventId()))){
if(!arrayList.contains(this.olapDAO.getEventStrValueForWaitEventId(k.getWaitEventId()))){
arrayList.add(
this.dao.getEventStrValueForWaitEventId(k.getWaitEventId()));
this.olapDAO.getEventStrValueForWaitEventId(k.getWaitEventId()));
}
});

Expand Down
Loading

0 comments on commit 1007d49

Please sign in to comment.