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

org.eclipse.persistence.internal.dynamic.DynamicPropertiesManager Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * Copyright (c) 2011, 2024 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0,
 * or the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

// Contributors:
//     dclarke, mnorman - Dynamic Persistence
//       http://wiki.eclipse.org/EclipseLink/Development/Dynamic
//       (https://bugs.eclipse.org/bugs/show_bug.cgi?id=200045)
//
package org.eclipse.persistence.internal.dynamic;

//javase imports

import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.exceptions.DynamicException;
import org.eclipse.persistence.internal.dynamic.DynamicEntityImpl.PropertyWrapper;
import org.eclipse.persistence.mappings.DatabaseMapping;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Information about a property is extracted (through DynamicType) from the entity's ClassDescriptor
 * 

* Important - DynamicPropertiesManager is NOT thread-safe * @author mnorman */ public class DynamicPropertiesManager { /** * All DynamicEntity classes have a public static field 'DPM' of type DynamicPropertiesManager * */ public static final String PROPERTIES_MANAGER_FIELD = "DPM"; protected DynamicTypeImpl type; protected DynamicPropertiesInitializatonPolicy dpInitializatonPolicy = new DynamicPropertiesInitializatonPolicy(); public DynamicPropertiesManager() { super(); } public DynamicType getType() { return type; } public void setType(DynamicType type) { this.type = (DynamicTypeImpl)type; } public DynamicPropertiesInitializatonPolicy getInitializatonPolicy() { return dpInitializatonPolicy; } public void setInitializatonPolicy(DynamicPropertiesInitializatonPolicy dpInitializatonPolicy) { this.dpInitializatonPolicy = dpInitializatonPolicy; } // lifecycle callback public void postConstruct(DynamicEntity entity) { // first step, create 'slots' in propertiesMap createSlots((DynamicEntityImpl)entity); // next step, initialize 'slot' values initializeSlotValues((DynamicEntityImpl)entity); } protected void createSlots(DynamicEntityImpl entity) { Map propertiesMap = entity.getPropertiesMap(); List propertyNames = getPropertyNames(); if (propertyNames != null) { for (String propertyName : propertyNames) { propertiesMap.put(propertyName, new PropertyWrapper()); } } } protected void initializeSlotValues(DynamicEntityImpl entity) { getInitializatonPolicy().initializeProperties(type, entity); } // delegate to descriptor public boolean contains(String propertyName) { boolean contains = false; if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { if (dm.getAttributeName().equals(propertyName)) { contains = true; break; } } } return contains; } // delegate to descriptor public List getPropertyNames() { List propertyNames = new ArrayList<>(); if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { propertyNames.add(dm.getAttributeName()); } } return propertyNames; } public void checkSet(String propertyName, Object value) { if (contains(propertyName)) { type.checkSet(propertyName, value); } else { throw DynamicException.invalidPropertyName(type, propertyName); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy