use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.
the class DatasourceInMemoryServiceHelper method getSerializeableResultSet.
public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
SerializedResultSet serializedResultSet = null;
SQLConnection sqlConnection = null;
try {
sqlConnection = getConnection(connectionName);
sqlConnection.setMaxRows(rowLimit);
sqlConnection.setReadOnly(true);
IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
marshallableResultSet.setResultSet(resultSet);
IPentahoMetaData ipmd = resultSet.getMetaData();
if (ipmd instanceof SQLMetaData) {
// Hack warning - get JDBC column types
// TODO: Need to generalize this amongst all IPentahoResultSets
SQLMetaData smd = (SQLMetaData) ipmd;
int[] columnTypes = smd.getJDBCColumnTypes();
List<List<String>> data = new ArrayList<List<String>>();
for (MarshallableRow row : marshallableResultSet.getRows()) {
String[] rowData = row.getCell();
List<String> rowDataList = new ArrayList<String>(rowData.length);
for (int j = 0; j < rowData.length; j++) {
rowDataList.add(rowData[j]);
}
data.add(rowDataList);
}
serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
}
} catch (Exception e) {
logger.error(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceInMemoryServiceHelper.ERROR_0005_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
return serializedResultSet;
}
use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.
the class DatasourceServiceHelper method getSerializeableResultSet.
public static SerializedResultSet getSerializeableResultSet(String connectionName, String query, int rowLimit, IPentahoSession session) throws DatasourceServiceException {
SerializedResultSet serializedResultSet = null;
SQLConnection sqlConnection = null;
try {
sqlConnection = (SQLConnection) PentahoConnectionFactory.getConnection(IPentahoConnection.SQL_DATASOURCE, connectionName, PentahoSessionHolder.getSession(), null);
sqlConnection.setMaxRows(rowLimit);
sqlConnection.setReadOnly(true);
IPentahoResultSet resultSet = sqlConnection.executeQuery(query);
// $NON-NLS-1$
logger.debug("ResultSet is not scrollable. Copying into memory");
if (!resultSet.isScrollable()) {
resultSet = convertToMemoryResultSet(resultSet);
}
MarshallableResultSet marshallableResultSet = new MarshallableResultSet();
marshallableResultSet.setResultSet(resultSet);
IPentahoMetaData ipmd = resultSet.getMetaData();
int[] columnTypes = null;
if (ipmd instanceof SQLMetaData) {
SQLMetaData smd = (SQLMetaData) ipmd;
columnTypes = smd.getJDBCColumnTypes();
} else if (ipmd instanceof MemoryMetaData) {
MemoryMetaData mmd = (MemoryMetaData) ipmd;
String[] columnTypesAsString = mmd.getColumnTypes();
columnTypes = new int[columnTypesAsString.length];
for (int i = 0; i < columnTypesAsString.length; i++) {
columnTypes[i] = Integer.parseInt(columnTypesAsString[i]);
}
}
if (columnTypes != null) {
// Hack warning - get JDBC column types
// TODO: Need to generalize this amongst all IPentahoResultSets
List<List<String>> data = new ArrayList<List<String>>();
for (MarshallableRow row : marshallableResultSet.getRows()) {
String[] rowData = row.getCell();
List<String> rowDataList = new ArrayList<String>(rowData.length);
for (int j = 0; j < rowData.length; j++) {
rowDataList.add(rowData[j]);
}
data.add(rowDataList);
}
serializedResultSet = new SerializedResultSet(columnTypes, marshallableResultSet.getColumnNames().getColumnName(), data);
}
} catch (Exception e) {
logger.error(Messages.getErrorString("DatasourceServiceHelper.ERROR_0001_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceHelper.ERROR_0001_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} finally {
if (sqlConnection != null) {
sqlConnection.close();
}
}
return serializedResultSet;
}
use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.
the class DSWDatasourceServiceImpl method doPreview.
public SerializedResultSet doPreview(String connectionName, String query, String previewLimit) throws DatasourceServiceException {
if (!hasDataAccessPermission()) {
// $NON-NLS-1$
logger.error(Messages.getErrorString("DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
throw new DatasourceServiceException(Messages.getErrorString(// $NON-NLS-1$
"DatasourceServiceImpl.ERROR_0001_PERMISSION_DENIED"));
}
SerializedResultSet returnResultSet;
try {
connectionName = UtilHtmlSanitizer.getInstance().safeEscapeHtml(connectionName);
executeQuery(connectionName, query, previewLimit);
returnResultSet = DatasourceServiceHelper.getSerializeableResultSet(connectionName, query, Integer.parseInt(previewLimit), PentahoSessionHolder.getSession());
} catch (QueryValidationException e) {
throw new DatasourceServiceException(Messages.getErrorString("DatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (SqlQueriesNotSupportedException e) {
// $NON-NLS-1$
throw new DatasourceServiceException(e.getLocalizedMessage(), e);
}
return returnResultSet;
}
use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.
the class DSWDatasourceServiceImpl method loadBusinessData.
public BusinessData loadBusinessData(String domainId, String modelId) throws DatasourceServiceException {
Domain domain = getMetadataDomainRepository().getDomain(domainId);
List<List<String>> data = null;
if (domain.getPhysicalModels().get(0) instanceof InlineEtlPhysicalModel) {
InlineEtlPhysicalModel model = (InlineEtlPhysicalModel) domain.getPhysicalModels().get(0);
String relativePath = PentahoSystem.getSystemSetting("file-upload-defaults/relative-path", // $NON-NLS-1$
String.valueOf(CsvTransformGenerator.DEFAULT_RELATIVE_UPLOAD_FILE_PATH));
String csvFileLoc = PentahoSystem.getApplicationContext().getSolutionPath(relativePath);
data = DatasourceServiceHelper.getCsvDataSample(csvFileLoc + model.getFileLocation(), model.getHeaderPresent(), model.getDelimiter(), model.getEnclosure(), 5);
} else {
SqlPhysicalModel model = (SqlPhysicalModel) domain.getPhysicalModels().get(0);
String query = model.getPhysicalTables().get(0).getTargetTable();
SerializedResultSet resultSet = DatasourceServiceHelper.getSerializeableResultSet(model.getDatasource().getDatabaseName(), query, 5, PentahoSessionHolder.getSession());
data = resultSet.getData();
}
return new BusinessData(domain, data);
}
use of org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl method loadBusinessData.
public BusinessData loadBusinessData(String domainId, String modelId) throws DatasourceServiceException {
Domain domain = getMetadataDomainRepository().getDomain(domainId);
List<List<String>> data = null;
if (domain.getPhysicalModels().get(0) instanceof InlineEtlPhysicalModel) {
InlineEtlPhysicalModel model = (InlineEtlPhysicalModel) domain.getPhysicalModels().get(0);
data = DatasourceInMemoryServiceHelper.getCsvDataSample(model.getFileLocation(), model.getHeaderPresent(), model.getDelimiter(), model.getEnclosure(), 5);
} else {
SqlPhysicalModel model = (SqlPhysicalModel) domain.getPhysicalModels().get(0);
String query = model.getPhysicalTables().get(0).getTargetTable();
SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(model.getDatasource().getDatabaseName(), query, 5, null);
data = resultSet.getData();
}
return new BusinessData(domain, data);
}
Aggregations