pm.getFetchPlan().addGroup(FetchGroups.FETCH_DATABASE_ON_MTABLE); query = pm.newQuery(MTable.class, filterBuilder.toString()); Collection<MTable> tables = (Collection<MTable>) query.executeWithArray(parameterVals.toArray(new String[parameterVals.size()]));
/** * Reset the PersistenceManager */ protected void reset() { // Reset the Fetch Plan to its DFG setting getFetchPlan().clearGroups().addGroup(FetchPlan.DEFAULT); apmf.releasePersistenceManager(this); closed = true; srm = null; tx = null; }
public Set<MSentryRole> getRolesForGroups(PersistenceManager pm, Set<String> groups) { Set<MSentryRole> result = Sets.newHashSet(); if (groups != null) { Query query = pm.newQuery(MSentryGroup.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); query.setFilter(":p1.contains(this.groupName)"); FetchGroup grp = pm.getFetchGroup(MSentryGroup.class, "fetchRoles"); grp.addMember("roles"); pm.getFetchPlan().addGroup("fetchRoles"); List<MSentryGroup> sentryGroups = (List) query.execute(groups.toArray()); if (sentryGroups != null) { for (MSentryGroup sentryGroup : sentryGroups) { result.addAll(sentryGroup.getRoles()); } } } return result; }
private Set<MSentryRole> getRolesForUsers(PersistenceManager pm, Set<String> users) { Set<MSentryRole> result = Sets.newHashSet(); if (users != null) { Query query = pm.newQuery(MSentryUser.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); query.setFilter(":p1.contains(this.userName)"); FetchGroup grp = pm.getFetchGroup(MSentryUser.class, "fetchRoles"); grp.addMember("roles"); pm.getFetchPlan().addGroup("fetchRoles"); List<MSentryUser> sentryUsers = (List) query.execute(users.toArray()); if (sentryUsers != null) { for (MSentryUser sentryUser : sentryUsers) { result.addAll(sentryUser.getRoles()); } } } return result; }
public static List getAllObjectsDetached( PersistenceManager pm, Class clazz, String ordering, List/* <String> */fetchGroups ) { Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( clazz, true ); Query query = pm.newQuery( extent ); if ( ordering != null ) { query.setOrdering( ordering ); } for ( Iterator i = fetchGroups.iterator(); i.hasNext(); ) { pm.getFetchPlan().addGroup( (String) i.next() ); } List result = (List) query.execute(); result = (List) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollbackIfActive( tx ); } }
/** * Get list of all roles. Should be called inside transaction. * @param pm Persistence manager instance * @return List of all roles */ @SuppressWarnings("unchecked") public List<MSentryRole> getAllRoles(PersistenceManager pm) { Query query = pm.newQuery(MSentryRole.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); FetchGroup grp = pm.getFetchGroup(MSentryRole.class, "fetchGroups"); grp.addMember("groups"); pm.getFetchPlan().addGroup("fetchGroups"); return (List<MSentryRole>) query.execute(); }
public List<Project> getProjectsInGroupWithDependencies( int projectGroupId ) throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( Project.class, true ); Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId ); query.setOrdering( "name ascending" ); pm.getFetchPlan().addGroup( PROJECT_DEPENDENCIES_FETCH_GROUP ); pm.getFetchPlan().addGroup( PROJECTGROUP_PROJECTS_FETCH_GROUP ); List<Project> result = (List<Project>) query.execute(); result = (List<Project>) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollback( tx ); } }
public List<Project> getProjectsInGroupWithDependencies( int projectGroupId ) throws ContinuumObjectNotFoundException, ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( Project.class, true ); Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId ); query.setOrdering( "name ascending" ); pm.getFetchPlan().addGroup( PROJECT_DEPENDENCIES_FETCH_GROUP ); pm.getFetchPlan().addGroup( PROJECTGROUP_PROJECTS_FETCH_GROUP ); List result = (List) query.execute(); result = (List) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollback( tx ); } }
public BuildResult getLatestBuildResultForProjectWithDetails( int projectId ) { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); pm.getFetchPlan().addGroup( BUILD_RESULT_WITH_DETAILS_FETCH_GROUP ); Extent extent = pm.getExtent( BuildResult.class, true ); Query query = pm.newQuery( extent ); query.declareParameters( "int projectId" ); query.setFilter( "this.project.id == projectId && this.project.latestBuildId == this.id" ); List<BuildResult> result = (List<BuildResult>) query.execute( projectId ); result = (List<BuildResult>) pm.detachCopyAll( result ); tx.commit(); if ( result != null && !result.isEmpty() ) { return result.get( 0 ); } } finally { rollback( tx ); } return null; }
public List<BuildResult> getBuildResultsForProject( int projectId, long fromDate ) { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); pm.getFetchPlan().addGroup( BUILD_RESULT_WITH_DETAILS_FETCH_GROUP ); try { tx.begin(); Extent extent = pm.getExtent( BuildResult.class, true ); Query query = pm.newQuery( extent ); query.declareParameters( "int projectId, long fromDate" ); query.setFilter( "this.project.id == projectId && this.startTime > fromDate" ); List result = (List) query.execute( new Integer( projectId ), new Long( fromDate ) ); result = (List) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollback( tx ); } }
/** * Get a single role with the given name inside a transaction * @param pm Persistence Manager instance * @param roleName Role name (should not be null) * @return single role with the given name */ public MSentryRole getRole(PersistenceManager pm, String roleName) { Query query = pm.newQuery(MSentryRole.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); query.setFilter("this.roleName == :roleName"); query.setUnique(true); FetchGroup grp = pm.getFetchGroup(MSentryRole.class, "fetchPrivileges"); grp.addMember("privileges"); pm.getFetchPlan().addGroup("fetchPrivileges"); return (MSentryRole) query.execute(roleName); }
/** * Get a single user with the given name inside a transaction * @param pm Persistence Manager instance * @param userName User name (should not be null) * @return single user with the given name */ public MSentryUser getUser(PersistenceManager pm, String userName) { Query query = pm.newQuery(MSentryUser.class); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); query.setFilter("this.userName == :userName"); query.setUnique(true); FetchGroup grp = pm.getFetchGroup(MSentryUser.class, "fetchPrivileges"); grp.addMember("privileges"); pm.getFetchPlan().addGroup("fetchPrivileges"); return (MSentryUser) query.execute(userName); }
public BuildDefinitionTemplate getContinuumBuildDefinitionTemplateWithType( String type ) throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true ); Query query = pm.newQuery( extent ); query.declareImports( "import java.lang.String" ); query.declareParameters( "String type" ); query.setFilter( "continuumDefault == true && this.type == type" ); pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS ); List result = (List) query.execute( type ); if ( result == null || result.isEmpty() ) { return null; } return (BuildDefinitionTemplate) pm.detachCopy( result.get( 0 ) ); } finally { tx.commit(); rollback( tx ); } }
public static Object addObject( PersistenceManager pm, Object object, String fetchGroups[] ) { Transaction tx = pm.currentTransaction(); try { tx.begin(); if ( fetchGroups != null ) { for ( int i = 0; i >= fetchGroups.length; i++ ) { pm.getFetchPlan().addGroup( fetchGroups[i] ); } } pm.makePersistent( object ); object = pm.detachCopy( object ); tx.commit(); return object; } finally { rollbackIfActive( tx ); } }
public List<Project> getProjectsWithDependenciesByGroupId( int projectGroupId ) { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( Project.class, true ); Query query = pm.newQuery( extent, "projectGroup.id == " + projectGroupId ); pm.getFetchPlan().addGroup( PROJECT_DEPENDENCIES_FETCH_GROUP ); List<Project> result = (List<Project>) query.execute(); result = (List<Project>) pm.detachCopyAll( result ); tx.commit(); return result; } finally { rollback( tx ); } }
public List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates() throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true ); Query query = pm.newQuery( extent ); query.setFilter( "continuumDefault == true" ); pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS ); List result = (List) query.execute(); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
public void addBuildResult( Project project, BuildResult build ) throws ContinuumStoreException, ContinuumObjectNotFoundException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); pm.getFetchPlan().addGroup( PROJECT_WITH_BUILDS_FETCH_GROUP ); Object objectId = pm.newObjectIdInstance( Project.class, new Integer( project.getId() ) ); project = (Project) pm.getObjectById( objectId ); build = (BuildResult) makePersistent( pm, build, false ); // TODO: these are in the wrong spot - set them on success (though // currently some depend on latest build being the one in progress) project.setLatestBuildId( build.getId() ); project.setState( build.getState() ); project.addBuildResult( build ); tx.commit(); } finally { rollback( tx ); } }
public List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates() throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true ); Query query = pm.newQuery( extent ); query.setFilter( "continuumDefault == true" ); pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS ); List result = (List) query.execute(); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
public List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String type ) throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true ); Query query = pm.newQuery( extent ); query.declareImports( "import java.lang.String" ); query.declareParameters( "String type" ); query.setFilter( "this.type == type" ); pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS ); List result = (List) query.execute( type ); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }
public List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String type ) throws ContinuumStoreException { PersistenceManager pm = getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true ); Query query = pm.newQuery( extent ); query.declareImports( "import java.lang.String" ); query.declareParameters( "String type" ); query.setFilter( "this.type == type" ); pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS ); List result = (List) query.execute( type ); return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result ); } finally { tx.commit(); rollback( tx ); } }