use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class DefaultDbImportAction method saveLoaded.
/**
* Save imported data.
* This can create DataMap and/or Project files.
*/
protected void saveLoaded(DataMap dataMap, DbImportConfiguration config) throws MalformedURLException {
ConfigurationTree<ConfigurationNode> projectRoot;
if (config.getCayenneProject() == null) {
// Old version of cdbimport, no Cayenne project, need to save only DataMap
projectRoot = new ConfigurationTree<>(dataMap);
} else {
// Cayenne project is present
DataChannelDescriptor dataChannelDescriptor;
if (config.getCayenneProject().exists()) {
// Cayenne project file exists, need to read it and push DataMap inside
URLResource configurationResource = new URLResource(config.getCayenneProject().toURI().toURL());
ConfigurationTree<DataChannelDescriptor> configurationTree = dataChannelDescriptorLoader.load(configurationResource);
if (!configurationTree.getLoadFailures().isEmpty()) {
throw new CayenneRuntimeException("Unable to load cayenne project %s, %s", config.getCayenneProject(), configurationTree.getLoadFailures().iterator().next().getDescription());
}
dataChannelDescriptor = configurationTree.getRootNode();
// remove old copy of DataMap if it's there
DataMap oldDataMap = dataChannelDescriptor.getDataMap(dataMap.getName());
if (oldDataMap != null) {
dataChannelDescriptor.getDataMaps().remove(oldDataMap);
}
} else {
// No project file yet, can simply create empty project with resulting DataMap
dataChannelDescriptor = new DataChannelDescriptor();
dataChannelDescriptor.setName(getProjectNameFromFileName(config.getCayenneProject().getName()));
dataChannelDescriptor.setConfigurationSource(new URLResource(config.getCayenneProject().toURI().toURL()));
logger.info("Project file does not exist. New project will be saved into '" + config.getCayenneProject().getAbsolutePath());
}
dataChannelDescriptor.getDataMaps().add(dataMap);
projectRoot = new ConfigurationTree<>(dataChannelDescriptor);
}
Project project = new Project(projectRoot);
projectSaver.save(project);
logger.info("");
logger.info("All changes saved.");
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class VelocitySQLTemplateProcessor method processTemplate.
SQLStatement processTemplate(String template, SimpleNode parsedTemplate, Map<String, Object> parameters) {
List<ParameterBinding> bindings = new ArrayList<>();
List<ColumnDescriptor> results = new ArrayList<>();
parameters.put(BINDINGS_LIST_KEY, bindings);
parameters.put(RESULT_COLUMNS_LIST_KEY, results);
parameters.put(HELPER_KEY, renderingUtils);
String sql;
try {
sql = buildStatement(new VelocityContext(parameters), template, parsedTemplate);
} catch (Exception e) {
throw new CayenneRuntimeException("Error processing Velocity template", e);
}
ParameterBinding[] bindingsArray = new ParameterBinding[bindings.size()];
bindings.toArray(bindingsArray);
ColumnDescriptor[] resultsArray = new ColumnDescriptor[results.size()];
results.toArray(resultsArray);
return new SQLStatement(sql, resultsArray, bindingsArray);
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class XMPPBridge method startupExternal.
@Override
protected void startupExternal() throws Exception {
// validate settings
if (xmppHost == null) {
throw new CayenneRuntimeException("Null 'xmppHost', can't start XMPPBridge");
}
// shutdown old bridge
if (connected) {
shutdownExternal();
}
try {
// connect and log in to chat
if (secureConnection) {
int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_SECURE_PORT;
this.connection = new SSLXMPPConnection(xmppHost, port);
} else {
int port = xmppPort > 0 ? xmppPort : DEFAULT_XMPP_PORT;
this.connection = new XMPPConnection(xmppHost, port);
}
if (loginId != null) {
// it is important to provide a (pseudo) globally unique string as the
// third argument ("sessionHandle" is such string); without it same
// loginId can not be reused from the same machine.
connection.login(loginId, password, sessionHandle);
} else {
connection.loginAnonymously();
}
} catch (XMPPException e) {
throw new CayenneRuntimeException("Error connecting to XMPP Server: %s", e.getLocalizedMessage());
}
String service = chatService != null ? chatService : DEFAULT_CHAT_SERVICE;
try {
groupChat = connection.createGroupChat(externalSubject + '@' + service + "." + connection.getHost());
groupChat.join(sessionHandle);
groupChat.addMessageListener(new XMPPListener());
} catch (XMPPException e) {
throw new CayenneRuntimeException("Error setting up a group chat: %s", e.getLocalizedMessage());
}
this.connected = true;
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class ProjectController method getDataMapPreferences.
/**
* Returns preferences object for the current DataMap. If no preferences
* exist for the current DataMap, a new Preferences object is created. If no
* DataMap is currently selected, an exception is thrown. An optional
* nameSuffix allows to address more than one defaults instance for a single
* DataMap.
*/
public DataMapDefaults getDataMapPreferences(String nameSuffix) {
DataMap map = getCurrentDataMap();
if (map == null) {
throw new CayenneRuntimeException("No DataMap selected");
}
Preferences pref;
if (nameSuffix == null || nameSuffix.length() == 0) {
pref = getPreferenceForDataDomain().node("DataMap").node(map.getName());
} else {
pref = getPreferenceForDataDomain().node("DataMap").node(map.getName()).node(nameSuffix);
}
return (DataMapDefaults) application.getCayenneProjectPreferences().getProjectDetailObject(DataMapDefaults.class, pref);
}
use of org.apache.cayenne.CayenneRuntimeException in project cayenne by apache.
the class GraphMap method createGraphBuilder.
public GraphBuilder createGraphBuilder(GraphType type, boolean doLayout) {
try {
GraphBuilder builder = type.getBuilderClass().newInstance();
builder.buildGraph(getProjectController(), domain, doLayout);
put(type, builder);
return builder;
} catch (Exception e) {
throw new CayenneRuntimeException("Could not instantiate GraphBuilder", e);
}
}
Aggregations