public String getTableNameOfColumn() { Column column = (Column) getAnnotation(Column.class.getName()); String tableName = null; if (column != null) { tableName = column.table(); } if (tableName == null || tableName.isEmpty()) { return null; } return tableName; } }
public void addOrderBy(Class<?> clazz, String field, boolean ascending) { if (field == null) { return; } Field f; Pair<Class<?>, Field> pair = ReflectUtil.getAnyField(clazz, field); assert (pair != null) : "Can't find field " + field + " in " + clazz.getName(); clazz = pair.first(); f = pair.second(); Column column = f.getAnnotation(Column.class); String name = column != null ? column.name() : field; StringBuilder order = new StringBuilder(); if (column == null || column.table() == null || column.table().length() == 0) { order.append(DbUtil.getTableName(clazz)); } else { order.append(column.table()); } order.append(".").append(name).append(ascending ? " ASC " : " DESC "); if (_orderBy == null) { _orderBy = order.insert(0, " ORDER BY ").toString(); } else { _orderBy = order.insert(0, _orderBy + ", ").toString(); } }
@Test public void testColumnAllAttributes() throws Exception { reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" ); assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( Column.class ); Column column = reader.getAnnotation( Column.class ); assertEquals( "col1", column.name() ); assertTrue( column.unique() ); assertFalse( column.nullable() ); assertFalse( column.insertable() ); assertFalse( column.updatable() ); assertEquals( "int", column.columnDefinition() ); assertEquals( "table1", column.table() ); assertEquals( 50, column.length() ); assertEquals( 2, column.precision() ); assertEquals( 1, column.scale() ); }
@Test public void testColumnNoAttributes() throws Exception { reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" ); assertAnnotationPresent( ElementCollection.class ); assertAnnotationPresent( Column.class ); Column column = reader.getAnnotation( Column.class ); assertEquals( "", column.name() ); assertFalse( column.unique() ); assertTrue( column.nullable() ); assertTrue( column.insertable() ); assertTrue( column.updatable() ); assertEquals( "", column.columnDefinition() ); assertEquals( "", column.table() ); assertEquals( 255, column.length() ); assertEquals( 0, column.precision() ); assertEquals( 0, column.scale() ); }
assertTrue( overrides[0].column().updatable() ); assertEquals( "", overrides[0].column().columnDefinition() ); assertEquals( "", overrides[0].column().table() ); assertEquals( 255, overrides[0].column().length() ); assertEquals( 0, overrides[0].column().precision() ); assertFalse( overrides[1].column().updatable() ); assertEquals( "int", overrides[1].column().columnDefinition() ); assertEquals( "table1", overrides[1].column().table() ); assertEquals( 50, overrides[1].column().length() ); assertEquals( 2, overrides[1].column().precision() );
assertTrue( overrides[0].column().updatable() ); assertEquals( "", overrides[0].column().columnDefinition() ); assertEquals( "", overrides[0].column().table() ); assertEquals( 255, overrides[0].column().length() ); assertEquals( 0, overrides[0].column().precision() ); assertFalse( overrides[1].column().updatable() ); assertEquals( "int", overrides[1].column().columnDefinition() ); assertEquals( "table1", overrides[1].column().table() ); assertEquals( 50, overrides[1].column().length() ); assertEquals( 2, overrides[1].column().precision() );
assertTrue( overrides[0].column().updatable() ); assertEquals( "", overrides[0].column().columnDefinition() ); assertEquals( "", overrides[0].column().table() ); assertEquals( 255, overrides[0].column().length() ); assertEquals( 0, overrides[0].column().precision() ); assertFalse( overrides[1].column().updatable() ); assertEquals( "int", overrides[1].column().columnDefinition() ); assertEquals( "table1", overrides[1].column().table() ); assertEquals( 50, overrides[1].column().length() ); assertEquals( 2, overrides[1].column().precision() );
if (column == null || (column.insertable() && column.table().length() == 0)) { flags = Flag.Insertable.setTrue(flags); if (column == null || (column.updatable() && column.table().length() == 0)) { flags = Flag.Updatable.setTrue(flags); if (column != null && column.table().length() > 0) { table = column.table();
protected void readColumn(Column columnAnn, DeployBeanProperty prop) { if (!isEmpty(columnAnn.name())) { String dbColumn = databasePlatform.convertQuotedIdentifiers(columnAnn.name()); prop.setDbColumn(dbColumn); } prop.setDbInsertable(columnAnn.insertable()); prop.setDbUpdateable(columnAnn.updatable()); prop.setNullable(columnAnn.nullable()); prop.setUnique(columnAnn.unique()); if (columnAnn.precision() > 0) { prop.setDbLength(columnAnn.precision()); } else if (columnAnn.length() != 255) { // set default 255 on DbTypeMap prop.setDbLength(columnAnn.length()); } prop.setDbScale(columnAnn.scale()); prop.setDbColumnDefn(columnAnn.columnDefinition()); String baseTable = descriptor.getBaseTable(); String tableName = columnAnn.table(); if (!"".equals(tableName) && !tableName.equalsIgnoreCase(baseTable)) { // its on a secondary table... prop.setSecondaryTable(tableName); } }
? null : nameNormalizer.normalizeIdentifierQuoting( col.columnDefinition() ); final String tableName = nameNormalizer.normalizeIdentifierQuoting( col.table() ); final String columnName = nameNormalizer.normalizeIdentifierQuoting( col.name() ); Ejb3Column column = new Ejb3Column();
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public ColumnMetadataImpl(AbstractLocator locator, Column annotation) { super(); this.locator = locator; this.columnDefinition = annotation.columnDefinition(); this.insertable = annotation.insertable(); this.length = annotation.length(); this.name = annotation.name(); this.nullable = annotation.nullable(); this.precision = annotation.precision(); this.scale = annotation.scale(); this.table = annotation.table(); this.unique = annotation.unique(); this.updatable = annotation.updatable(); }
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public ColumnMetadataImpl(AbstractLocator locator, Column annotation) { super(); this.locator = locator; this.columnDefinition = annotation.columnDefinition(); this.insertable = annotation.insertable(); this.length = annotation.length(); this.name = annotation.name(); this.nullable = annotation.nullable(); this.precision = annotation.precision(); this.scale = annotation.scale(); this.table = annotation.table(); this.unique = annotation.unique(); this.updatable = annotation.updatable(); }
/** * @param locator * the java locator * @param annotation * the annotation * * @since 2.0.0 */ public ColumnMetadataImpl(AbstractLocator locator, Column annotation) { super(); this.locator = locator; this.columnDefinition = annotation.columnDefinition(); this.insertable = annotation.insertable(); this.length = annotation.length(); this.name = annotation.name(); this.nullable = annotation.nullable(); this.precision = annotation.precision(); this.scale = annotation.scale(); this.table = annotation.table(); this.unique = annotation.unique(); this.updatable = annotation.updatable(); }
protected void readColumn(Column columnAnn, DeployBeanProperty prop) { if (!isEmpty(columnAnn.name())) { String dbColumn = databasePlatform.convertQuotedIdentifiers(columnAnn.name()); prop.setDbColumn(dbColumn); } prop.setDbInsertable(columnAnn.insertable()); prop.setDbUpdateable(columnAnn.updatable()); prop.setNullable(columnAnn.nullable()); prop.setUnique(columnAnn.unique()); if (columnAnn.precision() > 0) { prop.setDbLength(columnAnn.precision()); } else if (columnAnn.length() != 255) { // set default 255 on DbTypeMap prop.setDbLength(columnAnn.length()); } prop.setDbScale(columnAnn.scale()); prop.setDbColumnDefn(columnAnn.columnDefinition()); String baseTable = descriptor.getBaseTable(); String tableName = columnAnn.table(); if (!"".equals(tableName) && !tableName.equalsIgnoreCase(baseTable)) { // its on a secondary table... prop.setSecondaryTable(tableName); } }
protected void readColumn(Column columnAnn, DeployBeanProperty prop) { if (!isEmpty(columnAnn.name())) { String dbColumn = databasePlatform.convertQuotedIdentifiers(columnAnn.name()); prop.setDbColumn(dbColumn); } prop.setDbInsertable(columnAnn.insertable()); prop.setDbUpdateable(columnAnn.updatable()); prop.setNullable(columnAnn.nullable()); prop.setUnique(columnAnn.unique()); if (columnAnn.precision() > 0) { prop.setDbLength(columnAnn.precision()); } else if (columnAnn.length() != 255) { // set default 255 on DbTypeMap prop.setDbLength(columnAnn.length()); } prop.setDbScale(columnAnn.scale()); prop.setDbColumnDefn(columnAnn.columnDefinition()); String baseTable = descriptor.getBaseTable(); String tableName = columnAnn.table(); if (!"".equals(tableName) && !tableName.equalsIgnoreCase(baseTable)) { // its on a secondary table... prop.setSecondaryTable(tableName); } }
private void readColumn(Column columnAnn, DeployBeanProperty prop) { if (!isEmpty(columnAnn.name())){ String dbColumn = databasePlatform.convertQuotedIdentifiers(columnAnn.name()); prop.setDbColumn(dbColumn); } prop.setDbInsertable(columnAnn.insertable()); prop.setDbUpdateable(columnAnn.updatable()); prop.setNullable(columnAnn.nullable()); prop.setUnique(columnAnn.unique()); if (columnAnn.precision() > 0){ prop.setDbLength(columnAnn.precision()); } else if (columnAnn.length() != 255){ // set default 255 on DbTypeMap prop.setDbLength(columnAnn.length()); } prop.setDbScale(columnAnn.scale()); prop.setDbColumnDefn(columnAnn.columnDefinition()); String baseTable = descriptor.getBaseTable(); String tableName = columnAnn.table(); if (tableName.equals("") || tableName.equalsIgnoreCase(baseTable)) { // its a base table property... } else { // its on a secondary table... prop.setSecondaryTable(tableName); //DeployTableJoin tableJoin = info.getTableJoin(tableName); //tableJoin.addProperty(prop); } }
public ColumnConfig(Column column) { setName(column.name()); setUnique(column.unique()); setNullable(column.nullable()); setInsertable(column.insertable()); setUpdatable(column.updatable()); setColumnDefinition(column.columnDefinition()); setTable(column.table()); setLength(column.length()); setPrecision(column.precision()); setScale(column.scale()); }
/** * Fill the column value by introspection */ public void introspect(Column column) { setName(column.name()); setUnique(column.unique()); setNullable(column.nullable()); setInsertable(column.insertable()); setUpdatable(column.updatable()); setColumnDefinition(column.columnDefinition()); setTable(column.table()); setLength(column.length()); setPrecision(column.precision()); setScale(column.scale()); } }
/** * INTERNAL: */ public MetadataColumn(Column column, String attributeName, AnnotatedElement annotatedElement) { this(attributeName, annotatedElement); if (column != null) { // Apply the values from the column annotation. m_databaseField.setUnique(column.unique()); m_databaseField.setNullable(column.nullable()); m_databaseField.setUpdatable(column.updatable()); m_databaseField.setInsertable(column.insertable()); m_databaseField.setScale(column.scale()); m_databaseField.setLength(column.length()); m_databaseField.setPrecision(column.precision()); m_databaseField.setName(column.name()); m_databaseField.setTableName(column.table()); m_databaseField.setColumnDefinition(column.columnDefinition()); } }