// Take control of the JDO instead of using the store, and configure a new persistence factory
// that won't generate new object IDs.
Properties properties = new Properties();
properties.putAll( factory.getProperties() );
properties.setProperty( "org.jpox.metadata.jdoFileExtension", "jdorepl" );
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory( properties );
PlexusJdoUtils.addObject( pmf.getPersistenceManager(), database.getSystemConfiguration() );
Map<Integer, Schedule> schedules = new HashMap<Integer, Schedule>();
for ( Iterator i = database.getSchedules().iterator(); i.hasNext(); )
{
Schedule schedule = (Schedule) i.next();
schedule = (Schedule) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), schedule );
schedules.put( Integer.valueOf( schedule.getId() ), schedule );
}
Map<Integer, Installation> installations = new HashMap<Integer, Installation>();
for ( Iterator i = database.getInstallations().iterator(); i.hasNext(); )
{
Installation installation = (Installation) i.next();
installation = (Installation) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), installation );
installations.put( Integer.valueOf( installation.getInstallationId() ), installation );
}
Map<Integer, Profile> profiles = new HashMap<Integer, Profile>();
for ( Iterator i = database.getProfiles().iterator(); i.hasNext(); )
{
Profile profile = (Profile) i.next();
// process installations
if ( profile.getJdk() != null )
{
profile.setJdk( installations.get( profile.getJdk().getInstallationId() ) );
}
if ( profile.getBuilder() != null )
{
profile.setBuilder( installations.get( profile.getBuilder().getInstallationId() ) );
}
profile = (Profile) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), profile );
profiles.put( Integer.valueOf( profile.getId() ), profile );
}
Map<Integer, LocalRepository> localRepositories = new HashMap<Integer, LocalRepository>();
for ( LocalRepository localRepository : (List<LocalRepository>) database.getLocalRepositories() )
{
localRepository =
(LocalRepository) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), localRepository );
localRepositories.put( Integer.valueOf( localRepository.getId() ), localRepository );
}
Map<Integer, ProjectGroup> projectGroups = new HashMap<Integer, ProjectGroup>();
for ( Iterator i = database.getProjectGroups().iterator(); i.hasNext(); )
{
ProjectGroup projectGroup = (ProjectGroup) i.next();
// first, we must map up any schedules, etc.
processBuildDefinitions( projectGroup.getBuildDefinitions(), schedules, profiles, localRepositories );
for ( Iterator j = projectGroup.getProjects().iterator(); j.hasNext(); )
{
Project project = (Project) j.next();
processBuildDefinitions( project.getBuildDefinitions(), schedules, profiles, localRepositories );
}
if ( projectGroup.getLocalRepository() != null )
{
projectGroup.setLocalRepository( localRepositories.get(
Integer.valueOf( projectGroup.getLocalRepository().getId() ) ) );
}
projectGroup = (ProjectGroup) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), projectGroup );
projectGroups.put( Integer.valueOf( projectGroup.getId() ), projectGroup );
}
// create project scm root data (CONTINUUM-2040)
Map<Integer, ProjectScmRoot> projectScmRoots = new HashMap<Integer, ProjectScmRoot>();
Set<Integer> keys = projectGroups.keySet();
int id = 1;
for( Integer key : keys )
{
ProjectGroup projectGroup = projectGroups.get( key );
String url = " ";
try
{
List<Project> projects =
ProjectSorter.getSortedProjects( getProjectsByGroupIdWithDependencies( pmf, projectGroup.getId() ),
log );
for ( Iterator j = projects.iterator(); j.hasNext(); )
{
Project project = (Project) j.next();
if ( !project.getScmUrl().trim().startsWith( url ) )
{
url = project.getScmUrl();
ProjectScmRoot projectScmRoot = new ProjectScmRoot();
projectScmRoot.setId( id );
projectScmRoot.setProjectGroup( projectGroup );
projectScmRoot.setScmRootAddress( url );
projectScmRoot.setState( project.getState() );
projectScmRoot = (ProjectScmRoot) PlexusJdoUtils.addObject( pmf.getPersistenceManager(), projectScmRoot );
projectScmRoots.put( Integer.valueOf( projectScmRoot.getId() ), projectScmRoot );
id++;
}
}
}