/** Remove assembly from persistent state */ void remove(AssemblyId aid) { Connection c = null; EasyStatement stmt; try { c = getConnection(); stmt = new EasyStatement(c, "DELETE FROM DEPLOY_RESOURCES WHERE ASSEMBLY = ? AND VERSION = ?"); stmt.write(aid.getAssemblyName()); stmt.write(aid.getAssemblyVersion()); stmt.execute(); stmt.close(); stmt = new EasyStatement(c, "DELETE FROM DEPLOY_COMPONENTS WHERE ASSEMBLY = ? AND VERSION = ?"); stmt.write(aid.getAssemblyName()); stmt.write(aid.getAssemblyVersion()); stmt.execute(); stmt.close(); stmt = new EasyStatement(c, "DELETE FROM DEPLOY_ASSEMBLIES WHERE ASSEMBLY = ? AND VERSION = ?"); stmt.write(aid.getAssemblyName()); stmt.write(aid.getAssemblyVersion()); stmt.execute(); stmt.close(); } catch (SQLException e) { throw new PersistenceException(e); } finally { close(c); } }
/** * Retires any currently active version and activates the given version of assembly. * * @param assembly * @param version * @throws PersistenceException */ void activate(String assembly, int version) throws PersistenceException { retire(assembly); Connection c = null; try { c = getConnection(); EasyStatement inserta = new EasyStatement( c, "UPDATE DEPLOY_ASSEMBLIES SET CACTIVE = 1 WHERE ASSEMBLY = ? AND VERSION = ?"); try { inserta.write(assembly); inserta.write(version); inserta.execute(); } finally { inserta.close(); } } catch (SQLException e) { throw new PersistenceException(e); } finally { close(c); } }
/** Add a deployed assembly */ void add( DeployedAssembly assemblyStateFromFileSystem, List<DeployedComponent> componentsDeployment) throws PersistenceException { if (LOG.isDebugEnabled()) LOG.debug( "Persisting assembly: " + assemblyStateFromFileSystem + ", components: " + componentsDeployment); String name = assemblyStateFromFileSystem.getAssemblyId().getAssemblyName(); int version = assemblyStateFromFileSystem.getAssemblyId().getAssemblyVersion(); String adir = _deployDir .toURI() .relativize((new File(assemblyStateFromFileSystem.getAssemblyDir())).toURI()) .getPath(); boolean active = true; Connection c = null; try { c = getConnection(); // Insert assembly if (LOG.isDebugEnabled()) LOG.debug("INSERT_DEPLOYMENT_ASSEMBLY: " + name + "-" + version); EasyStatement inserta = new EasyStatement(c, "INSERT INTO DEPLOY_ASSEMBLIES VALUES (?,?,?,?)"); try { inserta.write(name); inserta.write(version); inserta.write(adir); inserta.write(active ? 1 : 0); inserta.execute(); } finally { inserta.close(); } // Insert components for (DeployedComponent dc : assemblyStateFromFileSystem.getDeployedComponents()) { File assemblyDir = new File(assemblyStateFromFileSystem.getAssemblyDir()); String component = dc.getComponentId().getComponentName(); String cdir = assemblyDir.toURI().relativize(new File(dc.getComponentDir()).toURI()).getPath(); String manager = dc.getComponentManagerName(); if (LOG.isDebugEnabled()) LOG.debug("INSERT_DEPLOYMENT_COMPONENT: " + name + "-" + version + "/" + component); EasyStatement insertc = new EasyStatement(c, "INSERT INTO DEPLOY_COMPONENTS VALUES (?,?,?,?,?)"); try { insertc.write(name); insertc.write(version); insertc.write(component); insertc.write(manager); insertc.write(cdir); insertc.execute(); } finally { insertc.close(); } } // Insert resources for (DeployedComponent component : componentsDeployment) { // only if the file system says the component is deployed if (assemblyStateFromFileSystem.getDeployedComponents().contains(component)) { for (String resource : component.getDeployedResources()) { if (LOG.isDebugEnabled()) LOG.debug("INSERT_DEPLOYMENT_RESOURCE: " + name + "-" + version + "/" + component); EasyStatement stmt = new EasyStatement( c, "INSERT INTO DEPLOY_RESOURCES(ASSEMBLY, VERSION, COMPONENT, MANAGER, RESOURCE_ID) VALUES(?, ?, ?, ?, ?)"); stmt.write(component.getComponentId().getAssemblyId().getAssemblyName()); stmt.write(component.getComponentId().getAssemblyId().getAssemblyVersion()); stmt.write(component.getComponentId().getComponentName()); stmt.write(component.getComponentManagerName()); stmt.write(resource); stmt.execute(); stmt.close(); } } } } catch (SQLException e) { throw new PersistenceException(e); } finally { close(c); } }