Java Code Examples for javax.jdo.Query#setFilter()
The following examples show how to use
javax.jdo.Query#setFilter() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrivilegeOperatePersistence.java From incubator-sentry with Apache License 2.0 | 6 votes |
/** * Explore Privilege graph and collect privileges that are belong to the specific privilege */ @SuppressWarnings("unchecked") private Set<MSentryGMPrivilege> populateIncludePrivileges(Set<MSentryRole> roles, MSentryGMPrivilege parent, PersistenceManager pm) { Set<MSentryGMPrivilege> childrens = Sets.newHashSet(); Query query = pm.newQuery(MSentryGMPrivilege.class); StringBuilder filters = new StringBuilder(); //add populateIncludePrivilegesQuery filters.append(MSentryGMPrivilege.populateIncludePrivilegesQuery(parent)); // add filter for role names if (roles != null && roles.size() > 0) { query.declareVariables("org.apache.sentry.provider.db.service.model.MSentryRole role"); List<String> rolesFiler = new LinkedList<String>(); for (MSentryRole role : roles) { rolesFiler.add("role.roleName == \"" + role.getRoleName() + "\" "); } filters.append("&& roles.contains(role) " + "&& (" + Joiner.on(" || ").join(rolesFiler) + ")"); } query.setFilter(filters.toString()); List<MSentryGMPrivilege> privileges = (List<MSentryGMPrivilege>)query.execute(); childrens.addAll(privileges); return childrens; }
Example 2
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 6 votes |
/** * Returns a List of all Vulnerabilities. * @return a List of Vulnerability objects */ @SuppressWarnings("unchecked") public PaginatedResult getVulnerabilities() { PaginatedResult result; final Query query = pm.newQuery(Vulnerability.class); if (orderBy == null) { query.setOrdering("id asc"); } if (filter != null) { query.setFilter("vulnId.toLowerCase().matches(:vulnId)"); final String filterString = ".*" + filter.toLowerCase() + ".*"; result = execute(query, filterString); } else { result = execute(query); } for (Vulnerability vulnerability: result.getList(Vulnerability.class)) { vulnerability.setAffectedProjectCount(this.getProjects(vulnerability).size()); } return result; }
Example 3
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a List of all VulnerableSoftware objects that match the specified vendor/product/version. * @return a List of matching VulnerableSoftware objects */ @SuppressWarnings("unchecked") public List<VulnerableSoftware> getAllVulnerableSoftware(final String part, final String vendor, final String product, final String version) { final Query query = pm.newQuery(VulnerableSoftware.class); query.setFilter("part == :part && vendor == :vendor && product == :product && version == :version"); return (List<VulnerableSoftware>)query.executeWithArray(part, vendor, product, version); }
Example 4
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a List of all Policy objects. * @return a List of all Policy objects */ @SuppressWarnings("unchecked") public PaginatedResult getPolicies() { final Query query = pm.newQuery(Policy.class); if (orderBy == null) { query.setOrdering("name asc"); } if (filter != null) { query.setFilter("name.toLowerCase().matches(:filter)"); final String filterString = ".*" + filter.toLowerCase() + ".*"; return execute(query, filterString); } return execute(query); }
Example 5
Source File: SentryStore.java From incubator-sentry with Apache License 2.0 | 5 votes |
private boolean hasAnyServerPrivileges(Set<String> roleNames, String serverName) { if (roleNames == null || roleNames.isEmpty()) { return false; } boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); Query query = pm.newQuery(MSentryPrivilege.class); query.declareVariables("org.apache.sentry.provider.db.service.model.MSentryRole role"); List<String> rolesFiler = new LinkedList<String>(); for (String rName : roleNames) { rolesFiler.add("role.roleName == \"" + rName.trim().toLowerCase() + "\""); } StringBuilder filters = new StringBuilder("roles.contains(role) " + "&& (" + Joiner.on(" || ").join(rolesFiler) + ") "); filters.append("&& serverName == \"" + serverName.trim().toLowerCase() + "\""); query.setFilter(filters.toString()); query.setResult("count(this)"); Long numPrivs = (Long) query.execute(); rollbackTransaction = false; commitTransaction(pm); return numPrivs > 0; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } }
Example 6
Source File: GuideToJDO.java From tutorials with MIT License | 5 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) public void QueryJDOQL() { PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null); PersistenceManager pm = pmf.getPersistenceManager(); Transaction tx = pm.currentTransaction(); try { tx.begin(); // Declarative JDOQL : LOGGER.log(Level.INFO, "Declarative JDOQL --------------------------------------------------------------"); Query qDJDOQL = pm.newQuery(Product.class); qDJDOQL.setFilter("name == 'Tablet' && price == price_value"); qDJDOQL.declareParameters("double price_value"); List<Product> resultsqDJDOQL = qDJDOQL.setParameters(80.0).executeList(); Iterator<Product> iterDJDOQL = resultsqDJDOQL.iterator(); while (iterDJDOQL.hasNext()) { Product p = iterDJDOQL.next(); LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.name, p.price }); } LOGGER.log(Level.INFO, "--------------------------------------------------------------"); tx.commit(); } finally { if (tx.isActive()) { tx.rollback(); } pm.close(); } }
Example 7
Source File: DelegateSentryStore.java From incubator-sentry with Apache License 2.0 | 5 votes |
@Override public Set<String> getGroupsByRoles(String component, Set<String> roles) throws SentryUserException { roles = toTrimmedLower(roles); Set<String> groupNames = Sets.newHashSet(); if (roles.size() == 0) { return groupNames; } PersistenceManager pm = null; try{ pm = openTransaction(); //get groups by roles Query query = pm.newQuery(MSentryGroup.class); StringBuilder filters = new StringBuilder(); query.declareVariables("org.apache.sentry.provider.db.service.model.MSentryRole role"); List<String> rolesFiler = new LinkedList<String>(); for (String role : roles) { rolesFiler.add("role.roleName == \"" + role + "\" "); } filters.append("roles.contains(role) " + "&& (" + Joiner.on(" || ").join(rolesFiler) + ")"); query.setFilter(filters.toString()); List<MSentryGroup> groups = (List<MSentryGroup>)query.execute(); if (groups == null) { return groupNames; } for (MSentryGroup group : groups) { groupNames.add(group.getGroupName()); } return groupNames; } finally { if (pm != null) { commitTransaction(pm); } } }
Example 8
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a list of projects by it's name. * @param name the name of the Projects (required) * @return a List of Project objects */ @SuppressWarnings("unchecked") public PaginatedResult getProjects(final String name, final boolean excludeInactive) { final Query query = pm.newQuery(Project.class); if (orderBy == null) { query.setOrdering("version desc"); } if (excludeInactive) { query.setFilter("name == :name && active == true"); } else { query.setFilter("name == :name"); } return execute(query, name); }
Example 9
Source File: ShardedCounter.java From appengine-modules-sample-java with Apache License 2.0 | 5 votes |
public void increment(int count) { int shardCount = 0; PersistenceManager pm = PMF.get().getPersistenceManager(); try { final Counter current = getThisCounter(pm); shardCount = current.getShardCount(); } finally { pm.close(); } final Random generator = new Random(); final int shardNum = generator.nextInt(shardCount); pm = PMF.get().getPersistenceManager(); try { final Query randomShardQuery = pm.newQuery(CounterShard.class); randomShardQuery.setFilter( "counterName == nameParam && shardNumber == numParam"); randomShardQuery.declareParameters("String nameParam, int numParam"); final List<CounterShard> shards = (List<CounterShard>) randomShardQuery .execute(counterName, shardNum); if (shards != null && !shards.isEmpty()) { final CounterShard shard = shards.get(0); shard.increment(count); pm.makePersistent(shard); } } finally { pm.close(); } }
Example 10
Source File: VideoRepository.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public Collection<Video> findByName(String name){ Query query = PMF.get().getPersistenceManager().newQuery(Video.class); query.setFilter("name == n"); query.declareParameters("String n"); return (List<Video>)query.execute(name); }
Example 11
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a List of all License objects. * @return a List of all License objects */ @SuppressWarnings("unchecked") public PaginatedResult getLicenses() { final Query query = pm.newQuery(License.class); query.getFetchPlan().addGroup(License.FetchGroup.ALL.name()); if (orderBy == null) { query.setOrdering("name asc"); } if (filter != null) { query.setFilter("name.toLowerCase().matches(:filter) || licenseId.toLowerCase().matches(:filter)"); final String filterString = ".*" + filter.toLowerCase() + ".*"; return execute(query, filterString); } return execute(query); }
Example 12
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a List of all CPE objects that match the specified vendor/product/version. * @return a List of matching CPE objects */ @SuppressWarnings("unchecked") public List<Cpe> getCpes(final String part, final String vendor, final String product, final String version) { final Query query = pm.newQuery(Cpe.class); query.setFilter("part == :part && vendor == :vendor && product == :product && version == :version"); return (List<Cpe>)query.executeWithArray(part, vendor, product, version); }
Example 13
Source File: SqlItemPeer.java From seldon-server with Apache License 2.0 | 5 votes |
public Collection<Item> getAlphabeticItems(int limit,int dimension,ConsumerBean cb) { Integer type = null; //check if there is a filter over item_type if(dimension != Constants.DEFAULT_DIMENSION) { DimensionBean d = ItemService.getDimension(cb, dimension); type = d.getItemType(); } Query query = pm.newQuery( Item.class, "" ); if(type != null) { query.setFilter("type == " + type); } query.setOrdering("name asc,itemId desc"); query.setRange(0, limit); Collection<Item> c = (Collection<Item>) query.execute(); return c; }
Example 14
Source File: TestSentryRole.java From incubator-sentry with Apache License 2.0 | 5 votes |
private MSentryRole getMSentryRole(PersistenceManager pm, String roleName) { Query query = pm.newQuery(MSentryRole.class); query.setFilter("this.roleName == t"); query.declareParameters("java.lang.String t"); query.setUnique(true); MSentryRole sentryRole = (MSentryRole) query.execute(roleName); return sentryRole; }
Example 15
Source File: SqlItemPeer.java From seldon-server with Apache License 2.0 | 5 votes |
public Collection<Item> getItems(int limit,int dimension,ConsumerBean cb) { Integer type = null; //check if there is a filter over item_type if(dimension != Constants.DEFAULT_DIMENSION) { DimensionBean d = ItemService.getDimension(cb, dimension); type = d.getItemType(); } Query query = pm.newQuery( Item.class, "" ); if(type != null) { query.setFilter("type == " + type); } query.setOrdering("itemId desc"); query.setRange(0, limit); Collection<Item> c = (Collection<Item>) query.execute(); return c; }
Example 16
Source File: QueryManager.java From dependency-track with Apache License 2.0 | 5 votes |
/** * Returns a List of all LicenseGroup objects. * @return a List of all LicenseGroup objects */ @SuppressWarnings("unchecked") public PaginatedResult getLicenseGroups() { final Query query = pm.newQuery(LicenseGroup.class); if (orderBy == null) { query.setOrdering("name asc"); } if (filter != null) { query.setFilter("name.toLowerCase().matches(:filter)"); final String filterString = ".*" + filter.toLowerCase() + ".*"; return execute(query, filterString); } return execute(query); }
Example 17
Source File: SentryStore.java From incubator-sentry with Apache License 2.0 | 4 votes |
private Set<MSentryPrivilege> getChildPrivileges(PersistenceManager pm, Set<String> roleNames, MSentryPrivilege parent) throws SentryInvalidInputException { // Column and URI do not have children if (!isNULL(parent.getColumnName()) || !isNULL(parent.getURI())) { return new HashSet<MSentryPrivilege>(); } Query query = pm.newQuery(MSentryPrivilege.class); query.declareVariables("org.apache.sentry.provider.db.service.model.MSentryRole role"); List<String> rolesFiler = new LinkedList<String>(); for (String rName : roleNames) { rolesFiler.add("role.roleName == \"" + rName.trim().toLowerCase() + "\""); } StringBuilder filters = new StringBuilder("roles.contains(role) " + "&& (" + Joiner.on(" || ").join(rolesFiler) + ")"); filters.append(" && serverName == \"" + parent.getServerName() + "\""); if (!isNULL(parent.getDbName())) { filters.append(" && dbName == \"" + parent.getDbName() + "\""); if (!isNULL(parent.getTableName())) { filters.append(" && tableName == \"" + parent.getTableName() + "\""); filters.append(" && columnName != \"__NULL__\""); } else { filters.append(" && tableName != \"__NULL__\""); } } else { filters.append(" && (dbName != \"__NULL__\" || URI != \"__NULL__\")"); } query.setFilter(filters.toString()); query.setResult("privilegeScope, serverName, dbName, tableName, columnName," + " URI, action, grantOption"); Set<MSentryPrivilege> privileges = new HashSet<MSentryPrivilege>(); for (Object[] privObj : (List<Object[]>) query.execute()) { MSentryPrivilege priv = new MSentryPrivilege(); priv.setPrivilegeScope((String) privObj[0]); priv.setServerName((String) privObj[1]); priv.setDbName((String) privObj[2]); priv.setTableName((String) privObj[3]); priv.setColumnName((String) privObj[4]); priv.setURI((String) privObj[5]); priv.setAction((String) privObj[6]); priv.setGrantOption((Boolean) privObj[7]); privileges.add(priv); } return privileges; }
Example 18
Source File: SentryStore.java From incubator-sentry with Apache License 2.0 | 4 votes |
/** * This returns a Mapping of AuthZObj(db/table) -> (Role -> permission) */ public Map<String, HashMap<String, String>> retrieveFullPrivilegeImage() { Map<String, HashMap<String, String>> retVal = new HashMap<String, HashMap<String,String>>(); boolean rollbackTransaction = true; PersistenceManager pm = null; try { pm = openTransaction(); Query query = pm.newQuery(MSentryPrivilege.class); String filters = "(serverName != \"__NULL__\") " + "&& (dbName != \"__NULL__\") " + "&& (URI == \"__NULL__\")"; query.setFilter(filters.toString()); query .setOrdering("serverName ascending, dbName ascending, tableName ascending"); List<MSentryPrivilege> privileges = (List<MSentryPrivilege>) query .execute(); rollbackTransaction = false; for (MSentryPrivilege mPriv : privileges) { String authzObj = mPriv.getDbName(); if (!isNULL(mPriv.getTableName())) { authzObj = authzObj + "." + mPriv.getTableName(); } HashMap<String, String> pUpdate = retVal.get(authzObj); if (pUpdate == null) { pUpdate = new HashMap<String, String>(); retVal.put(authzObj, pUpdate); } for (MSentryRole mRole : mPriv.getRoles()) { String existingPriv = pUpdate.get(mRole.getRoleName()); if (existingPriv == null) { pUpdate.put(mRole.getRoleName(), mPriv.getAction().toUpperCase()); } else { pUpdate.put(mRole.getRoleName(), existingPriv + "," + mPriv.getAction().toUpperCase()); } } } commitTransaction(pm); return retVal; } finally { if (rollbackTransaction) { rollbackTransaction(pm); } } }
Example 19
Source File: PrivilegeOperatePersistence.java From incubator-sentry with Apache License 2.0 | 4 votes |
private MSentryGMPrivilege getPrivilege(MSentryGMPrivilege privilege, PersistenceManager pm) { Query query = pm.newQuery(MSentryGMPrivilege.class); query.setFilter(MSentryGMPrivilege.toQuery(privilege)); query.setUnique(true); return (MSentryGMPrivilege)query.execute(); }
Example 20
Source File: JdoSqlFilter.java From Android_Code_Arbiter with GNU Lesser General Public License v3.0 | 4 votes |
public void testJdoSafeFilter(String filterValue) { PersistenceManager pm = getPM(); Query q = pm.newQuery(UserEntity.class); q.setFilter("id == 1"); }