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) 1998-2018 Caucho Technology -- all rights reserved
*
* This file is part of Resin(R) Open Source
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Resin Open Source is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Resin Open Source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
* of NON-INFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with Resin Open Source; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Scott Ferguson
*/
package com.caucho.amber.field;
import com.caucho.amber.expr.AmberExpr;
import com.caucho.amber.expr.PathExpr;
import com.caucho.amber.manager.AmberConnection;
import com.caucho.amber.manager.AmberPersistenceUnit;
import com.caucho.amber.query.QueryParser;
import com.caucho.amber.table.AmberTable;
import com.caucho.amber.table.AmberColumn;
import com.caucho.amber.type.AmberBeanType;
import com.caucho.amber.type.EntityType;
import com.caucho.bytecode.JType;
import com.caucho.bytecode.JTypeWrapper;
import com.caucho.config.ConfigException;
import com.caucho.java.JavaWriter;
import com.caucho.util.CharBuffer;
import com.caucho.util.L10N;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Configuration for a bean's property
*/
abstract public class AbstractField implements AmberField {
private static final L10N L = new L10N(AbstractField.class);
private static final Logger log
= Logger.getLogger(AbstractField.class.getName());
final AmberBeanType _sourceType;
private String _name;
private JType _type;
private Method _getterMethod;
private Method _setterMethod;
private boolean _isLazy = true;
private boolean _isOverride;
private int _updateIndex;
private int _loadGroupIndex = -1;
AbstractField(AmberBeanType sourceType)
{
_sourceType = sourceType;
}
AbstractField(AmberBeanType sourceType, String name)
throws ConfigException
{
this(sourceType);
setName(name);
if (log.isLoggable(Level.FINER))
log.finer(_sourceType + " field " + this);
}
/**
* Sets the name.
*/
public void setName(String name)
throws ConfigException
{
_name = name;
ClassLoader loader
= getSourceType().getPersistenceUnit().getTempClassLoader();
if (! isFieldAccess()) {
char ch = name.charAt(0);
if (Character.isLowerCase(ch))
name = Character.toUpperCase(ch) + name.substring(1);
String getter = "get" + name;
String setter = "set" + name;
_getterMethod = AmberBeanType.getGetter(getBeanClass(), getter);
if (_getterMethod == null) {
getter = "is" + name;
_getterMethod = AmberBeanType.getGetter(getBeanClass(), getter);
}
/* jpa/0u21
if (_getterMethod == null)
throw new ConfigException(L.l("{0}: {1} has no matching getter.",
getBeanClass().getName(), name));
*/
if (_getterMethod == null) {
Field field = AmberBeanType.getField(getBeanClass(), _name);
if (field == null)
throw new ConfigException(L.l("{0}: {1} has no matching field.",
getBeanClass().getName(), _name));
_type = JTypeWrapper.create(field.getGenericType(), loader);
}
else {
_type = JTypeWrapper.create(_getterMethod.getGenericReturnType(),
loader);
_setterMethod = AmberBeanType.getSetter(getBeanClass(), setter);
}
}
else {
Field field = AmberBeanType.getField(getBeanClass(), name);
if (field == null)
throw new ConfigException(L.l("{0}: {1} has no matching field.",
getBeanClass().getName(), name));
_type = JTypeWrapper.create(field.getGenericType(), loader);
}
/*
if (_setterMethod == null && ! isAbstract())
throw new ConfigException(L.l("{0}: {1} has no matching setter.",
getBeanClass().getName(), name));
*/
}
/**
* Returns the field name.
*/
public String getName()
{
return _name;
}
/**
* Sets the java type.
*/
protected void setJavaType(JType type)
{
_type = type;
}
/**
* Returns the owning entity class.
*/
public AmberBeanType getSourceType()
{
return _sourceType;
}
/**
* Returns the amber manager.
*/
public AmberPersistenceUnit getPersistenceUnit()
{
return getSourceType().getPersistenceUnit();
}
/**
* Returns the bean class.
*/
public Class getBeanClass()
{
return getSourceType().getBeanClass();
}
/**
* Returns the source type as
* entity or mapped-superclass.
*/
public EntityType getEntitySourceType()
{
return (EntityType) getSourceType();
}
/**
* Returns the table containing the field's columns.
*/
public AmberTable getTable()
{
return getEntitySourceType().getTable();
}
/**
* Returns the column for the field
*/
public AmberColumn getColumn()
{
return null;
}
/**
* Returns the column for the field
*/
public void setColumn(AmberColumn column)
{
}
/**
* Returns the property index.
*/
public int getIndex()
{
return _updateIndex;
}
/**
* Set the property index.
*/
public void setIndex(int index)
{
_updateIndex = index;
}
/**
* Returns the property's group index.
*/
public int getLoadGroupIndex()
{
return _loadGroupIndex;
}
/**
* Returns the property's group index.
*/
protected void setLoadGroupIndex(int index)
{
_loadGroupIndex = index;
}
/**
* Returns the load group mask.
*/
public long getCreateLoadMask(int group)
{
int index = getLoadGroupIndex();
if (64 * group <= index && index < 64 * (group + 1))
return 1L << (index % 64);
else
return 0;
}
/**
* Returns true for a lazy field.
*/
public boolean isLazy()
{
return _isLazy;
}
/**
* Set true for a lazy field.
*/
public void setLazy(boolean isLazy)
{
_isLazy = isLazy;
}
/**
* Returns true for an override
*/
public boolean isOverride()
{
return _isOverride;
}
/**
* Returns true for an override
*/
public void setOverride(boolean isOverride)
{
_isOverride = isOverride;
}
/**
* Returns true for a key
*/
public boolean isKey()
{
return false;
}
/**
* Returns the getter name.
*/
public String getJavaTypeName()
{
return getJavaTypeName(getJavaClass());
}
/**
* Returns the Java code for the type.
*/
private String getJavaTypeName(Class cl)
{
if (cl.isArray())
return getJavaTypeName(cl.getComponentType()) + "[]";
else
return cl.getName();
}
/**
* Returns the field's type
*/
public JType getJavaType()
{
return _type;
}
/**
* Returns the field's class
*/
public Class getJavaClass()
{
return getJavaType().getRawType().getJavaClass();
}
/**
* Returns true if values are accessed by the fields.
*/
public boolean isFieldAccess()
{
return getSourceType().isFieldAccess();
}
/**
* Returns true if the methods are abstract.
*/
public boolean isAbstract()
{
// jpa/0u21
return (_getterMethod != null
&& Modifier.isAbstract(_getterMethod.getModifiers()));
}
/**
* Returns true if the field is cascadable.
*/
public boolean isCascadable()
{
return false;
}
/**
* Returns true if the methods are abstract.
*/
public boolean isUpdateable()
{
return true;
}
/**
* Creates a copy of the field for a parent
*/
public AmberField override(AmberBeanType table)
{
throw new UnsupportedOperationException(getClass().getName());
}
/**
* Initialize the field.
*/
public void init()
throws ConfigException
{
if (_loadGroupIndex < 0) {
if (_isLazy)
_loadGroupIndex = getEntitySourceType().nextLoadGroupIndex();
else
_loadGroupIndex = getEntitySourceType().getDefaultLoadGroupIndex();
}
}
/**
* Generates the post constructor initialization.
*/
public void generatePostConstructor(JavaWriter out)
throws IOException
{
}
/**
* Generates any prologue.
*/
public void generatePrologue(JavaWriter out, HashSet