use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class DbImportConfigurationValidator method validate.
public void validate() throws Exception {
DataNodeDescriptor dataNodeDescriptor = config.createDataNodeDescriptor();
DbAdapter adapter;
try {
DataSource dataSource = injector.getInstance(DataSourceFactory.class).getDataSource(dataNodeDescriptor);
adapter = injector.getInstance(DbAdapterFactory.class).createAdapter(dataNodeDescriptor, dataSource);
} catch (Exception ex) {
throw new Exception("Error creating DataSource or DbAdapter for DataNodeDescriptor (" + dataNodeDescriptor + ")", ex);
}
if (adapter != null && !adapter.supportsCatalogsOnReverseEngineering() && !isReverseEngineeringCatalogsEmpty()) {
String message = "Your database does not support catalogs on reverse engineering. " + "It allows to connect to only one at the moment. " + "Please don't note catalogs in <dbimport> configuration.";
throw new Exception(message);
}
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class DBCP2DataSourceFactoryTest method testGetDataSource_InvalidLocation.
@Test
public void testGetDataSource_InvalidLocation() throws Exception {
String baseUrl = getClass().getPackage().getName().replace('.', '/');
URL url = getClass().getClassLoader().getResource(baseUrl + "/");
assertNotNull(url);
DataNodeDescriptor nodeDescriptor = new DataNodeDescriptor();
nodeDescriptor.setConfigurationSource(new URLResource(url));
nodeDescriptor.setParameters("testDBCP2.properties.nosuchfile");
DBCPDataSourceFactory factory = new DBCPDataSourceFactory();
try {
factory.getDataSource(nodeDescriptor);
fail("didn't throw on absent config file");
} catch (IOException ex) {
// expected
}
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class MainDataNodeEditor method setNodeName.
public void setNodeName(String newName) {
if (node == null) {
return;
}
// validate...
if (newName == null) {
throw new ValidationException("Empty DataNode Name");
}
ProjectController parent = (ProjectController) getParent();
DataNodeDefaults oldPref = parent.getDataNodePreferences();
DataChannelDescriptor dataChannelDescriptor = (DataChannelDescriptor) getApplication().getProject().getRootNode();
Collection<DataNodeDescriptor> matchingNode = dataChannelDescriptor.getNodeDescriptors();
Iterator<DataNodeDescriptor> it = matchingNode.iterator();
while (it.hasNext()) {
DataNodeDescriptor node = it.next();
if (node.getName().equals(newName)) {
// there is an entity with the same name
throw new ValidationException("There is another DataNode named '" + newName + "'. Use a different name.");
}
}
// passed validation, set value...
// TODO: fixme....there is a slight chance that domain is different than
// the one
// cached node belongs to
ProjectUtil.setDataNodeName((DataChannelDescriptor) parent.getProject().getRootNode(), node, newName);
oldPref.copyPreferences(newName);
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class LinkDataMapUndoableEdit method undo.
@Override
public void undo() throws CannotUndoException {
if (node != null) {
node.getDataMapNames().remove(map.getName());
mediator.fireDataNodeEvent(new DataNodeEvent(this, node));
}
if (!unlinkedNodes.isEmpty()) {
for (DataNodeDescriptor unlinkedNode : unlinkedNodes) {
unlinkedNode.getDataMapNames().add(map.getName());
mediator.fireDataNodeEvent(new DataNodeEvent(this, unlinkedNode));
}
}
}
use of org.apache.cayenne.configuration.DataNodeDescriptor in project cayenne by apache.
the class PasteUndoableEdit method undo.
@Override
public void undo() throws CannotUndoException {
RemoveAttributeAction rAttributeAction = actionManager.getAction(RemoveAttributeAction.class);
RemoveAction rAction = actionManager.getAction(RemoveAction.class);
RemoveRelationshipAction rRelationShipAction = actionManager.getAction(RemoveRelationshipAction.class);
RemoveCallbackMethodAction rCallbackMethodAction = actionManager.getAction(RemoveCallbackMethodAction.class);
RemoveProcedureParameterAction rProcedureParamAction = actionManager.getAction(RemoveProcedureParameterAction.class);
if (content instanceof DataMap) {
if (where instanceof DataChannelDescriptor) {
rAction.removeDataMap((DataMap) content);
} else if (where instanceof DataNodeDescriptor) {
rAction.removeDataMapFromDataNode((DataNodeDescriptor) where, (DataMap) content);
}
} else if (where instanceof DataMap) {
if (content instanceof DbEntity) {
rAction.removeDbEntity(map, (DbEntity) content);
} else if (content instanceof ObjEntity) {
rAction.removeObjEntity(map, (ObjEntity) content);
} else if (content instanceof Embeddable) {
rAction.removeEmbeddable(map, (Embeddable) content);
} else if (content instanceof QueryDescriptor) {
rAction.removeQuery(map, (QueryDescriptor) content);
} else if (content instanceof Procedure) {
rAction.removeProcedure(map, (Procedure) content);
}
} else if (where instanceof DbEntity) {
if (content instanceof DbEntity) {
rAction.removeDbEntity(map, (DbEntity) content);
} else if (content instanceof DbAttribute) {
rAttributeAction.removeDbAttributes(map, (DbEntity) where, new DbAttribute[] { (DbAttribute) content });
} else if (content instanceof DbRelationship) {
rRelationShipAction.removeDbRelationships((DbEntity) where, new DbRelationship[] { (DbRelationship) content });
}
} else if (where instanceof ObjEntity) {
if (content instanceof ObjEntity) {
rAction.removeObjEntity(map, (ObjEntity) content);
} else if (content instanceof ObjAttribute) {
rAttributeAction.removeObjAttributes((ObjEntity) where, new ObjAttribute[] { (ObjAttribute) content });
} else if (content instanceof ObjRelationship) {
rRelationShipAction.removeObjRelationships((ObjEntity) where, new ObjRelationship[] { (ObjRelationship) content });
} else if (content instanceof ObjCallbackMethod) {
ObjCallbackMethod[] methods = new ObjCallbackMethod[] { (ObjCallbackMethod) content };
for (ObjCallbackMethod callbackMethod : methods) {
rCallbackMethodAction.removeCallbackMethod(methods[0].getCallbackType(), callbackMethod.getName());
}
}
} else if (where instanceof Procedure) {
final Procedure procedure = (Procedure) where;
if (content instanceof ProcedureParameter) {
rProcedureParamAction.removeProcedureParameters(procedure, new ProcedureParameter[] { (ProcedureParameter) content });
}
} else if (where instanceof Embeddable) {
if (content instanceof Embeddable) {
rAction.removeEmbeddable(map, (Embeddable) content);
} else if (content instanceof EmbeddableAttribute) {
rAttributeAction.removeEmbeddableAttributes((Embeddable) where, new EmbeddableAttribute[] { (EmbeddableAttribute) content });
}
}
}
Aggregations