Java Code Examples for org.pentaho.metadata.model.LogicalColumn#setPhysicalColumn()
The following examples show how to use
org.pentaho.metadata.model.LogicalColumn#setPhysicalColumn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoModeler.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 5 votes |
private LogicalTable createBusinessTable( SqlPhysicalTable physicalTable, String locale ) { // Create a business table with a new ID and localized name // LogicalTable businessTable = new LogicalTable( null, physicalTable ); // Try to set the name of the business table to something nice (beautify) // String tableName = PhysicalTableImporter.beautifyName( physicalTable.getTargetTable() ); businessTable.setName( new LocalizedString( locale, tableName ) ); businessTable.setId( Util.proposeSqlBasedLogicalTableId( locale, businessTable, physicalTable ) ); // Add columns to this by copying the physical columns to the business // columns... // for ( IPhysicalColumn physicalColumn : physicalTable.getPhysicalColumns() ) { LogicalColumn businessColumn = new LogicalColumn(); businessColumn.setPhysicalColumn( physicalColumn ); businessColumn.setLogicalTable( businessTable ); // We're done, add the business column. // // Propose a new ID businessColumn.setId( Util.proposeSqlBasedLogicalColumnId( locale, businessTable, (SqlPhysicalColumn) physicalColumn ) ); businessTable.addLogicalColumn( businessColumn ); } return businessTable; }
Example 2
Source File: ThinModelIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testSqlLogicalModel() { String locale = LocaleHelper.getLocale().toString(); // this sql model is the minimum required for // MQL execution SqlPhysicalModel model = new SqlPhysicalModel(); SqlDataSource dataSource = new SqlDataSource(); dataSource.setDatabaseName( "SampleData" ); model.setDatasource( dataSource ); SqlPhysicalTable table = new SqlPhysicalTable( model ); table.setId( "PT1" ); model.getPhysicalTables().add( table ); table.setTargetTableType( TargetTableType.INLINE_SQL ); table.setTargetTable( "select distinct customername from customers" ); SqlPhysicalColumn column = new SqlPhysicalColumn( table ); column.setId( "PC1" ); column.setTargetColumn( "customername" ); column.setName( new LocalizedString( locale, "Customer Name" ) ); column.setDescription( new LocalizedString( locale, "Customer Description" ) ); column.setDataType( DataType.STRING ); // logical model LogicalModel logicalModel = new LogicalModel(); model.setId( "MODEL" ); model.setName( new LocalizedString( locale, "My Model" ) ); model.setDescription( new LocalizedString( locale, "A Description of the Model" ) ); LogicalTable logicalTable = new LogicalTable(); logicalTable.setPhysicalTable( table ); LogicalColumn logicalColumn = new LogicalColumn(); logicalColumn.setId( "LC_CUSTOMERNAME" ); logicalColumn.setPhysicalColumn( column ); // test name inheritance Assert.assertEquals( column.getName().getString( Locale.getDefault().toString() ), logicalColumn.getName() .getString( Locale.getDefault().toString() ) ); // test datatype inheritance Assert.assertEquals( column.getDataType(), logicalColumn.getDataType() ); Category mainCategory = new Category(); mainCategory.setId( "CATEGORY" ); mainCategory.setName( new LocalizedString( locale, "Category" ) ); // replacement for formula / is exact could be // target column + target column type (calculated, exact, etc) }
Example 3
Source File: ThinModelIT.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
@Test public void testSerializeSqlPhysicalModel() { String locale = LocaleHelper.getLocale().toString(); SqlPhysicalModel model = new SqlPhysicalModel(); SqlDataSource dataSource = new SqlDataSource(); dataSource.setDatabaseName( "SampleData" ); model.setDatasource( dataSource ); SqlPhysicalTable table = new SqlPhysicalTable( model ); model.getPhysicalTables().add( table ); table.setTargetTableType( TargetTableType.INLINE_SQL ); table.setTargetTable( "select * from customers" ); SqlPhysicalColumn column = new SqlPhysicalColumn( table ); column.setTargetColumn( "customername" ); column.setName( new LocalizedString( locale, "Customer Name" ) ); column.setDescription( new LocalizedString( locale, "Customer Name Desc" ) ); column.setDataType( DataType.STRING ); table.getPhysicalColumns().add( column ); LogicalModel logicalModel = new LogicalModel(); model.setId( "MODEL" ); model.setName( new LocalizedString( locale, "My Model" ) ); model.setDescription( new LocalizedString( locale, "A Description of the Model" ) ); LogicalTable logicalTable = new LogicalTable(); logicalTable.setPhysicalTable( table ); logicalModel.getLogicalTables().add( logicalTable ); LogicalColumn logicalColumn = new LogicalColumn(); logicalColumn.setId( "LC_CUSTOMERNAME" ); logicalColumn.setPhysicalColumn( column ); logicalTable.addLogicalColumn( logicalColumn ); Category mainCategory = new Category(); mainCategory.setId( "CATEGORY" ); mainCategory.setName( new LocalizedString( locale, "Category" ) ); mainCategory.addLogicalColumn( logicalColumn ); logicalModel.getCategories().add( mainCategory ); Domain domain = new Domain(); domain.addPhysicalModel( model ); domain.addLogicalModel( logicalModel ); // basic tests SerializationService service = new SerializationService(); String xml = service.serializeDomain( domain ); // System.out.println(xml); Domain domain2 = service.deserializeDomain( xml ); Assert.assertEquals( 1, domain2.getPhysicalModels().size() ); SqlPhysicalModel model2 = (SqlPhysicalModel) domain2.getPhysicalModels().get( 0 ); Assert.assertEquals( "SampleData", model2.getDatasource().getDatabaseName() ); Assert.assertEquals( 1, model.getPhysicalTables().size() ); Assert.assertEquals( TargetTableType.INLINE_SQL, model.getPhysicalTables().get( 0 ).getTargetTableType() ); Assert.assertEquals( 1, domain.getLogicalModels().size() ); Assert.assertEquals( 1, domain.getLogicalModels().get( 0 ).getCategories().size() ); Assert.assertEquals( 1, domain.getLogicalModels().get( 0 ).getCategories().get( 0 ).getLogicalColumns().size() ); Assert.assertEquals( domain.getLogicalModels().get( 0 ).getLogicalTables().get( 0 ).getLogicalColumns().get( 0 ), domain.getLogicalModels().get( 0 ).getCategories().get( 0 ).getLogicalColumns().get( 0 ) ); Assert.assertEquals( "Customer Name", domain.getLogicalModels().get( 0 ).getCategories().get( 0 ) .getLogicalColumns().get( 0 ).getName().getString( "en_US" ) ); Assert.assertEquals( "Customer Name Desc", domain.getLogicalModels().get( 0 ).getCategories().get( 0 ) .getLogicalColumns().get( 0 ).getDescription().getString( "en_US" ) ); }
Example 4
Source File: TestHelper.java From pentaho-metadata with GNU Lesser General Public License v2.1 | 4 votes |
public static Domain getBasicDomain() { String locale = LocaleHelper.getLocale().toString(); SqlPhysicalModel model = new SqlPhysicalModel(); SqlDataSource dataSource = new SqlDataSource(); dataSource.setDatabaseName( "SampleData" ); model.setDatasource( dataSource ); SqlPhysicalTable table = new SqlPhysicalTable( model ); table.setId( "PT1" ); model.getPhysicalTables().add( table ); table.setTargetTableType( TargetTableType.INLINE_SQL ); table.setTargetTable( "select * from customers" ); SqlPhysicalColumn column = new SqlPhysicalColumn( table ); column.setId( "PC1" ); column.setTargetColumn( "customername" ); column.setName( new LocalizedString( locale, "Customer Name" ) ); column.setDescription( new LocalizedString( locale, "Customer Name Desc" ) ); column.setDataType( DataType.STRING ); table.getPhysicalColumns().add( column ); LogicalModel logicalModel = new LogicalModel(); logicalModel.setId( "MODEL" ); logicalModel.setName( new LocalizedString( locale, "My Model" ) ); logicalModel.setDescription( new LocalizedString( locale, "A Description of the Model" ) ); LogicalTable logicalTable = new LogicalTable(); logicalTable.setId( "LT" ); logicalTable.setPhysicalTable( table ); logicalTable.setLogicalModel( logicalModel ); logicalModel.getLogicalTables().add( logicalTable ); LogicalColumn logicalColumn = new LogicalColumn(); logicalColumn.setId( "LC_CUSTOMERNAME" ); logicalColumn.setPhysicalColumn( column ); logicalColumn.setLogicalTable( logicalTable ); logicalTable.addLogicalColumn( logicalColumn ); Category mainCategory = new Category( logicalModel ); mainCategory.setId( "CATEGORY" ); mainCategory.setName( new LocalizedString( locale, "Category" ) ); mainCategory.addLogicalColumn( logicalColumn ); logicalModel.getCategories().add( mainCategory ); Domain domain = new Domain(); domain.setId( "DOMAIN" ); domain.addPhysicalModel( model ); domain.addLogicalModel( logicalModel ); return domain; }