Search in sources :

Example 1 with MockGeneratorRegistry

use of org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorRegistry in project dbeaver by dbeaver.

the class MockDataSettings method init.

// populate attribute generators properties map
public void init(MockDataExecuteWizard wizard) throws DBException {
    List<DBSDataManipulator> databaseObjects = wizard.getDatabaseObjects();
    // TODO only the first
    DBSDataManipulator dataManipulator = databaseObjects.iterator().next();
    entity = (DBSEntity) dataManipulator;
    attributes = new ArrayList<>();
    try {
        DBeaverUI.run(wizard.getContainer(), true, true, new DBRRunnableWithProgress() {

            @Override
            public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                try {
                    attributes.addAll(DBUtils.getRealAttributes(entity.getAttributes(monitor)));
                    MockGeneratorRegistry generatorRegistry = MockGeneratorRegistry.getInstance();
                    for (DBSAttributeBase attribute : attributes) {
                        AttributeGeneratorProperties generatorProperties = new AttributeGeneratorProperties(attribute);
                        attributeGenerators.put(attribute.getName(), generatorProperties);
                        // ((JDBCColumnKeyType) attribute).isInUniqueKey()
                        List<DBSEntityReferrer> attributeReferrers = DBUtils.getAttributeReferrers(monitor, (DBSEntityAttribute) attribute);
                        if (!CommonUtils.isEmpty(attributeReferrers)) {
                            MockGeneratorDescriptor generator = generatorRegistry.getGenerator(FK_GENERATOR_ID);
                            putGenerator(generatorProperties, generator);
                        } else {
                            List<MockGeneratorDescriptor> generators = generatorRegistry.findAllGenerators(dataManipulator.getDataSource(), attribute);
                            for (MockGeneratorDescriptor generator : generators) {
                                putGenerator(generatorProperties, generator);
                            }
                        }
                    }
                } catch (DBException e) {
                    throw new InvocationTargetException(e);
                }
            }
        });
    } catch (InvocationTargetException e) {
        DBUserInterface.getInstance().showError("Transfer init failed", "Can't start data transfer", e.getTargetException());
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : DBException(org.jkiss.dbeaver.DBException) MockGeneratorDescriptor(org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor) MockGeneratorRegistry(org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) DBRRunnableWithProgress(org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress) DBRProgressMonitor(org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DBException (org.jkiss.dbeaver.DBException)1 MockGeneratorDescriptor (org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorDescriptor)1 MockGeneratorRegistry (org.jkiss.dbeaver.ext.mockdata.model.MockGeneratorRegistry)1 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)1 DBRRunnableWithProgress (org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress)1