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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations