本文整理汇总了Java中org.apache.metamodel.util.MutableRef类的典型用法代码示例。如果您正苦于以下问题:Java MutableRef类的具体用法?Java MutableRef怎么用?Java MutableRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MutableRef类属于org.apache.metamodel.util包,在下文中一共展示了MutableRef类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTable
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
private static Table getTable(final UpdateableDataContext dataContext, final String sheetName,
final String[] columnNames) {
final Schema schema = dataContext.getDefaultSchema();
Table table = schema.getTableByName(sheetName);
if (table == null) {
final MutableRef<Table> tableRef = new MutableRef<>();
dataContext.executeUpdate(callback -> {
final TableCreationBuilder tableBuilder = callback.createTable(schema, sheetName);
for (final String columnName : columnNames) {
tableBuilder.withColumn(columnName);
}
tableRef.set(tableBuilder.execute());
});
table = tableRef.get();
}
return table;
}
示例2: SingleColumnNamePropertyWidget
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
@Inject
public SingleColumnNamePropertyWidget(final ConfiguredPropertyDescriptor propertyDescriptor,
final ComponentBuilder componentBuilder) {
super(componentBuilder, propertyDescriptor);
_tableRef = new MutableRef<>();
Enum<?>[] enumConstants = (Enum<?>[]) propertyDescriptor.getType().getEnumConstants();
if (!propertyDescriptor.isRequired()) {
enumConstants = CollectionUtils.array(new Enum<?>[] { null }, enumConstants);
}
_comboBox = new SourceColumnComboBox();
final String currentValue = getCurrentValue();
setValue(currentValue);
addComboListener(item -> fireValueChanged());
add(_comboBox);
}
示例3: testInsertValues
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public void testInsertValues() throws Exception {
final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
final MutableTable table = new MutableTable("foo");
table.addColumn(new MutableColumn("foo"));
table.addColumn(new MutableColumn("bar"));
table.addColumn(new MutableColumn("baz"));
RowInsertionBuilder insertBuilder = new AbstractRowInsertionBuilder<UpdateCallback>(
null, table) {
@Override
public void execute() throws MetaModelException {
assertEquals("[1, 2, 3]", Arrays.toString(getValues()));
executed.set(true);
}
};
assertFalse(executed.get().booleanValue());
insertBuilder.value(0, 1).value("bar", 2)
.value(table.getColumnByName("baz"), 3).execute();
assertTrue(executed.get());
assertEquals("Row[values=[1, 2, 3]]", insertBuilder.toRow().toString());
}
示例4: createSparkLauncher
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public SparkLauncher createSparkLauncher(final File hadoopConfDir, final String configurationHdfsPath,
final String jobHdfsPath, final String resultHdfsPath) throws Exception {
// mimic env. variables
final Map<String, String> env = new HashMap<>();
env.put("HADOOP_CONF_DIR", hadoopConfDir.getAbsolutePath());
env.put("YARN_CONF_DIR", hadoopConfDir.getAbsolutePath());
final SparkLauncher sparkLauncher = new SparkLauncher(env);
sparkLauncher.setSparkHome(_sparkHome);
sparkLauncher.setMaster("yarn-cluster");
sparkLauncher.setAppName("DataCleaner");
final MutableRef<String> primaryJar = new MutableRef<>();
final List<String> jars = buildJarFiles(primaryJar);
logger.info("Using JAR files: {}", jars);
for (final String jar : jars) {
sparkLauncher.addJar(jar);
}
sparkLauncher.setMainClass(Main.class.getName());
sparkLauncher.setConf("spark.serializer", "org.apache.spark.serializer.JavaSerializer");
// the primary jar is always the first argument
sparkLauncher.addAppArgs(primaryJar.get());
sparkLauncher.addAppArgs(toHadoopPath(configurationHdfsPath));
sparkLauncher.addAppArgs(toHadoopPath(jobHdfsPath));
if (!StringUtils.isNullOrEmpty(resultHdfsPath)) {
final Properties properties = new Properties();
properties.setProperty("datacleaner.result.hdfs.path", resultHdfsPath);
final File tempFile = File.createTempFile("job-", ".properties");
properties.store(new FileWriter(tempFile), "DataCleaner Spark runner properties");
final URI uri = copyFileToHdfs(tempFile,
_fileSystem.getHomeDirectory().toUri().resolve("temp/" + tempFile.getName()).toString());
sparkLauncher.addAppArgs(uri.toString());
}
return sparkLauncher;
}
示例5: buildJarFiles
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
private List<String> buildJarFiles(final MutableRef<String> primaryJarRef) throws IOException {
final List<String> list = new ArrayList<>();
final Path directoryPath = new Path(_jarDirectoryPath);
final RemoteIterator<LocatedFileStatus> files = _fileSystem.listFiles(directoryPath, false);
while (files.hasNext()) {
final LocatedFileStatus file = files.next();
final Path path = file.getPath();
final String filename = path.getName();
boolean primaryJar = false;
for (final String prefix : PRIMARY_JAR_FILENAME_PREFIXES) {
if (filename.startsWith(prefix)) {
primaryJarRef.set(path.toString());
primaryJar = true;
break;
}
}
if (!primaryJar) {
list.add(path.toString());
}
}
if (primaryJarRef.get() == null) {
throw new IllegalArgumentException(
"Failed to find primary jar (starting with '" + PRIMARY_JAR_FILENAME_PREFIXES[0]
+ "') in JAR file directory: " + _jarDirectoryPath);
}
return list;
}
示例6: DCModuleImpl
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
/**
* Creates a DCModule based on a parent module. This constructor is
* convenient when you want to create a module with overridden getter
* methods.
*
* @param parent
* @param analysisJobBuilder
* the AnalysisJobBuilder to use within this module, or null if a
* new AnalysisJobBuilder should be created.
*/
public DCModuleImpl(final DCModule parent, final AnalysisJobBuilder analysisJobBuilder) {
final DCModuleImpl p = (DCModuleImpl) parent;
_undecoratedConfigurationRef = p._undecoratedConfigurationRef;
_userPreferencesRef = p._userPreferencesRef;
_configuration = p._configuration;
_windowContext = p._windowContext;
if (analysisJobBuilder == null) {
_analysisJobBuilderRef = new MutableRef<>();
} else {
_analysisJobBuilderRef = ImmutableRef.of(analysisJobBuilder);
}
}
示例7: getAnalysisJobBuilder
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
@Provides
public AnalysisJobBuilder getAnalysisJobBuilder(final DataCleanerConfiguration configuration) {
AnalysisJobBuilder ajb = _analysisJobBuilderRef.get();
if (ajb == null && _analysisJobBuilderRef instanceof MutableRef) {
ajb = new AnalysisJobBuilder(configuration);
final MutableRef<AnalysisJobBuilder> ref = (MutableRef<AnalysisJobBuilder>) _analysisJobBuilderRef;
ref.set(ajb);
}
return ajb;
}
示例8: MultipleMappedColumnsPropertyWidget
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
/**
* Constructs the property widget
*
* @param beanJobBuilder
* the transformer job builder for the table lookup
* @param inputColumnsProperty
* the property representing the columns to use for setting up
* conditional lookup (InputColumn[])
* @param mappedColumnsProperty
* the property representing the mapped columns in the datastore
* (String[])
*/
public MultipleMappedColumnsPropertyWidget(final ComponentBuilder componentBuilder,
final ConfiguredPropertyDescriptor inputColumnsProperty,
final ConfiguredPropertyDescriptor mappedColumnsProperty) {
super(componentBuilder, inputColumnsProperty);
_mappedColumnComboBoxes = new WeakHashMap<>();
_comboBoxDecorations = new IdentityHashMap<>();
_mappedColumnsProperty = mappedColumnsProperty;
_tableRef = new MutableRef<>();
_mappedColumnNamesPropertyWidget = new MappedColumnNamesPropertyWidget(componentBuilder, mappedColumnsProperty);
final InputColumn<?>[] currentValue = getCurrentValue();
final String[] currentMappedColumnsValue =
(String[]) componentBuilder.getConfiguredProperty(mappedColumnsProperty);
if (currentValue != null && currentMappedColumnsValue != null) {
// first create combo's, then set value (so combo is ready before it
// is requested)
_mappedColumnNamesPropertyWidget.setValue(currentMappedColumnsValue);
final int minLength = Math.min(currentValue.length, currentMappedColumnsValue.length);
for (int i = 0; i < minLength; i++) {
final InputColumn<?> inputColumn = currentValue[i];
final String mappedColumnName = currentMappedColumnsValue[i];
createComboBox(inputColumn, new MutableColumn(mappedColumnName));
}
setValue(currentValue);
}
}
示例9: SchemaNamePropertyWidget
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public SchemaNamePropertyWidget(final ComponentBuilder componentBuilder,
final ConfiguredPropertyDescriptor propertyDescriptor) {
super(componentBuilder, propertyDescriptor);
_comboBox = new DCComboBox<>();
_comboBox.setRenderer(new SchemaStructureComboBoxListRenderer(false));
_comboBox.setEditable(false);
addComboListener(item -> fireValueChanged());
add(_comboBox);
_datastoreRef = new MutableRef<>();
setValue(getCurrentValue());
}
示例10: testExecute
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public void testExecute() throws Exception {
final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
Schema schema = new MutableSchema("schema");
AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
schema, "tablename") {
@Override
public Table execute() throws MetaModelException {
executed.set(true);
return getTable();
}
};
assertFalse(executed.get().booleanValue());
builder.withColumn("foo").ofType(ColumnType.VARCHAR).asPrimaryKey().ofNativeType("vch").ofSize(1234)
.nullable(true);
builder.withColumn("bar").withColumn("baz").nullable(false);
Table table = builder.execute();
assertTrue(executed.get().booleanValue());
assertEquals("tablename", table.getName());
assertEquals(3, table.getColumnCount());
assertEquals("Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
table.getColumn(0).toString());
assertEquals("Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
table.getColumn(1).toString());
assertEquals("Column[name=baz,columnNumber=2,type=null,nullable=false,nativeType=null,columnSize=null]",
table.getColumn(2).toString());
System.out.println(builder.toSql());
assertEquals("CREATE TABLE schema.tablename (foo VARCHAR(1234),bar,baz NOT NULL, PRIMARY KEY(foo))", builder.toSql());
}
示例11: testLike
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public void testLike() throws Exception {
final MutableRef<Boolean> executed = new MutableRef<Boolean>(false);
Schema schema = new MutableSchema("schema");
AbstractTableCreationBuilder<UpdateCallback> builder = new AbstractTableCreationBuilder<UpdateCallback>(null,
schema, "tablename") {
@Override
public Table execute() throws MetaModelException {
executed.set(true);
return toTable();
}
};
assertFalse(executed.get().booleanValue());
MutableTable likeTable = new MutableTable("blablablabla");
likeTable.addColumn(new MutableColumn("foo", ColumnType.VARCHAR, likeTable, 0, 1234, "vch", true, null, false,
null).setPrimaryKey(true));
likeTable.addColumn(new MutableColumn("bar"));
likeTable.addColumn(new MutableColumn("baz"));
builder.like(likeTable);
Table table = builder.execute();
assertTrue(executed.get().booleanValue());
assertEquals("tablename", table.getName());
assertEquals(3, table.getColumnCount());
assertEquals("Column[name=foo,columnNumber=0,type=VARCHAR,nullable=true,nativeType=vch,columnSize=1234]",
table.getColumn(0).toString());
assertTrue(table.getColumn(0).isPrimaryKey());
assertEquals("Column[name=bar,columnNumber=1,type=null,nullable=null,nativeType=null,columnSize=null]",
table.getColumn(1).toString());
assertEquals("Column[name=baz,columnNumber=2,type=null,nullable=null,nativeType=null,columnSize=null]",
table.getColumn(2).toString());
}
示例12: TableLookupOutputColumnsPropertyWidget
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public TableLookupOutputColumnsPropertyWidget(final ComponentBuilder componentBuilder,
final ConfiguredPropertyDescriptor propertyDescriptor) {
super(componentBuilder, propertyDescriptor);
_comboBoxes = new ArrayList<>();
_tableRef = new MutableRef<>();
_comboBoxPanel = new DCPanel();
_comboBoxPanel.setLayout(new VerticalLayout(2));
final JButton addButton = WidgetFactory.createSmallButton(IconUtils.ACTION_ADD_DARK);
addButton.addActionListener(e -> {
addComboBox(null, true);
fireValueChanged();
});
final JButton removeButton = WidgetFactory.createSmallButton(IconUtils.ACTION_REMOVE_DARK);
removeButton.addActionListener(e -> {
final int componentCount = _comboBoxPanel.getComponentCount();
if (componentCount > 0) {
removeComboBox();
_comboBoxPanel.updateUI();
fireValueChanged();
}
});
final DCPanel buttonPanel = new DCPanel();
buttonPanel.setBorder(new EmptyBorder(0, 4, 0, 0));
buttonPanel.setLayout(new VerticalLayout(2));
buttonPanel.add(addButton);
buttonPanel.add(removeButton);
final DCPanel outerPanel = new DCPanel();
outerPanel.setLayout(new BorderLayout());
outerPanel.add(_comboBoxPanel, BorderLayout.CENTER);
outerPanel.add(buttonPanel, BorderLayout.EAST);
add(outerPanel);
final String[] currentValue = getCurrentValue();
setValue(currentValue);
}
示例13: SingleTableNamePropertyWidget
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
/**
* Creates the property widget
*
* @param componentBuilder
* @param propertyDescriptor
* @param windowContext
*/
public SingleTableNamePropertyWidget(final ComponentBuilder componentBuilder,
final ConfiguredPropertyDescriptor propertyDescriptor, final WindowContext windowContext) {
super(componentBuilder, propertyDescriptor);
_schemaRef = new MutableRef<>();
_datastoreRef = new MutableRef<>();
_comboBox = new DCComboBox<>();
_comboBox.setRenderer(new SchemaStructureComboBoxListRenderer(false));
_comboBox.setEditable(false);
addComboListener(item -> fireValueChanged());
final JButton createTableButton = WidgetFactory.createSmallButton(IconUtils.ACTION_CREATE_TABLE);
createTableButton.setToolTipText("Create table");
createTableButton.addActionListener(e -> {
final Schema schema = _schemaRef.get();
final Datastore datastore = _datastoreRef.get();
if (datastore instanceof UpdateableDatastore) {
final UpdateableDatastore updateableDatastore = (UpdateableDatastore) datastore;
final CreateTableDialog dialog = new CreateTableDialog(windowContext, updateableDatastore, schema,
getCreateTableColumnSuggestions());
dialog.addListener((datastore1, schema1, tableName) -> {
try (UpdateableDatastoreConnection con = datastore1.openConnection()) {
con.getDataContext().refreshSchemas();
final Schema newSchema = con.getDataContext().getSchemaByName(schema1.getName());
setSchema(datastore1, newSchema);
setValue(tableName);
}
});
dialog.open();
}
});
_panelAroundButton = DCPanel.around(createTableButton);
_panelAroundButton.setBorder(WidgetUtils.BORDER_EMPTY);
_panelAroundButton.setVisible(false);
final DCPanel panel = new DCPanel();
panel.setLayout(new BorderLayout());
panel.add(_comboBox, BorderLayout.CENTER);
panel.add(_panelAroundButton, BorderLayout.EAST);
add(panel);
setValue(getCurrentValue());
}
示例14: testCloseNoRaceConditions
import org.apache.metamodel.util.MutableRef; //导入依赖的package包/类
public void testCloseNoRaceConditions() throws Exception {
final int threadCount = 5000;
final Thread[] threads = new Thread[threadCount];
final AtomicInteger raceConditions = new AtomicInteger();
class TestConnection extends UsageAwareDatastoreConnection<DataContext> {
public TestConnection() {
super(null);
}
private final AtomicInteger _closeCount = new AtomicInteger();
@Override
public SchemaNavigator getSchemaNavigator() {
throw new UnsupportedOperationException();
}
@Override
public DataContext getDataContext() {
throw new UnsupportedOperationException();
}
@Override
protected void closeInternal() {
try {
Thread.sleep(14);
} catch (InterruptedException e) {
}
int closeCount = _closeCount.incrementAndGet();
if (closeCount != 1) {
raceConditions.incrementAndGet();
}
}
}
final AtomicInteger creations = new AtomicInteger();
final AtomicInteger reuses = new AtomicInteger();
final MutableRef<TestConnection> conRef = new MutableRef<TestConnection>();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
@Override
public void run() {
TestConnection con = conRef.get();
if (con != null && con.requestUsage()) {
reuses.incrementAndGet();
} else {
con = new TestConnection();
conRef.set(con);
creations.incrementAndGet();
}
try {
Thread.sleep((long) (Math.random() * 10));
} catch (InterruptedException e) {
}
con.close();
}
};
}
for (int i = 0; i < threads.length; i++) {
if (raceConditions.get() > 0) {
break;
}
threads[i].start();
}
assertTrue(creations.get() > 0);
assertTrue(creations.get() < threadCount);
assertTrue(reuses.get() > 0);
assertEquals("Found " + raceConditions
+ " race conditions! Object creation and close() method is not thread safe!", 0, raceConditions.get());
}