private static void accountStats() { AmazonDynamoDBDAO dao = AmazonDynamoDBDAO.getInstance(); System.out.println("-----------------"); System.out.println("Grabbing all Accounts"); System.out.println("-----------------"); PaginatedScanList<Account> accounts = dao.getAllAccounts(); System.out.println("Number of Accounts : " + accounts.size()); accounts = dao.getAllRedditAccounts(); System.out.println("Number of Reddit Accounts : " + accounts.size()); accounts = dao.getAllFacebookAccounts(); System.out.println("Number of Facebook Accounts : " + accounts.size()); System.out.println("-----------------"); accounts = dao.getAllDonatedAccounts(); System.out.println("Number Donated : " + accounts.size()); accounts = dao.getAllFriendsAccounts(); System.out.println("Number Friends : " + accounts.size()); System.out.println("-----------------"); }
private static void clearDomains() { System.out.println("Are you sure you want to do that Dave?"); if (1 == 1) return; AmazonDynamoDBDAO dao = AmazonDynamoDBDAO.getInstance(); System.out.println("-----------------"); System.out.println("Clearing all domains in domainsv2"); System.out.println("-----------------"); PaginatedScanList<Domain> domains = dao.getAllDomains(); int count = 0; for (Domain domain : domains) { count++; dao.domainDeleteDomain(domain.getDomainName(), domain.getAccountToken()); if (count % 100 == 0) { System.out.println("Cleared : " + count); } } System.out.println("Cleared : " + count); }
private static void clearAccounts() { System.out.println("Are you sure you want to do that Dave?"); if (1 == 1) return; AmazonDynamoDBDAO dao = AmazonDynamoDBDAO.getInstance(); System.out.println("-----------------"); System.out.println("Clearing all accounts in accountsv2"); System.out.println("-----------------"); PaginatedScanList<Account> accounts = dao.getAllAccounts(); int count = 0; for (Account account : accounts) { count++; dao.accountDeleteAccountLeaveDomains(account.getEmail()); if (count % 100 == 0) { System.out.println("Cleared : " + count); } } System.out.println("Cleared : " + count); }
public static void fillTable() throws UnknownHostException { ProvisionedThroughput provisionedThroughput = new ProvisionedThroughput(); provisionedThroughput.setReadCapacityUnits(1L); provisionedThroughput.setWriteCapacityUnits(1L); if (!client.listTables().getTableNames().contains("User")) { CreateTableRequest createTableRequest = new CreateTableRequest() .withTableName("User") .withKeySchema( new KeySchemaElement().withAttributeName("id") .withKeyType(KeyType.HASH)) .withProvisionedThroughput(provisionedThroughput) .withAttributeDefinitions( new AttributeDefinition().withAttributeName("id").withAttributeType( ScalarAttributeType.S)); client.createTable(createTableRequest); } else { DynamoDBScanExpression scan = new DynamoDBScanExpression(); PaginatedScanList<User> users = mapper.scan(User.class, scan); for (User user : users) { Map<String, AttributeValue> key = new HashMap<String, AttributeValue>(); key.put("id", new AttributeValue().withS(user.getId())); client.deleteItem(new DeleteItemRequest("User", key)); } } u1 = addUser("Jaakko", "Jantunen", 20, Gender.MALE, null); u2 = addUser("Jaakki", "Jantunen", 30, Gender.FEMALE, "One detail"); u3 = addUser("Jaana", "Aakkonen", 40, Gender.MALE, "No details"); u4 = addUser("Jaana", "BeekkoNen", 50, Gender.FEMALE, null); }
public void sessionsCleanUpOldSessions() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("lastHit", new Condition() .withComparisonOperator(ComparisonOperator.LT.toString()) .withAttributeValueList(new AttributeValue().withN(""+(System.currentTimeMillis()-(Session.TTL_SESSIONS_SECONDS * 1000)))) ); PaginatedScanList<Session> result = mapper.scan(Session.class, scanExpression); mapper.batchDelete(result); }
public PaginatedScanList<Account> getAllDonatedAccounts() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("accountType",new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue[] { new AttributeValue().withS(Account.ACCOUNT_DONATE) })); PaginatedScanList<Account> accounts = mapper.scan(Account.class,scanExpression); return accounts; }
public PaginatedScanList<Account> getAllFriendsAccounts() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("accountType",new Condition() .withComparisonOperator(ComparisonOperator.EQ.toString()) .withAttributeValueList(new AttributeValue[] { new AttributeValue().withS(Account.ACCOUNT_FRIENDS_OF_DUCK) })); PaginatedScanList<Account> accounts = mapper.scan(Account.class,scanExpression); return accounts; }
public PaginatedScanList<Account> getAllRedditAccounts() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("email",new Condition() .withComparisonOperator(ComparisonOperator.CONTAINS.toString()) .withAttributeValueList(new AttributeValue[] { new AttributeValue().withS("@reddit") })); PaginatedScanList<Account> accounts = mapper.scan(Account.class,scanExpression); return accounts; }
public PaginatedScanList<Account> getAllFacebookAccounts() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); scanExpression.addFilterCondition("email",new Condition() .withComparisonOperator(ComparisonOperator.CONTAINS.toString()) .withAttributeValueList(new AttributeValue[] { new AttributeValue().withS("#facebook") })); PaginatedScanList<Account> accounts = mapper.scan(Account.class,scanExpression); return accounts; }
private static void domainStats() { AmazonDynamoDBDAO dao = AmazonDynamoDBDAO.getInstance(); System.out.println("-----------------"); System.out.println("Grabbing all Domains"); System.out.println("-----------------"); PaginatedScanList<Domain> domains = dao.getAllDomains(); System.out.println("Number of Domains : " + domains.size()); System.out.println("-----------------"); }
/** * Find all rows in table given the entity object * * @return a list of entities found * @throws DataAccessException */ public List<T> findAll() throws DataAccessException { DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression(); DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING); PaginatedScanList<T> paginatedScanList = dynamoDBMapper.scan(getType(), dynamoDBScanExpression, config); paginatedScanList.loadAllResults(); List<T> list = new ArrayList<T>(paginatedScanList.size()); Iterator<T> iterator = paginatedScanList.iterator(); while (iterator.hasNext()) { T element = iterator.next(); list.add(element); } return list; }
@Override public Page<T> findAll(Pageable pageable) { if (pageable.getSort() != null) { throw new UnsupportedOperationException("Sorting not supported for find all scan operations"); } DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); // Scan to the end of the page after the requested page int scanTo = pageable.getOffset() + (2 * pageable.getPageSize()); scanExpression.setLimit(scanTo); PaginatedScanList<T> paginatedScanList = dynamoDBOperations.scan(domainType, scanExpression); Iterator<T> iterator = paginatedScanList.iterator(); int processedCount = 0; if (pageable.getOffset() > 0) { processedCount = scanThroughResults(iterator, pageable.getOffset()); if (processedCount < pageable.getOffset()) return new PageImpl<T>(new ArrayList<T>()); } // Scan ahead to retrieve the next page count List<T> results = readPageOfResults(iterator, pageable.getPageSize()); assertScanEnabled(enableScanPermissions.isFindAllPaginatedScanEnabled(), "findAll(Pageable pageable)"); assertScanCountEnabled(enableScanPermissions.isFindAllUnpaginatedScanCountEnabled(), "findAll(Pageable pageable)"); int totalCount = dynamoDBOperations.count(domainType, scanExpression); return new PageImpl<T>(results, pageable, totalCount); }
@Override public <T> PaginatedScanList<T> scan(Class<T> domainClass, DynamoDBScanExpression scanExpression) { PaginatedScanList<T> results = dynamoDBMapper.scan(domainClass, scanExpression); maybeEmitEvent(new AfterScanEvent<T>(results)); return results; }
public PaginatedScanList<Account> getAllAccounts() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); PaginatedScanList<Account> accounts = mapper.scan(Account.class,scanExpression); return accounts; }
public PaginatedScanList<Domain> getAllDomains() { DynamoDBScanExpression scanExpression = new DynamoDBScanExpression(); PaginatedScanList<Domain> domains = mapper.scan(Domain.class,scanExpression); return domains; }
@Override public List<Q> fetch() { PaginatedScanList<? extends Q> result = query(); return cast(result); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private List<Q> cast(PaginatedScanList result) { return new ArrayList<Q>(result); }
public Iterable<Session> listSessions() { PaginatedScanList<DynamoSessionItem> sessions = mapper.scan(DynamoSessionItem.class, new DynamoDBScanExpression()); return new SessionConverterIterable(sessions); }
public AfterScanEvent(PaginatedScanList<T> source) { super(source); }
/** * Counts all rows in this specific table. * Use it carefully since it loads all results from DynamoDB. To be honest there are only * a few situations where this could be considered a wise solution. * * @return a amount of rows found * @throws DataAccessException */ public int count() throws DataAccessException { DynamoDBScanExpression dynamoDBScanExpression = new DynamoDBScanExpression(); DynamoDBMapperConfig config = new DynamoDBMapperConfig(DynamoDBMapperConfig.PaginationLoadingStrategy.EAGER_LOADING); PaginatedScanList<T> paginatedScanList = dynamoDBMapper.scan(getType(), dynamoDBScanExpression, config); paginatedScanList.loadAllResults(); return paginatedScanList.size(); }
/*** * * Query DynamoDb using the given scan expression * @param clazz - The Java class specifying the return type * @param scanExpression - The dynamoDb query expression * @return paginatedScanList */ public <T> PaginatedScanList<T> query(final Class<T> clazz, final DynamoDBScanExpression scanExpression){ final PaginatedScanList<T> itemList = mapper.scan(clazz, scanExpression); return itemList; }
public <T> PaginatedScanList<T> scan(Class<T> domainClass,DynamoDBScanExpression scanExpression);