All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deephacks.tools4j.config.admin.AdminContext Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
/**
 * 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.deephacks.tools4j.config.admin;

import com.google.common.base.Optional;
import org.deephacks.tools4j.config.admin.query.BeanQuery;
import org.deephacks.tools4j.config.admin.query.BeanQueryBuilder;
import org.deephacks.tools4j.config.model.AbortRuntimeException;
import org.deephacks.tools4j.config.model.Bean;
import org.deephacks.tools4j.config.model.Bean.BeanId;
import org.deephacks.tools4j.config.model.Schema;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 

* Central interface for provisioning configuration to applications. *

* Configuration is read-only from an application runtime perspective and can only be * changed using this interface. Configuration changes will be reloaded automatically by * applications at runtime. *

*

* Read operations will return {@link Bean} that will always have schema initialized, including * properties and references traversed and fetched eagerly. *

* Provisioning operations are relieved from having {@link Bean} schema initalized, nor * must references be set recusivley, {@link BeanId} is enough to indicate references. *

* * @author Kristoffer Sjogren */ public abstract class AdminContext { private static final String CORE_IMPL = "org.deephacks.tools4j.config.internal.core.admin.AdminCoreContext"; private static AdminContext ctx; protected AdminContext() { // only core should implement this class if (!getClass().getName().equals(CORE_IMPL)) { throw new IllegalArgumentException("Only AdminCoreContext is allowed to" + "implement this interface."); } } /** * @return the admin context. */ public static synchronized AdminContext get() { if (ctx != null) { return ctx; } try { ctx = (AdminContext) Class.forName(CORE_IMPL).newInstance(); } catch (Exception e) { throw new RuntimeException(e); } return ctx; } /** * Get a single bean as identified by the id. * * @param beanId id of the bean to be fetched. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract Optional get(final BeanId beanId) throws AbortRuntimeException; /** * List all bean instances of particular schema. * * @param schemaName of beans to be listed. * @return beans matching the schema. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract List list(final String schemaName) throws AbortRuntimeException; /** * List a sepecific set of bean instances of particular schema. * * @param schemaName of beans to be listed. * @param instanceIds the ids that should be listed. * @return bean of matching type. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract List list(final String schemaName, final Collection instanceIds) throws AbortRuntimeException; /** * Create a bean. * * @param bean to be created. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void create(final Bean bean) throws AbortRuntimeException; /** * Convenience method for {@link AdminContext#create(Bean)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @param object to be created. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see */ public abstract void createObject(final Object object) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#create(Bean)}. * * @param beans to be created. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void create(final Collection beans) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#createObject(Object)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @param objects to be created. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see */ public abstract void createObjects(final Collection objects) throws AbortRuntimeException; /** * Overwrite/set existing bean instances with provided data. * *

* Already persisted properties associated with the instance * will be removed if they are missing from the provided bean instances. *

* * @param bean with values to be written. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void set(final Bean bean) throws AbortRuntimeException; /** * Convenience method for {@link AdminContext#set(Bean)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @param object with values to be written. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void setObject(final Object object) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#set(Bean)}. * * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void set(final Collection beans) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#setObject(Object)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @param objects with values to be written. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void setObjects(final Collection objects) throws AbortRuntimeException; /** * Convenience method for {@link AdminContext#merge(Bean)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @param bean to be merged. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void merge(final Bean bean) throws AbortRuntimeException; /** *

* Merges the provided bean properties with an already existing instance. *

* Properties not provided will remain untouched in storage, hence this method can * be used to set or delete a single property. *

* * @param object to be merged. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void mergeObject(final Object object) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#merge(Bean)}. * * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void merge(final Collection beans) throws AbortRuntimeException; /** * Collection variant of {@link AdminContext#mergeObject(Object)}. * *

* Should generally not be used in production since it generates a bit of * overhead in terms of performance. *

* * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void mergeObjects(final Collection objects) throws AbortRuntimeException; /** * Delete a bean. *

* Beans are only allowed to be deleted if they are not referenced by other beans, * in order to enforce referential integrity. *

*

* Delete operations are not cascading, which means that a bean's references * are not deleted along with the bean itself. *

. * * @param bean to be deleted * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void delete(final BeanId bean) throws AbortRuntimeException; /** * This is the collection variant of {@link AdminContext#delete(BeanId)}. * * @param schemaName the name of the schema that covers all instance ids. * @param instanceIds instance ids to be deleted. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract void delete(final String schemaName, final Collection instanceIds) throws AbortRuntimeException; /** * Get all schemas available in the system. The keys of the map is the name * of the schema. This method can be useful for dynamic schema discovery and * display. * * @return a map of schemas indexed on schema name. * @throws AbortRuntimeException is thrown when the system itself cannot * recover from a certain event and must therefore abort execution, see * {@link org.deephacks.tools4j.config.model.Events}. */ public abstract Map getSchemas(); /** * Create a new query used for retrieving bean instances using flexible composition * of Criterion objects, used to narrow number of beans in the result set. * * A bean query can also be used to paginate through result sets. * * Fields do NOT need to be indexed. * * @see {@link BeanQueryBuilder} * * @param schemaName schemaName to query * @return Used for composing a query in conjuction with {@link BeanQueryBuilder}. */ public abstract BeanQuery newQuery(String schemaName); }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy