Skip to content

Commit

Permalink
IN PROGRESS - issue SPAGOBI-1607: As SpagoBI User I want to have a se…
Browse files Browse the repository at this point in the history
…rver side cache of the resultsets generated by the execution of dataset used by the cockpit

https://spagobi.eng.it/jira/browse/SPAGOBI-1607

git-svn-id: svn://svn.forge.objectweb.org/svnroot/spagobi/V_4.x/Server/trunk@22001 99afaf0d-6903-0410-885a-c66a8bbb5f81
  • Loading branch information
mcortella committed Feb 14, 2014
1 parent 8cd4570 commit 8936dea
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
**/
package it.eng.spagobi.dataset.cache;

import it.eng.spagobi.dataset.cache.impl.sqldbcache.SQLDBCache;
import it.eng.spagobi.tools.datasource.bo.IDataSource;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
**/
package it.eng.spagobi.dataset.cache;

import it.eng.spagobi.dataset.cache.impl.sqldbcache.FilterCriteria;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.GroupCriteria;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.ProjectionCriteria;
import it.eng.spagobi.tools.dataset.bo.IDataSet;
import it.eng.spagobi.tools.dataset.common.datastore.IDataStore;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;
package it.eng.spagobi.dataset.cache.impl.sqldbcache;


/**
* @author Marco Cortella ([email protected])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;
package it.eng.spagobi.dataset.cache.impl.sqldbcache;

/**
* @author Marco Cortella ([email protected])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;
package it.eng.spagobi.dataset.cache.impl.sqldbcache;

/**
* @author Marco Cortella ([email protected])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;
package it.eng.spagobi.dataset.cache.impl.sqldbcache;



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,18 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;

package it.eng.spagobi.dataset.cache.impl.sqldbcache;

import it.eng.spago.error.EMFUserError;
import it.eng.spagobi.commons.bo.Config;
import it.eng.spagobi.commons.dao.DAOFactory;
import it.eng.spagobi.commons.dao.IConfigDAO;
import it.eng.spagobi.dataset.cache.ICache;
import it.eng.spagobi.dataset.cache.ICacheActivity;
import it.eng.spagobi.dataset.cache.ICacheEvent;
import it.eng.spagobi.dataset.cache.ICacheListener;
import it.eng.spagobi.dataset.cache.ICacheMetadata;
import it.eng.spagobi.dataset.cache.ICacheTrigger;
import it.eng.spagobi.tools.dataset.bo.AbstractJDBCDataset;
import it.eng.spagobi.tools.dataset.bo.IDataSet;
import it.eng.spagobi.tools.dataset.common.datastore.DataStore;
Expand All @@ -45,16 +55,35 @@
public class SQLDBCache implements ICache {

static private Logger logger = Logger.getLogger(SQLDBCache.class);

public static final String CACHE_NAME_PREFIX_CONFIG = "SPAGOBI.CACHE.NAMEPREFIX";


// Key is resultsetSignature, Entry is Table Name
private HashMap<String,String> cacheRegistry;

private IDataSource dataSource;

private Config tableNamePrefixConfig;

public SQLDBCache(IDataSource dataSource){
this.dataSource = dataSource;
cacheRegistry = new HashMap<String,String>();
try {
IConfigDAO configDao = DAOFactory.getSbiConfigDAO();
tableNamePrefixConfig = configDao.loadConfigParametersByLabel(CACHE_NAME_PREFIX_CONFIG);
if (tableNamePrefixConfig.isActive()){
String tablePrefix = tableNamePrefixConfig.getValueCheck();
eraseExistingTables(tablePrefix.toUpperCase());
}

} catch (EMFUserError e) {
logger.debug("Impossible to instantiate SbiConfigDAO in SQLDBCache");
} catch (Exception e) {
logger.debug("Impossible to instantiate SbiConfigDAO in SQLDBCache");
}



}

Expand All @@ -74,6 +103,16 @@ public IDataSource getDataSource() {
public void setDataSource(IDataSource dataSource) {
this.dataSource = dataSource;
}

/**
* Erase existing tables that begins with the prefix
* @param prefix table name prefix
*
*/
private void eraseExistingTables(String prefix){
PersistedTableManager persistedTableManager = new PersistedTableManager();
persistedTableManager.dropTablesWithPrefix(getDataSource(), prefix);
}


