org.eiichiro.acidhouse.appengine.AppEngineUpdate Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of acidhouse-appengine Show documentation
Show all versions of acidhouse-appengine Show documentation
Acid House Implementation for Google App Engine
The newest version!
/*
* Copyright (C) 2011 Eiichiro Uchiumi. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eiichiro.acidhouse.appengine;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.eiichiro.acidhouse.Filter;
import org.eiichiro.acidhouse.GetList;
import org.eiichiro.acidhouse.Update;
import org.eiichiro.acidhouse.metamodel.Metamodel;
import org.eiichiro.acidhouse.metamodel.Property;
/**
* {@code AppEngineUpdate} is a App Engine Low-level Datastore API based
* implentation of {@code Update}.
*
* @author Eiichiro Uchiumi
*/
public class AppEngineUpdate implements Update {
private Logger logger = Logger.getLogger(getClass().getName());
private final Metamodel metamodel;
private final AppEngineDatastoreSession session;
private List> filters = new ArrayList>(0);
private Map, Object> properties = new HashMap, Object>(0);
/**
* Constructs a new {@code AppEngineUpdate} with the specified metamodel of
* entity and {@code AppEngineDatastoreSession}.
*
* @param metamodel The metamodel of entity to update with this command.
* @param session {@code AppEngineDatastoreSession} instance for this command.
*/
public AppEngineUpdate(Metamodel metamodel, AppEngineDatastoreSession session) {
this.metamodel = metamodel;
this.session = session;
}
/**
* Executes {@code AppEngineUpdate} with {@code AppEngineDatastoreSession}.
*
* @return The number of updated entity.
*/
@SuppressWarnings("unchecked")
@Override
public Integer execute() {
logger.fine("Executing [AppEngineUpdate] command");
if (properties.size() == 0) {
throw new IllegalStateException("'properties' must be set");
}
GetList command = session.get(metamodel);
if (filters != null) {
command.filter(filters.toArray(new Filter>[] {}));
}
int i = 0;
for (E entity : command.execute()) {
for (Property, ?> property : properties.keySet()) {
Object object = properties.get(property);
if (object instanceof Modification) {
Modification