use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class ValueMetaBaseTest method testGetBinaryWithLength_WhenBinarySqlTypesOfVertica.
@Test
public void testGetBinaryWithLength_WhenBinarySqlTypesOfVertica() throws Exception {
final int binaryColumnIndex = 1;
final int varbinaryColumnIndex = 2;
final int expectedBinarylength = 1;
final int expectedVarBinarylength = 80;
ValueMetaBase obj = new ValueMetaBase();
DatabaseMeta dbMeta = Mockito.spy(new DatabaseMeta());
DatabaseInterface databaseInterface = new Vertica5DatabaseMeta();
dbMeta.setDatabaseInterface(databaseInterface);
ResultSet resultSet = Mockito.mock(ResultSet.class);
ResultSetMetaData metaData = Mockito.mock(ResultSetMetaData.class);
Mockito.when(resultSet.getMetaData()).thenReturn(metaData);
Mockito.when(metaData.getColumnType(binaryColumnIndex)).thenReturn(Types.BINARY);
Mockito.when(metaData.getPrecision(binaryColumnIndex)).thenReturn(expectedBinarylength);
Mockito.when(metaData.getColumnDisplaySize(binaryColumnIndex)).thenReturn(expectedBinarylength * 2);
Mockito.when(metaData.getColumnType(varbinaryColumnIndex)).thenReturn(Types.BINARY);
Mockito.when(metaData.getPrecision(varbinaryColumnIndex)).thenReturn(expectedVarBinarylength);
Mockito.when(metaData.getColumnDisplaySize(varbinaryColumnIndex)).thenReturn(expectedVarBinarylength * 2);
// get value meta for binary type
ValueMetaInterface binaryValueMeta = obj.getValueFromSQLType(dbMeta, TEST_NAME, metaData, binaryColumnIndex, false, false);
assertNotNull(binaryValueMeta);
assertTrue(TEST_NAME.equals(binaryValueMeta.getName()));
assertTrue(ValueMetaInterface.TYPE_BINARY == binaryValueMeta.getType());
assertTrue(expectedBinarylength == binaryValueMeta.getLength());
Assert.assertFalse(binaryValueMeta.isLargeTextField());
// get value meta for varbinary type
ValueMetaInterface varbinaryValueMeta = obj.getValueFromSQLType(dbMeta, TEST_NAME, metaData, varbinaryColumnIndex, false, false);
assertNotNull(varbinaryValueMeta);
assertTrue(TEST_NAME.equals(varbinaryValueMeta.getName()));
assertTrue(ValueMetaInterface.TYPE_BINARY == varbinaryValueMeta.getType());
assertTrue(expectedVarBinarylength == varbinaryValueMeta.getLength());
Assert.assertFalse(varbinaryValueMeta.isLargeTextField());
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DataHandler method getConnectionSpecificInfo.
private void getConnectionSpecificInfo(DatabaseMeta meta) {
// Hostname:
if (hostNameBox != null) {
meta.setHostname(hostNameBox.getValue());
}
// Database name:
if (databaseNameBox != null) {
meta.setDBName(databaseNameBox.getValue());
}
// Username:
if (userNameBox != null) {
meta.setUsername(userNameBox.getValue());
}
// Password:
if (passwordBox != null) {
meta.setPassword(passwordBox.getValue());
}
if (databaseDialectList != null) {
DatabaseInterface databaseInterface = meta.getDatabaseInterface();
if (databaseInterface instanceof GenericDatabaseMeta) {
((GenericDatabaseMeta) databaseInterface).setDatabaseDialect(databaseDialectList.getValue());
}
}
// Streaming result cursor:
if (resultStreamingCursorCheck != null) {
meta.setStreamingResults(resultStreamingCursorCheck.isChecked());
}
// Data tablespace:
if (dataTablespaceBox != null) {
meta.setDataTablespace(dataTablespaceBox.getValue());
}
// Index tablespace
if (indexTablespaceBox != null) {
meta.setIndexTablespace(indexTablespaceBox.getValue());
}
if (serverInstanceBox != null) {
meta.setSQLServerInstance(serverInstanceBox.getValue());
if (optionsParameterTree != null && optionsParameterTree.getRootChildren() != null) {
for (int i = 0; i < optionsParameterTree.getRootChildren().getItemCount(); i++) {
XulTreeItem potRow = optionsParameterTree.getRootChildren().getItem(i);
if (potRow != null && potRow.getRow() != null) {
XulTreeCell cell = potRow.getRow().getCell(0);
XulTreeCell cell2 = potRow.getRow().getCell(1);
if (cell != null && cell.getLabel() != null && cell.getLabel().equals("instance")) {
cell2.setLabel(serverInstanceBox.getValue());
if (serverInstanceBox.getValue().trim().length() == 0) {
cell.setLabel("");
}
}
}
}
}
}
// SQL Server double decimal separator
if (doubleDecimalSeparatorCheck != null) {
meta.setUsingDoubleDecimalAsSchemaTableSeparator(doubleDecimalSeparatorCheck.isChecked());
}
// SAP Attributes...
if (languageBox != null) {
meta.getAttributes().put("SAPLanguage", languageBox.getValue());
}
if (systemNumberBox != null) {
meta.getAttributes().put("SAPSystemNumber", systemNumberBox.getValue());
}
if (clientBox != null) {
meta.getAttributes().put("SAPClient", clientBox.getValue());
}
// Generic settings...
if (customUrlBox != null) {
meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_URL, customUrlBox.getValue());
}
if (customDriverClassBox != null) {
meta.getAttributes().put(GenericDatabaseMeta.ATRRIBUTE_CUSTOM_DRIVER_CLASS, customDriverClassBox.getValue());
}
// Server Name: (Informix)
if (serverNameBox != null) {
meta.setServername(serverNameBox.getValue());
}
// Microsoft SQL Server Use Integrated Security
if (useIntegratedSecurityCheck != null) {
Boolean useIntegratedSecurity = useIntegratedSecurityCheck.isChecked();
meta.getAttributes().put(MSSQLServerNativeDatabaseMeta.ATTRIBUTE_USE_INTEGRATED_SECURITY, useIntegratedSecurity != null ? useIntegratedSecurity.toString() : "false");
}
if (webAppName != null) {
meta.setDBName(webAppName.getValue());
}
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigExceptionPropSetY.
/**
* Property value has priority
*/
@Test
public void testExceptionStrategyWithPacketTooBigExceptionPropSetY() {
System.setProperty(DatabaseLogExceptionFactory.KETTLE_GLOBAL_PROP_NAME, PROPERTY_VALUE_TRUE);
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
PacketTooBigException e = new PacketTooBigException();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(THROWABLE, strategyName);
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-kettle by pentaho.
the class DatabaseLogExceptionFactoryTest method testExceptionStrategyWithPacketTooBigException.
/**
* PDI-5153
* Test that in case of PacketTooBigException exception there will be no stack trace in log
*/
@Test
public void testExceptionStrategyWithPacketTooBigException() {
DatabaseMeta databaseMeta = mock(DatabaseMeta.class);
DatabaseInterface databaseInterface = new MySQLDatabaseMeta();
PacketTooBigException e = new PacketTooBigException();
when(logTable.getDatabaseMeta()).thenReturn(databaseMeta);
when(databaseMeta.getDatabaseInterface()).thenReturn(databaseInterface);
LogExceptionBehaviourInterface exceptionStrategy = DatabaseLogExceptionFactory.getExceptionStrategy(logTable, new KettleDatabaseException(e));
String strategyName = exceptionStrategy.getClass().getName();
assertEquals(SUPPRESSABLE_WITH_SHORT_MESSAGE, strategyName);
}
use of org.pentaho.di.core.database.DatabaseInterface in project pentaho-platform by pentaho.
the class SqlMetadataQueryExec method getActiveDatabaseMeta.
protected DatabaseMeta getActiveDatabaseMeta(DatabaseMeta databaseMeta) {
if (getForceDbDialect() || driverClassesToForceMeta.contains(databaseMeta.getDriverClass())) {
return databaseMeta;
}
// retrieve a temporary connection to determine if a dialect change is necessary
// for generating the MQL Query.
SQLConnection tempConnection = getConnection(databaseMeta);
try {
// if the connection type is not of the current dialect, regenerate the query
DatabaseInterface di = getDatabaseInterface(tempConnection);
if ((di != null) && (!databaseMeta.getPluginId().equals(di.getPluginId()))) {
// we need to reinitialize our mqlQuery object and reset the query.
// note that using this di object wipes out connection info
DatabaseMeta meta = (DatabaseMeta) databaseMeta.clone();
DatabaseInterface di2 = (DatabaseInterface) di.clone();
di2.setAccessType(databaseMeta.getAccessType());
di2.setDatabaseName(databaseMeta.getDatabaseName());
di2.setAttributes(databaseMeta.getAttributes());
di2.setUsername(databaseMeta.getUsername());
di2.setPassword(databaseMeta.getPassword());
di2.setHostname(databaseMeta.getHostname());
meta.setDatabaseInterface(di2);
return meta;
} else {
return databaseMeta;
}
} finally {
if (tempConnection != null) {
tempConnection.close();
}
}
}
Aggregations