本文整理汇总了Java中org.apache.ojb.broker.metadata.ClassDescriptor.getFieldDescriptorByName方法的典型用法代码示例。如果您正苦于以下问题:Java ClassDescriptor.getFieldDescriptorByName方法的具体用法?Java ClassDescriptor.getFieldDescriptorByName怎么用?Java ClassDescriptor.getFieldDescriptorByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.metadata.ClassDescriptor
的用法示例。
在下文中一共展示了ClassDescriptor.getFieldDescriptorByName方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getValue
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* retrieve the value of attribute[fieldNum] from the object.
* @return Object the value of attribute[fieldNum]
*/
Object getValue(int fieldNum)
{
String attributeName = getAttributeName(fieldNum);
ClassDescriptor cld = broker.getClassDescriptor(pc.getClass());
// field could be a primitive typed attribute...
AttributeDescriptorBase fld = cld.getFieldDescriptorByName(attributeName);
// field could be a reference attribute...
if (fld == null)
{
fld = cld.getObjectReferenceDescriptorByName(attributeName);
}
// or it could be a collection attribute:
if (fld == null)
{
fld = cld.getCollectionDescriptorByName(attributeName);
}
Object value = fld.getPersistentField().get(pc);
return value;
}
示例2: checkArguments
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
@Override
public void checkArguments(Class<? extends PersistableBusinessObject> businessObjectClass, Set<String> attributeNames, boolean checkOjbEncryptConfig) {
if ((businessObjectClass == null) || (attributeNames == null)) {
throw new IllegalArgumentException(
"PostDataLoadEncryptionServiceImpl.encrypt does not allow a null business object Class or attributeNames Set");
}
final ClassDescriptor classDescriptor;
try {
classDescriptor = getClassDescriptor(businessObjectClass);
} catch (ClassNotPersistableException e) {
throw new IllegalArgumentException(
"PostDataLoadEncryptionServiceImpl.encrypt does not handle business object classes that do not have a corresponding ClassDescriptor defined in the OJB repository",
e);
}
for (String attributeName : attributeNames) {
if (classDescriptor.getFieldDescriptorByName(attributeName) == null) {
throw new IllegalArgumentException(
new StringBuffer("Attribute ")
.append(attributeName)
.append(
" specified to PostDataLoadEncryptionServiceImpl.encrypt is not in the OJB repository ClassDescriptor for Class ")
.append(businessObjectClass).toString());
}
if (checkOjbEncryptConfig && !(classDescriptor.getFieldDescriptorByName(attributeName).getFieldConversion() instanceof OjbKualiEncryptDecryptFieldConversion)) {
throw new IllegalArgumentException(
new StringBuffer("Attribute ")
.append(attributeName)
.append(" of business object Class ")
.append(businessObjectClass)
.append(
" specified to PostDataLoadEncryptionServiceImpl.encrypt is not configured for encryption in the OJB repository")
.toString());
}
}
}
示例3: isMappedColumn
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
public static boolean isMappedColumn(String clazz, String fieldName, Collection<DescriptorRepository> descriptorRepositories) {
final ClassDescriptor cd = findClassDescriptor(clazz, descriptorRepositories);
if (cd != null) {
return cd.getFieldDescriptorByName(fieldName) != null ||
cd.getObjectReferenceDescriptorByName(fieldName) != null ||
cd.getCollectionDescriptorByName(fieldName) != null;
}
return false;
}
示例4: customizeQuery
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* In addition to what the referenced method does, this also fixes a mysql order by issue (see class comments)
*
* @see org.apache.ojb.broker.accesslayer.QueryCustomizerDefaultImpl#customizeQuery(java.lang.Object,
* org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
* org.apache.ojb.broker.query.QueryByCriteria)
*/
@Override
public Query customizeQuery(Object anObject, PersistenceBroker broker, CollectionDescriptor cod, QueryByCriteria query) {
boolean platformMySQL = broker.serviceSqlGenerator().getPlatform() instanceof PlatformMySQLImpl;
Map<String, String> attributes = getAttributes();
for (String attributeName : attributes.keySet()) {
if (!attributeName.startsWith(ORDER_BY_FIELD)) {
continue;
}
String fieldName = attributeName.substring(ORDER_BY_FIELD.length());
ClassDescriptor itemClassDescriptor = broker.getClassDescriptor(cod.getItemClass());
FieldDescriptor orderByFieldDescriptior = itemClassDescriptor.getFieldDescriptorByName(fieldName);
// the column to sort on derived from the property name
String orderByColumnName = orderByFieldDescriptior.getColumnName();
// ascending or descending
String fieldValue = attributes.get(attributeName);
boolean ascending = (StringUtils.equals(fieldValue, ASCENDING));
// throw an error if not ascending or descending
if (!ascending && StringUtils.equals(fieldValue, DESCENDING)) {
throw new RuntimeException("neither ASC nor DESC was specified in ojb file for " + fieldName);
}
if (platformMySQL) {
// by negating the column name in MySQL we can get nulls last (ascending or descending)
String mysqlPrefix = (ascending) ? MYSQL_NEGATION : "";
query.addOrderBy(mysqlPrefix + orderByColumnName, false);
} else {
query.addOrderBy(orderByColumnName, ascending);
}
}
return query;
}
示例5: getExtentClasses
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* Searches the class descriptor for the ojbConcrete class attribute
* if it finds the concrete class attribute, append a where clause which
* specifies we can load all classes that are this type or extents of this type.
* @param cld
* @return the extent classes
*/
private static Collection getExtentClasses(ClassDescriptor cld)
{
/**
* 1. check if this class has a ojbConcreteClass attribute
*/
FieldDescriptor fd = cld.getFieldDescriptorByName(ClassDescriptor.OJB_CONCRETE_CLASS);
Collection classes = new HashSet(); // use same class only once
if (fd != null)
{
classes.add(cld.getClassOfObject().getName());
}
/**
* 2. if this class has extents/is an extent search for all extents
*/
if (cld.isExtent())
{
Vector extentClasses = cld.getExtentClasses();
/**
* 3. get all extents for this class
*/
for (int i = 0; i < extentClasses.size(); i++)
{
Class ec = (Class) extentClasses.get(i);
ClassDescriptor extCld = cld.getRepository().getDescriptorFor(ec);
classes.addAll(getExtentClasses(extCld));
}
}
return classes;
}
示例6: getFldFromJoin
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* Get FieldDescriptor from joined superclass.
*/
private FieldDescriptor getFldFromJoin(TableAlias aTableAlias, String aColName)
{
FieldDescriptor fld = null;
// Search Join Structure for attribute
if (aTableAlias.joins != null)
{
Iterator itr = aTableAlias.joins.iterator();
while (itr.hasNext())
{
Join join = (Join) itr.next();
ClassDescriptor cld = join.right.cld;
if (cld != null)
{
fld = cld.getFieldDescriptorByName(aColName);
if (fld != null)
{
break;
}
}
}
}
return fld;
}
示例7: buildForeignKey
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
private void buildForeignKey(ClassDescriptor foreignClassDescriptor, Vector foreignKeyIndices, ClassDescriptor classDescriptor) {
if(classDescriptor.isAbstract() || classDescriptor.isInterface())
{
logger.debug( "Skip foreign key build, found abstract base class or interface " + classDescriptor.getClassNameOfObject() );
return;
}
StringBuffer buffer = new StringBuffer(256);
buildForeignKeyHeader(foreignClassDescriptor.getFullTableName(), buffer);
for (int i = 0; i < foreignKeyIndices.size(); i++) {
String columnName = null;
Object obj = foreignKeyIndices.get(i);
if (obj instanceof Integer)
{
int foreignKeyIndex = ((Integer) obj).intValue();
columnName = classDescriptor.getFieldDescriptorByIndex(foreignKeyIndex).getColumnName();
}
else
{
FieldDescriptor fld = classDescriptor.getFieldDescriptorByName((String) obj);
if(fld == null)
{
logger.debug( "FieldDescriptor for foreign key parameter \n" + obj + " was not found in ClassDescriptor \n" + classDescriptor );
}
else columnName = fld.getColumnName();
}
FieldDescriptor foreignColumn = foreignClassDescriptor.getPkFields()[i];
String foreignColumnName = foreignColumn.getColumnName();
buildReferenceForColumn(buffer, columnName, foreignColumnName);
}
buffer.append(" </foreign-key>\n");
addReferenceToTable(classDescriptor.getFullTableName(), buffer.toString());
}
示例8: customizeQuery
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* In addition to what the referenced method does, this also fixes a mysql order by issue (see class comments)
* @see org.apache.ojb.broker.accesslayer.QueryCustomizerDefaultImpl#customizeQuery(java.lang.Object,
* org.apache.ojb.broker.PersistenceBroker, org.apache.ojb.broker.metadata.CollectionDescriptor,
* org.apache.ojb.broker.query.QueryByCriteria)
*/
@Override
public Query customizeQuery(Object anObject, PersistenceBroker broker, CollectionDescriptor cod, QueryByCriteria query) {
boolean platformMySQL = broker.serviceSqlGenerator().getPlatform() instanceof PlatformMySQLImpl;
Map<String, String> attributes = getAttributes();
for (String attributeName : attributes.keySet()) {
if (!attributeName.startsWith(ORDER_BY_FIELD)) {
continue;
}
String fieldName = attributeName.substring(ORDER_BY_FIELD.length());
ClassDescriptor itemClassDescriptor = broker.getClassDescriptor(cod.getItemClass());
FieldDescriptor orderByFieldDescriptior = itemClassDescriptor.getFieldDescriptorByName(fieldName);
// the column to sort on derived from the property name
String orderByColumnName = orderByFieldDescriptior.getColumnName();
// ascending or descending
String fieldValue = attributes.get(attributeName);
boolean ascending = (StringUtils.equals(fieldValue, ASCENDING));
// throw an error if not ascending or descending
if (!ascending && StringUtils.equals(fieldValue, DESCENDING)) {
throw new RuntimeException("neither ASC nor DESC was specified in ojb file for " + fieldName);
}
if (platformMySQL) {
// by negating the column name in MySQL we can get nulls last (ascending or descending)
String mysqlPrefix = (ascending) ? MYSQL_NEGATION : "";
query.addOrderBy(mysqlPrefix + orderByColumnName, false);
}
else {
query.addOrderBy(orderByColumnName, ascending);
}
}
return query;
}
示例9: findFieldDescriptor
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
public static FieldDescriptor findFieldDescriptor(String clazz, String fieldName, Collection<DescriptorRepository> descriptorRepositories) {
final ClassDescriptor cd = findClassDescriptor(clazz, descriptorRepositories);
return cd != null ? cd.getFieldDescriptorByName(fieldName) : null;
}
示例10: processDumpDataDictionary_MaintenanceDocumentCollections
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
protected void processDumpDataDictionary_MaintenanceDocumentCollections(Class<BusinessObject> boClass) {
DataDictionaryDumperSection detailSection = getDetailSectionForBoClass(boClass);
detailSection.setCollection(true);
if (boClass != null) {
ClassDescriptor cd = dr.getDescriptorFor(boClass);
List<MaintainableSectionDefinition> sections = maintDocSvc.getMaintainableSections(jstlKey);
Collection<ReferenceDefinition> existenceChecks = maintDocSvc.getDefaultExistenceChecks(jstlKey);
Collection<AttributeDefinition> items = ddSvc.getDataDictionary().getBusinessObjectEntry(boClass.getSimpleName()).getAttributes();
for (AttributeDefinition item : items) {
DataDictionaryDumperDocumentRow detailRow = new DataDictionaryDumperDocumentRow();
//System.out.println(entityClass + " item name " + item.getName() + " item class " + item.getClass());
if (item.getName().endsWith("versionNumber")) {
continue;
}
StringBuilder row = new StringBuilder(1000);
FieldDescriptor fd = cd.getFieldDescriptorByName(item.getName());
LookupDefinition ld = null;
InquiryDefinition id = null;
if (ddSvc.getDataDictionary().getBusinessObjectEntry(boClass.getSimpleName()) != null) {
ld = ((BusinessObjectEntry)ddSvc.getDataDictionary().getBusinessObjectEntry(boClass.getSimpleName())).getLookupDefinition();
id = ((BusinessObjectEntry)ddSvc.getDataDictionary().getBusinessObjectEntry(boClass.getSimpleName())).getInquiryDefinition();
}
List<String> lookupFields = (ld == null) ? Collections.EMPTY_LIST : ld.getLookupFieldNames();
List<String> resultFields = (ld == null) ? Collections.EMPTY_LIST : ld.getResultFieldNames();
detailRow.setName(ddSvc.getAttributeLabel(boClass, item.getName()));
detailRow.setFieldName(item.getName());
detailRow.setRequired(item.isRequired());
if (ddSvc.getAttributeValidatingExpression(boClass, item.getName()) != null) {
detailRow.setValidationRules(ddSvc.getAttributeValidatingExpression(boClass, item.getName()).toString());
}
else {
detailRow.setValidationRules("(null)");
}
if (ddSvc.getAttributeMaxLength(boClass, item.getName()) != null) {
detailRow.setMaxLength(ddSvc.getAttributeMaxLength(boClass, item.getName()).toString());
}
else {
detailRow.setMaxLength("(null)");
}
detailRow.setExistenceCheck(hasExistenceCheck(existenceChecks, item.getName()));
detailRow.setLookupParam(lookupFields.contains(item.getName()));
detailRow.setLookupResult(resultFields.contains(item.getName()));
try {
String fullControlDefinition = ddSvc.getAttributeControlDefinition(boClass, item.getName()).getClass().getSimpleName();
detailRow.setControlDefinition(fullControlDefinition.substring(0, fullControlDefinition.indexOf("ControlDefinition")));
}
catch (NullPointerException npe) {
// Probably from a collection at .getClass
break;
}
AttributeSecurity fieldSecurity = ddSvc.getAttributeSecurity(boClass.getName(), item.getName());
if (fieldSecurity != null) {
detailRow.setFieldSecurity((fieldSecurity.isHide() ? "Hide<br>" : "") + (fieldSecurity.isMask() ? "Mask<br>" : "") + (fieldSecurity.isPartialMask() ? "Partial Mask<br>" : "") + (fieldSecurity.isReadOnly() ? "Read Only" : ""));
}
else {
detailRow.setFieldSecurity("");
}
if (fd != null) {
detailRow.setFieldType(fd.getColumnType());
detailRow.setColumn(fd.getColumnName());
detailRow.setColumnNo(fd.getColNo());
rowList.add(detailRow);
}
else {
unprocessedRows.add(detailRow);
}
}
}
Collections.sort(rowList);
detailSection.setDocumentRows(rowList);
sectionList.add(detailSection);
}
示例11: processMetaData
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
public Object processMetaData(DatabaseMetaData databaseMetaData) throws SQLException, MetaDataAccessException {
Class workingBusinessObjectClass = businessObjectClass;
String workingPropertyName = propertyName;
while (workingPropertyName.contains(".")) {
try {
workingBusinessObjectClass = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass).getObjectReferenceDescriptorByName(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).getItemClass();
}
catch (Exception e1) {
LOG.debug(new StringBuffer("Unable to get property type via reference descriptor for property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" of BusinessObject class ").append(workingBusinessObjectClass).toString(), e1);
try {
workingBusinessObjectClass = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass).getCollectionDescriptorByName(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).getItemClass();
}
catch (Exception e2) {
LOG.debug(new StringBuffer("Unable to get property type via collection descriptor of property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" of BusinessObject class ").append(workingBusinessObjectClass).toString(), e2);
BusinessObject businessObject = null;
try {
businessObject = (BusinessObject)workingBusinessObjectClass.newInstance();
}
catch (Exception e3) {
if (LOG.isDebugEnabled()) {
LOG.debug("Unable to instantiate BusinessObject class " + workingBusinessObjectClass, e3);
}
return populateAndReturnNonPersistableInstance();
}
try {
workingBusinessObjectClass = PropertyUtils.getPropertyType(businessObject, workingPropertyName.substring(0, workingPropertyName.indexOf(".")));
}
catch (Exception e4) {
LOG.debug(new StringBuffer("Unable to get type of property ").append(workingPropertyName.substring(0, workingPropertyName.indexOf("."))).append(" for BusinessObject class ").append(workingBusinessObjectClass).toString(), e4);
return populateAndReturnNonPersistableInstance();
}
}
}
if (workingBusinessObjectClass == null) {
return populateAndReturnNonPersistableInstance();
}
else {
workingPropertyName = workingPropertyName.substring(workingPropertyName.indexOf(".") + 1);
}
}
if (!PersistableBusinessObject.class.isAssignableFrom(workingBusinessObjectClass)) {
return populateAndReturnNonPersistableInstance();
}
ClassDescriptor classDescriptor = org.apache.ojb.broker.metadata.MetadataManager.getInstance().getGlobalRepository().getDescriptorFor(workingBusinessObjectClass);
if (classDescriptor == null) {
return populateAndReturnNonPersistableInstance();
}
tableName = classDescriptor.getFullTableName();
if (classDescriptor.getFieldDescriptorByName(workingPropertyName) == null) {
return populateAndReturnNonPersistableInstance();
}
columnName = classDescriptor.getFieldDescriptorByName(workingPropertyName).getColumnName();
ResultSet resultSet = databaseMetaData.getColumns(null, null, tableName, columnName);
if (resultSet.next()) {
dataType = resultSet.getString("TYPE_NAME");
length = resultSet.getInt("COLUMN_SIZE");
decimalPlaces = resultSet.getInt("DECIMAL_DIGITS");
encrypted = classDescriptor.getFieldDescriptorByName(workingPropertyName).getFieldConversion() instanceof OjbKualiEncryptDecryptFieldConversion;
}
resultSet.close();
return this;
}
示例12: getMaxIdForClass
import org.apache.ojb.broker.metadata.ClassDescriptor; //导入方法依赖的package包/类
/**
* lookup current maximum value for a single field in
* table the given class descriptor was associated.
*/
public static long getMaxIdForClass(
PersistenceBroker brokerForClass, ClassDescriptor cldForOriginalOrExtent, FieldDescriptor original)
throws PersistenceBrokerException
{
FieldDescriptor field = null;
if (!original.getClassDescriptor().equals(cldForOriginalOrExtent))
{
// check if extent match not the same table
if (!original.getClassDescriptor().getFullTableName().equals(
cldForOriginalOrExtent.getFullTableName()))
{
// we have to look for id's in extent class table
field = cldForOriginalOrExtent.getFieldDescriptorByName(original.getAttributeName());
}
}
else
{
field = original;
}
if (field == null)
{
// if null skip this call
return 0;
}
String column = field.getColumnName();
long result = 0;
ResultSet rs = null;
Statement stmt = null;
StatementManagerIF sm = brokerForClass.serviceStatementManager();
String table = cldForOriginalOrExtent.getFullTableName();
// String column = cld.getFieldDescriptorByName(fieldName).getColumnName();
String sql = SM_SELECT_MAX + column + SM_FROM + table;
try
{
//lookup max id for the current class
stmt = sm.getGenericStatement(cldForOriginalOrExtent, Query.NOT_SCROLLABLE);
rs = stmt.executeQuery(sql);
rs.next();
result = rs.getLong(1);
}
catch (Exception e)
{
log.warn("Cannot lookup max value from table " + table + " for column " + column +
", PB was " + brokerForClass + ", using jdbc-descriptor " +
brokerForClass.serviceConnectionManager().getConnectionDescriptor(), e);
}
finally
{
try
{
sm.closeResources(stmt, rs);
}
catch (Exception ignore)
{
// ignore it
}
}
return result;
}