Search in sources :

Example 1 with PersistentDataStoreException

use of codeu.model.store.persistence.PersistentDataStoreException in project CodeU-Spring-2018 by jwang281.

the class PersistentDataStore method loadMessages.

/**
 * Loads all Message objects from the Datastore service and returns them in a List.
 *
 * @throws PersistentDataStoreException if an error was detected during the load from the
 *     Datastore service
 */
public List<Message> loadMessages() throws PersistentDataStoreException {
    List<Message> messages = new ArrayList<>();
    // Retrieve all messages from the datastore.
    Query query = new Query("chat-messages");
    PreparedQuery results = datastore.prepare(query);
    for (Entity entity : results.asIterable()) {
        try {
            UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
            UUID conversationUuid = UUID.fromString((String) entity.getProperty("conv_uuid"));
            UUID authorUuid = UUID.fromString((String) entity.getProperty("author_uuid"));
            Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
            String content = (String) entity.getProperty("content");
            Message message = new Message(uuid, conversationUuid, authorUuid, content, creationTime);
            messages.add(message);
        } catch (Exception e) {
            // database entity definition mismatches, or service mismatches.
            throw new PersistentDataStoreException(e);
        }
    }
    return messages;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException) Message(codeu.model.data.Message) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) UUID(java.util.UUID) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException)

Example 2 with PersistentDataStoreException

use of codeu.model.store.persistence.PersistentDataStoreException in project CodeU-Spring-2018 by jwang281.

the class PersistentDataStore method loadConversations.

/**
 * Loads all Conversation objects from the Datastore service and returns them in a List.
 *
 * @throws PersistentDataStoreException if an error was detected during the load from the
 *     Datastore service
 */
public List<Conversation> loadConversations() throws PersistentDataStoreException {
    List<Conversation> conversations = new ArrayList<>();
    // Retrieve all conversations from the datastore.
    Query query = new Query("chat-conversations");
    PreparedQuery results = datastore.prepare(query);
    for (Entity entity : results.asIterable()) {
        try {
            UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
            UUID ownerUuid = UUID.fromString((String) entity.getProperty("owner_uuid"));
            String title = (String) entity.getProperty("title");
            Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
            Conversation conversation = new Conversation(uuid, ownerUuid, title, creationTime);
            conversations.add(conversation);
        } catch (Exception e) {
            // database entity definition mismatches, or service mismatches.
            throw new PersistentDataStoreException(e);
        }
    }
    return conversations;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException)

Example 3 with PersistentDataStoreException

use of codeu.model.store.persistence.PersistentDataStoreException in project CodeU-Spring-2018 by maksymko.

the class PersistentDataStore method loadUsers.

/**
 * Loads all User objects from the Datastore service and returns them in a List.
 *
 * @throws PersistentDataStoreException if an error was detected during the load from the
 *     Datastore service
 */
public List<User> loadUsers() throws PersistentDataStoreException {
    List<User> users = new ArrayList<>();
    // Retrieve all users from the datastore.
    Query query = new Query("chat-users");
    PreparedQuery results = datastore.prepare(query);
    for (Entity entity : results.asIterable()) {
        try {
            UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
            String userName = (String) entity.getProperty("username");
            String password = (String) entity.getProperty("password");
            Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
            User user = new User(uuid, userName, password, creationTime);
            users.add(user);
        } catch (Exception e) {
            // database entity definition mismatches, or service mismatches.
            throw new PersistentDataStoreException(e);
        }
    }
    return users;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) User(codeu.model.data.User) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) UUID(java.util.UUID) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException)

Example 4 with PersistentDataStoreException

use of codeu.model.store.persistence.PersistentDataStoreException in project CodeU-Spring-2018 by maksymko.

the class PersistentDataStore method loadConversations.

/**
 * Loads all Conversation objects from the Datastore service and returns them in a List.
 *
 * @throws PersistentDataStoreException if an error was detected during the load from the
 *     Datastore service
 */
public List<Conversation> loadConversations() throws PersistentDataStoreException {
    List<Conversation> conversations = new ArrayList<>();
    // Retrieve all conversations from the datastore.
    Query query = new Query("chat-conversations");
    PreparedQuery results = datastore.prepare(query);
    for (Entity entity : results.asIterable()) {
        try {
            UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
            UUID ownerUuid = UUID.fromString((String) entity.getProperty("owner_uuid"));
            String title = (String) entity.getProperty("title");
            Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
            Conversation conversation = new Conversation(uuid, ownerUuid, title, creationTime);
            conversations.add(conversation);
        } catch (Exception e) {
            // database entity definition mismatches, or service mismatches.
            throw new PersistentDataStoreException(e);
        }
    }
    return conversations;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Conversation(codeu.model.data.Conversation) UUID(java.util.UUID) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException)

Example 5 with PersistentDataStoreException

use of codeu.model.store.persistence.PersistentDataStoreException in project CodeU-Spring-2018 by maksymko.

the class PersistentDataStore method loadMessages.

/**
 * Loads all Message objects from the Datastore service and returns them in a List.
 *
 * @throws PersistentDataStoreException if an error was detected during the load from the
 *     Datastore service
 */
public List<Message> loadMessages() throws PersistentDataStoreException {
    List<Message> messages = new ArrayList<>();
    // Retrieve all messages from the datastore.
    Query query = new Query("chat-messages");
    PreparedQuery results = datastore.prepare(query);
    for (Entity entity : results.asIterable()) {
        try {
            UUID uuid = UUID.fromString((String) entity.getProperty("uuid"));
            UUID conversationUuid = UUID.fromString((String) entity.getProperty("conv_uuid"));
            UUID authorUuid = UUID.fromString((String) entity.getProperty("author_uuid"));
            Instant creationTime = Instant.parse((String) entity.getProperty("creation_time"));
            String content = (String) entity.getProperty("content");
            Message message = new Message(uuid, conversationUuid, authorUuid, content, creationTime);
            messages.add(message);
        } catch (Exception e) {
            // database entity definition mismatches, or service mismatches.
            throw new PersistentDataStoreException(e);
        }
    }
    return messages;
}
Also used : Entity(com.google.appengine.api.datastore.Entity) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException) Message(codeu.model.data.Message) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) Query(com.google.appengine.api.datastore.Query) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PreparedQuery(com.google.appengine.api.datastore.PreparedQuery) UUID(java.util.UUID) PersistentDataStoreException(codeu.model.store.persistence.PersistentDataStoreException)

Aggregations

PersistentDataStoreException (codeu.model.store.persistence.PersistentDataStoreException)6 Entity (com.google.appengine.api.datastore.Entity)6 PreparedQuery (com.google.appengine.api.datastore.PreparedQuery)6 Query (com.google.appengine.api.datastore.Query)6 Instant (java.time.Instant)6 ArrayList (java.util.ArrayList)6 UUID (java.util.UUID)6 Conversation (codeu.model.data.Conversation)2 Message (codeu.model.data.Message)2 User (codeu.model.data.User)2