/* (non-Javadoc)
Expand Down Expand Up @@ -256,9 +295,14 @@ public void put(IDataSet dataset,String resultsetSignature, IDataStore resultset
//2- Ricava la struttura della tabella da creare dal resultset (SQL CREATE) - attenzione ai dialetti DBMS
//3- Ricava i dati dal resultset da inserire nella tabella appena creata (SQL INSERT) - attenzione ai dialetti DBMS
PersistedTableManager persistedTableManager = new PersistedTableManager();
String tablePrefix = null;

try {
String tableName = persistedTableManager.generateRandomTableName();
if (tableNamePrefixConfig.isActive()){
tablePrefix = tableNamePrefixConfig.getValueCheck();
tablePrefix.toUpperCase();
}
String tableName = persistedTableManager.generateRandomTableName(tablePrefix);
persistedTableManager.persistDataset(dataset, resultset, getDataSource(), tableName);
//4- Aggiorna il cacheRegistry con la nuova coppia <resultsetSignature,nometabellaCreata>
cacheRegistry.put(resultsetSignature, tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
package it.eng.spagobi.dataset.cache;
package it.eng.spagobi.dataset.cache.impl.sqldbcache;


import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
package it.eng.spagobi.engine.cockpit.services.editor;

import it.eng.spago.security.IEngUserProfile;
import it.eng.spagobi.dataset.cache.FilterCriteria;
import it.eng.spagobi.dataset.cache.GroupCriteria;
import it.eng.spagobi.dataset.cache.ICache;
import it.eng.spagobi.dataset.cache.Operand;
import it.eng.spagobi.dataset.cache.ProjectionCriteria;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.FilterCriteria;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.GroupCriteria;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.Operand;
import it.eng.spagobi.dataset.cache.impl.sqldbcache.ProjectionCriteria;
import it.eng.spagobi.engine.cockpit.CockpitEngineConfig;
import it.eng.spagobi.engine.cockpit.CockpitEngineInstance;
import it.eng.spagobi.services.proxy.DataSetServiceProxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,7 @@
<CONFIG label="SPAGOBI.SECURITY.DEFAULT_ROLE_ON_SIGNUP" name="Default user role name" description="Default user role on signup" isActive="true" valueCheck="/spagobi/user" valueType="STRING" category="SECURITY"/>
<CONFIG label="SPAGOBI.SECURITY.ACTIVE_SIGNUP_FUNCTIONALITY" name="SPAGOBI.SECURITY.ACTIVE_SIGNUP_FUNCTIONALITY" description="Enables the signup functionality for the final user" isActive="false" valueCheck="false" valueType="STRING" category="SECURITY"/>

<CONFIG label="SPAGOBI.CACHE.NAMEPREFIX" name="SPAGOBI.CACHE.NAMEPREFIX" description="Prefix for cache tables name" isActive="true" valueCheck="sbicache" valueType="STRING" category="GENERIC_CONFIGURATION"/>

</CONFIGS>

Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void persistDataset(IDataSet dataSet, IDataStore datastore, IDataSource d

private IDataStore normalizeFileDataSet(IDataSet dataSet, IDataStore datastore){
if (dataSet instanceof FileDataSet){
//TODO: Change dataStore fields type according to the metadata specified on the DataSet metadata
//Change dataStore fields type according to the metadata specified on the DataSet metadata
//because FileDataSet has all dataStore field set as String by default
IMetaData dataStoreMetaData = datastore.getMetaData();
IMetaData dataSetMetaData = dataSet.getMetadata();
Expand Down Expand Up @@ -527,15 +527,62 @@ public void dropTableIfExists(IDataSource datasource, String tableName){
}
}

/*
public void dropTablesWithPrefix(IDataSource datasource, String prefix){
logger.debug("Dropping Tables with name prefix " + prefix + " if they exists...");

String dialect = datasource.getHibDialectClass();

String statement = null;

//get the list of tables names
if (dialect.contains(DIALECT_ORACLE)) {
statement = "SELECT TABLE_NAME "+
"FROM USER_TABLES "+
"WHERE TABLE_NAME LIKE '" + prefix.toUpperCase() + "%'";
} else if (dialect.contains(DIALECT_SQLSERVER) || (dialect.contains(DIALECT_MYSQL) || dialect.contains(DIALECT_POSTGRES))){
statement = "SELECT TABLE_NAME "+
"FROM INFORMATION_SCHEMA.TABLES " +
"WHERE TABLE_NAME LIKE '" + prefix.toLowerCase()+ "%'";
}

if ((statement != null) && (!statement.isEmpty())){
IDataStore dataStore = datasource.executeStatement(statement,0,0);
int dataStoreRecordsCount = Integer.parseInt(String.valueOf(dataStore.getRecordsCount()));

if (dataStoreRecordsCount > 0){
//iterate the dataStore for each table name found then delete it
for (int i=0; i < dataStoreRecordsCount; i++){
IRecord rec = dataStore.getRecordAt(i);
for (int j=0; j<rec.getFields().size(); j++){
IField field = rec.getFieldAt(j);
Object fieldValue = field.getValue();
if (fieldValue instanceof String){
String tableName = (String)fieldValue;
//delete table
dropTableIfExists(datasource,tableName);
}
}
}
}

}
logger.debug("Dropped Tables with name prefix " + prefix );

}

/**
* Create a random unique name for a creating a new table
* @param prefix an optional prefix to use for the generated table name
*/
public String generateRandomTableName(){
public String generateRandomTableName(String prefix){
UUIDGenerator uuidGen = UUIDGenerator.getInstance();
UUID uuidObj = uuidGen.generateTimeBasedUUID();
String generatedId = uuidObj.toString();
generatedId = generatedId.replaceAll("-", "");
generatedId = StringUtils.convertNonAscii(generatedId);
if ((prefix != null) && (!prefix.isEmpty())){
generatedId = prefix+generatedId;
}
if (generatedId.length() > 30) {
generatedId = generatedId.substring(0, 30);
}
Expand Down

0 comments on commit 8936dea

Please sign in to comment.