Search in sources :

Example 71 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryMetaStoreDelegate method parseAttribute.

private KDBRMetaStoreAttribute parseAttribute(ObjectId elementId, RowMetaAndData attributeRow) throws KettleException {
    try {
        Long attributeId = attributeRow.getInteger(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_ID_ELEMENT_ATTRIBUTE);
        String key = attributeRow.getString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_KEY, null);
        String value = attributeRow.getString(KettleDatabaseRepository.FIELD_ELEMENT_ATTRIBUTE_VALUE, null);
        Object object = parseAttributeValue(value);
        KDBRMetaStoreAttribute attribute = new KDBRMetaStoreAttribute(this, key, object);
        attribute.setObjectId(new LongObjectId(attributeId));
        return attribute;
    } catch (Exception e) {
        throw new KettleException("Unable to parse attribute from attribute row: " + attributeRow.toString(), e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId) KDBRMetaStoreAttribute(org.pentaho.di.repository.kdr.delegates.metastore.KDBRMetaStoreAttribute) KettleException(org.pentaho.di.core.exception.KettleException) KettleDatabaseException(org.pentaho.di.core.exception.KettleDatabaseException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleValueException(org.pentaho.di.core.exception.KettleValueException)

Example 72 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConditionDelegate method loadCondition.

/**
 * Read a condition from the repository.
 *
 * @param id_condition
 *          The condition id
 * @throws KettleException
 *           if something goes wrong.
 */
public Condition loadCondition(ObjectId id_condition) throws KettleException {
    Condition condition = new Condition();
    try {
        RowMetaAndData r = getCondition(id_condition);
        if (r != null) {
            condition.setNegated(r.getBoolean("NEGATED", false));
            condition.setOperator(Condition.getOperator(r.getString("OPERATOR", null)));
            long conditionId = r.getInteger("ID_CONDITION", -1L);
            if (conditionId > 0) {
                condition.setObjectId(new LongObjectId(conditionId));
            } else {
                condition.setObjectId(null);
            }
            ObjectId[] subids = repository.getSubConditionIDs(condition.getObjectId());
            if (subids.length == 0) {
                condition.setLeftValuename(r.getString("LEFT_NAME", null));
                condition.setFunction(Condition.getFunction(r.getString("CONDITION_FUNCTION", null)));
                condition.setRightValuename(r.getString("RIGHT_NAME", null));
                long id_value = r.getInteger("ID_VALUE_RIGHT", -1L);
                if (id_value > 0) {
                    ValueMetaAndData v = repository.loadValueMetaAndData(new LongObjectId(id_value));
                    condition.setRightExact(v);
                }
            } else {
                for (int i = 0; i < subids.length; i++) {
                    condition.addCondition(loadCondition(subids[i]));
                }
            }
            return condition;
        } else {
            throw new KettleException("Condition with id_condition=" + id_condition + " could not be found in the repository");
        }
    } catch (KettleException dbe) {
        throw new KettleException("Error loading condition from the repository (id_condition=" + id_condition + ")", dbe);
    }
}
Also used : Condition(org.pentaho.di.core.Condition) KettleException(org.pentaho.di.core.exception.KettleException) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ObjectId(org.pentaho.di.repository.ObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData)

Example 73 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryConnectionDelegate method getValueToIdMap.

public Map<String, LongObjectId> getValueToIdMap(String tablename, String idfield, String lookupfield) throws KettleException {
    String sql = new StringBuilder("SELECT ").append(lookupfield).append(", ").append(idfield).append(" FROM ").append(tablename).toString();
    Map<String, LongObjectId> result = new HashMap<String, LongObjectId>();
    for (Object[] row : callRead(() -> database.getRows(sql, new RowMeta(), new Object[] {}, ResultSet.FETCH_FORWARD, false, -1, null))) {
        result.put(String.valueOf(row[0]), new LongObjectId(((Number) row[1]).longValue()));
    }
    return result;
}
Also used : ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RowMeta(org.pentaho.di.core.row.RowMeta) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) RepositoryObject(org.pentaho.di.repository.RepositoryObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) LongObjectId(org.pentaho.di.repository.LongObjectId)

Example 74 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class BaseDatabaseMetaTest method testGettersSetters.

@Test
public void testGettersSetters() {
    // Note - this method should *ONLY* use the jndi meta and not the odbc or native ones.
    // This is the only method in this test class that mutates the meta.
    jndiMeta.setUsername("FOO");
    assertEquals("FOO", jndiMeta.getUsername());
    jndiMeta.setPassword("BAR");
    assertEquals("BAR", jndiMeta.getPassword());
    jndiMeta.setAccessType(DatabaseMeta.TYPE_ACCESS_JNDI);
    assertEquals("", jndiMeta.getUsername());
    assertEquals("", jndiMeta.getPassword());
    assertFalse(jndiMeta.isChanged());
    jndiMeta.setChanged(true);
    assertTrue(jndiMeta.isChanged());
    jndiMeta.setName("FOO");
    assertEquals("FOO", jndiMeta.getName());
    assertEquals("FOO", jndiMeta.getDisplayName());
    jndiMeta.setName(null);
    assertNull(jndiMeta.getName());
    assertEquals("FOO", jndiMeta.getDisplayName());
    jndiMeta.setDisplayName(null);
    assertNull(jndiMeta.getDisplayName());
    jndiMeta.setDatabaseName("FOO");
    assertEquals("FOO", jndiMeta.getDatabaseName());
    assertEquals("-1", jndiMeta.getDatabasePortNumberString());
    jndiMeta.setDatabasePortNumberString("9876");
    assertEquals("9876", jndiMeta.getDatabasePortNumberString());
    jndiMeta.setDatabasePortNumberString(null);
    // not sure I agree with this behavior
    assertEquals("9876", jndiMeta.getDatabasePortNumberString());
    jndiMeta.setHostname("FOO");
    assertEquals("FOO", jndiMeta.getHostname());
    LongObjectId id = new LongObjectId(9876);
    jndiMeta.setObjectId(id);
    assertEquals(id, jndiMeta.getObjectId());
    jndiMeta.setServername("FOO");
    assertEquals("FOO", jndiMeta.getServername());
    jndiMeta.setDataTablespace("FOO");
    assertEquals("FOO", jndiMeta.getDataTablespace());
    jndiMeta.setIndexTablespace("FOO");
    assertEquals("FOO", jndiMeta.getIndexTablespace());
    Properties attrs = jndiMeta.getAttributes();
    Properties testAttrs = new Properties();
    testAttrs.setProperty("FOO", "BAR");
    jndiMeta.setAttributes(testAttrs);
    assertEquals(testAttrs, jndiMeta.getAttributes());
    // reset attributes back to what they were...
    jndiMeta.setAttributes(attrs);
    jndiMeta.setSupportsBooleanDataType(true);
    assertTrue(jndiMeta.supportsBooleanDataType());
    jndiMeta.setSupportsTimestampDataType(true);
    assertTrue(jndiMeta.supportsTimestampDataType());
    jndiMeta.setPreserveReservedCase(false);
    assertFalse(jndiMeta.preserveReservedCase());
    jndiMeta.addExtraOption("JNDI", "FOO", "BAR");
    Map<String, String> expectedOptionsMap = new HashMap<String, String>();
    expectedOptionsMap.put("JNDI.FOO", "BAR");
    assertEquals(expectedOptionsMap, jndiMeta.getExtraOptions());
    jndiMeta.setConnectSQL("SELECT COUNT(*) FROM FOO");
    assertEquals("SELECT COUNT(*) FROM FOO", jndiMeta.getConnectSQL());
    jndiMeta.setUsingConnectionPool(true);
    assertTrue(jndiMeta.isUsingConnectionPool());
    jndiMeta.setMaximumPoolSize(15);
    assertEquals(15, jndiMeta.getMaximumPoolSize());
    jndiMeta.setInitialPoolSize(5);
    assertEquals(5, jndiMeta.getInitialPoolSize());
    jndiMeta.setPartitioned(true);
    assertTrue(jndiMeta.isPartitioned());
    PartitionDatabaseMeta[] clusterInfo = new PartitionDatabaseMeta[1];
    PartitionDatabaseMeta aClusterDef = new PartitionDatabaseMeta("FOO", "BAR", "WIBBLE", "NATTIE");
    aClusterDef.setUsername("FOOUSER");
    aClusterDef.setPassword("BARPASSWORD");
    clusterInfo[0] = aClusterDef;
    jndiMeta.setPartitioningInformation(clusterInfo);
    PartitionDatabaseMeta[] gotPartitions = jndiMeta.getPartitioningInformation();
    // MB: Can't use arrayEquals because the PartitionDatabaseMeta doesn't have a toString. :(
    // assertArrayEquals( clusterInfo, gotPartitions );
    assertTrue(gotPartitions != null);
    if (gotPartitions != null) {
        assertEquals(1, gotPartitions.length);
        PartitionDatabaseMeta compareWith = gotPartitions[0];
        // MB: Can't use x.equals(y) because PartitionDatabaseMeta doesn't override equals... :(
        assertEquals(aClusterDef.getClass(), compareWith.getClass());
        assertEquals(aClusterDef.getDatabaseName(), compareWith.getDatabaseName());
        assertEquals(aClusterDef.getHostname(), compareWith.getHostname());
        assertEquals(aClusterDef.getPartitionId(), compareWith.getPartitionId());
        assertEquals(aClusterDef.getPassword(), compareWith.getPassword());
        assertEquals(aClusterDef.getPort(), compareWith.getPort());
        assertEquals(aClusterDef.getUsername(), compareWith.getUsername());
    }
    Properties poolProperties = new Properties();
    poolProperties.put("FOO", "BAR");
    poolProperties.put("BAR", "FOO");
    poolProperties.put("ZZZZZZZZZZZZZZ", "Z.Z.Z.Z.Z.Z.Z.Z.a.a.a.a.a.a.a.a.a");
    poolProperties.put("TOM", "JANE");
    poolProperties.put("AAAAAAAAAAAAA", "BBBBB.BBB.BBBBBBB.BBBBBBBB.BBBBBBBBBBBBBB");
    jndiMeta.setConnectionPoolingProperties(poolProperties);
    Properties compareWithProps = jndiMeta.getConnectionPoolingProperties();
    assertEquals(poolProperties, compareWithProps);
    jndiMeta.setStreamingResults(false);
    assertFalse(jndiMeta.isStreamingResults());
    jndiMeta.setQuoteAllFields(true);
    jndiMeta.setForcingIdentifiersToLowerCase(true);
    jndiMeta.setForcingIdentifiersToUpperCase(true);
    assertTrue(jndiMeta.isQuoteAllFields());
    assertTrue(jndiMeta.isForcingIdentifiersToLowerCase());
    assertTrue(jndiMeta.isForcingIdentifiersToUpperCase());
    jndiMeta.setUsingDoubleDecimalAsSchemaTableSeparator(true);
    assertTrue(jndiMeta.isUsingDoubleDecimalAsSchemaTableSeparator());
    jndiMeta.setPreferredSchemaName("FOO");
    assertEquals("FOO", jndiMeta.getPreferredSchemaName());
}
Also used : HashMap(java.util.HashMap) LongObjectId(org.pentaho.di.repository.LongObjectId) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Properties(java.util.Properties) Test(org.junit.Test)

Example 75 with LongObjectId

use of org.pentaho.di.repository.LongObjectId in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryTest method testInsertClusterSlave.

@Test
public void testInsertClusterSlave() throws KettleException {
    ArgumentCaptor<String> argumentTableName = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<RowMetaAndData> argumentTableData = ArgumentCaptor.forClass(RowMetaAndData.class);
    doNothing().when(repo.connectionDelegate).insertTableRow(argumentTableName.capture(), argumentTableData.capture());
    doReturn(new LongObjectId(357)).when(repo.connectionDelegate).getNextClusterSlaveID();
    SlaveServer testSlave = new SlaveServer("slave1", "fakelocal", "9081", "fakeuser", "fakepass");
    testSlave.setObjectId(new LongObjectId(864));
    ClusterSchema testSchema = new ClusterSchema("schema1", Arrays.asList(testSlave));
    testSchema.setObjectId(new LongObjectId(159));
    ObjectId result = repo.insertClusterSlave(testSchema, testSlave);
    RowMetaAndData insertRecord = argumentTableData.getValue();
    assertEquals(KettleDatabaseRepository.TABLE_R_CLUSTER_SLAVE, argumentTableName.getValue());
    assertEquals(3, insertRecord.size());
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(0).getType());
    assertEquals(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_CLUSTER_SLAVE, insertRecord.getValueMeta(0).getName());
    assertEquals(Long.valueOf(357), insertRecord.getInteger(0));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(1).getType());
    assertEquals(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_CLUSTER, insertRecord.getValueMeta(1).getName());
    assertEquals(Long.valueOf(159), insertRecord.getInteger(1));
    assertEquals(ValueMetaInterface.TYPE_INTEGER, insertRecord.getValueMeta(2).getType());
    assertEquals(KettleDatabaseRepository.FIELD_CLUSTER_SLAVE_ID_SLAVE, insertRecord.getValueMeta(2).getName());
    assertEquals(Long.valueOf(864), insertRecord.getInteger(2));
    assertEquals(new LongObjectId(357), result);
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) LongObjectId(org.pentaho.di.repository.LongObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) LongObjectId(org.pentaho.di.repository.LongObjectId) SlaveServer(org.pentaho.di.cluster.SlaveServer) ClusterSchema(org.pentaho.di.cluster.ClusterSchema) Test(org.junit.Test)

Aggregations

LongObjectId (org.pentaho.di.repository.LongObjectId)81 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)54 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)36 ObjectId (org.pentaho.di.repository.ObjectId)30 KettleException (org.pentaho.di.core.exception.KettleException)18 Test (org.junit.Test)17 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)17 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)14 Matchers.anyString (org.mockito.Matchers.anyString)10 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)10 ArrayList (java.util.ArrayList)9 RepositoryDirectory (org.pentaho.di.repository.RepositoryDirectory)9 RepositoryObject (org.pentaho.di.repository.RepositoryObject)8 MetaStoreDependenciesExistsException (org.pentaho.metastore.api.exceptions.MetaStoreDependenciesExistsException)8 MetaStoreElementExistException (org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)8 MetaStoreElementTypeExistsException (org.pentaho.metastore.api.exceptions.MetaStoreElementTypeExistsException)8 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)8 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)7 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)7 StringObjectId (org.pentaho.di.repository.StringObjectId)7