use of com.ramussoft.common.PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class EngineFactory method createJournaledEngine.
public Engine createJournaledEngine(DirectoryJournalFactory journalFactory) {
try {
JDBCTemplate template = new JDBCTemplate(createNewConnectionA());
suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
suits.add(new IDEF0PluginProvider());
Properties ps = getPropeties();
if (ps != null) {
String suitNames = ps.getProperty("AdditionalSuits");
if (suitNames != null)
PluginFactory.loadAdditionalSuits(suitNames, suits);
canUndoRedo = !"false".equals(ps.getProperty("CanUndoRedo"));
}
suits.addAll(getAdditionalSuits());
createUniversalPersistentFactory(template, (ps == null) ? null : ps.getProperty("PersistentPluginsProvider"));
factory = createPluginFactory(suits);
String prefix = "ramus_";
impl = new ServerIEngineImpl(0, template, prefix, factory);
accessor = impl.getAccessor();
persistentFactory = new PersistentFactory(prefix, factory.getAttributePlugins(), template);
persistentFactory.rebuild();
checkIfGroupsExists();
Engine result;
Journaled journaled;
if (cachedData == null) {
JournaledEngine journaledEngine2 = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor);
result = journaledEngine2;
journaled = journaledEngine2.getJournal();
} else {
JournaledEngine engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), journalFactory, accessor) {
@Override
protected void initPlugins(PluginFactory pluginFactory, AccessRules accessor) {
}
};
journaled = engine.getJournal();
CachedEngine cachedEngine = new CachedEngine(engine, cachedData);
for (Plugin plugin : factory.getPlugins()) plugin.init(cachedEngine, accessor);
result = cachedEngine;
}
EngineLogExtension engineLogExtension = new EngineLogExtension(result, journaled);
log = new Log(result, journaled) {
protected Event createEvent(String type, UpdateEventCallback callback) {
String user = "admin";
if (impl.getServerAccessRules() != null)
user = impl.getServerAccessRules().getUser().getLogin();
long id = impl.nextValue("qualifiers_log_seq");
return callback.createEvent(this, id, new Timestamp(System.currentTimeMillis()), type, user, null);
}
};
log.addExtension(engineLogExtension);
log.addExtension(new StorageLogExtension(new JDBCTemplate(createNewConnection()), prefix));
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of com.ramussoft.common.PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class EngineFactory method createPluginFactory.
protected PluginFactory createPluginFactory(List<PluginProvider> list) {
ArrayList<Plugin> plugins = new ArrayList<Plugin>();
for (PluginProvider suit : list) {
plugins.addAll(suit.getPlugins());
}
plugins.add(new AbstractPlugin() {
@Override
public String getName() {
return "Log";
}
@Override
public Class getFunctionalInterface() {
return ILog.class;
}
@Override
public Object createFunctionalInterfaceObject(Engine engine, IEngine iEngine) {
return log;
}
});
PluginFactory factory = new PluginFactory(plugins);
return factory;
}
use of com.ramussoft.common.PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class EngineFactory method createUniversalPersistentFactory.
private void createUniversalPersistentFactory(JDBCTemplate template, String pluginsString) throws SQLException {
UniversalPersistentFactory factory = new UniversalPersistentFactory(template);
Collection<PersistentsPlugin> pls = getPersistentPlugins();
ArrayList<PersistentsPlugin> plugins = new ArrayList<PersistentsPlugin>();
plugins.addAll(pls);
if (pluginsString != null) {
StringTokenizer st = new StringTokenizer(pluginsString, ", ");
while (st.hasMoreTokens()) {
try {
String className = st.nextToken();
Class<?> clazz = Class.forName(className);
PersistentsPluginProvider plugin = (PersistentsPluginProvider) clazz.newInstance();
plugins.addAll(plugin.getPersistentsPlugins());
} catch (Exception e) {
e.printStackTrace();
}
}
}
for (PluginProvider pp : suits) {
if (pp instanceof PersistentsPluginProvider) {
plugins.addAll(((PersistentsPluginProvider) pp).getPersistentsPlugins());
}
}
for (PersistentsPlugin pp : plugins) {
List<Class> list = new ArrayList<Class>();
pp.addPersistents(list, factory);
factory.addClasses(list);
}
factory.rebuild();
}
use of com.ramussoft.common.PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class BaseImporter method main.
/**
* @param args
*/
public static void main(final String[] args) {
if (args.length == 0) {
System.err.println("Enter input file as parameter");
return;
}
MemoryDatabase database = new MemoryDatabase() {
@Override
protected Collection<? extends PluginProvider> getAdditionalSuits() {
ArrayList<PluginProvider> ps = new ArrayList<PluginProvider>(1);
ps.add(new IDEF0PluginProvider());
return ps;
}
@Override
protected File getFile() {
return new File(args[0]);
}
@Override
public Connection createConnection() throws SQLException {
return EngineFactory.createNewConnection();
}
@Override
protected String getJournalDirectoryName(String tmp) {
return null;
}
};
EngineFactory factory = new EngineFactory();
Engine s = database.getEngine(null);
IEngine d = factory.getEngine();
for (String streamName : s.getStreamNames()) {
byte[] bs = s.getStream(streamName);
if (bs == null) {
System.err.println("WARNING: stream " + streamName + " not found in the source");
} else
d.setStream(streamName, bs);
}
try {
((FileIEngineImpl) (database.getEngine(null).getDeligate())).close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of com.ramussoft.common.PluginProvider in project ramus by Vitaliy-Yakovchuk.
the class H2Database method createEngines.
private void createEngines() {
try {
JDBCTemplate template = createTemplate();
List<PluginProvider> suits = new ArrayList<PluginProvider>();
suits.add(new SimpleAttributePluginSuit());
PluginFactory factory = createPluginFactory(suits);
IEngineImpl impl = new IEngineImpl(0, template, PREFIX, factory) {
@Override
protected boolean deleteStreamBytes(String path) {
return false;
}
@Override
public byte[] getStream(String path) {
return null;
}
@Override
protected void writeStream(String path, byte[] bytes) {
}
};
accessor = impl.getAccessor();
PersistentFactory persistentFactory = new PersistentFactory(PREFIX, factory.getAttributePlugins(), template);
persistentFactory.rebuild();
String tmp = System.getProperty("java.io.tmpdir");
engine = new JournaledEngine(factory, impl, persistentFactory.getRows(), new DirectoryJournalFactory(new File(tmp)), accessor);
} catch (Exception e) {
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException();
}
}
Aggregations