use of com.servoy.j2db.persistence.ChangeHandler in project servoy-client by Servoy.
the class AbstractSolutionTest method buildSolution.
@Before
public void buildSolution() throws Exception {
TestNGClient.initSettings();
Types.getTypesInstance().registerTypes();
final File f = new File(NGClient.class.getProtectionDomain().getCodeSource().getLocation().getPath());
IPackageReader[] servicesReaders = null;
IPackageReader[] componentsReaders = null;
InMemPackageReader inMemPackageReader = getTestComponents();
if (f.isFile() && f.getName().startsWith("servoy_ngclient") && f.getName().endsWith(".jar")) {
// it is running from bundles/jars
ZipFile zipFile = new ZipFile(f);
componentsReaders = inMemPackageReader != null ? new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/"), inMemPackageReader } : new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoycore/"), new ZipPackageReader(zipFile, "war/servoydefault/") };
servicesReaders = new IPackageReader[] { new ZipPackageReader(zipFile, "war/servoyservices/") };
} else {
// it is running from sources/projects
File ngClientProjDir = f;
if (!new File(ngClientProjDir, "/war/servoycore/").exists()) {
ngClientProjDir = ngClientProjDir.getParentFile();
}
componentsReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile() + "/war/servoycore/"), new File(ngClientProjDir.getAbsoluteFile() + "/war/servoydefault/") }, // in eclipse we .. out of bin, in jenkins we .. out of @dot
inMemPackageReader);
servicesReaders = getReaders(new File[] { new File(ngClientProjDir.getAbsoluteFile(), "/war/servoyservices/") }, null);
}
WebComponentSpecProvider.init(componentsReaders, DefaultComponentPropertiesProvider.instance);
WebServiceSpecProvider.init(servicesReaders);
final TestRepository tr = new TestRepository();
try {
ApplicationServerRegistry.setApplicationServerSingleton(new TestApplicationServer(tr));
UUID uuid = UUID.randomUUID();
final RootObjectMetaData metadata = tr.createRootObjectMetaData(tr.getElementIdForUUID(uuid), uuid, "Test", IRepository.SOLUTIONS, 1, 1);
solution = (Solution) tr.createRootObject(metadata);
tr.cacheRootObject(solution);
solution.setChangeHandler(new ChangeHandler(tr));
fillTestSolution();
HttpSession testHttpsession = new TestHttpsession();
endpoint = new NGClientEndpoint() {
// for testing onstart of the NGClientEndpoint should not run
@Override
public void onStart() {
}
@Override
protected HttpSession getHttpSession(Session session) {
return testHttpsession;
}
};
NGClientWebsocketSession session = new NGClientWebsocketSession(new WebsocketSessionKey(testHttpsession.getId(), 1)) {
@Override
public void init(Map<String, List<String>> requestParams) throws Exception {
// override default init, shouldnt make another client.
}
@Override
protected IEventDispatcher createEventDispatcher() {
return new TestNGEventDispatcher(endpoint);
}
};
WebsocketSessionManager.addSession(session);
NGClientWebsocketSessionWindows windows = new NGClientWebsocketSessionWindows(session);
CurrentWindow.set(windows);
client = new TestNGClient(tr, session) {
@Override
public boolean loadSolutionsAndModules(SolutionMetaData solutionMetaData) {
boolean b = super.loadSolutionsAndModules(solutionMetaData);
IPersistIndex index = PersistIndexCache.getCachedIndex(solution);
solution.getChangeHandler().addIPersistListener((IItemChangeListener<IPersist>) index);
try {
setupData();
} catch (ServoyException e) {
e.printStackTrace();
}
return b;
}
};
J2DBGlobals.setServiceProvider(client);
client.setUseLoginSolution(false);
endpoint.start(new TestSession(), String.valueOf(session.getSessionKey().getClientnr()), "null", "42");
CurrentWindow.set(session.getWindows().iterator().next());
} catch (RepositoryException e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.servoy.j2db.persistence.ChangeHandler in project servoy-client by Servoy.
the class FlattenedSolution method getSolutionCopy.
public Solution getSolutionCopy(boolean create) {
if (mainSolution == null) {
if (loginFlattenedSolution != null) {
return loginFlattenedSolution.getSolutionCopy(create);
}
return null;
}
if (copySolution != null || !create)
return copySolution;
try {
SimplePersistFactory factory = getPersistFactory();
copySolution = SimplePersistFactory.createDummyCopy(mainSolution);
copySolution.setChangeHandler(new ChangeHandler(factory) {
// overwrite this new Object to skip the call to rootObject.registerNewObject(object); which shouldn't be needed for solution model solutions.
@Override
public IPersist createNewObject(ISupportChilds parent, int object_type_id, int element_id, UUID uuid) throws RepositoryException {
return factory.createObject(parent, object_type_id, element_id, uuid);
}
});
copySolution.getChangeHandler().addIPersistListener(this);
getIndex().setSolutionModelSolution(copySolution);
} catch (Exception e) {
Debug.error(e);
}
return copySolution;
}
Aggregations