use of org.mybatis.generator.exception.InvalidConfigurationException in project generator by mybatis.
the class MyBatisGeneratorTest method testGenerateIbatis2WithInvalidConfig.
@Test(expected = InvalidConfigurationException.class)
public void testGenerateIbatis2WithInvalidConfig() throws Exception {
List<String> warnings = new ArrayList<String>();
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(this.getClass().getClassLoader().getResourceAsStream("generatorConfigIbatis2_badConfig.xml"));
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
try {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
} catch (InvalidConfigurationException e) {
assertEquals(1, e.getErrors().size());
throw e;
}
}
use of org.mybatis.generator.exception.InvalidConfigurationException in project jeesuite-libs by vakinge.
the class MyBatisGeneratorTool method main.
public static void main(String[] args) {
List<String> warnings = new ArrayList<String>();
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
boolean overwrite = true;
File configFile = new File(path + "/../../src/test/resources/generator/generatorConfig.xml");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = null;
try {
config = cp.parseConfiguration(configFile);
} catch (IOException e) {
e.printStackTrace();
} catch (XMLParserException e) {
e.printStackTrace();
}
DefaultShellCallback callback = new DefaultShellCallback(overwrite);
MyBatisGenerator myBatisGenerator = null;
try {
myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
try {
myBatisGenerator.generate(null);
} catch (SQLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of org.mybatis.generator.exception.InvalidConfigurationException in project generator by mybatis.
the class MyBatisGeneratorTest method testGenerateInvalidConfigWithTwoConnectionSources.
@Test
void testGenerateInvalidConfigWithTwoConnectionSources() {
List<String> warnings = new ArrayList<>();
Configuration config = new Configuration();
Context context = new Context(ModelType.HIERARCHICAL);
context.setId("MyContext");
context.setConnectionFactoryConfiguration(new ConnectionFactoryConfiguration());
context.setJdbcConnectionConfiguration(new JDBCConnectionConfiguration());
config.addContext(context);
DefaultShellCallback shellCallback = new DefaultShellCallback(true);
InvalidConfigurationException e = assertThrows(InvalidConfigurationException.class, () -> {
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
myBatisGenerator.generate(null, null, null, false);
});
assertEquals(3, e.getErrors().size());
}
use of org.mybatis.generator.exception.InvalidConfigurationException in project generator by mybatis.
the class ShellRunner method main.
public static void main(String[] args) {
if (args.length == 0) {
usage();
System.exit(0);
// only to satisfy compiler, never returns
return;
}
Map<String, String> arguments = parseCommandLine(args);
if (arguments.containsKey(HELP_1)) {
usage();
System.exit(0);
// only to satisfy compiler, never returns
return;
}
if (!arguments.containsKey(CONFIG_FILE)) {
// $NON-NLS-1$
writeLine(getString("RuntimeError.0"));
return;
}
List<String> warnings = new ArrayList<>();
String configfile = arguments.get(CONFIG_FILE);
File configurationFile = new File(configfile);
if (!configurationFile.exists()) {
// $NON-NLS-1$
writeLine(getString("RuntimeError.1", configfile));
return;
}
Set<String> fullyqualifiedTables = new HashSet<>();
if (arguments.containsKey(TABLES)) {
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(arguments.get(TABLES), ",");
while (st.hasMoreTokens()) {
String s = st.nextToken().trim();
if (s.length() > 0) {
fullyqualifiedTables.add(s);
}
}
}
Set<String> contexts = new HashSet<>();
if (arguments.containsKey(CONTEXT_IDS)) {
StringTokenizer st = new StringTokenizer(arguments.get(CONTEXT_IDS), // $NON-NLS-1$
",");
while (st.hasMoreTokens()) {
String s = st.nextToken().trim();
if (s.length() > 0) {
contexts.add(s);
}
}
}
try {
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(configurationFile);
DefaultShellCallback shellCallback = new DefaultShellCallback(arguments.containsKey(OVERWRITE));
MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, shellCallback, warnings);
ProgressCallback progressCallback = arguments.containsKey(VERBOSE) ? new VerboseProgressCallback() : null;
myBatisGenerator.generate(progressCallback, contexts, fullyqualifiedTables);
} catch (XMLParserException e) {
// $NON-NLS-1$
writeLine(getString("Progress.3"));
writeLine();
for (String error : e.getErrors()) {
writeLine(error);
}
return;
} catch (SQLException | IOException e) {
e.printStackTrace(System.out);
return;
} catch (InvalidConfigurationException e) {
// $NON-NLS-1$
writeLine(getString("Progress.16"));
for (String error : e.getErrors()) {
writeLine(error);
}
return;
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
for (String warning : warnings) {
writeLine(warning);
}
if (warnings.isEmpty()) {
// $NON-NLS-1$
writeLine(getString("Progress.4"));
} else {
writeLine();
// $NON-NLS-1$
writeLine(getString("Progress.5"));
}
}
use of org.mybatis.generator.exception.InvalidConfigurationException in project generator by mybatis.
the class RunGeneratorThread method run.
/*
* (non-Javadoc)
*
* @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
*/
public void run(IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, 1000);
subMonitor.beginTask("Generating MyBatis/iBATIS Artifacts:", 1000);
setClassLoader();
try {
subMonitor.subTask("Parsing Configuration");
ConfigurationParser cp = new ConfigurationParser(warnings);
Configuration config = cp.parseConfiguration(inputFile.getLocation().toFile());
subMonitor.worked(50);
MyBatisGenerator mybatisGenerator = new MyBatisGenerator(config, new EclipseShellCallback(), warnings);
monitor.subTask("Generating Files from Database Tables");
SubMonitor spm = subMonitor.newChild(950);
mybatisGenerator.generate(new EclipseProgressCallback(spm));
} catch (InterruptedException e) {
throw new OperationCanceledException();
} catch (SQLException e) {
Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
throw new CoreException(status);
} catch (IOException e) {
Status status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, e.getMessage(), e);
Activator.getDefault().getLog().log(status);
throw new CoreException(status);
} catch (XMLParserException e) {
List<String> errors = e.getErrors();
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "XML Parser Errors\n See Details for more Information", null);
Iterator<String> iter = errors.iterator();
while (iter.hasNext()) {
Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
multiStatus.add(message);
}
throw new CoreException(multiStatus);
} catch (InvalidConfigurationException e) {
List<String> errors = e.getErrors();
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR, "Invalid Configuration\n See Details for more Information", null);
Iterator<String> iter = errors.iterator();
while (iter.hasNext()) {
Status message = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, iter.next(), null);
multiStatus.add(message);
}
throw new CoreException(multiStatus);
} finally {
monitor.done();
restoreClassLoader();
}
}
Aggregations