Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright (c) 2009-2014, Data Geekery GmbH (http://www.datageekery.com)
* All rights reserved.
*
* This work is dual-licensed
* - under the Apache Software License 2.0 (the "ASL")
* - under the jOOQ License and Maintenance Agreement (the "jOOQ License")
* =============================================================================
* You may choose which license applies to you:
*
* - If you're using this work with Open Source databases, you may choose
* either ASL or jOOQ License.
* - If you're using this work with at least one commercial database, you must
* choose jOOQ License
*
* For more information, please visit http://www.jooq.org/licenses
*
* Apache Software License 2.0:
* -----------------------------------------------------------------------------
* 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.
*
* jOOQ License and Maintenance Agreement:
* -----------------------------------------------------------------------------
* Data Geekery grants the Customer the non-exclusive, timely limited and
* non-transferable license to install and use the Software under the terms of
* the jOOQ License and Maintenance Agreement.
*
* This library is distributed with a LIMITED WARRANTY. See the jOOQ License
* and Maintenance Agreement for more details: http://www.jooq.org/licensing
*/
package org.jooq.impl;
import static java.util.Arrays.asList;
import static org.jooq.conf.SettingsTools.updatablePrimaryKeys;
import static org.jooq.impl.Utils.getAnnotatedGetter;
import static org.jooq.impl.Utils.getAnnotatedMembers;
import static org.jooq.impl.Utils.getMatchingGetter;
import static org.jooq.impl.Utils.getMatchingMembers;
import static org.jooq.impl.Utils.hasColumnAnnotations;
import static org.jooq.impl.Utils.indexOrFail;
import static org.jooq.impl.Utils.resetChangedOnNotNull;
import static org.jooq.impl.Utils.settings;
import java.lang.reflect.Method;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.jooq.Attachable;
import org.jooq.Converter;
import org.jooq.DataType;
import org.jooq.Field;
import org.jooq.Record;
import org.jooq.Record1;
import org.jooq.Record10;
import org.jooq.Record11;
import org.jooq.Record12;
import org.jooq.Record13;
import org.jooq.Record14;
import org.jooq.Record15;
import org.jooq.Record16;
import org.jooq.Record17;
import org.jooq.Record18;
import org.jooq.Record19;
import org.jooq.Record2;
import org.jooq.Record20;
import org.jooq.Record21;
import org.jooq.Record22;
import org.jooq.Record3;
import org.jooq.Record4;
import org.jooq.Record5;
import org.jooq.Record6;
import org.jooq.Record7;
import org.jooq.Record8;
import org.jooq.Record9;
import org.jooq.RecordMapper;
import org.jooq.Result;
import org.jooq.Table;
import org.jooq.UniqueKey;
import org.jooq.exception.InvalidResultException;
import org.jooq.exception.MappingException;
import org.jooq.tools.Convert;
import org.jooq.tools.StringUtils;
/**
* A general base class for all {@link Record} types
*
* @author Lukas Eder
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
abstract class AbstractRecord extends AbstractStore implements Record {
/**
* Generated UID
*/
private static final long serialVersionUID = -6052512608911220404L;
final RowImpl fields;
final Object[] values;
final Object[] originals;
final BitSet changed;
boolean fetched;
AbstractRecord(Collection extends Field>> fields) {
this(new RowImpl(fields));
}
AbstractRecord(Field>... fields) {
this(new RowImpl(fields));
}
AbstractRecord(RowImpl fields) {
int size = fields.size();
this.fields = fields;
this.values = new Object[size];
this.originals = new Object[size];
this.changed = new BitSet(size);
}
// ------------------------------------------------------------------------
// XXX: Attachable API
// ------------------------------------------------------------------------
@Override
final List getAttachables() {
List result = new ArrayList();
int size = size();
for (int i = 0; i < size; i++) {
if (values[i] instanceof Attachable) {
result.add((Attachable) values[i]);
}
}
return result;
}
// ------------------------------------------------------------------------
// XXX: FieldProvider API
// ------------------------------------------------------------------------
@Override
public final Field field(Field field) {
return fieldsRow().field(field);
}
@Override
public final Field> field(String name) {
return fieldsRow().field(name);
}
@Override
public final Field> field(int index) {
return index >= 0 && index < fields.size() ? fields.field(index) : null;
}
@Override
public final Field>[] fields() {
return fields.fields();
}
@Override
public final Field>[] fields(Field>... f) {
return fields.fields(f);
}
@Override
public final Field>[] fields(String... fieldNames) {
return fields.fields(fieldNames);
}
@Override
public final Field>[] fields(int... fieldIndexes) {
return fields.fields(fieldIndexes);
}
// ------------------------------------------------------------------------
// XXX: Record API
// ------------------------------------------------------------------------
@Override
public final int size() {
return fields.size();
}
@Override
public final T getValue(Field field) {
return (T) getValue(indexOrFail(fieldsRow(), field));
}
@Override
@Deprecated
public final T getValue(Field field, T defaultValue) {
T result = getValue(field);
return result != null ? result : defaultValue;
}
@Override
public final T getValue(Field> field, Class extends T> type) {
return Convert.convert(getValue(field), type);
}
@Override
@Deprecated
public final T getValue(Field> field, Class extends T> type, T defaultValue) {
final T result = getValue(field, type);
return result == null ? defaultValue : result;
}
@Override
public final U getValue(Field field, Converter super T, U> converter) {
return converter.from(getValue(field));
}
@Override
@Deprecated
public final U getValue(Field field, Converter super T, U> converter, U defaultValue) {
final U result = getValue(field, converter);
return result == null ? defaultValue : result;
}
@Override
public final Object getValue(int index) {
return values[safeIndex(index)];
}
@Override
@Deprecated
public final Object getValue(int index, Object defaultValue) {
final Object result = getValue(index);
return result == null ? defaultValue : result;
}
@Override
public final T getValue(int index, Class extends T> type) {
return Convert.convert(getValue(index), type);
}
@Override
@Deprecated
public final T getValue(int index, Class extends T> type, T defaultValue) {
final T result = getValue(index, type);
return result == null ? defaultValue : result;
}
@Override
public final U getValue(int index, Converter, U> converter) {
return Convert.convert(getValue(index), converter);
}
@Override
@Deprecated
public final U getValue(int index, Converter, U> converter, U defaultValue) {
final U result = getValue(index, converter);
return result == null ? defaultValue : result;
}
@Override
public final Object getValue(String fieldName) {
return getValue(indexOrFail(fieldsRow(), fieldName));
}
@Override
@Deprecated
public final Object getValue(String fieldName, Object defaultValue) {
return getValue(indexOrFail(fieldsRow(), fieldName), defaultValue);
}
@Override
public final T getValue(String fieldName, Class extends T> type) {
return Convert.convert(getValue(fieldName), type);
}
@Override
@Deprecated
public final T getValue(String fieldName, Class extends T> type, T defaultValue) {
final T result = getValue(fieldName, type);
return result == null ? defaultValue : result;
}
@Override
public final U getValue(String fieldName, Converter, U> converter) {
return Convert.convert(getValue(fieldName), converter);
}
@Override
@Deprecated
public final U getValue(String fieldName, Converter, U> converter, U defaultValue) {
final U result = getValue(fieldName, converter);
return result == null ? defaultValue : result;
}
/**
* Subclasses may type-unsafely set a value to a record index. This method
* takes care of converting the value to the appropriate type.
*/
protected final void setValue(int index, Object value) {
setValue(index, (Field) field(index), value);
}
@Override
public final void setValue(Field field, T value) {
setValue(indexOrFail(fields, field), field, value);
}
private final void setValue(int index, Field field, T value) {
// Relevant issues documenting this method's behaviour:
// [#945] Avoid bugs resulting from setting the same value twice
// [#948] To allow for controlling the number of hard-parses
// To allow for explicitly overriding default values
// [#979] Avoid modifying chnaged flag on unchanged primary key values
UniqueKey> key = getPrimaryKey();
// Normal fields' changed flag is always set to true
if (key == null || !key.getFields().contains(field)) {
changed.set(index);
}
// The primary key's changed flag might've been set previously
else if (changed.get(index)) {
changed.set(index);
}
// [#2764] Users may override updatability of primary key values
else if (updatablePrimaryKeys(settings(this))) {
changed.set(index);
}
// [#2698] If the primary key has not yet been set
else if (originals[index] == null) {
changed.set(index);
}
// [#979] If the primary key is being changed, all other fields' flags
// need to be set to true for in case this record is stored again, an
// INSERT statement will thus be issued
else {
// [#945] Be sure that changed is never reset to false
changed.set(index, changed.get(index) || !StringUtils.equals(values[index], value));
if (changed.get(index)) {
changed(true);
}
}
values[index] = value;
}
@Override
public final void setValue(Field field, U value, Converter converter) {
setValue(field, converter.to(value));
}
final void setValues(Field>[] fields, AbstractRecord record) {
fetched = record.fetched;
for (Field> field : fields) {
int targetIndex = indexOrFail(fieldsRow(), field);
int sourceIndex = indexOrFail(record.fieldsRow(), field);
values[targetIndex] = record.getValue(sourceIndex);
originals[targetIndex] = record.original(sourceIndex);
changed.set(targetIndex, record.changed(sourceIndex));
}
}
final void intern0(int fieldIndex) {
safeIndex(fieldIndex);
if (field(fieldIndex).getType() == String.class) {
values[fieldIndex] = ((String) values[fieldIndex]).intern();
originals[fieldIndex] = ((String) originals[fieldIndex]).intern();
}
}
final int safeIndex(int index) {
if (index >= 0 && index < values.length)
return index;
throw new IllegalArgumentException("No field at index " + index + " in Record type " + fieldsRow());
}
/**
* Subclasses may override this
*/
UniqueKey> getPrimaryKey() {
return null;
}
/*
* This method is overridden covariantly by TableRecordImpl
*/
@Override
public Record original() {
return Utils.newRecord(fetched, (Class) getClass(), fields.fields.fields, configuration())
.operate(new RecordOperation() {
@Override
public AbstractRecord operate(AbstractRecord record) throws RuntimeException {
for (int i = 0; i < originals.length; i++) {
record.values[i] = originals[i];
record.originals[i] = originals[i];
}
return record;
}
});
}
@Override
public final T original(Field field) {
return (T) original(indexOrFail(fieldsRow(), field));
}
@Override
public final Object original(int fieldIndex) {
return originals[safeIndex(fieldIndex)];
}
@Override
public final Object original(String fieldName) {
return original(indexOrFail(fieldsRow(), fieldName));
}
@Override
public final boolean changed() {
return !changed.isEmpty();
}
@Override
public final boolean changed(Field> field) {
return changed(indexOrFail(fieldsRow(), field));
}
@Override
public final boolean changed(int fieldIndex) {
return changed.get(safeIndex(fieldIndex));
}
@Override
public final boolean changed(String fieldName) {
return changed(indexOrFail(fieldsRow(), fieldName));
}
@Override
public final void changed(boolean c) {
changed.set(0, values.length, c);
// [#1995] If a value is meant to be "unchanged", the "original" should
// match the supposedly "unchanged" value.
if (!c) {
System.arraycopy(values, 0, originals, 0, values.length);
}
}
@Override
public final void changed(Field> field, boolean c) {
changed(indexOrFail(fieldsRow(), field), c);
}
@Override
public final void changed(int fieldIndex, boolean c) {
safeIndex(fieldIndex);
changed.set(fieldIndex, c);
// [#1995] If a value is meant to be "unchanged", the "original" should
// match the supposedly "unchanged" value.
if (!c)
originals[fieldIndex] = values[fieldIndex];
}
@Override
public final void changed(String fieldName, boolean c) {
changed(indexOrFail(fieldsRow(), fieldName), c);
}
@Override
public final void reset() {
changed.clear();
System.arraycopy(originals, 0, values, 0, originals.length);
}
@Override
public final void reset(Field> field) {
reset(indexOrFail(fieldsRow(), field));
}
@Override
public final void reset(int fieldIndex) {
safeIndex(fieldIndex);
changed.clear(fieldIndex);
values[fieldIndex] = originals[fieldIndex];
}
@Override
public final void reset(String fieldName) {
reset(indexOrFail(fieldsRow(), fieldName));
}
@Override
public final Object[] intoArray() {
return into(Object[].class);
}
@Override
public final List