{
return contentVO;
}
Database db = CastorDatabaseService.getDatabase();
ConstraintExceptionBuffer ceb = new ConstraintExceptionBuffer();
beginTransaction(db);
try
{
logger.info("Fetching the root content for the repository " + repositoryId);
//OQLQuery oql = db.getOQLQuery( "SELECT c FROM org.infoglue.cms.entities.content.impl.simple.ContentImpl c WHERE is_undefined(c.parentContent) AND c.repository.repositoryId = $1");
OQLQuery oql = db.getOQLQuery( "SELECT c FROM org.infoglue.cms.entities.content.impl.simple.SmallContentImpl c WHERE is_undefined(c.parentContentId) AND c.repositoryId = $1");
oql.bind(repositoryId);
QueryResults results = oql.execute(Database.READONLY);
if (results.hasMore())
{
Content content = (Content)results.next();
contentVO = content.getValueObject();
}
else
{
//None found - we create it and give it the name of the repository.
logger.info("Found no rootContent so we create a new....");
ContentVO rootContentVO = new ContentVO();
RepositoryVO repositoryVO = RepositoryController.getController().getRepositoryVOWithId(repositoryId);
rootContentVO.setCreatorName(userName);
rootContentVO.setName(repositoryVO.getName());
rootContentVO.setIsBranch(new Boolean(true));
Content content = create(db, null, null, repositoryId, rootContentVO);
contentVO = content.getValueObject();
}
results.close();
oql.close();
//If any of the validations or setMethods reported an error, we throw them up now before create.
ceb.throwIfNotEmpty();
commitTransaction(db);
}
catch(ConstraintException ce)
{