Angefangen, das Problem mit den Initalizern beim unload zu beseitigen. 

git-svn-id: https://svn.libreccm.org/ccm/trunk@3484 8810af33-2d31-482b-a856-94f89814c4df
master
tosmers 2015-06-15 13:22:25 +00:00
parent 825aa26231
commit e11267a809
11 changed files with 78 additions and 39 deletions

View File

@ -107,7 +107,6 @@ public abstract class AbstractContentTypeLoader extends PackageLoader {
* @param ctx The context to the unload-script
*/
private void createTypes(ScriptContext ctx) {
XMLContentTypeHandler handler = new XMLContentTypeHandler();
// Retrieve the content type definition file(s)
String[] contentTypes = getTypes();

View File

@ -83,7 +83,7 @@ public abstract class AbstractContentTypeUnloader extends PackageLoader {
* @param ctx The context to the unload-script
*/
private void sweepTypes(ScriptContext ctx) {
XMLContentTypeHandler handler = new XMLContentTypeHandler();
XMLContentTypeHandler handler = new XMLContentTypeHandler(false);
// Retrieve the content type definition file(s)
String[] contentTypes = getTypes();
for (String contentType : contentTypes) {
@ -130,10 +130,6 @@ public abstract class AbstractContentTypeUnloader extends PackageLoader {
for (Iterator it = types.iterator(); it.hasNext();) {
final ContentType type = (ContentType) it.next();
section.removeContentType(type);
//section.removeNotAssociatedContentTypes(type);
// necessary??
//type.getAuthoringKit().delete();
//type.delete();
}
}
}

View File

@ -24,6 +24,8 @@ import com.arsdigita.cms.ContentType;
import java.math.BigDecimal;
public interface ContentTypeHelper {
public void setName(String name) ;
/** @deprecated */
public void setLabel(String label) ;
@ -90,5 +92,7 @@ public interface ContentTypeHelper {
String component,
BigDecimal ordering) ;
public void saveType();
public void saveType();
public void deleteType();
}

View File

@ -329,10 +329,17 @@ public class ContentTypeHelperImpl implements ContentTypeHelper {
m_type.save();
}
@Override
public void saveType() {
m_kit.save();
m_type.save();
}
@Override
public void deleteType() {
m_kit.delete();
m_type.delete();
}
/**
* Generates the pedigree for this content type

View File

@ -20,7 +20,6 @@ package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.AuthoringKit;
import com.arsdigita.cms.ContentType;
import com.arsdigita.cms.contenttypes.ContentTypeInitializer;
import com.arsdigita.xml.XML;
import org.apache.log4j.Logger;
@ -48,7 +47,16 @@ public class XMLContentTypeHandler extends DefaultHandler {
private AuthoringKit m_authoringKit;
private int m_nextOrder;
private boolean m_including;
private boolean create;
public XMLContentTypeHandler() {
this.create = true;
}
public XMLContentTypeHandler(boolean create) {
this.create = create;
}
public List getContentTypes() {
return m_types;
}
@ -135,9 +143,15 @@ public class XMLContentTypeHandler extends DefaultHandler {
String qName, Attributes atts) {
if (name.equals("content-type")) {
// reset the helper
m_contentType.save();
m_authoringKit.save();
m_type.saveType();
if (create) {
m_contentType.save();
m_authoringKit.save();
m_type.saveType();
} else {
m_contentType.delete();
m_authoringKit.delete();
m_type.deleteType();
}
m_type = null;
}
}

View File

@ -657,7 +657,8 @@ class Load extends Command implements LoadCenter {
boolean success = true;
if (PackageLoader.exists(conn, "inits")
&& (line.hasOption("init") || all)) {
success = checkInitializerDependencies(loaders, "loader");
success = checkInitializerDependencies(loaders, "loader",
LoadType.LOAD);
}
return success;
}
@ -671,12 +672,13 @@ class Load extends Command implements LoadCenter {
* @param loaders A list of loaders to the corresponding packages
* to-be-loaded
* @param sessionName Name of the session
* @param type The load-type
* @return true on success, otherwise false
*/
@Override
public boolean checkInitializerDependencies(final Loader[] loaders,
String sessionName) {
return delegate.checkInitializerDependencies(loaders, sessionName);
String sessionName, LoadType type) {
return delegate.checkInitializerDependencies(loaders, sessionName, type);
}
/**

View File

@ -99,9 +99,10 @@ public interface LoadCenter {
* @param loaders A list of loaders to the corresponding packages
* to-be-loaded
* @param sessionName Name of the session
* @param type The load-type
* @return true on success, otherwise false
*/
boolean checkInitializerDependencies(final Loader[] loaders,
String sessionName);
String sessionName, LoadType type);
}

View File

@ -469,11 +469,12 @@ public class LoadCenterDelegate implements LoadCenter {
* @param loaders A list of loaders to the corresponding packages
* to-be-loaded
* @param sessionName Name of the session
* @param type The load-type
* @return true on success, otherwise false
*/
@Override
public boolean checkInitializerDependencies(final Loader[] loaders,
String sessionName) {
String sessionName, LoadType type) {
final List required = new ArrayList();
final List provided = new ArrayList();
addTo(required, InfoGetter.getRequiredInitializers(loaders));
@ -482,15 +483,26 @@ public class LoadCenterDelegate implements LoadCenter {
final Session boot = session(sessionName);
final List missing = getMissing(boot, required);
final List conflicts = getConflicts(boot, provided);
final List existing = getExisting(boot, provided);
if (!missing.isEmpty()) {
System.err.println("required initializers: " + missing);
return false;
}
if (!conflicts.isEmpty()) {
System.err.println("conflicting initializers: " + conflicts);
return false;
if (type==LoadType.LOAD) {
// Beim laden
if (!existing.isEmpty()) {
System.err.println("already existing initializers, "
+ "thus conflicting: " + existing);
return false;
}
} else if (type==LoadType.UNLOAD) {
if (existing.isEmpty()) {
System.err.println("not existing initializers,"
+ "thus not unloadable: " + existing);
return false;
}
}
return true;
}
@ -548,24 +560,24 @@ public class LoadCenterDelegate implements LoadCenter {
/**
* [SUPPORT]
* Returns all initializers, provided by initializers in the given list,
* which have already been initialized, thus all conflicting initializers.
* which have already been initialized, thus all existing initializers.
*
* used in: checkInitializerDependencies
*
* @param ssn The session for the db-connection
* @param inits List of initializers
* @return List of conflicting initializers
* @return List of existing initializers
*/
private static List getConflicts(Session ssn, List inits) {
List conflicts = new ArrayList();
private static List getExisting(Session ssn, List inits) {
List existing = new ArrayList();
for (Iterator it = inits.iterator(); it.hasNext(); ) {
String init = (String) it.next();
OID oid = new OID(ssn.getMetadataRoot().getObjectType(INIT), init);
if (ssn.retrieve(oid) != null) {
conflicts.add(init);
existing.add(init);
}
}
return conflicts;
return existing;
}

View File

@ -317,15 +317,18 @@ class Loader {
final List required = m_info.getRequiredInitializers();
for (Iterator it = inits.iterator(); it.hasNext(); ) {
String init = (String) it.next();
OID oid = new OID(INIT, init);
DataObject dataObject = ssn.retrieve(oid);
DataAssociation da =
DataObject dataObject = ssn.retrieve(new OID(INIT, init));
DataAssociation da1 =
(DataAssociation) dataObject.get("requirements");
for (Iterator reqIt = required.iterator(); reqIt.hasNext(); ) {
String reqInit = (String) reqIt.next();
da.remove(ssn.retrieve(new OID(INIT, reqInit)));
da1.remove(ssn.retrieve(new OID(INIT, reqInit)));
}
ssn.delete(oid);
DataAssociation da2 =
(DataAssociation) dataObject.get("inits");
da2.remove(ssn.retrieve(new OID(INIT, init)));
}
if (txn.inTxn()) {

View File

@ -305,16 +305,17 @@ class Unload extends Command implements LoadCenter {
* @param loaders A list of loaders to the corresponding packages
* to-be-loaded
* @param sessionName Name of the session
* @param type The load-type
* @return true on success, otherwise false
*/
@Override
public boolean checkInitializerDependencies(final Loader[] loaders,
String sessionName) {
return delegate.checkInitializerDependencies(loaders, sessionName);
String sessionName, LoadType type) {
return delegate.checkInitializerDependencies(loaders, sessionName, type);
}
/**
* Unloads the initializers. needed?
* Unloads the initializers.
*
* @param ssn The session for the db-connection
* @param unloaders The list of unloaders from the packages to be unloaded
@ -323,7 +324,8 @@ class Unload extends Command implements LoadCenter {
private boolean unloadInits(Connection conn, Session ssn, Loader[] unloaders) {
boolean passed = true;
if (PackageLoader.exists(conn, "inits")) {
passed &= checkInitializerDependencies(unloaders, "unloader");
passed &= checkInitializerDependencies(unloaders, "unloader",
LoadType.UNLOAD);
if (!passed) {
return false;
}

View File

@ -197,9 +197,8 @@ class DataObjectImpl implements DataObject {
builder.append(((Property) properties.next()).getName());
}
throw new PersistenceException(String.format(
"no such property: %s for %s. Available properties: %s",
property.toString(),
throw new PersistenceException(String.format("no such property: %s for %s. Available properties: %s",
property,
this.toString(),
builder.toString()));
}