Search in sources :

Example 6 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class SynchronizeAfterMerge method init.

public boolean init(StepMetaInterface smi, StepDataInterface sdi) {
    meta = (SynchronizeAfterMergeMeta) smi;
    data = (SynchronizeAfterMergeData) sdi;
    if (super.init(smi, sdi)) {
        try {
            meta.normalizeAllocationFields();
            data.realSchemaName = environmentSubstitute(meta.getSchemaName());
            if (meta.istablenameInField()) {
                if (Utils.isEmpty(meta.gettablenameField())) {
                    logError(BaseMessages.getString(PKG, "SynchronizeAfterMerge.Log.Error.TableFieldnameEmpty"));
                    return false;
                }
            }
            data.databaseMeta = meta.getDatabaseMeta();
            // if we are using Oracle then set releaseSavepoint to false
            if (data.databaseMeta.getDatabaseInterface() instanceof OracleDatabaseMeta) {
                data.releaseSavepoint = false;
            }
            data.commitSize = Integer.parseInt(environmentSubstitute("" + meta.getCommitSize()));
            data.batchMode = data.commitSize > 0 && meta.useBatchUpdate();
            // Batch updates are not supported on PostgreSQL (and look-a-likes) together with error handling (PDI-366)
            // 
            data.specialErrorHandling = getStepMeta().isDoingErrorHandling() && meta.getDatabaseMeta().supportsErrorHandlingOnBatchUpdates();
            data.supportsSavepoints = meta.getDatabaseMeta().getDatabaseInterface().useSafePoints();
            if (data.batchMode && data.specialErrorHandling) {
                data.batchMode = false;
                if (log.isBasic()) {
                    logBasic(BaseMessages.getString(PKG, "SynchronizeAfterMerge.Log.BatchModeDisabled"));
                }
            }
            if (meta.getDatabaseMeta() == null) {
                logError(BaseMessages.getString(PKG, "SynchronizeAfterMerge.Init.ConnectionMissing", getStepname()));
                return false;
            }
            data.db = new Database(this, meta.getDatabaseMeta());
            data.db.shareVariablesWith(this);
            if (getTransMeta().isUsingUniqueConnections()) {
                synchronized (getTrans()) {
                    data.db.connect(getTrans().getTransactionId(), getPartitionID());
                }
            } else {
                data.db.connect(getPartitionID());
            }
            data.db.setCommit(meta.getCommitSize());
            return true;
        } catch (KettleException ke) {
            logError(BaseMessages.getString(PKG, "SynchronizeAfterMerge.Log.ErrorOccurredDuringStepInitialize") + ke.getMessage());
        }
    }
    return false;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) Database(org.pentaho.di.core.database.Database)

Example 7 with OracleDatabaseMeta

use of org.pentaho.di.core.database.OracleDatabaseMeta in project pentaho-kettle by pentaho.

the class KettleDatabaseRepositoryCreationHelperTest method testCreateIndexLenghts.

/**
 * PDI-10237 test index name length.
 *
 * @throws KettleException
 */
@Test
public void testCreateIndexLenghts() throws KettleException {
    DatabaseMeta meta = mock(DatabaseMeta.class);
    when(meta.getStartQuote()).thenReturn("");
    when(meta.getEndQuote()).thenReturn("");
    when(meta.getQuotedSchemaTableCombination(anyString(), anyString())).thenAnswer(new Answer<String>() {

        @Override
        public String answer(InvocationOnMock invocation) throws Throwable {
            return invocation.getArguments()[1].toString();
        }
    });
    when(meta.getDatabaseInterface()).thenReturn(new OracleDatabaseMeta());
    Database db = mock(Database.class);
    when(db.getDatabaseMeta()).thenReturn(meta);
    // always return some create sql.
    when(db.getDDL(anyString(), any(RowMetaInterface.class), anyString(), anyBoolean(), anyString(), anyBoolean())).thenReturn("### CREATE TABLE;");
    when(repository.getDatabase()).thenReturn(db);
    when(repository.getDatabaseMeta()).thenReturn(meta);
    when(db.getCreateIndexStatement(anyString(), anyString(), any(String[].class), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean())).thenAnswer(lan);
    KettleDatabaseRepositoryCreationHelper helper = new KettleDatabaseRepositoryCreationHelper(repository);
    PluginRegistry.addPluginType(TwoWayPasswordEncoderPluginType.getInstance());
    PluginRegistry.init(false);
    String passwordEncoderPluginID = Const.NVL(EnvUtil.getSystemProperty(Const.KETTLE_PASSWORD_ENCODER_PLUGIN), "Kettle");
    Encr.init(passwordEncoderPluginID);
    List<String> statements = new ArrayList<String>();
    helper.createRepositorySchema(null, false, statements, true);
    for (String st : statements) {
        if (st == null || st.startsWith("#")) {
            continue;
        }
        assertTrue("Index name is not overlenght!: " + st, st.length() <= 30);
    }
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) Database(org.pentaho.di.core.database.Database) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Mockito.anyString(org.mockito.Mockito.anyString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) OracleDatabaseMeta(org.pentaho.di.core.database.OracleDatabaseMeta) Test(org.junit.Test)

Aggregations

OracleDatabaseMeta (org.pentaho.di.core.database.OracleDatabaseMeta)7 ArrayList (java.util.ArrayList)2 Database (org.pentaho.di.core.database.Database)2 KettleException (org.pentaho.di.core.exception.KettleException)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 SQLException (java.sql.SQLException)1 ParseException (java.text.ParseException)1 Properties (java.util.Properties)1 IWizard (org.eclipse.jface.wizard.IWizard)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 Test (org.junit.Test)1 Mockito.anyString (org.mockito.Mockito.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 GenericDatabaseMeta (org.pentaho.di.core.database.GenericDatabaseMeta)1 GreenplumDatabaseMeta (org.pentaho.di.core.database.GreenplumDatabaseMeta)1