// Path: src/main/java/com/jajja/jorm/Row.java
//     public static class Field {
//         private Object value = null;
//         private boolean isChanged = false;
// 
//         Field() {}
// 
//         public Field(Object value) {
//             setValue(value);
//             setChanged(true);
//         }
// 
//         void setValue(Object value) {
//             this.value = value;
//         }
// 
//         public <T> T value(Class<T> type) {
//             return convert(value, type);
//         }
// 
//         public Object rawValue() {
//             return value;
//         }
// 
//         public Record record() {
//             return (value instanceof Record) ? ((Record)value) : null;
//         }
// 
// //        @SuppressWarnings("unchecked")
// //        public <T extends Record> T ref(Transaction t, Class<T> clazz) throws SQLException {
// //            if (record() == null) {
// //              if (isReferenceCacheOnly) {
// //                  return null;
// //              }
// //              if (!flag(FLAG_REF_FETCH)) {
// //                  throw new IllegalAccessError("Reference fetching is disabled");
// //              }
// //              setValue(t.findById((Class<? extends Record>)clazz, value));
// //            }
// //            return (T)record();
// //        }
// 
//         public Object dereference() {
//             return (value instanceof Record) ? ((Record)value).id() : value;
//         }
// 
//         void setChanged(boolean isChanged) {
//             this.isChanged = isChanged;
//         }
// 
//         public boolean isChanged() {
//             return isChanged;
//         }
// 
//         @Override
//         public String toString() {
//             return String.format("Field [value => %s, isChanged => %s]", value, isChanged);
//         }
// 
//         @Override
//         public boolean equals(Object obj) {
//             if (obj instanceof Field) {
//                 Object v = ((Field)obj).value;
//                 return (value == v || (value != null && value.equals(v)));
//             }
//             return false;
//         }
// 
//         @Override
//         public int hashCode() {
//             return (value != null) ? value.hashCode() : 0;
//         }
//     }


import com.jajja.jorm.Row.Field;
/*
 * Copyright (C) 2014 Jajja Communications AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.jajja.jorm;


public class Composite {
    private final String[] columns;
    private int hashCode = 0;
    private boolean hashCodeSet = false;

    public Composite(String ... columns) {
        this.columns = StringPool.array(columns);
    }

    public static Composite get(Object o) {
        if (o instanceof String) {
            return new Composite((String)o);
        } else if (o instanceof Composite) {
            return (Composite)o;
        }
        throw new IllegalArgumentException();
    }

    public Value valueFrom(Row row) {
        Object[] values = new Object[columns.length];
        for (int i = 0; i < columns.length; i++) {
            values[i] = row.get(columns[i]);
        }
        return new Value(this, values);
    }

    public Value valueFrom(Row row, boolean noRefresh) {
        if (!noRefresh) {
            return valueFrom(row);
        }
        Object[] values = new Object[columns.length];
        for (int i = 0; i < columns.length; i++) {
// Path: src/main/java/com/jajja/jorm/Row.java
//     public static class Field {
//         private Object value = null;
//         private boolean isChanged = false;
// 
//         Field() {}
// 
//         public Field(Object value) {
//             setValue(value);
//             setChanged(true);
//         }
// 
//         void setValue(Object value) {
//             this.value = value;
//         }
// 
//         public <T> T value(Class<T> type) {
//             return convert(value, type);
//         }
// 
//         public Object rawValue() {
//             return value;
//         }
// 
//         public Record record() {
//             return (value instanceof Record) ? ((Record)value) : null;
//         }
// 
// //        @SuppressWarnings("unchecked")
// //        public <T extends Record> T ref(Transaction t, Class<T> clazz) throws SQLException {
// //            if (record() == null) {
// //              if (isReferenceCacheOnly) {
// //                  return null;
// //              }
// //              if (!flag(FLAG_REF_FETCH)) {
// //                  throw new IllegalAccessError("Reference fetching is disabled");
// //              }
// //              setValue(t.findById((Class<? extends Record>)clazz, value));
// //            }
// //            return (T)record();
// //        }
// 
//         public Object dereference() {
//             return (value instanceof Record) ? ((Record)value).id() : value;
//         }
// 
//         void setChanged(boolean isChanged) {
//             this.isChanged = isChanged;
//         }
// 
//         public boolean isChanged() {
//             return isChanged;
//         }
// 
//         @Override
//         public String toString() {
//             return String.format("Field [value => %s, isChanged => %s]", value, isChanged);
//         }
// 
//         @Override
//         public boolean equals(Object obj) {
//             if (obj instanceof Field) {
//                 Object v = ((Field)obj).value;
//                 return (value == v || (value != null && value.equals(v)));
//             }
//             return false;
//         }
// 
//         @Override
//         public int hashCode() {
//             return (value != null) ? value.hashCode() : 0;
//         }
//     }


// Path: src/main/java/com/jajja/jorm/Composite.java
import com.jajja.jorm.Row.Field;

/*
 * Copyright (C) 2014 Jajja Communications AB
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.jajja.jorm;


public class Composite {
    private final String[] columns;
    private int hashCode = 0;
    private boolean hashCodeSet = false;

    public Composite(String ... columns) {
        this.columns = StringPool.array(columns);
    }

    public static Composite get(Object o) {
        if (o instanceof String) {
            return new Composite((String)o);
        } else if (o instanceof Composite) {
            return (Composite)o;
        }
        throw new IllegalArgumentException();
    }

    public Value valueFrom(Row row) {
        Object[] values = new Object[columns.length];
        for (int i = 0; i < columns.length; i++) {
            values[i] = row.get(columns[i]);
        }
        return new Value(this, values);
    }

    public Value valueFrom(Row row, boolean noRefresh) {
        if (!noRefresh) {
            return valueFrom(row);
        }
        Object[] values = new Object[columns.length];
        for (int i = 0; i < columns.length; i++) {
            Field field = row.field(columns[i]);