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

org.eclipse.persistence.mappings.structures.ObjectArrayMapping Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * Copyright (c) 1998, 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:
//     Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.mappings.structures;

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.DescriptorException;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.queries.JoinedAttributeManager;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeCollectionMapping;
import org.eclipse.persistence.queries.ObjectBuildingQuery;

/**
 * 

Purpose: * In an object-relational data model, structures can contain "Arrays" or collections of other data-types. * In Oracle 8i, a Varray is typically used to represent a collection of primitive data or aggregate structures. * These arrays are stored with their parent structure in the same table.

* * ArrayMapping is used to map a collection of primitive data

* ObjectArrayMapping is used to map a collection of Oracle data-type * *

NOTE: Only Oracle8i supports Varray type. * * @author King (Yaoping) Wang * @since TOPLink/Java 3.0 * * @see ArrayMapping */ public class ObjectArrayMapping extends AbstractCompositeCollectionMapping { /** Arrays require a structure name, this is the ADT defined for the VARRAY. */ protected String structureName; /** * PUBLIC: * Return the name of the structure. * This is the name of the user defined data type as defined on the database. */ @Override public String getStructureName() { return structureName; } /** * INTERNAL: * Initialize the mapping. */ @Override public void initialize(AbstractSession session) throws DescriptorException { super.initialize(session); if ((getStructureName() == null) || getStructureName().isEmpty()) { throw DescriptorException.structureNameNotSetInMapping(this); } // For bug 2730536 convert the field to be an ObjectRelationalDatabaseField. ObjectRelationalDatabaseField field = (ObjectRelationalDatabaseField)getField(); field.setSqlType(java.sql.Types.ARRAY); field.setSqlTypeName(getStructureName()); // May require native connection in WLS to avoid wrapping wrapped. getDescriptor().setIsNativeConnectionRequired(true); } public void setFieldName(String fieldName) { this.setField(new ObjectRelationalDatabaseField(fieldName)); } /** * PUBLIC: * Set the name of the structure. * This is the name of the user defined data type as defined on the database. */ public void setStructureName(String structureName) { this.structureName = structureName; } @Override protected Object buildCompositeObject(ClassDescriptor descriptor, AbstractRecord nestedRow, ObjectBuildingQuery query, CacheKey parentCacheKey, JoinedAttributeManager joinManager, AbstractSession targetSession) { Object element = descriptor.getObjectBuilder().buildNewInstance(); descriptor.getObjectBuilder().buildAttributesIntoObject(element, parentCacheKey, nestedRow, query, joinManager, query.getExecutionFetchGroup(descriptor), false, targetSession); return element; } @Override protected AbstractRecord buildCompositeRow(Object attributeValue, AbstractSession session, AbstractRecord parentRow, WriteType writeType) { return this.getObjectBuilder(attributeValue, session).buildRow(attributeValue, session, writeType); } /** * INTERNAL: */ @Override public boolean isRelationalMapping() { return true; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy