private void createRoleIfNotExist(PersistenceManager pm, Set<String> existRoleNames, String roleName) throws Exception { String lowerRoleName = trimAndLower(roleName); // if the rolenName doesn't exist, create it. if (!existRoleNames.contains(lowerRoleName)) { // update the exist role name set existRoleNames.add(lowerRoleName); // Create role in the persistent storage pm.makePersistent(new MSentryRole(trimAndLower(roleName))); } }
private void createSentryRoleCore(PersistenceManager pm, String roleName) throws SentryAlreadyExistsException { MSentryRole mSentryRole = getMSentryRole(pm, roleName); if (mSentryRole == null) { MSentryRole mRole = new MSentryRole(roleName, System.currentTimeMillis()); pm.makePersistent(mRole); } else { throw new SentryAlreadyExistsException("Role: " + roleName); } }
/** * Create a sentry role and persist it. Role name is the primary key for the * role, so an attempt to create a role which exists fails with JDO exception. * * @param roleName: Name of the role being persisted. * The name is normalized. * @throws Exception */ public void createSentryRole(final String roleName) throws Exception { tm.executeTransactionWithRetry( pm -> { pm.setDetachAllOnCommit(false); // No need to detach objects String trimmedRoleName = trimAndLower(roleName); if (getRole(pm, trimmedRoleName) != null) { throw new SentryAlreadyExistsException("Role: " + trimmedRoleName); } pm.makePersistent(new MSentryRole(trimmedRoleName)); return null; }); }
SearchConstants.QUERY, true); MSentryRole role = new MSentryRole("r1", 290); mSentryGMPrivilege.setRoles(Sets.newHashSet(role));
SolrConstants.QUERY, true); MSentryRole role = new MSentryRole("r1", 290); mSentryGMPrivilege.setRoles(Sets.newHashSet(role));
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName1, System.currentTimeMillis())); commitTransaction(pm); pm.makePersistent(new MSentryRole(roleName2, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);
pm.makePersistent(new MSentryRole(roleName, System.currentTimeMillis())); commitTransaction(pm);