Search in sources :

Example 1 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class Neo4jSchemaForm method generateSchema.

private void generateSchema() throws NoSQLExtractSchemaException {
    if (metadataTable == null) {
        return;
    }
    String cypher = metadataTable.getAdditionalProperties().get(INeo4jConstants.CYPHER);
    if (cypher == null) {
        return;
    }
    IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(getConnection().getDbType());
    if (metadataProvider == null) {
        return;
    }
    List<MetadataColumn> columns = metadataProvider.extractColumns(getConnection(), cypher);
    metadataTable.getColumns().clear();
    metadataTable.getColumns().addAll(columns);
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider)

Example 2 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class CreateNoSQLSchemaAction method checkNoSQLConnection.

private boolean checkNoSQLConnection(final NoSQLConnection connection) {
    boolean checkedResult = false;
    try {
        IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(connection.getDbType());
        if (metadataProvider != null) {
            checkedResult = metadataProvider.checkConnection(connection);
        }
    } catch (Exception ex) {
        checkedResult = false;
        ExceptionHandler.process(ex);
    }
    if (!checkedResult) {
        // $NON-NLS-1$
        String mainMsg = Messages.getString("CreateNoSQLSchemaAction.connectionFailure.mainMsg");
        // $NON-NLS-1$
        String detailMsg = Messages.getString("CreateNoSQLSchemaAction.connectionFailure.detailMsg");
        new ErrorDialogWidthDetailArea(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), RepositoryNoSQLPlugin.PLUGIN_ID, mainMsg, detailMsg);
    }
    return checkedResult;
}
Also used : ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class Neo4jMetadataProviderTest method testLocalRetrieveSchema.

@Test
public void testLocalRetrieveSchema() throws Exception {
    EMap<String, String> attributes = localConnection.getAttributes();
    // $NON-NLS-1$
    attributes.put(INeo4jAttributes.REMOTE_SERVER, "false");
    attributes.put(INeo4jAttributes.DATABASE_PATH, tmpFolder.getCanonicalPath());
    attributes.put(INeo4jAttributes.DB_VERSION, INeo4jConstants.NEO4J_3_2_X);
    localConnection.setDbType("NEO4J");
    ExecutorService threadExecutor = null;
    try {
        threadExecutor = Executors.newSingleThreadExecutor();
        Future future = threadExecutor.submit(new Runnable() {

            public void run() {
                try {
                    Neo4jConnectionUtil.checkConnection(localConnection);
                    List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
                    String cypher = "create (n:Test {first_name : 'Peppa', last_name : 'Pig'})\r\nreturn n;";
                    IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(localConnection.getDbType());
                    metadataColumns = metadataProvider.extractColumns(localConnection, cypher);
                    String lastName = metadataColumns.get(0).getName();
                    assertEquals("last_name", lastName);
                    String firstName = metadataColumns.get(1).getName();
                    assertEquals("first_name", firstName);
                } catch (Exception e) {
                    fail(e.getMessage());
                }
            }
        });
        while (true) {
            if (future.get() == null) {
                break;
            }
            Thread.sleep(1000);
        }
    } catch (Exception exception) {
        fail(exception.getMessage());
    } finally {
        if (threadExecutor != null) {
            threadExecutor.shutdown();
            threadExecutor = null;
        }
    }
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider) Test(org.junit.Test)

Example 4 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class CreateNoSQLSchemaAction method checkNoSQLConnectionInIndependentThread.

