use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConditionDelegate method insertValue.
public synchronized ObjectId insertValue(String name, String type, String value_str, boolean isnull, ObjectId id_value_prev) throws KettleException {
ObjectId id_value = lookupValue(name, type, value_str, isnull);
if (id_value == null) {
id_value = repository.connectionDelegate.getNextValueID();
// Let's see if the same value is not yet available?
String tablename = KettleDatabaseRepository.TABLE_R_VALUE;
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_VALUE_ID_VALUE), id_value);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_NAME), name);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE), type);
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_VALUE_VALUE_STR), value_str);
table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_VALUE_IS_NULL), Boolean.valueOf(isnull));
repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), tablename);
repository.connectionDelegate.getDatabase().setValuesInsert(table);
repository.connectionDelegate.getDatabase().insertRow();
repository.connectionDelegate.getDatabase().closeInsert();
}
return id_value;
}
use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryConditionDelegate method insertCondition.
public synchronized ObjectId insertCondition(ObjectId id_condition_parent, Condition condition) throws KettleException {
ObjectId id = repository.connectionDelegate.getNextConditionID();
String tablename = KettleDatabaseRepository.TABLE_R_CONDITION;
RowMetaAndData table = new RowMetaAndData();
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION), id);
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_CONDITION_PARENT), id_condition_parent);
table.addValue(new ValueMetaBoolean(KettleDatabaseRepository.FIELD_CONDITION_NEGATED), Boolean.valueOf(condition.isNegated()));
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_OPERATOR), condition.getOperatorDesc());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_LEFT_NAME), condition.getLeftValuename());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_CONDITION_FUNCTION), condition.getFunctionDesc());
table.addValue(new ValueMetaString(KettleDatabaseRepository.FIELD_CONDITION_RIGHT_NAME), condition.getRightValuename());
ObjectId id_value = null;
ValueMetaAndData v = condition.getRightExact();
if (v != null) {
// We have to make sure that all data is saved irrespective of locale differences.
// Here is where we force that
//
ValueMetaInterface valueMeta = v.getValueMeta();
valueMeta.setDecimalSymbol(ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL);
valueMeta.setGroupingSymbol(ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL);
switch(valueMeta.getType()) {
case ValueMetaInterface.TYPE_NUMBER:
valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK);
break;
case ValueMetaInterface.TYPE_INTEGER:
valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK);
break;
case ValueMetaInterface.TYPE_DATE:
valueMeta.setConversionMask(ValueMetaAndData.VALUE_REPOSITORY_DATE_CONVERSION_MASK);
break;
default:
break;
}
String stringValue = valueMeta.getString(v.getValueData());
id_value = insertValue(valueMeta.getName(), valueMeta.getTypeDesc(), stringValue, valueMeta.isNull(v.getValueData()), condition.getRightExactID());
condition.setRightExactID(id_value);
}
table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_CONDITION_ID_VALUE_RIGHT), id_value);
repository.connectionDelegate.getDatabase().prepareInsert(table.getRowMeta(), tablename);
repository.connectionDelegate.getDatabase().setValuesInsert(table);
repository.connectionDelegate.getDatabase().insertRow();
repository.connectionDelegate.getDatabase().closeInsert();
return id;
}
use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.
the class CacheDatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR VARCHAR(15) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR TIMESTAMP ) ", cdm.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR CHAR(1) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR INT ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", // I believe this is a bug!
cdm.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DOUBLE ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR DECIMAL(5, 7) ) ", cdm.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD COLUMN ( BAR UNKNOWN ) ", cdm.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, cdm.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(15)", cdm.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
}
use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.
the class Exasol4DatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() {
assertEquals(" WHERE ROWNUM <= 15", nativeMeta.getLimitClause(15));
assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLQueryFields("FOO"));
assertEquals("SELECT /*+FIRST_ROWS*/ * FROM FOO WHERE 1=0", nativeMeta.getSQLTableExists("FOO"));
assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLQueryColumnFields("FOO", "BAR"));
assertEquals("SELECT /*+FIRST_ROWS*/ FOO FROM BAR WHERE 1=0", nativeMeta.getSQLColumnExists("FOO", "BAR"));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP COLUMN BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR TIMESTAMP ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR BOOLEAN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 15, 5), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR DECIMAL(15, 5) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 15, 5), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR INTEGER ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(15) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR VARCHAR(2000000) ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR UNKNOWN ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD ( BAR BIGINT NOT NULL PRIMARY KEY ) ", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));
}
use of org.pentaho.di.core.row.value.ValueMetaBoolean in project pentaho-kettle by pentaho.
the class HypersonicDatabaseMetaTest method testSQLStatements.
@Test
public void testSQLStatements() throws Exception {
HypersonicDatabaseMeta nativeMeta = new HypersonicDatabaseMeta();
nativeMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_NATIVE);
HypersonicDatabaseMeta odbcMeta = new HypersonicDatabaseMeta();
odbcMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_ODBC);
assertEquals("TRUNCATE TABLE FOO", nativeMeta.getTruncateTableStatement("FOO"));
assertEquals("SELECT * FROM FOO", nativeMeta.getSQLQueryFields("FOO"));
assertEquals("SELECT 1 FROM FOO", nativeMeta.getSQLTableExists("FOO"));
assertEquals("ALTER TABLE FOO ADD BAR TIMESTAMP", nativeMeta.getAddColumnStatement("FOO", new ValueMetaDate("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR TIMESTAMP", nativeMeta.getAddColumnStatement("FOO", new ValueMetaTimestamp("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR CHAR(1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR DOUBLE PRECISION", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 0, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR INTEGER", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(10, 3)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(10, 3)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 3), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(21, 4)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 21, 4), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR LONGVARCHAR", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", nativeMeta.getMaxVARCHARLength() + 2, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR VARCHAR(15)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", // Bug here - invalid SQL
nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 10, -7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(22, 7)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 22, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR DOUBLE PRECISION", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", -10, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(5, 7)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 5, 7), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR UNKNOWN", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInternetAddress("BAR"), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 0, INCREMENT BY 1) PRIMARY KEY", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", true, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 0, INCREMENT BY 1) PRIMARY KEY", nativeMeta.getAddColumnStatement("FOO", new ValueMetaNumber("BAR", 26, 8), "BAR", true, "", false));
String lineSep = System.getProperty("line.separator");
assertEquals("ALTER TABLE FOO DROP BAR" + lineSep, nativeMeta.getDropColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR(15)", nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR", 15, 0), "", false, "", true));
assertEquals("ALTER TABLE FOO ALTER COLUMN BAR VARCHAR()", // I think this is a bug ..
nativeMeta.getModifyColumnStatement("FOO", new ValueMetaString("BAR"), "", false, "", true));
assertEquals("ALTER TABLE FOO ADD BAR SMALLINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR", 4, 0), "", true, "", false));
// do a boolean check
odbcMeta.setSupportsBooleanDataType(true);
assertEquals("ALTER TABLE FOO ADD BAR BOOLEAN", odbcMeta.getAddColumnStatement("FOO", new ValueMetaBoolean("BAR"), "", false, "", false));
odbcMeta.setSupportsBooleanDataType(false);
assertEquals("ALTER TABLE FOO ADD BAR BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 0, INCREMENT BY 1) PRIMARY KEY", nativeMeta.getAddColumnStatement("FOO", new ValueMetaInteger("BAR"), "BAR", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR BIGINT", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 10, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR NUMERIC(22, 0)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBigNumber("BAR", 22, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR VARCHAR(1)", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 1, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR LONGVARCHAR", nativeMeta.getAddColumnStatement("FOO", new ValueMetaString("BAR", 16777250, 0), "", false, "", false));
assertEquals("ALTER TABLE FOO ADD BAR UNKNOWN", nativeMeta.getAddColumnStatement("FOO", new ValueMetaBinary("BAR", 16777250, 0), "", false, "", false));
assertEquals("insert into FOO(FOOKEY, FOOVERSION) values (0, 1)", nativeMeta.getSQLInsertAutoIncUnknownDimensionRow("FOO", "FOOKEY", "FOOVERSION"));
}
Aggregations