Package javax.jdo

Examples of javax.jdo.Transaction


    }
    PersistenceManagerFactory pmf = PMF.get();
    PersistenceManager pm = null;
    try{
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      try{
        tx.begin();
        pm.makePersistent(sum);
        tx.commit();
        log.info("[SummaryCronService#execute()] save summary: " + sum);
      }finally{
        if(tx!=null&&tx.isActive()) tx.rollback();
      }
    }finally{
      if(pm!=null) pm.close();
    }
    log.info("[SummaryCronService#execute()] end: " +
View Full Code Here


    List<Result> resultList = results.getResultList();
    PersistenceManagerFactory pmf = PMF.get();
    PersistenceManager pm = null;
    try{
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      try{
        for(Result r: resultList){
          tx.begin();
          log.info("[ResultsCronService#execute()] " +
              "insert result list (pre): " + r);
          pm.makePersistentAll(r);
          log.info("[ResultsCronService#execute()] " +
              "insert result (post): " + resultList.size());
          tx.commit();
         
          log.info("[ResultsCronService#execute()] commited");
        }
        StatisticsManager.getInstance().clearResults();
      }finally{
        if(tx!=null&&tx.isActive()) tx.rollback();
      }
    }finally{
      if(pm!=null) pm.close();
    }
    log.info("[ResultsCronService#execute()] end: " +
View Full Code Here

    Summary summary = null;
    PersistenceManagerFactory pmf = PMF.get();
    PersistenceManager pm = null;
    try{
      pm = pmf.getPersistenceManager();
      Transaction tx = pm.currentTransaction();
      try{
        tx.begin();
        summary =
            pm.getObjectById(Summary.class, Summary.DBKEY_SUMMARY);
        log.info("[StatisticsManager#retrieveSummary()] got from " +
            "database: " + summary);
        tx.commit();
      }catch(Exception e){
        log.log(Level.INFO,
            "[StatisticsManager#retrieveSummary()] exception " +
            "during getting summary", e);
        if(tx!=null && tx.isActive()) tx.rollback();
        summary = null;
      }
    }finally{
      if(pm!=null){
        pm.close();
View Full Code Here

        // first delete link beetwen profile and this installation
        // then removing this
        //attachAndDelete( installation );
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            // this must be done in the same transaction
            tx.begin();

            // first removing linked jdk

            Extent extent = pm.getExtent( Profile.class, true );

            Query query = pm.newQuery( extent );

            query.declareImports( "import java.lang.String" );

            query.declareParameters( "String name" );

            query.setFilter( "this.jdk.name == name" );

            Collection<Profile> result = (Collection) query.execute( installation.getName() );

            if ( result.size() != 0 )
            {
                for ( Profile profile : result )
                {
                    profile.setJdk( null );
                    pm.makePersistent( profile );
                }
            }

            // removing linked builder
            query = pm.newQuery( extent );

            query.declareImports( "import java.lang.String" );

            query.declareParameters( "String name" );

            query.setFilter( "this.builder.name == name" );

            result = (Collection) query.execute( installation.getName() );

            if ( result.size() != 0 )
            {
                for ( Profile profile : result )
                {
                    profile.setBuilder( null );
                    pm.makePersistent( profile );
                }
            }

            // removing linked env Var
            query = pm.newQuery( extent );

            query.declareImports( "import java.lang.String" );
            query.declareImports( "import " + Installation.class.getName() );

            query.declareParameters( "Installation installation" );

            query.setFilter( "environmentVariables.contains(installation)" );

            //query = pm
            //    .newQuery( "SELECT FROM profile WHERE environmentVariables.contains(installation) && installation.name == name" );

            result = (Collection) query.execute( installation );

            if ( result.size() != 0 )
            {
                for ( Profile profile : result )
                {
                    List<Installation> newEnvironmentVariables = new ArrayList<Installation>();
                    for ( Installation current : (Iterable<Installation>) profile.getEnvironmentVariables() )
                    {
                        if ( !StringUtils.equals( current.getName(), installation.getName() ) )
                        {
                            newEnvironmentVariables.add( current );
                        }
                    }
                    profile.setEnvironmentVariables( newEnvironmentVariables );
                    pm.makePersistent( profile );
                }
            }

            pm.deletePersistent( installation );

            tx.commit();

        }
        finally
        {
            rollback( tx );
View Full Code Here

    public Installation getInstallation( int installationId )
        throws ContinuumStoreException
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( Installation.class, true );

            Query query = pm.newQuery( extent );

            query.declareImports( "import java.lang.String" );

            query.declareParameters( "int installationId" );

            query.setFilter( "this.installationId == installationId" );

            Collection result = (Collection) query.execute( installationId );

            if ( result.size() == 0 )
            {
                tx.commit();

                return null;
            }

            Object object = pm.detachCopy( result.iterator().next() );

            tx.commit();

            return (Installation) object;
        }
        finally
        {
View Full Code Here

    public Map<Integer, Integer> getDefaultBuildDefinitions()
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( Project.class, true );

            Query query = pm.newQuery( extent );

            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );

            query.setFilter( "this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject == true" );

            query.declareVariables( "BuildDefinition buildDef" );

            query.setResult( "this.id, buildDef.id" );

            List result = (List) query.execute();

            // result = (List) pm.detachCopyAll( result );

            Map<Integer, Integer> builds = new HashMap<Integer, Integer>();

            if ( result != null && !result.isEmpty() )
            {
                for ( Object aResult : result )
                {
                    Object[] obj = (Object[]) aResult;

                    builds.put( (Integer) obj[0], (Integer) obj[1] );
                }

                return builds;
            }
        }
        finally
        {
            tx.commit();

            rollback( tx );
        }

        return null;
View Full Code Here

    public List<BuildDefinition> getDefaultBuildDefinitionsForProjectGroup( int projectGroupId )
        throws ContinuumStoreException
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( ProjectGroup.class, true );

            Query query = pm.newQuery( extent );

            query.declareImports( "import " + BuildDefinition.class.getName() );

            query.declareParameters( "int projectGroupId" );

            query.setFilter(
                "this.id == projectGroupId && this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject == true" );

            query.declareVariables( "BuildDefinition buildDef" );

            query.setResult( "buildDef" );

            List<BuildDefinition> result = (List<BuildDefinition>) query.execute( projectGroupId );

            result = (List<BuildDefinition>) pm.detachCopyAll( result );

            tx.commit();

            if ( result != null )
            {
                return result;
            }
View Full Code Here

    public BuildDefinition getDefaultBuildDefinitionForProject( int projectId )
        throws ContinuumStoreException
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( BuildDefinition.class, true );

            Query query = pm.newQuery( extent );

            query.declareImports( "import " + Project.class.getName() );

            query.declareParameters( "int projectId" );

            query.setFilter(
                "project.id == projectId && project.buildDefinitions.contains(this) && this.defaultForProject == true" );

            query.declareVariables( "Project project" );

            query.setResult( "this" );

            List<BuildDefinition> result = (List<BuildDefinition>) query.execute( projectId );

            result = (List<BuildDefinition>) pm.detachCopyAll( result );

            tx.commit();

            if ( result != null && !result.isEmpty() )
            {
                return result.get( 0 );
            }
View Full Code Here

    public List<BuildDefinition> getAllTemplates()
        throws ContinuumStoreException
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( BuildDefinition.class, true );

            Query query = pm.newQuery( extent );
            query.setFilter( "this.template == true" );
            List result = (List) query.execute();
            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
        }
        finally
        {
            tx.commit();

            rollback( tx );
        }
    }
View Full Code Here

    public List<BuildDefinition> getBuildDefinitionsBySchedule( int scheduleId )
    {
        PersistenceManager pm = getPersistenceManager();

        Transaction tx = pm.currentTransaction();

        try
        {
            tx.begin();

            Extent extent = pm.getExtent( BuildDefinition.class, true );

            Query query = pm.newQuery( extent );

            query.declareParameters( "int scheduleId" );

            query.setFilter( "this.schedule.id == scheduleId" );

            List result = (List) query.execute( scheduleId );

            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
        }
        finally
        {
            tx.commit();

            rollback( tx );
        }
    }
View Full Code Here

TOP

Related Classes of javax.jdo.Transaction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.