protected boolean checkNoSQLConnectionInIndependentThread(final NoSQLConnection connection) {
    final AtomicBoolean checkedResult = new AtomicBoolean(true);
    IRunnableWithProgress runnableWithProgress = new IRunnableWithProgress() {

        @Override
        public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
            // $NON-NLS-1$
            monitor.beginTask(Messages.getString("CreateNoSQLSchemaAction.checkConnection"), IProgressMonitor.UNKNOWN);
            Display display = PlatformUI.getWorkbench().getDisplay();
            display.syncExec(new Runnable() {

                @Override
                public void run() {
                    try {
                        IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(connection.getDbType());
                        if (metadataProvider != null) {
                            checkedResult.set(metadataProvider.checkConnection(connection));
                        }
                    } catch (Exception e) {
                        checkedResult.set(false);
                        ExceptionHandler.process(e);
                    } finally {
                        monitor.done();
                    }
                }
            });
            if (!checkedResult.get()) {
                display.syncExec(new Runnable() {

                    @Override
                    public void run() {
                        // $NON-NLS-1$
                        String mainMsg = Messages.getString("CreateNoSQLSchemaAction.connectionFailure.mainMsg");
                        // $NON-NLS-1$
                        String detailMsg = Messages.getString("CreateNoSQLSchemaAction.connectionFailure.detailMsg");
                        new ErrorDialogWidthDetailArea(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), RepositoryNoSQLPlugin.PLUGIN_ID, mainMsg, detailMsg);
                        return;
                    }
                });
            }
        }
    };
    ProgressMonitorDialog dialog = new ProgressMonitorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell());
    try {
        dialog.run(true, true, runnableWithProgress);
    } catch (Exception e) {
        checkedResult.set(false);
        ExceptionHandler.process(e);
    }
    return checkedResult.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) ProgressMonitorDialog(org.eclipse.jface.dialogs.ProgressMonitorDialog) ErrorDialogWidthDetailArea(org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) Display(org.eclipse.swt.widgets.Display)

Example 5 with IMetadataProvider

use of org.talend.repository.nosql.metadata.IMetadataProvider in project tbd-studio-se by Talend.

the class AbstractNoSQLSchemaForm method pressGuessSchemaButton.

protected void pressGuessSchemaButton() {
    boolean doit = true;
    if (tableEditorView.getMetadataEditor().getBeanCount() > 0) {
        doit = // $NON-NLS-1$
        MessageDialog.openConfirm(// $NON-NLS-1$
        getShell(), // $NON-NLS-1$
        Messages.getString("AbstractNoSQLSchemaForm.DialogUpdateTitle"), // $NON-NLS-1$
        Messages.getString("AbstractNoSQLSchemaForm.DialogUpdateMsg"));
    }
    if (doit) {
        List<MetadataColumn> metadataColumns = new ArrayList<MetadataColumn>();
        IMetadataProvider metadataProvider = NoSQLRepositoryFactory.getInstance().getMetadataProvider(getConnection().getDbType());
        if (metadataProvider != null) {
            String tableName = tableCombo.getText();
            try {
                metadataColumns = metadataProvider.extractColumns(getConnection(), tableName);
            } catch (NoSQLExtractSchemaException e) {
                ExceptionHandler.process(e);
            }
        }
        tableEditorView.getMetadataEditor().removeAll();
        tableEditorView.getMetadataEditor().addAll(metadataColumns);
    }
    updateGuessSchemaButton();
    changeTableNavigatorStatus(checkFieldsValue());
}
Also used : MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ArrayList(java.util.ArrayList) NoSQLExtractSchemaException(org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException) IMetadataProvider(org.talend.repository.nosql.metadata.IMetadataProvider)

Aggregations

IMetadataProvider (org.talend.repository.nosql.metadata.IMetadataProvider)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ErrorDialogWidthDetailArea (org.talend.commons.ui.swt.dialogs.ErrorDialogWidthDetailArea)3 MetadataColumn (org.talend.core.model.metadata.builder.connection.MetadataColumn)3 ArrayList (java.util.ArrayList)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 ProgressMonitorDialog (org.eclipse.jface.dialogs.ProgressMonitorDialog)2 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)2 List (java.util.List)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Display (org.eclipse.swt.widgets.Display)1 Test (org.junit.Test)1 NoSQLExtractSchemaException (org.talend.repository.nosql.exceptions.NoSQLExtractSchemaException)1 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)1