svnno****@sourc*****
svnno****@sourc*****
2009年 4月 13日 (月) 00:56:19 JST
Revision: 3217 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=3217 Author: daisuke_m Date: 2009-04-13 00:56:19 +0900 (Mon, 13 Apr 2009) Log Message: ----------- mavenプラグイン整備。 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DatabaseCleaner.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DefaultDatabaseConnectionConfig.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DriverUtil.java eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/JiemamyMojoTest.java hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java Added Paths: ----------- eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/CleanDatabaseMojoTest.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DatabaseCleaner.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DatabaseCleaner.java 2009-04-10 16:43:27 UTC (rev 3216) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DatabaseCleaner.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -69,7 +69,9 @@ URL[] paths = config.getDriverJarPaths(); String className = config.getDriverClassName(); + Driver driver = DriverUtil.getDriverInstance(paths, className); + connection = driver.connect(config.getUri(), props); SqlExecuter sqlExecuter = new SqlExecuter(connection); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DefaultDatabaseConnectionConfig.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DefaultDatabaseConnectionConfig.java 2009-04-10 16:43:27 UTC (rev 3216) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DefaultDatabaseConnectionConfig.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -48,6 +48,9 @@ } public URL[] getDriverJarPaths() { + if (driverJarPaths == null) { + return new URL[0]; + } return driverJarPaths.clone(); } Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DriverUtil.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DriverUtil.java 2009-04-10 16:43:27 UTC (rev 3216) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/utils/DriverUtil.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -98,13 +98,24 @@ */ public static Driver getDriverInstance(URL[] paths, String fqcn) throws InstantiationException, IllegalAccessException, DriverNotFoundException, IOException { + Driver driver = null; + List<Class<? extends Driver>> classes = getDriverClasses(paths); for (Class<? extends Driver> clazz : classes) { if (clazz.getName().equals(fqcn)) { - return clazz.newInstance(); + driver = clazz.newInstance(); + break; } } - throw new DriverNotFoundException(fqcn); + + if (driver == null) { + try { + driver = (Driver) Class.forName(fqcn).newInstance(); + } catch (ClassNotFoundException e) { + throw new DriverNotFoundException(fqcn); + } + } + return driver; } private DriverUtil() { Added: eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java (rev 0) +++ eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -0,0 +1,138 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/04/12 + * + * This file is part of Jiemamy. + * + * 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.jiemamy.maven; + +import java.io.IOException; +import java.net.URL; +import java.sql.Connection; +import java.sql.Driver; +import java.sql.SQLException; +import java.util.Properties; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +import org.jiemamy.Jiemamy; +import org.jiemamy.composer.ImportException; +import org.jiemamy.composer.importer.DefaultDatabaseImportConfig; +import org.jiemamy.dialect.Dialect; +import org.jiemamy.exception.DriverNotFoundException; +import org.jiemamy.utils.DatabaseCleaner; +import org.jiemamy.utils.DriverUtil; +import org.jiemamy.utils.JmIOUtil; + +/** + * TODO for daisuke + * + * @goal cleanDatabase + * @phase pre-integration-test + * @author daisuke + */ +public class CleanDatabaseMojo extends AbstractMojo { + + /** TODO for daisuke */ + private static final String DIALECT = "org.jiemamy.dialect.postgresql.PostgresqlDialect"; + + /** + * @parameter + * @required + */ + private String username; + + /** + * @parameter + * @required + */ + private String password; + + /** + * @parameter + * @required + */ + private String driver; + + /** + * @parameter + * @required + */ + private String uri; + + + public void execute() throws MojoExecutionException { + Jiemamy jiemamy = Jiemamy.newInstance(); + jiemamy.getFactory().getRootModel().setDialectClassName(DIALECT); + DefaultDatabaseImportConfig config = new DefaultDatabaseImportConfig(); + + Connection connection = null; + try { + config.setDriverClassName(driver); + config.setUsername(username); + config.setPassword(password); + config.setImportDataSet(false); + config.setDialect((Dialect) Class.forName(DIALECT).newInstance()); + config.setUri(uri); + + Properties props = new Properties(); + props.setProperty("user", config.getUsername()); + props.setProperty("password", config.getPassword()); + + URL[] paths = config.getDriverJarPaths(); + String className = config.getDriverClassName(); + + Driver driver = DriverUtil.getDriverInstance(paths, className); + + connection = driver.connect(config.getUri(), props); + + if (connection == null) { + getLog().error("connection failed"); + throw new MojoExecutionException("connection failed"); + } + + DatabaseCleaner databaseCleaner = new DatabaseCleaner(); + config.setDialect(jiemamy.getDialect(jiemamy.getFactory().getRootModel())); + config.setSchema(jiemamy.getFactory().getRootModel().getSchemaName()); + + databaseCleaner.clean(config); + } catch (DriverNotFoundException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("Driver not found: " + config.getDriverClassName(), e); + } catch (InstantiationException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } catch (IllegalAccessException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } catch (IOException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } catch (SQLException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } catch (ClassNotFoundException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } catch (ImportException e) { + // TODO Auto-generated catch block + throw new MojoExecutionException("", e); + } finally { + JmIOUtil.closeQuietly(connection); + } + } + +} Property changes on: eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/CleanDatabaseMojo.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java 2009-04-10 16:43:27 UTC (rev 3216) +++ eros/maven-jiemamy-plugin/trunk/src/main/java/org/jiemamy/maven/JiemamyMojo.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -36,8 +36,8 @@ /** * Goal which execute Exporter. * - * @goal execute - * @phase process-resources + * @goal jiemamy + * @phase pre-integration-test * @author daisuke */ public class JiemamyMojo extends AbstractMojo { @@ -59,7 +59,7 @@ private String exporterClass; /** - * Parameter for exorter. default-value="null" + * Parameter for exorter. * @parameter */ private Map<String, Object> parameter; @@ -92,10 +92,10 @@ // TODO Exporter指定されたら、Configも変えなきゃだよな…。 DefaultSqlExportConfig config = new DefaultSqlExportConfig(); - config.setOutputFile((File) parameter.get(SqlExporter.OUTPUT_FILE)); - config.setOverwrite((Boolean) parameter.get(SqlExporter.OVERWRITE)); - Object indexObject = parameter.get(SqlExporter.DATA_SET_INDEX); - config.setDataSetIndex(indexObject == null ? -1 : (Integer) indexObject); + config.setOutputFile(new File((String) parameter.get(SqlExporter.OUTPUT_FILE))); + config.setOverwrite(Boolean.valueOf((String) parameter.get(SqlExporter.OVERWRITE))); + String indexObject = (String) parameter.get(SqlExporter.DATA_SET_INDEX); + config.setDataSetIndex(indexObject == null ? -1 : Integer.valueOf(indexObject)); getLog().info("Executing Exporter..."); Added: eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/CleanDatabaseMojoTest.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/CleanDatabaseMojoTest.java (rev 0) +++ eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/CleanDatabaseMojoTest.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -0,0 +1,82 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/03/03 + * + * This file is part of Jiemamy. + * + * 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.jiemamy.maven; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * {@link JiemamyMojo}のテストクラス。 + * + * @author daisuke + */ +public class CleanDatabaseMojoTest { + + /** テスト対象 */ + private CleanDatabaseMojo cleanDatabaseMojo; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + cleanDatabaseMojo = new CleanDatabaseMojo(); + +// HashMap<String, Object> parameter = new HashMap<String, Object>(); +// parameter.put(SqlExporter.OUTPUT_FILE, outputFile); +// parameter.put(SqlExporter.OVERWRITE, true); +// +// Field parameterField = JiemamyMojo.class.getDeclaredField("parameter"); +// parameterField.setAccessible(true); +// parameterField.set(cleanDatabaseMojo, parameter); +// +// Field inputFileField = JiemamyMojo.class.getDeclaredField("inputFile"); +// inputFileField.setAccessible(true); +// inputFileField.set(cleanDatabaseMojo, inputFile); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + cleanDatabaseMojo = null; + } + + /** + * DBがクリーンされる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_DBがクリーンされる() throws Exception { + + // TODO CREATE TABLE + +// cleanDatabaseMojo.execute(); + + // TODO assertion + } +} Property changes on: eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/CleanDatabaseMojoTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Modified: eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/JiemamyMojoTest.java =================================================================== --- eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/JiemamyMojoTest.java 2009-04-10 16:43:27 UTC (rev 3216) +++ eros/maven-jiemamy-plugin/trunk/src/test/java/org/jiemamy/maven/JiemamyMojoTest.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -44,7 +44,7 @@ private static final File inputFile = new File("src/test/resources/sample.xml"); /** テスト用出力ファイル */ - private static final File outputFile = new File("target/output.sql"); + private static final String outputFile = "target/output.sql"; /** テスト対象 */ private JiemamyMojo jiemamyMojo; @@ -61,7 +61,7 @@ HashMap<String, Object> parameter = new HashMap<String, Object>(); parameter.put(SqlExporter.OUTPUT_FILE, outputFile); - parameter.put(SqlExporter.OVERWRITE, true); + parameter.put(SqlExporter.OVERWRITE, "true"); Field parameterField = JiemamyMojo.class.getDeclaredField("parameter"); parameterField.setAccessible(true); @@ -89,17 +89,18 @@ */ @Test public void test01_エクスポート先にファイルが生成される() throws Exception { - if (outputFile.exists()) { - boolean delete = outputFile.delete(); + File file = new File(outputFile); + if (file.exists()) { + boolean delete = file.delete(); assertThat(delete, is(true)); - assertThat(outputFile.exists(), is(false)); + assertThat(file.exists(), is(false)); } jiemamyMojo.execute(); - assertThat(outputFile.exists(), is(true)); + assertThat(file.exists(), is(true)); - String contents = FileUtils.readFileToString(outputFile, CharEncoding.UTF_8); + String contents = FileUtils.readFileToString(file, CharEncoding.UTF_8); assertThat(contents.startsWith("BEGIN;"), is(true)); } } Modified: hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java =================================================================== --- hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java 2009-04-10 16:43:27 UTC (rev 3216) +++ hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/root/RootEditDialogDataSetTab.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -49,6 +49,7 @@ import org.jiemamy.EventBroker; import org.jiemamy.Jiemamy; import org.jiemamy.JiemamyFactory; +import org.jiemamy.JiemamyProperty.DataSetProperty; import org.jiemamy.eclipse.editor.dialog.AbstractEditListener; import org.jiemamy.eclipse.editor.dialog.EditListener; import org.jiemamy.eclipse.ui.AbstractTableEditor; @@ -335,6 +336,9 @@ JiemamyFactory factory = jiemamy.getFactory(); DataSetModel dataSetModel = factory.newModel(DataSetModel.class); + String newName = "DATASET_" + (dataSets.size() + 1); + jiemamyFacade.changeModelProperty(dataSetModel, DataSetProperty.name, newName); + jiemamyFacade.addDataSet(dataSetModel); int addedIndex = dataSets.indexOf(dataSetModel); Modified: hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java =================================================================== --- hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-04-10 16:43:27 UTC (rev 3216) +++ hestia/trunk/org.jiemamy.eclipse.ui/src/main/java/org/jiemamy/eclipse/editor/dialog/table/TableEditDialogColumnTab.java 2009-04-12 15:56:19 UTC (rev 3217) @@ -816,7 +816,6 @@ */ private void createAdvancedEditComponents(Composite parent) { GridLayout layout; - GridData gd; Label label; // ExpandBar expandBar = new ExpandBar(parent, SWT.V_SCROLL); // expandBar.setSpacing(8); @@ -841,14 +840,6 @@ // expAdvanced.setHeight(cmpAdvanced.computeSize(SWT.DEFAULT, SWT.DEFAULT).y); label = new Label(cmpAdvanced, SWT.NULL); - label.setText("デフォルト値(&F)"); // RESOURCE - - txtDefaultValue = new Text(cmpAdvanced, SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 3; - txtDefaultValue.setLayoutData(gd); - - label = new Label(cmpAdvanced, SWT.NULL); label.setText("制約名(&M)"); // RESOURCE txtCheckName = new Text(cmpAdvanced, SWT.BORDER); @@ -861,12 +852,16 @@ txtCheckExpression.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); label = new Label(cmpAdvanced, SWT.NULL); + label.setText("デフォルト値(&F)"); // RESOURCE + + txtDefaultValue = new Text(cmpAdvanced, SWT.BORDER); + txtDefaultValue.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + label = new Label(cmpAdvanced, SWT.NULL); label.setText("説明(&D)"); // RESOURCE txtDescription = new Text(cmpAdvanced, SWT.MULTI | SWT.BORDER); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 3; - txtDescription.setLayoutData(gd); + txtDescription.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); } private void updateModel() {