- refresh on data improved in the tree panel in order to implement the cascade refresh using a thread (refreshDataTree method modified). queue mechanism added to make asynchronous the communication with the ThreadDataLoader. class GWTdbManagerSErviceImpl modified.
- The classes as GxtBorder, GxtTree, GxtToolbar has been modified to manage events "loadingTreeFinishedEvent and RefreshDataFinishedEvent" related to the refreshData button but their code has been commented because not useful. git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/databases-manager-portlet@100602 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
4a2a2f2cc3
commit
9b569d41a3
|
@ -16,7 +16,6 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryData
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.LoadTablesEvent;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.RandomSamplingEvent;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.RefreshDataEvent;
|
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.SamplingEvent;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.SelectedItemEvent;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.SelectedTableEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.SelectedTableEvent;
|
||||||
|
@ -25,7 +24,6 @@ import org.gcube.portlets.user.databasesmanager.client.events.SmartSamplingEvent
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
|
import org.gcube.portlets.user.databasesmanager.client.events.SubmitQueryEvent;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.LoadTablesEventHandler;
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.LoadTablesEventHandler;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RandomSamplingEventHandler;
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RandomSamplingEventHandler;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.RefreshDataEventHandler;
|
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SamplingEventHandler;
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SamplingEventHandler;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler;
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.SelectedItemEventHandler;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.ShowCreateTableEventHandler;
|
import org.gcube.portlets.user.databasesmanager.client.events.interfaces.ShowCreateTableEventHandler;
|
||||||
|
@ -327,14 +325,12 @@ public class GxtBorderLayoutPanel extends ContentPanel {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(RefreshDataEvent.TYPE,
|
// eventBus.addHandler(RefreshDataEvent.TYPE,
|
||||||
new RefreshDataEventHandler() {
|
// new RefreshDataEventHandler() {
|
||||||
|
// @Override
|
||||||
@Override
|
// public void onRefreshData(RefreshDataEvent refreshDataEvent) {
|
||||||
public void onRefreshData(RefreshDataEvent refreshDataEvent) {
|
// }
|
||||||
|
// });
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// method to load the tables list
|
// method to load the tables list
|
||||||
|
|
|
@ -344,7 +344,7 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
// Window.alert(caught.getMessage());
|
// Window.alert(caught.getMessage());
|
||||||
rootLogger.log(Level.SEVERE, "FAILURE RPC getResource");
|
rootLogger.log(Level.SEVERE, "FAILURE RPC getResource");
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if (caught instanceof SessionExpiredException) {
|
||||||
rootLogger.log(Level.INFO, "Session expired");
|
rootLogger.log(Level.INFO, "Session expired");
|
||||||
CheckSession.showLogoutDialog();
|
CheckSession.showLogoutDialog();
|
||||||
return;
|
return;
|
||||||
|
@ -356,6 +356,8 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
if (tree.isMasked()) {
|
if (tree.isMasked()) {
|
||||||
tree.unmask();
|
tree.unmask();
|
||||||
}
|
}
|
||||||
|
// in order to enable the refresh cache button
|
||||||
|
// eventBus.fireEvent(new LoadingTreeFinishedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -372,6 +374,8 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
|
|
||||||
if (tree.isMasked())
|
if (tree.isMasked())
|
||||||
tree.unmask();
|
tree.unmask();
|
||||||
|
// in order to enable the refresh cache button
|
||||||
|
// eventBus.fireEvent(new LoadingTreeFinishedEvent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// rootLogger.log(Level.SEVERE, "End RPC - getResource");
|
// rootLogger.log(Level.SEVERE, "End RPC - getResource");
|
||||||
|
@ -390,7 +394,7 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
// Window.alert(caught.getMessage());
|
// Window.alert(caught.getMessage());
|
||||||
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBInfo");
|
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBInfo");
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if (caught instanceof SessionExpiredException) {
|
||||||
rootLogger.log(Level.INFO, "Session expired");
|
rootLogger.log(Level.INFO, "Session expired");
|
||||||
CheckSession.showLogoutDialog();
|
CheckSession.showLogoutDialog();
|
||||||
return;
|
return;
|
||||||
|
@ -514,7 +518,7 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
treePanel.setExpanded(child, false);
|
treePanel.setExpanded(child, false);
|
||||||
}
|
}
|
||||||
if (DatabaseType
|
if (DatabaseType
|
||||||
.equals(ConstantsPortlet.POSTGRES)){
|
.equals(ConstantsPortlet.POSTGRES)) {
|
||||||
child.setDatabaseType(ConstantsPortlet.POSTGRES);
|
child.setDatabaseType(ConstantsPortlet.POSTGRES);
|
||||||
}
|
}
|
||||||
children.add(child);
|
children.add(child);
|
||||||
|
@ -561,7 +565,7 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
// Window.alert(caught.getMessage());
|
// Window.alert(caught.getMessage());
|
||||||
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBSchema");
|
rootLogger.log(Level.SEVERE, "FAILURE RPC getDBSchema");
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if (caught instanceof SessionExpiredException) {
|
||||||
rootLogger.log(Level.INFO, "Session expired");
|
rootLogger.log(Level.INFO, "Session expired");
|
||||||
CheckSession.showLogoutDialog();
|
CheckSession.showLogoutDialog();
|
||||||
return;
|
return;
|
||||||
|
@ -729,23 +733,35 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
} else if (Depth == 3) { // database
|
} else if (Depth == 3) { // database
|
||||||
elementType = "database";
|
elementType = "database";
|
||||||
String database = selectedItem.getName();
|
String database = selectedItem.getName();
|
||||||
//get the database type
|
// get the database type
|
||||||
// String dbType = selectedItem.getDatabaseType();
|
// String dbType = selectedItem.getDatabaseType();
|
||||||
FileModel parent = store.getParent(selectedItem);
|
FileModel parent = store.getParent(selectedItem);
|
||||||
String resource = parent.getName();
|
String resource = parent.getName();
|
||||||
|
|
||||||
if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.POSTGRES))){ //refresh schema list and query executed
|
if (selectedItem.getDatabaseType() != null
|
||||||
inputData.put("ResourceName", resource);
|
&& (selectedItem.getDatabaseType()
|
||||||
inputData.put("DatabaseName", database);
|
.equals(ConstantsPortlet.POSTGRES))) { // refresh
|
||||||
|
// schema
|
||||||
|
// list and
|
||||||
|
// query
|
||||||
|
// executed
|
||||||
|
inputData.put("ResourceName", resource);
|
||||||
|
inputData.put("DatabaseName", database);
|
||||||
}
|
}
|
||||||
if (selectedItem.getDatabaseType()!=null && (selectedItem.getDatabaseType().equals(ConstantsPortlet.MYSQL))){ //refresh tables list, query executed and samplings
|
if (selectedItem.getDatabaseType() != null
|
||||||
inputData.put("ResourceName", resource);
|
&& (selectedItem.getDatabaseType()
|
||||||
inputData.put("DatabaseName", database);
|
.equals(ConstantsPortlet.MYSQL))) { // refresh
|
||||||
inputData.put("SchemaName", "");
|
// tables list,
|
||||||
|
// query
|
||||||
|
// executed and
|
||||||
|
// samplings
|
||||||
|
inputData.put("ResourceName", resource);
|
||||||
|
inputData.put("DatabaseName", database);
|
||||||
|
inputData.put("SchemaName", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if (Depth == 4) { // Schema. Refresh tables list, query executed
|
||||||
} else if (Depth == 4) { // Schema. Refresh tables list, query executed and samplings
|
// and samplings
|
||||||
elementType = "schema";
|
elementType = "schema";
|
||||||
String schema = selectedItem.getName();
|
String schema = selectedItem.getName();
|
||||||
FileModel db = store.getParent(selectedItem);
|
FileModel db = store.getParent(selectedItem);
|
||||||
|
@ -767,7 +783,7 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
rootLogger.log(Level.SEVERE, "FAILURE refreshDataTree");
|
rootLogger.log(Level.SEVERE, "FAILURE refreshDataTree");
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if (caught instanceof SessionExpiredException) {
|
||||||
rootLogger.log(Level.INFO, "Session expired");
|
rootLogger.log(Level.INFO, "Session expired");
|
||||||
CheckSession.showLogoutDialog();
|
CheckSession.showLogoutDialog();
|
||||||
return;
|
return;
|
||||||
|
@ -779,6 +795,10 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
if (tree.isMasked()) {
|
if (tree.isMasked()) {
|
||||||
tree.unmask();
|
tree.unmask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fire an event in order to activate the refresh cache
|
||||||
|
// button
|
||||||
|
// eventBus.fireEvent(new RefreshDataFinishedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -978,6 +998,9 @@ public class GxtTreePanel extends LayoutContainer {
|
||||||
if (tree.isMasked()) {
|
if (tree.isMasked()) {
|
||||||
tree.unmask();
|
tree.unmask();
|
||||||
}
|
}
|
||||||
|
// fire an event in order to activate the refresh cache
|
||||||
|
// button
|
||||||
|
// eventBus.fireEvent(new RefreshDataFinishedEvent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,8 @@ public class GxtToolbarFunctionality {
|
||||||
// proposed query displayed in the submit query form
|
// proposed query displayed in the submit query form
|
||||||
private String queryForSubmitOperation = "select * from %1$s limit 10";
|
private String queryForSubmitOperation = "select * from %1$s limit 10";
|
||||||
private boolean isTableSelected = false;
|
private boolean isTableSelected = false;
|
||||||
|
// variable to control the deactivate/activate of the refresh data button
|
||||||
|
private boolean treeLoaded = false;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
// public GxtToolbarFunctionality(HandlerManager eBus) {
|
// public GxtToolbarFunctionality(HandlerManager eBus) {
|
||||||
|
@ -166,7 +168,8 @@ public class GxtToolbarFunctionality {
|
||||||
btnSimpleSample.disable();
|
btnSimpleSample.disable();
|
||||||
btnSmartSample.disable();
|
btnSmartSample.disable();
|
||||||
btnRandomSample.disable();
|
btnRandomSample.disable();
|
||||||
btnRefresCachedData.disable();
|
// btnRefresCachedData.disable();
|
||||||
|
btnRefresCachedData.enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHandler() {
|
private void addHandler() {
|
||||||
|
@ -209,6 +212,31 @@ public class GxtToolbarFunctionality {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// eventBus.addHandler(RefreshDataFinishedEvent.TYPE,
|
||||||
|
// new RefreshDataFinishedEventHandler() {
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
|
// public void onRefreshDataFinished(
|
||||||
|
// RefreshDataFinishedEvent refreshDataFinishedEvent) {
|
||||||
|
// // in order to activate the button
|
||||||
|
// if (!btnRefresCachedData.isEnabled()) {
|
||||||
|
// btnRefresCachedData.enable();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// eventBus.addHandler(LoadingTreeFinishedEvent.TYPE,
|
||||||
|
// new LoadingTreeFinishedEventHandler() {
|
||||||
|
// @Override
|
||||||
|
// public void onLoadingTreeFinished(
|
||||||
|
// LoadingTreeFinishedEvent loadingTreeEvent) {
|
||||||
|
// treeLoaded = true;
|
||||||
|
// if (!btnRefresCachedData.isEnabled()) {
|
||||||
|
// btnRefresCachedData.enable();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSelectionListenersOnToolBar() {
|
private void addSelectionListenersOnToolBar() {
|
||||||
|
@ -418,10 +446,11 @@ public class GxtToolbarFunctionality {
|
||||||
public void componentSelected(ButtonEvent ce) {
|
public void componentSelected(ButtonEvent ce) {
|
||||||
|
|
||||||
rootLogger.log(Level.INFO, "REFRESH BUTTON");
|
rootLogger.log(Level.INFO, "REFRESH BUTTON");
|
||||||
|
// deactivate the button
|
||||||
|
// btnRefresCachedData.disable();
|
||||||
// fire event
|
// fire event
|
||||||
eventBus.fireEvent(new RefreshDataEvent());
|
eventBus.fireEvent(new RefreshDataEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +465,11 @@ public class GxtToolbarFunctionality {
|
||||||
switch (infoTreeDepthSelectedItem) {
|
switch (infoTreeDepthSelectedItem) {
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
btnRefresCachedData.enable();
|
// if (treeLoaded == true) {
|
||||||
|
// btnRefresCachedData.enable();
|
||||||
|
// } else {
|
||||||
|
// btnRefresCachedData.disable();
|
||||||
|
// }
|
||||||
btnTablesList.disable();
|
btnTablesList.disable();
|
||||||
btnSubmitQuery.disable();
|
btnSubmitQuery.disable();
|
||||||
// btnGetInfo.disable();
|
// btnGetInfo.disable();
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class ConstantsPortlet {
|
||||||
public static final String ALGID_SMARTSAMPLEONTABLE="SMARTSAMPLEONTABLE";
|
public static final String ALGID_SMARTSAMPLEONTABLE="SMARTSAMPLEONTABLE";
|
||||||
public static final String ALGID_RANDOMSAMPLEONTABLE="RANDOMSAMPLEONTABLE";
|
public static final String ALGID_RANDOMSAMPLEONTABLE="RANDOMSAMPLEONTABLE";
|
||||||
|
|
||||||
|
//elements type
|
||||||
|
public static final String RESOURCESLIST="RESOURCESLIST";
|
||||||
|
public static final String RESOURCE="RESOURCE";
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -25,6 +26,8 @@ import net.sf.ehcache.config.CacheConfiguration;
|
||||||
import net.sf.ehcache.config.MemoryUnit;
|
import net.sf.ehcache.config.MemoryUnit;
|
||||||
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
import net.sf.ehcache.store.MemoryStoreEvictionPolicy;
|
||||||
|
|
||||||
|
import opennlp.tools.parser.Cons;
|
||||||
|
|
||||||
import org.apache.regexp.RE;
|
import org.apache.regexp.RE;
|
||||||
import org.apache.xpath.operations.Bool;
|
import org.apache.xpath.operations.Bool;
|
||||||
import org.gcube.application.framework.core.session.ASLSession;
|
import org.gcube.application.framework.core.session.ASLSession;
|
||||||
|
@ -63,12 +66,16 @@ import org.gcube.portlets.user.databasesmanager.client.datamodel.SamplingResultW
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.Row;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
import org.gcube.portlets.user.databasesmanager.client.datamodel.SubmitQueryResultWithFileFromServlet;
|
||||||
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
import org.gcube.portlets.user.databasesmanager.client.utils.ConstantsPortlet;
|
||||||
|
import org.gcube.portlets.user.databasesmanager.server.util.DataExchangedThroughQueue;
|
||||||
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
|
import org.gcube.portlets.user.databasesmanager.server.util.SessionUtil;
|
||||||
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
|
import org.gcube.portlets.user.databasesmanager.shared.SessionExpiredException;
|
||||||
import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException;
|
import org.gcube.portlets.user.databasesmanager.shared.StatisticalManagerException;
|
||||||
|
import org.hibernate.engine.JoinSequence.Join;
|
||||||
|
|
||||||
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
|
import com.extjs.gxt.ui.client.data.BasePagingLoadResult;
|
||||||
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
|
import com.extjs.gxt.ui.client.data.PagingLoadConfig;
|
||||||
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
import com.extjs.gxt.ui.client.data.PagingLoadResult;
|
||||||
|
import com.google.gwt.dom.client.Element;
|
||||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||||
import com.thoughtworks.xstream.XStream;
|
import com.thoughtworks.xstream.XStream;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
@ -88,6 +95,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
// variables to check thread execution
|
// variables to check thread execution
|
||||||
private static HashMap<String, Boolean> threadsStarted = new HashMap<String, Boolean>();
|
private static HashMap<String, Boolean> threadsStarted = new HashMap<String, Boolean>();
|
||||||
private static boolean endThread = false;
|
private static boolean endThread = false;
|
||||||
|
private static boolean threadExecutionFinished = false;
|
||||||
|
private static ConcurrentLinkedQueue<DataExchangedThroughQueue> queue = new ConcurrentLinkedQueue<DataExchangedThroughQueue>();
|
||||||
|
private static ThreadDataLoader dataLoader;
|
||||||
|
|
||||||
public GWTdbManagerServiceImpl() throws Exception {
|
public GWTdbManagerServiceImpl() throws Exception {
|
||||||
}
|
}
|
||||||
|
@ -150,6 +160,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
logger.info("dbmanager-> Folder computationResult created in : "
|
logger.info("dbmanager-> Folder computationResult created in : "
|
||||||
+ this.getServletContext().getRealPath(""));
|
+ this.getServletContext().getRealPath(""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create the thread DataLoader
|
||||||
|
dataLoader = new ThreadDataLoader();
|
||||||
|
logger.info("dbmanager-> Thread Dataloader created");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("dbmanager-> ", e);
|
logger.error("dbmanager-> ", e);
|
||||||
|
|
||||||
|
@ -191,7 +205,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
super.destroy();
|
super.destroy();
|
||||||
|
|
||||||
// set endThread variable
|
// set endThread variable
|
||||||
setEndThreadvariable();
|
setEndThreadvariable(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -291,14 +305,16 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
// get scope
|
// get scope
|
||||||
String scope = session.getScope();
|
String scope = session.getScope();
|
||||||
|
|
||||||
// check if the thread is alreday started
|
// check if the thread is already started
|
||||||
Boolean value = getThreadStarted(scope);
|
Boolean value = getThreadStarted(scope);
|
||||||
if ((value == null) || (value.booleanValue() == false)) {
|
if ((value == null) || (value.booleanValue() == false)) {
|
||||||
ThreadLoaderData loader = new ThreadLoaderData(scope);
|
DataExchangedThroughQueue dataqueue = new DataExchangedThroughQueue(
|
||||||
Thread t = new Thread(loader);
|
scope);
|
||||||
|
queue.offer(dataqueue);
|
||||||
|
Thread t = new Thread(dataLoader);
|
||||||
t.start();
|
t.start();
|
||||||
|
|
||||||
logger.info("dbmanager-> Thread created in order to load all data");
|
logger.info("dbmanager-> Thread DataLoader started in order to load data tree");
|
||||||
}
|
}
|
||||||
|
|
||||||
// initialize variables with application startup
|
// initialize variables with application startup
|
||||||
|
@ -2050,7 +2066,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
private synchronized net.sf.ehcache.Element getDataFromCache(String key) {
|
private synchronized net.sf.ehcache.Element getDataFromCache(String key) {
|
||||||
net.sf.ehcache.Element data = null;
|
net.sf.ehcache.Element data = null;
|
||||||
if (DBCache != null) {
|
if (DBCache != null) {
|
||||||
|
|
||||||
data = DBCache.get(key);
|
data = DBCache.get(key);
|
||||||
|
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -2077,9 +2095,10 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
GeneralOutputFromServlet result = null;
|
GeneralOutputFromServlet result = null;
|
||||||
|
|
||||||
// build key
|
|
||||||
if (inputData != null && inputData.size() != 0) {
|
if (inputData != null && inputData.size() != 0) {
|
||||||
// System.out.println("server-> input size not null");
|
|
||||||
|
DataExchangedThroughQueue dataQueue = null;
|
||||||
|
|
||||||
String key = "";
|
String key = "";
|
||||||
String keyUsedForQueryRefresh = "";
|
String keyUsedForQueryRefresh = "";
|
||||||
String keyUsedForSamplingsRefresh = "";
|
String keyUsedForSamplingsRefresh = "";
|
||||||
|
@ -2087,13 +2106,17 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
String keyUsedForRandomSamplingRefresh = "";
|
String keyUsedForRandomSamplingRefresh = "";
|
||||||
|
|
||||||
if (!ElementType.equals("")) {
|
if (!ElementType.equals("")) {
|
||||||
// System.out.println("server-> element type not null");
|
// build key
|
||||||
switch (ElementType) {
|
switch (ElementType) {
|
||||||
case "listResources":
|
case "listResources":
|
||||||
key = scope + inputData.get("listResources");
|
key = scope + inputData.get("listResources");
|
||||||
|
dataQueue = new DataExchangedThroughQueue(scope);
|
||||||
break;
|
break;
|
||||||
case "resource":
|
case "resource":
|
||||||
key = scope + inputData.get("ResourceName");
|
key = scope + inputData.get("ResourceName");
|
||||||
|
dataQueue = new DataExchangedThroughQueue(scope,
|
||||||
|
"resource", inputData.get("ResourceName"),
|
||||||
|
null, null, null);
|
||||||
break;
|
break;
|
||||||
case "database":
|
case "database":
|
||||||
if (element.getDatabaseType().equals(
|
if (element.getDatabaseType().equals(
|
||||||
|
@ -2107,6 +2130,18 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
+ ConstantsPortlet.ALGID_SUBMITQUERY + key;
|
+ ConstantsPortlet.ALGID_SUBMITQUERY + key;
|
||||||
|
|
||||||
refreshSubmittedQueryInCache(keyUsedForQueryRefresh);
|
refreshSubmittedQueryInCache(keyUsedForQueryRefresh);
|
||||||
|
// loader = new ThreadLoaderData(scope, "database",
|
||||||
|
// inputData.get("ResourceName"),
|
||||||
|
// inputData.get("DatabaseName"), null,
|
||||||
|
// element.getDatabaseType());
|
||||||
|
// loader = new ThreadLoaderData(scope, "database",
|
||||||
|
// inputData, ConstantsPortlet.POSTGRES);
|
||||||
|
|
||||||
|
dataQueue = new DataExchangedThroughQueue(scope,
|
||||||
|
"database", inputData.get("ResourceName"),
|
||||||
|
inputData.get("DatabaseName"), null,
|
||||||
|
element.getDatabaseType());
|
||||||
|
key = scope + key;
|
||||||
}
|
}
|
||||||
if (element.getDatabaseType().equals(
|
if (element.getDatabaseType().equals(
|
||||||
ConstantsPortlet.MYSQL)) { // refresh table
|
ConstantsPortlet.MYSQL)) { // refresh table
|
||||||
|
@ -2130,6 +2165,21 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
|
|
||||||
refreshSamplingsInCache(keyUsedForSamplingsRefresh,
|
refreshSamplingsInCache(keyUsedForSamplingsRefresh,
|
||||||
keyUsedForSmartSamplingRefresh);
|
keyUsedForSmartSamplingRefresh);
|
||||||
|
|
||||||
|
// loader = new ThreadLoaderData(scope, "database",
|
||||||
|
// inputData, ConstantsPortlet.MYSQL);
|
||||||
|
|
||||||
|
// loader = new ThreadLoaderData(scope, "database",
|
||||||
|
// inputData.get("ResourceName"),
|
||||||
|
// inputData.get("DatabaseName"),
|
||||||
|
// inputData.get("SchemaName"),
|
||||||
|
// element.getDatabaseType());
|
||||||
|
|
||||||
|
dataQueue = new DataExchangedThroughQueue(scope,
|
||||||
|
"database", inputData.get("ResourceName"),
|
||||||
|
inputData.get("DatabaseName"),
|
||||||
|
inputData.get("SchemaName"),
|
||||||
|
element.getDatabaseType());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -2156,22 +2206,33 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
refreshSamplingsInCache(keyUsedForSamplingsRefresh,
|
refreshSamplingsInCache(keyUsedForSamplingsRefresh,
|
||||||
keyUsedForSmartSamplingRefresh);
|
keyUsedForSmartSamplingRefresh);
|
||||||
|
|
||||||
|
// loader = new ThreadLoaderData(scope, "schema",
|
||||||
|
// inputData, ConstantsPortlet.POSTGRES);
|
||||||
|
|
||||||
|
dataQueue = new DataExchangedThroughQueue(scope,
|
||||||
|
"schema", inputData.get("ResourceName"),
|
||||||
|
inputData.get("DatabaseName"),
|
||||||
|
inputData.get("SchemaName"),
|
||||||
|
element.getDatabaseType());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("server->KEY: " + key);
|
// TODO ***DATA NULL IN CACHE MANAGEMENT
|
||||||
|
logger.trace("Check if data of the node is present in cache with key: : " + key);
|
||||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
|
||||||
if (dataFromCache != null) {
|
if (dataFromCache != null) {
|
||||||
// System.out.println("server-> data in cache with key: " +
|
logger.trace("data of the node is in cache");
|
||||||
// key);
|
|
||||||
refreshCache(key);
|
|
||||||
// System.out.println("server-> data removed from cache with key: "
|
|
||||||
// + key);
|
|
||||||
|
|
||||||
|
logger.info("dbmanager-> Starting the data removing process in cache from the node");
|
||||||
|
|
||||||
|
// refresh data in cache. Remove data related to the subtree
|
||||||
|
// with the selected element as root
|
||||||
|
refreshDataInCache(element, ElementType, scope, key, null);
|
||||||
|
|
||||||
|
// recover the refresh data of the item selected
|
||||||
if (!ElementType.equals("")) {
|
if (!ElementType.equals("")) {
|
||||||
// System.out.println("server-> element type not null");
|
|
||||||
switch (ElementType) {
|
switch (ElementType) {
|
||||||
case "listResources":
|
case "listResources":
|
||||||
List<FileModel> output1 = getResource();
|
List<FileModel> output1 = getResource();
|
||||||
|
@ -2187,30 +2248,45 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
if (element.getDatabaseType() != null
|
if (element.getDatabaseType() != null
|
||||||
&& (element.getDatabaseType()
|
&& (element.getDatabaseType()
|
||||||
.equals(ConstantsPortlet.POSTGRES))) { // refresh
|
.equals(ConstantsPortlet.POSTGRES))) { // refresh
|
||||||
// schema
|
// schema list
|
||||||
// list
|
|
||||||
List<FileModel> output3 = getDBSchema(inputData);
|
List<FileModel> output3 = getDBSchema(inputData);
|
||||||
result = new GeneralOutputFromServlet(output3);
|
result = new GeneralOutputFromServlet(output3);
|
||||||
}
|
}
|
||||||
if (element.getDatabaseType() != null
|
if (element.getDatabaseType() != null
|
||||||
&& element.getDatabaseType().equals(
|
&& element.getDatabaseType().equals(
|
||||||
ConstantsPortlet.MYSQL)) { // refresh
|
ConstantsPortlet.MYSQL)) { // refresh
|
||||||
// table
|
// table list
|
||||||
// list
|
|
||||||
getTables(inputData, ConstantsPortlet.DATABASE);
|
getTables(inputData, ConstantsPortlet.DATABASE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "schema":
|
case "schema":
|
||||||
getTables(inputData, ConstantsPortlet.SCHEMA);
|
getTables(inputData, ConstantsPortlet.SCHEMA);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the thread execution is terminated. If yes, a
|
||||||
|
// new
|
||||||
|
// thread is started otherwise no because the thread in
|
||||||
|
// running
|
||||||
|
// state will also serve this request received in the queue.
|
||||||
|
// The thread will run in backgroung to load the data
|
||||||
|
// related to
|
||||||
|
// the subtree with the item selected as root.
|
||||||
|
if (isThreadExecutionFinished()) {
|
||||||
|
logger.info("dbmanager-> Starting the launch of the Thread DataLoader execution");
|
||||||
|
queue.offer(dataQueue);
|
||||||
|
Thread t = new Thread(dataLoader);
|
||||||
|
t.start();
|
||||||
|
} else {
|
||||||
|
logger.info("dbmanager-> The Thread DataLoader is already running");
|
||||||
|
queue.offer(dataQueue);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("dbmanager-> ", e);
|
logger.error("dbmanager-> ", e);
|
||||||
if (!(e instanceof StatisticalManagerException)) {
|
if (!(e instanceof StatisticalManagerException)) {
|
||||||
|
@ -2222,9 +2298,158 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void refreshDataInCache(FileModel element, String ElementType,
|
||||||
|
String scope, String key, String DBType) {
|
||||||
|
logger.info("dbmanager-> Refresh Data Request of element "
|
||||||
|
+ ElementType + " in Cache with KEY: " + key);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// get data from cache
|
||||||
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
|
||||||
|
Object value = null;
|
||||||
|
if (dataFromCache != null) {
|
||||||
|
logger.info("dbmanager-> Data is in cache");
|
||||||
|
|
||||||
|
value = dataFromCache.getObjectValue();
|
||||||
|
if (value != null) {
|
||||||
|
if (!ElementType.equals("")) {
|
||||||
|
switch (ElementType) {
|
||||||
|
case "listResources":
|
||||||
|
// refresh resources
|
||||||
|
List<FileModel> resources = (List<FileModel>) value;
|
||||||
|
// refresh cache
|
||||||
|
refreshCache(key);
|
||||||
|
logger.trace("element: " + ElementType
|
||||||
|
+ " with key: " + key + " removed in cache");
|
||||||
|
// apply the refresh on children
|
||||||
|
for (int i = 0; i < resources.size(); i++) {
|
||||||
|
key = scope + resources.get(i).getName();
|
||||||
|
refreshDataInCache(element, "resource", null,
|
||||||
|
key, null);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "resource":
|
||||||
|
// refresh databases
|
||||||
|
LinkedHashMap<String, FileModel> DBdata = (LinkedHashMap<String, FileModel>) value;
|
||||||
|
// refresh cache
|
||||||
|
refreshCache(key);
|
||||||
|
logger.trace("element " + ElementType
|
||||||
|
+ " with key: " + key + " removed in cache");
|
||||||
|
// apply the refresh on children
|
||||||
|
HashMap<String, String> DBlist = new HashMap<String, String>();
|
||||||
|
|
||||||
|
if (DBdata != null) {
|
||||||
|
Set<String> keys = DBdata.keySet();
|
||||||
|
Object[] array = keys.toArray();
|
||||||
|
|
||||||
|
int numIterations = (DBdata.size()) / 5;
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
for (i = 0; i < numIterations; i++) {
|
||||||
|
String DBName = "";
|
||||||
|
|
||||||
|
for (j = (i * 5); j < (i + 1) * 5; j++) {
|
||||||
|
|
||||||
|
if (array[j].toString().contains(
|
||||||
|
"Database Name")) {
|
||||||
|
DBName = DBdata.get(
|
||||||
|
array[j].toString())
|
||||||
|
.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array[j].toString().contains(
|
||||||
|
"Driver Name")) {
|
||||||
|
String driver = DBdata.get(
|
||||||
|
array[j].toString())
|
||||||
|
.getName();
|
||||||
|
|
||||||
|
if (driver.toUpperCase().contains(
|
||||||
|
ConstantsPortlet.POSTGRES)) {
|
||||||
|
|
||||||
|
DBlist.put(
|
||||||
|
DBName,
|
||||||
|
ConstantsPortlet.POSTGRES);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (driver.toUpperCase().contains(
|
||||||
|
ConstantsPortlet.MYSQL)) {
|
||||||
|
DBlist.put(DBName,
|
||||||
|
ConstantsPortlet.MYSQL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<String> keys = DBlist.keySet();
|
||||||
|
Object[] array = keys.toArray();
|
||||||
|
|
||||||
|
for (int i = 0; i < array.length; i++) {
|
||||||
|
String databaseType = DBlist.get(array[i]
|
||||||
|
.toString());
|
||||||
|
// if (databaseType
|
||||||
|
// .equals(ConstantsPortlet.POSTGRES)) {
|
||||||
|
String newkey = key + array[i].toString();
|
||||||
|
refreshDataInCache(element, "database", null,
|
||||||
|
newkey, databaseType);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "database":
|
||||||
|
if (DBType == null) {
|
||||||
|
DBType = element.getDatabaseType();
|
||||||
|
}
|
||||||
|
// refresh schema (db postgres) or tables (db mysql)
|
||||||
|
List<FileModel> schemaList = (List<FileModel>) value;
|
||||||
|
|
||||||
|
refreshCache(key); // refresh schema
|
||||||
|
logger.trace("element " + ElementType
|
||||||
|
+ " with key: " + key + " removed in cache");
|
||||||
|
if (DBType.equals(ConstantsPortlet.POSTGRES)) {
|
||||||
|
// SCHEMA
|
||||||
|
for (int i = 0; i < schemaList.size(); i++) {
|
||||||
|
String newkey = key
|
||||||
|
+ schemaList.get(i).getName();
|
||||||
|
refreshDataInCache(element, "schema", null,
|
||||||
|
newkey, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (DBType.equals(ConstantsPortlet.MYSQL)) {
|
||||||
|
// refresh tables
|
||||||
|
key = key + "";
|
||||||
|
refreshCache(key); // refresh tables
|
||||||
|
logger.trace("element " + ElementType
|
||||||
|
+ " with key: " + key
|
||||||
|
+ " removed in cache");
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "schema":
|
||||||
|
// refresh tables (db postgres)
|
||||||
|
refreshCache(key);
|
||||||
|
logger.trace("element " + ElementType
|
||||||
|
+ " with key: " + key + " removed in cache");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.info("dbmanager-> Data not in cache");
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("dbmanager-> ", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private synchronized void refreshCache(String key) throws Exception {
|
private synchronized void refreshCache(String key) throws Exception {
|
||||||
// try {
|
// try {
|
||||||
|
// System.out.println("SIZE CACHE PRE REMOVING: " + DBCache.getSize());
|
||||||
DBCache.remove(key);
|
DBCache.remove(key);
|
||||||
|
// System.out.println("SIZE CACHE POST REMOVING: " + DBCache.getSize());
|
||||||
// } catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
// TODO: handle exception
|
// TODO: handle exception
|
||||||
// logger.error("dbmanager-> ", e);
|
// logger.error("dbmanager-> ", e);
|
||||||
|
@ -2237,6 +2462,9 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
private synchronized void refreshSubmittedQueryInCache(String key)
|
private synchronized void refreshSubmittedQueryInCache(String key)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|
||||||
|
logger.info("dbmanager-> refreshing submitted queries in cache with key:"
|
||||||
|
+ key);
|
||||||
|
|
||||||
List<String> keysInCache = DBCache.getKeys();
|
List<String> keysInCache = DBCache.getKeys();
|
||||||
int listSize = keysInCache.size();
|
int listSize = keysInCache.size();
|
||||||
List<String> keysToBeRemoved = new ArrayList<>();
|
List<String> keysToBeRemoved = new ArrayList<>();
|
||||||
|
@ -2258,6 +2486,11 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
String keyUsedForSamplingsRefresh,
|
String keyUsedForSamplingsRefresh,
|
||||||
String keyUsedForSmartSamplingRefresh) throws Exception {
|
String keyUsedForSmartSamplingRefresh) throws Exception {
|
||||||
|
|
||||||
|
logger.info("dbmanager-> refreshing samplings and smart sampling in cache with keys: "
|
||||||
|
+ keyUsedForSamplingsRefresh
|
||||||
|
+ " "
|
||||||
|
+ keyUsedForSmartSamplingRefresh);
|
||||||
|
|
||||||
List<String> keysInCache = DBCache.getKeys();
|
List<String> keysInCache = DBCache.getKeys();
|
||||||
int listSize = keysInCache.size();
|
int listSize = keysInCache.size();
|
||||||
List<String> keysToBeRemoved = new ArrayList<>();
|
List<String> keysToBeRemoved = new ArrayList<>();
|
||||||
|
@ -2339,8 +2572,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
return queryParsed;
|
return queryParsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void setEndThreadvariable() {
|
private synchronized void setEndThreadvariable(boolean value) {
|
||||||
endThread = true;
|
endThread = value;
|
||||||
logger.info("dbmanager-> Variable EndThread set in order to stop the thread execution");
|
logger.info("dbmanager-> Variable EndThread set in order to stop the thread execution");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2349,6 +2582,14 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
return endThread;
|
return endThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private synchronized void setThreadExecutionFinished(boolean value) {
|
||||||
|
threadExecutionFinished = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized boolean isThreadExecutionFinished() {
|
||||||
|
return threadExecutionFinished;
|
||||||
|
}
|
||||||
|
|
||||||
private List<FileModel> recoverResources(String scope) throws Exception {
|
private List<FileModel> recoverResources(String scope) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -2373,6 +2614,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
// String key = inputParameters.get(0).getDefaultValue();
|
// String key = inputParameters.get(0).getDefaultValue();
|
||||||
String key = scope + "listResources";
|
String key = scope + "listResources";
|
||||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
logger.trace("element added in cache with key: " + key);
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
if (dataFromCache != null) {
|
if (dataFromCache != null) {
|
||||||
|
@ -2454,6 +2696,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
// check if data exist considering as key the input parameters
|
// check if data exist considering as key the input parameters
|
||||||
String key = scope + inputParameters.get(0).getValue();
|
String key = scope + inputParameters.get(0).getValue();
|
||||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
logger.trace("element added in cache with key: " + key);
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
if (dataFromCache != null) {
|
if (dataFromCache != null) {
|
||||||
|
@ -2564,8 +2807,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
// check if data exist considering as key the input parameters
|
// check if data exist considering as key the input parameters
|
||||||
String key = scope + inputParameters.get(0).getValue()
|
String key = scope + inputParameters.get(0).getValue()
|
||||||
+ inputParameters.get(1).getValue();
|
+ inputParameters.get(1).getValue();
|
||||||
|
|
||||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
logger.trace("element put in cache with key: " + key);
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
if (dataFromCache != null) {
|
if (dataFromCache != null) {
|
||||||
|
@ -2687,8 +2930,8 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
String key = scope + inputParameters.get(0).getValue()
|
String key = scope + inputParameters.get(0).getValue()
|
||||||
+ inputParameters.get(1).getValue()
|
+ inputParameters.get(1).getValue()
|
||||||
+ inputParameters.get(2).getValue();
|
+ inputParameters.get(2).getValue();
|
||||||
|
|
||||||
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
net.sf.ehcache.Element dataFromCache = getDataFromCache(key);
|
||||||
|
logger.trace("element put in cache with key: " + key);
|
||||||
|
|
||||||
Object value = null;
|
Object value = null;
|
||||||
if (dataFromCache != null) {
|
if (dataFromCache != null) {
|
||||||
|
@ -2761,38 +3004,94 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
|
|
||||||
// thread that loads data on the resources
|
// thread that loads data on the resources
|
||||||
private class ThreadLoaderData implements Runnable {
|
private class ThreadDataLoader implements Runnable {
|
||||||
private String scope;
|
|
||||||
|
|
||||||
public ThreadLoaderData(String s) {
|
public ThreadDataLoader() {
|
||||||
scope = s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
logger.info("dbmanager-> Thread DataLoader running");
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// add an element related to the thread
|
setThreadExecutionFinished(false);
|
||||||
updateThreadsStarted(scope, true);
|
|
||||||
|
|
||||||
if (!getEndThreadvariable()) {
|
while (!queue.isEmpty()) {
|
||||||
List<FileModel> resources = recoverResources(scope);
|
|
||||||
|
|
||||||
int i = 0;
|
logger.info("dbmanager-> Queue to exchange data with the thread not empty");
|
||||||
while ((!getEndThreadvariable()) && (i < resources.size())) {
|
|
||||||
getDatabase(resources.get(i).getName());
|
// recover data from queue
|
||||||
i++;
|
DataExchangedThroughQueue node = queue.poll();
|
||||||
// logger.info("dbmanager-> ***thread inside the root while");
|
if (node != null) {
|
||||||
|
String scope = node.getScope();
|
||||||
|
// add an element related to the thread in the hashmap
|
||||||
|
updateThreadsStarted(scope, true);
|
||||||
|
boolean loadTree = node.treeToBeLoaded();
|
||||||
|
|
||||||
|
// System.out.println("value loadTree: " + loadTree);
|
||||||
|
if (loadTree == false) { // load the subtree with the
|
||||||
|
// node as root
|
||||||
|
if (!getEndThreadvariable()) {
|
||||||
|
String elementType = node.elementType();
|
||||||
|
String resource = node.resource();
|
||||||
|
|
||||||
|
logger.info("dbmanager-> Starting the node refreshing process");
|
||||||
|
|
||||||
|
switch (elementType) {
|
||||||
|
case "resource":
|
||||||
|
getDatabase(scope, resource);
|
||||||
|
break;
|
||||||
|
case "database":
|
||||||
|
String DBType = node.DBType();
|
||||||
|
String database = node.database();
|
||||||
|
if (DBType
|
||||||
|
.equals(ConstantsPortlet.POSTGRES)) {
|
||||||
|
getSchema(scope, resource, database);
|
||||||
|
}
|
||||||
|
if (DBType.equals(ConstantsPortlet.MYSQL)) {
|
||||||
|
String schema = node.schema();
|
||||||
|
getTables(scope, resource, database,
|
||||||
|
schema,
|
||||||
|
ConstantsPortlet.DATABASE);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "schema":
|
||||||
|
String db = node.database();
|
||||||
|
String schema = node.schema();
|
||||||
|
getTables(scope, resource, db, schema,
|
||||||
|
ConstantsPortlet.SCHEMA);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else { // load the tree
|
||||||
|
logger.info("dbmanager-> Starting the tree loading");
|
||||||
|
|
||||||
|
if (!getEndThreadvariable()) {
|
||||||
|
List<FileModel> resources = recoverResources(scope);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
while ((!getEndThreadvariable())
|
||||||
|
&& (i < resources.size())) {
|
||||||
|
getDatabase(scope, resources.get(i)
|
||||||
|
.getName());
|
||||||
|
i++;
|
||||||
|
// logger.info("dbmanager-> ***thread inside the while checking the EndThread variable");
|
||||||
|
}
|
||||||
|
// logger.info("dbmanager-> ***thread outside the while checking the EndThread variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// logger.info("dbmanager-> ***thread outside the root while");
|
|
||||||
}
|
}
|
||||||
// logger.info("dbmanager-> ***Thread execution terminated");
|
// thread terminates its execution
|
||||||
|
setThreadExecutionFinished(true);
|
||||||
|
logger.info("dbmanager-> Thread DataLoader execution terminated");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("dbmanager-> ", e);
|
logger.error("dbmanager-> ", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getDatabase(String resourceName) {
|
private void getDatabase(String scope, String resourceName) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -2825,30 +3124,13 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
ConstantsPortlet.POSTGRES)) {
|
ConstantsPortlet.POSTGRES)) {
|
||||||
// get schema
|
// get schema
|
||||||
List<FileModel> schemaList = getSchema(
|
List<FileModel> schemaList = getSchema(
|
||||||
resourceName, DBName);
|
scope, resourceName, DBName);
|
||||||
// recover tables
|
|
||||||
if (schemaList != null) {
|
|
||||||
int z = 0;
|
|
||||||
while ((!getEndThreadvariable())
|
|
||||||
&& (z < schemaList.size())) {
|
|
||||||
// for (int i = 0; i <
|
|
||||||
// schemaList.size(); i++) {
|
|
||||||
String schemaName = schemaList.get(
|
|
||||||
z).getName();
|
|
||||||
// System.out.println("SchemaName: "
|
|
||||||
// + schemaName);
|
|
||||||
getTables(resourceName, DBName,
|
|
||||||
schemaName,
|
|
||||||
ConstantsPortlet.SCHEMA);
|
|
||||||
z++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (driver.toUpperCase().contains(
|
if (driver.toUpperCase().contains(
|
||||||
ConstantsPortlet.MYSQL)) {
|
ConstantsPortlet.MYSQL)) {
|
||||||
// get tables
|
// get tables
|
||||||
getTables(resourceName, DBName, "",
|
getTables(scope, resourceName, DBName, "",
|
||||||
ConstantsPortlet.DATABASE);
|
ConstantsPortlet.DATABASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2861,7 +3143,7 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FileModel> getSchema(String resourceName,
|
private List<FileModel> getSchema(String scope, String resourceName,
|
||||||
String databaseName) {
|
String databaseName) {
|
||||||
|
|
||||||
List<FileModel> schemaList = null;
|
List<FileModel> schemaList = null;
|
||||||
|
@ -2872,14 +3154,29 @@ public class GWTdbManagerServiceImpl extends RemoteServiceServlet implements
|
||||||
dataInputForSchema.put("DatabaseName", databaseName);
|
dataInputForSchema.put("DatabaseName", databaseName);
|
||||||
|
|
||||||
schemaList = recoverSchema(scope, dataInputForSchema);
|
schemaList = recoverSchema(scope, dataInputForSchema);
|
||||||
|
|
||||||
|
// recover tables
|
||||||
|
if (schemaList != null) {
|
||||||
|
int z = 0;
|
||||||
|
while ((!getEndThreadvariable()) && (z < schemaList.size())) {
|
||||||
|
// for (int i = 0; i <
|
||||||
|
// schemaList.size(); i++) {
|
||||||
|
String schemaName = schemaList.get(z).getName();
|
||||||
|
getTables(scope, resourceName, databaseName,
|
||||||
|
schemaName, ConstantsPortlet.SCHEMA);
|
||||||
|
z++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("dbmanager-> ", e);
|
logger.error("dbmanager-> ", e);
|
||||||
}
|
}
|
||||||
return schemaList;
|
return schemaList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getTables(String resourceName, String databaseName,
|
private void getTables(String scope, String resourceName,
|
||||||
String schemaName, String elementType) {
|
String databaseName, String schemaName, String elementType) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
LinkedHashMap<String, String> dataInputForTables = new LinkedHashMap<String, String>();
|
LinkedHashMap<String, String> dataInputForTables = new LinkedHashMap<String, String>();
|
||||||
dataInputForTables.put("ResourceName", resourceName);
|
dataInputForTables.put("ResourceName", resourceName);
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
package org.gcube.portlets.user.databasesmanager.server.util;
|
||||||
|
|
||||||
|
public class DataExchangedThroughQueue {
|
||||||
|
|
||||||
|
private String scope;
|
||||||
|
private boolean loadTree = false;
|
||||||
|
// private LinkedHashMap<String, String> Data;
|
||||||
|
private String elementType;
|
||||||
|
private String resource;
|
||||||
|
private String database;
|
||||||
|
private String schema;
|
||||||
|
private String DBType;
|
||||||
|
|
||||||
|
public DataExchangedThroughQueue(String scopeValue) {
|
||||||
|
scope = scopeValue;
|
||||||
|
loadTree = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataExchangedThroughQueue(String scopeValue, String elemType,
|
||||||
|
String resourceName, String databaseName, String schemaName,
|
||||||
|
String databaseType) {
|
||||||
|
scope = scopeValue;
|
||||||
|
loadTree = false;
|
||||||
|
elementType = elemType;
|
||||||
|
resource = resourceName;
|
||||||
|
database = databaseName;
|
||||||
|
schema = schemaName;
|
||||||
|
DBType = databaseType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean treeToBeLoaded() {
|
||||||
|
return loadTree;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String elementType() {
|
||||||
|
return elementType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String resource() {
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String database() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String schema() {
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String DBType() {
|
||||||
|
return DBType;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue