org.eclipse.persistence.eis.EISMappedRecord Maven / Gradle / Ivy
/*
* 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.eis;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import java.io.StringWriter;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Vector;
/**
* An EISMappedRecord
acts as a Record
* wrapper. It allows database row field-value pair mappings to be used as a
* mapped record implementation.
*
* @author James
* @since OracleAS TopLink 10g (10.0.3)
*/
public class EISMappedRecord extends AbstractRecord {
protected Map record;
protected EISAccessor accessor;
/**
* Create a database row wrapper for the record.
*/
public EISMappedRecord(Map record, EISAccessor accessor) {
setRecord(record);
setAccessor(accessor);
}
/**
* INTERNAL:
* getFields() is sued internally in a few places, so try to make that work for mapped records.
*/
@Override
public Vector getFields() {
return new Vector<>(getRecord().keySet());
}
/**
* INTERNAL:
* getValues() is sued internally in a few places, so try to make that work for mapped records.
*/
@Override
public Vector getValues() {
return new Vector<>(getRecord().values());
}
/**
* Forward the request to the record.
*/
@Override
public Set keySet() {
Set keys = getRecord().keySet();
// Handle bug in Attunity record. It returns null for the keys.
if (keys == null) {
return new HashSet(1);
}
return keys;
}
/**
* Forward the request to the record.
*/
@Override
public Collection values() {
return getRecord().values();
}
/**
* Forward the request to the record.
*/
@Override
public int size() {
return getRecord().size();
}
/**
* Return if the row is empty.
* For some reason Attunity MappedRecords think they are empty when not,
* so always return false.
*/
@Override
public boolean isEmpty() {
return false;
}
/**
* Forward the request to the record.
*/
@Override
public void clear() {
getRecord().clear();
}
/**
* Forward the request to the record.
*/
@Override
public Object get(String key) {
return getRecord().get(key);
}
/**
* Forward the request to the record.
* Wrapped nested records and collections to SDKFieldValues.
*/
@Override
public Object get(DatabaseField field) {
Object value = get(field.getName());
if (value instanceof Map) {
Vector nestedRows = new Vector<>(1);
nestedRows.add(new EISMappedRecord((Map)value, getAccessor()));
value = nestedRows;
} else if (value instanceof List values) {
Vector