提交 f491c61b 编写于 作者: S serge-rider

Merge remote-tracking branch 'origin/devel' into devel

......@@ -5,6 +5,10 @@
<extension-point id="org.jkiss.dbeaver.mockGenerator" name="Mock data generator" schema="schema/org.jkiss.dbeaver.mockGenerator.exsd"/>
<extension point="org.eclipse.ui.handlers">
<handler commandId="org.jkiss.dbeaver.ext.mockdata.button" class="org.jkiss.dbeaver.ext.mockdata.handlers.MockDataHandler" />
</extension>
<extension point="org.jkiss.dbeaver.tools">
<tools>
<tool
......@@ -46,6 +50,18 @@
<extension point="org.jkiss.dbeaver.mockGenerator">
<generator
id="booleanConstantGenerator"
label="Constant"
description="Constant boolean value"
class="org.jkiss.dbeaver.ext.mockdata.generator.ConstantGenerator">
<type kind="BOOLEAN"/>
<propertyGroup label="General">
<property id="value" label="Value" type="boolean" defaultValue="TRUE"/>
</propertyGroup>
</generator>
<generator
id="booleanRandomGenerator"
label="Random"
......@@ -67,6 +83,18 @@
</propertyGroup>
</generator>
<generator
id="dateConstantGenerator"
label="Constant"
description="Constant date value"
class="org.jkiss.dbeaver.ext.mockdata.generator.ConstantGenerator">
<type kind="DATETIME"/>
<propertyGroup label="General">
<property id="value" label="Value" type="string" description="Date format: DD-MM-YYYY"/>
</propertyGroup>
</generator>
<generator
id="dateRandomGenerator"
label="Random"
......@@ -106,6 +134,18 @@
-->
</generator>
<generator
id="numericConstantGenerator"
label="Constant"
description="Constant numeric value"
class="org.jkiss.dbeaver.ext.mockdata.generator.ConstantGenerator">
<type kind="NUMERIC"/>
<propertyGroup label="General">
<property id="value" label="Value" type="numeric" defaultValue="0"/>
</propertyGroup>
</generator>
<generator
id="numericRandomGenerator"
label="Random"
......@@ -128,6 +168,18 @@
</propertyGroup>
</generator>
<generator
id="stringConstantGenerator"
label="Constant"
description="Constant string"
class="org.jkiss.dbeaver.ext.mockdata.generator.ConstantGenerator">
<type kind="STRING"/>
<propertyGroup label="General">
<property id="value" label="Value" type="string"/>
</propertyGroup>
</generator>
<generator
id="stringTextGenerator"
label="Text"
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2017 Serge Rider (serge@jkiss.org)
* Copyright (C) 2010-2017 Eugene Fradkin (eugene.fradkin@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ext.mockdata.generator;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.model.DBPDataKind;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.dbeaver.model.struct.DBSDataManipulator;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Map;
public class ConstantGenerator extends AbstractMockValueGenerator {
private static SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy"); //$NON-NLS-1$
private Object value;
@Override
public void init(DBSDataManipulator container, DBSAttributeBase attribute, Map<Object, Object> properties) throws DBException {
super.init(container, attribute, properties);
Object value = properties.get("value"); //$NON-NLS-1$
if (value != null) {
if (attribute.getDataKind() == DBPDataKind.DATETIME) {
try {
this.value = DATE_FORMAT.parse((String) value);
} catch (ParseException e) {
throw new DBException("Can't parse the value '" + value + "' as a date", e);
}
} else {
this.value = value;
}
} else {
if (attribute.getDataKind() == DBPDataKind.STRING) {
this.value = "";
}
}
}
@Override
public Object generateOneValue(DBRProgressMonitor monitor) throws DBException, IOException {
if (isGenerateNULL()) {
return null;
} else {
return value;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册