Search in sources :

Example 1 with DefaultTransformWriterConflictResolver

use of org.jumpmind.symmetric.io.data.writer.DefaultTransformWriterConflictResolver in project symmetric-ds by JumpMind.

the class MongoDataLoaderFactory method getDataWriter.

@Override
public IDataWriter getDataWriter(String sourceNodeId, ISymmetricDialect symmetricDialect, TransformWriter transformWriter, List<IDatabaseWriterFilter> filters, List<IDatabaseWriterErrorHandler> errorHandlers, List<? extends Conflict> conflictSettings, List<ResolvedData> resolvedData) {
    try {
        if (objectMapper == null) {
            objectMapper = (IDBObjectMapper) Class.forName("org.jumpmind.symmetric.io.SimpleDBObjectMapper").newInstance();
        }
        Method method = objectMapper.getClass().getMethod("setDefaultDatabaseName", String.class);
        if (method != null) {
            method.invoke(objectMapper, parameterService.getString("mongodb.default.databasename", "default"));
        }
    } catch (Exception e) {
        log.debug("Failed to call setDefaultDatabaseName on mapper", e);
    }
    try {
        Class<?> clientManagerClass = Class.forName("org.jumpmind.symmetric.io.SimpleMongoClientManager");
        Constructor<?> clientManagerConstrutor = clientManagerClass.getConstructor(new Class<?>[] { IParameterService.class, String.class });
        Class<?> dbWriterClass = Class.forName("org.jumpmind.symmetric.io.MongoDatabaseWriter");
        Constructor<?> dbWriterConstructor = dbWriterClass.getConstructor(new Class<?>[] { IDBObjectMapper.class, IMongoClientManager.class, IDatabaseWriterConflictResolver.class, DatabaseWriterSettings.class });
        Object clientManager = clientManagerConstrutor.newInstance(parameterService, typeName);
        return (IDataWriter) dbWriterConstructor.newInstance(objectMapper, clientManager, new DefaultTransformWriterConflictResolver(transformWriter), buildDatabaseWriterSettings(filters, errorHandlers, conflictSettings, resolvedData));
    } catch (Exception e) {
        log.warn("Failed to create the mongo database writer.  Check to see if all of the required jars have been added");
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        } else {
            throw new RuntimeException(e);
        }
    }
}
Also used : DefaultTransformWriterConflictResolver(org.jumpmind.symmetric.io.data.writer.DefaultTransformWriterConflictResolver) Method(java.lang.reflect.Method) IDataWriter(org.jumpmind.symmetric.io.data.IDataWriter)

Aggregations

Method (java.lang.reflect.Method)1 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)1 DefaultTransformWriterConflictResolver (org.jumpmind.symmetric.io.data.writer.DefaultTransformWriterConflictResolver)1