use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.
the class RemoteActiveSolutionHandler method loadCachedSolution.
private Solution loadCachedSolution(RootObjectMetaData solutionDef, long lastModified, ConcurrentMap<String, IServer> serverProxies) {
int solID = solutionDef.getRootObjectId();
Solution s = null;
// try disk load
File file = null;
FileInputStream fis = null;
BufferedInputStream bis = null;
GZIPInputStream zip = null;
ObjectInputStream ois = null;
try {
URL url = getServiceProvider().getServerURL();
String name = (url.getHost() + '_' + url.getPort()) + '_' + solutionDef.getName();
file = new // $NON-NLS-1$
File(// $NON-NLS-1$
getServiceProvider().getSettings().getProperty(SMARTCLIENT_SHARED_SOLUTION_DIR_PROPERTY_NAME, System.getProperty("user.home")), // $NON-NLS-1$
J2DBGlobals.CLIENT_LOCAL_DIR + name + ".solution");
if (file.exists()) {
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
zip = new GZIPInputStream(bis);
ois = new ObjectInputStream(zip);
long stored_asus = ois.readLong();
if (stored_asus == lastModified) {
Solution fileSolution = (Solution) ois.readObject();
if (// check if same
fileSolution.getSolutionID() == solID) {
s = fileSolution;
s.setServerProxies(serverProxies);
Utils.closeInputStream(ois);
if (Debug.tracing()) {
Debug.trace("Loaded cached solution from: " + file);
}
} else {
Utils.closeInputStream(ois);
file.delete();
if (Debug.tracing()) {
Debug.trace("Cached solution from: " + file + " was not valid");
}
}
} else {
Utils.closeInputStream(ois);
file.delete();
if (Debug.tracing()) {
Debug.trace("Cached solution from: " + file + " was not to old");
}
}
}
} catch (// can fail when classes are changed and do not longer match
Exception e) {
s = null;
// no need to show to user
Debug.trace(e);
Utils.closeInputStream(ois);
Utils.closeInputStream(fis);
try {
// if error happens just delete the file
if (file != null)
file.delete();
} catch (Exception e1) {
Debug.error(e1);
}
}
return s;
}
use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.
the class RemoteActiveSolutionHandler method loadActiveSolutions.
@Override
public Solution[] loadActiveSolutions(final RootObjectMetaData[] solutionDefs) throws RepositoryException, RemoteException {
final int[] sol_ids = new int[solutionDefs.length];
for (int i = 0; i < sol_ids.length; i++) {
sol_ids[i] = solutionDefs[i].getRootObjectId();
}
final Solution[] retval = new Solution[solutionDefs.length];
ThrowingRunnable<RepositoryException, RemoteException> r = new ThrowingRunnable<RepositoryException, RemoteException>() {
@Override
public void run() {
try {
long[] asus = getApplicationServer().getActiveRootObjectsLastModified(sol_ids);
ConcurrentMap<String, IServer> sps = getRepository().getServerProxies(solutionDefs);
for (int i = 0; i < solutionDefs.length; i++) {
Solution s = loadCachedSolution(solutionDefs[i], asus[i], sps);
if (s == null) {
// do full load
s = loadSolution(solutionDefs[i]);
}
if (s != null) {
if (s.getRepository() == null) {
// transient
s.setRepository(getRepository());
}
loadedActiveSolutionUpdateSequences.put(new Integer(s.getSolutionID()), new Long(asus[i]));
s.setServerProxies(sps);
}
retval[i] = s;
}
} catch (RepositoryException eo) {
e1 = eo;
} catch (RemoteException et) {
e2 = et;
}
}
};
UIUtils.runWhileDispatchingEvents(r, getServiceProvider());
return retval;
}
use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.
the class Debug method insertClientInfo.
@SuppressWarnings("nls")
private static boolean insertClientInfo(boolean insert) {
IServiceProvider serviceProvider = J2DBGlobals.getServiceProvider();
if (insert && serviceProvider != null) {
Solution solution = serviceProvider.getSolution();
String clientID = serviceProvider.getClientID();
if (solution != null && clientID != null) {
if (MDC.get("clientid") == null) {
MDC.put("clientid", clientID);
MDC.put("solution", solution.getName());
String username = serviceProvider.getUserName();
if (username != null)
MDC.put("username", username);
String useruuid = serviceProvider.getUserUID();
if (useruuid != null)
MDC.put("useruuid", username);
ClientInfo clientInfo = serviceProvider.getClientInfo();
if (clientInfo != null) {
MDC.put("clienttype", IApplication.getApplicationTypeAsString(clientInfo.getApplicationType()));
MDC.put("hostname", clientInfo.getHostName());
MDC.put("hostaddress", clientInfo.getHostAddress());
}
return true;
}
} else {
MDC.remove("clientid");
MDC.remove("solution");
MDC.remove("username");
MDC.remove("useruuid");
MDC.remove("clienttype");
MDC.remove("hostname");
MDC.remove("hostaddress");
}
} else {
MDC.remove("clientid");
MDC.remove("solution");
MDC.remove("username");
MDC.remove("useruuid");
MDC.remove("clienttype");
MDC.remove("hostname");
MDC.remove("hostaddress");
}
return false;
}
use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.
the class PersistHelper method getOrderedStyleSheets.
public static List<String> getOrderedStyleSheets(FlattenedSolution fs) {
List<String> styleSheets = new ArrayList<String>();
List<Solution> orderedModules = new ArrayList<Solution>();
orderedModules.add(fs.getSolution());
if (fs.getModules() != null) {
buildOrderedModulesList(fs.getSolution(), orderedModules, new ArrayList<Solution>(Arrays.asList(fs.getModules())));
}
for (Solution solution : orderedModules) {
if (solution.getStyleSheetID() > 0) {
Media media = fs.getMedia(solution.getStyleSheetID());
if (media != null) {
if (!styleSheets.contains(media.getName())) {
styleSheets.add(media.getName());
}
} else {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.warn("Stylesheet set for solution '" + solution.getName() + "' cannot be found");
}
}
}
return styleSheets;
}
use of com.servoy.j2db.persistence.Solution in project servoy-client by Servoy.
the class ClientState method loadSecuritySettings.
public void loadSecuritySettings(FlattenedSolution root) throws ServoyException, RemoteException {
if (clientInfo.getUserUid() != null) {
Solution sol = root.getSolution();
String[] groups = clientInfo.getUserGroups();
if (// fall back on retrieval of groups based on user_uid
groups == null) {
groups = getUserManager().getUserGroups(clientInfo.getClientId(), clientInfo.getUserUid());
}
root.clearSecurityAccess();
int[] sids = new int[] { sol.getSolutionID() };
int[] srns = new int[] { sol.getReleaseNumber() };
Solution[] modules = root.getModules();
if (modules != null) {
sids = new int[modules.length + 1];
sids[0] = sol.getSolutionID();
srns = new int[modules.length + 1];
srns[0] = sol.getReleaseNumber();
for (int i = 0; i < modules.length; i++) {
Solution module = modules[i];
sids[i + 1] = module.getSolutionID();
srns[i + 1] = module.getReleaseNumber();
}
}
Pair<Map<Object, Integer>, Set<Object>> securityAccess = getUserManager().getSecurityAccess(clientInfo.getClientId(), sids, srns, groups);
root.addSecurityAccess(securityAccess);
if (foundSetManager != null) {
((FoundSetManager) foundSetManager).flushSecuritySettings();
}
}
}
Aggregations