本文整理汇总了Java中org.apache.ojb.broker.metadata.FieldDescriptor.getColumnName方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor.getColumnName方法的具体用法?Java FieldDescriptor.getColumnName怎么用?Java FieldDescriptor.getColumnName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.metadata.FieldDescriptor
的用法示例。
在下文中一共展示了FieldDescriptor.getColumnName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getColName
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
{
FieldDescriptor fld = null;
String result;
if (translate)
{
fld = getFieldDescriptor(aTableAlias, aPathInfo);
}
if (fld != null)
{
// BRJ : No alias for delete
result = fld.getColumnName();
}
else
{
result = aPathInfo.column;
}
return result;
}
示例2: customizeQuery
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的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;
}
示例3: extractOjbConcreteClass
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
protected String extractOjbConcreteClass(ClassDescriptor cld, ResultSet rs, Map row)
{
FieldDescriptor fld = m_cld.getOjbConcreteClassField();
if (fld == null)
{
return null;
}
try
{
Object tmp = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
// allow field-conversion for discriminator column too
String result = (String) fld.getFieldConversion().sqlToJava(tmp);
result = result != null ? result.trim() : null;
if (result == null || result.length() == 0)
{
throw new PersistenceBrokerException(
"ojbConcreteClass field for class " + cld.getClassNameOfObject()
+ " returned null or 0-length string");
}
else
{
/*
arminw: Make sure that we don't read discriminator field twice from the ResultSet.
*/
row.put(fld.getColumnName(), result);
return result;
}
}
catch(SQLException e)
{
throw new PersistenceBrokerException("Unexpected error while try to read 'ojbConcretClass'" +
" field from result set using column name " + fld.getColumnName() + " main class" +
" was " + m_cld.getClassNameOfObject(), e);
}
}
示例4: buildForeignKey
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的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());
}
示例5: createSequence
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
/**
* Creates new row in table
* @param broker
* @param field
* @param sequenceName
* @param maxKey
* @throws Exception
*/
protected void createSequence(PersistenceBroker broker, FieldDescriptor field,
String sequenceName, long maxKey) throws Exception
{
Statement stmt = null;
try
{
stmt = broker.serviceStatementManager().getGenericStatement(field.getClassDescriptor(), Query.NOT_SCROLLABLE);
stmt.execute(sp_createSequenceQuery(sequenceName, maxKey));
}
catch (Exception e)
{
log.error(e);
throw new SequenceManagerException("Could not create new row in "+SEQ_TABLE_NAME+" table - TABLENAME=" +
sequenceName + " field=" + field.getColumnName(), e);
}
finally
{
try
{
if (stmt != null) stmt.close();
}
catch (SQLException sqle)
{
if(log.isDebugEnabled())
log.debug("Threw SQLException while in createSequence and closing stmt", sqle);
// ignore it
}
}
}
示例6: customizeQuery
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的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;
}
示例7: getAnnotationNodes
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
List<MemberValuePair> pairs = new ArrayList<MemberValuePair>();
final String access = fd.getAccess();
if ("readonly".equals(access)) {
pairs.add(new MemberValuePair("insertable", new BooleanLiteralExpr(false)));
pairs.add(new MemberValuePair("updatable", new BooleanLiteralExpr(false)));
} else if ("readwrite".equals(access)) {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field access is readwrite keeping @Column attributes (insertable, updatable) at defaults");
} else if ("anonymous".equals(access)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field access is anonymous, the field should not exist in the java class as is the meaning anonymous access");
} else if (access == null) {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field access is null keeping @Column attributes (insertable, updatable) at defaults");
} else {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field access is " + access + ", unsupported conversion to @Column attributes");
}
final String columnName = fd.getColumnName();
if (StringUtils.isNotBlank(columnName)) {
pairs.add(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? columnName.toUpperCase() : columnName)));
} else {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field column is blank");
}
/* don't bother with column type attribute...this is mostly taken care of automatically by JPA
final String columnType = fd.getColumnType();
if (StringUtils.isNotBlank(columnType)) {
LOG.error(enclosingClass + "." + fieldName + " for the mapped class " + mappedClass + " field column type is " + columnType + ", unsupported conversion to @Column attributes");
}
*/
final boolean required = fd.isRequired();
if (required) {
pairs.add(new MemberValuePair("nullable", new BooleanLiteralExpr(false)));
} else {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field is nullable keeping @Column attribute (nullable) at default");
}
final int length = fd.getLength();
if (length > 0) {
pairs.add(new MemberValuePair("length", new IntegerLiteralExpr(String.valueOf(length))));
} else {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field length is not set keeping @Column attribute (length) at default");
}
final int precision = fd.getPrecision();
if (precision > 0) {
pairs.add(new MemberValuePair("precision", new IntegerLiteralExpr(String.valueOf(precision))));
} else {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field precision is not set keeping @Column attribute (precision) at default");
}
final int scale = fd.getScale();
if (scale > 0) {
pairs.add(new MemberValuePair("scale", new IntegerLiteralExpr(String.valueOf(scale))));
} else {
LOG.debug(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field scale is not set keeping @Column attribute (scale) at default");
}
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), pairs),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
return null;
}
示例8: getColName
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
/**
* Answer the column name for alias and path info<br>
* if translate try to convert attribute name into column name otherwise use attribute name<br>
* if a FieldDescriptor is found for the attribute name the column name is taken from
* there prefixed with the alias (firstname -> A0.F_NAME).
*/
protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
{
String result = null;
// no translation required, use attribute name
if (!translate)
{
return aPathInfo.column;
}
// BRJ: special alias for the indirection table has no ClassDescriptor
if (aTableAlias.cld == null && M_N_ALIAS.equals(aTableAlias.alias))
{
return getIndirectionTableColName(aTableAlias, aPathInfo.path);
}
// translate attribute name into column name
FieldDescriptor fld = getFieldDescriptor(aTableAlias, aPathInfo);
if (fld != null)
{
m_attrToFld.put(aPathInfo.path, fld);
// added to suport the super reference descriptor
if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table) && aTableAlias.hasJoins())
{
Iterator itr = aTableAlias.joins.iterator();
while (itr.hasNext())
{
Join join = (Join) itr.next();
if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
{
result = join.right.alias + "." + fld.getColumnName();
break;
}
}
if (result == null)
{
result = aPathInfo.column;
}
}
else
{
result = aTableAlias.alias + "." + fld.getColumnName();
}
}
else if ("*".equals(aPathInfo.column))
{
result = aPathInfo.column;
}
else
{
// throw new IllegalArgumentException("No Field found for : " + aPathInfo.column);
result = aPathInfo.column;
}
return result;
}
示例9: getMaxIdForClass
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的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;
}