StructGetter.java
/***************************************************************************
Copyright 2012 Emily Estes
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.
***************************************************************************/
package net.metanotion.sqlc;
import java.sql.ResultSet;
import net.metanotion.util.reflect.Initializer;
import net.metanotion.scripting.StructManager;
import net.metanotion.sqlc.setters.RSGetter;
public final class StructGetter implements net.metanotion.util.types.Parser<Object> {
public final RSGetter[] fields;
public final StructManager sm;
public final String struct;
public StructGetter(RSGetter[] fields, StructManager sm, String struct) {
this.fields = fields;
this.sm = sm;
this.struct = struct;
}
@Override public Object parse(final Object o) throws Exception {
final ResultSet data = (ResultSet) o;
Initializer c = sm.getStruct(struct);
for(RSGetter f: fields) { c.put(f.name, f.get(data)); }
return c.instance();
}
@Override public Class<Object> outputInterface() { return Object.class; }
}