Search in sources :

Example 36 with CayenneRuntimeException

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.");
}
Also used : URLResource(org.apache.cayenne.resource.URLResource) Project(org.apache.cayenne.project.Project) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) ConfigurationNode(org.apache.cayenne.configuration.ConfigurationNode) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMap(org.apache.cayenne.map.DataMap)

Example 37 with CayenneRuntimeException

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);
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) ColumnDescriptor(org.apache.cayenne.access.jdbc.ColumnDescriptor) ArrayList(java.util.ArrayList) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) SQLStatement(org.apache.cayenne.access.jdbc.SQLStatement) ParameterBinding(org.apache.cayenne.access.translator.ParameterBinding) ExpressionException(org.apache.cayenne.exp.ExpressionException) ParseException(org.apache.velocity.runtime.parser.ParseException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Example 38 with CayenneRuntimeException

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;
}
Also used : SSLXMPPConnection(org.jivesoftware.smack.SSLXMPPConnection) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) SSLXMPPConnection(org.jivesoftware.smack.SSLXMPPConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException)

Example 39 with CayenneRuntimeException

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);
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) DataMapDefaults(org.apache.cayenne.modeler.pref.DataMapDefaults) ProjectStatePreferences(org.apache.cayenne.modeler.pref.ProjectStatePreferences) Preferences(java.util.prefs.Preferences) DataMap(org.apache.cayenne.map.DataMap)

Example 40 with CayenneRuntimeException

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);
    }
}
Also used : CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException) CayenneRuntimeException(org.apache.cayenne.CayenneRuntimeException)

Aggregations

CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)168 Test (org.junit.Test)25 DbAttribute (org.apache.cayenne.map.DbAttribute)21 DataMap (org.apache.cayenne.map.DataMap)19 ObjectId (org.apache.cayenne.ObjectId)18 ObjEntity (org.apache.cayenne.map.ObjEntity)18 Persistent (org.apache.cayenne.Persistent)17 Expression (org.apache.cayenne.exp.Expression)17 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)17 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 DbEntity (org.apache.cayenne.map.DbEntity)14 IOException (java.io.IOException)13 List (java.util.List)12 ObjRelationship (org.apache.cayenne.map.ObjRelationship)12 DbRelationship (org.apache.cayenne.map.DbRelationship)10 DateTestEntity (org.apache.cayenne.testdo.date_time.DateTestEntity)10 File (java.io.File)9 Connection (java.sql.Connection)9 SQLException (java.sql.SQLException)9