You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2013/08/04 20:04:15 UTC
svn commit: r1510286 [3/3] - in /cayenne/main/trunk:
framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/
framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/access/
framework/cayenne-core-unpublished/src/main/java/org/a...
Modified: cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java (original)
+++ cayenne/main/trunk/framework/cayenne-wocompat-unpublished/src/main/java/org/apache/cayenne/wocompat/EOQuery.java Sun Aug 4 18:04:14 2013
@@ -40,9 +40,9 @@ import org.apache.cayenne.query.SelectQu
import org.apache.cayenne.query.SortOrder;
/**
- * A descriptor of SelectQuery loaded from EOModel. It is an informal "decorator" of
- * Cayenne SelectQuery to provide access to the extra information of WebObjects
- * EOFetchSpecification.
+ * A descriptor of SelectQuery loaded from EOModel. It is an informal
+ * "decorator" of Cayenne SelectQuery to provide access to the extra information
+ * of WebObjects EOFetchSpecification.
*
* @since 1.1
*/
@@ -66,19 +66,16 @@ public class EOQuery<T> extends SelectQu
try {
if (fetchLimit instanceof Number) {
setFetchLimit(((Number) fetchLimit).intValue());
- }
- else {
+ } else {
setFetchLimit(Integer.parseInt(fetchLimit.toString()));
}
- }
- catch (NumberFormatException nfex) {
+ } catch (NumberFormatException nfex) {
// ignoring...
}
}
// sort orderings
- List<Map<String, String>> orderings = (List<Map<String, String>>) plistMap
- .get("sortOrderings");
+ List<Map<String, String>> orderings = (List<Map<String, String>>) plistMap.get("sortOrderings");
if (orderings != null && !orderings.isEmpty()) {
for (Map<String, String> ordering : orderings) {
boolean asc = !"compareDescending:".equals(ordering.get("selectorName"));
@@ -104,7 +101,8 @@ public class EOQuery<T> extends SelectQu
}
}
- // data rows - note that we do not support fetching individual columns in the
+ // data rows - note that we do not support fetching individual columns
+ // in the
// modeler...
if (plistMap.containsKey("rawRowKeyPaths")) {
setFetchingDataRows(true);
@@ -114,8 +112,7 @@ public class EOQuery<T> extends SelectQu
public String getEOName() {
if (root instanceof EOObjEntity) {
return ((EOObjEntity) root).localQueryName(getName());
- }
- else {
+ } else {
return getName();
}
}
@@ -168,16 +165,17 @@ public class EOQuery<T> extends SelectQu
}
Map valueMap = (Map) value;
- if (!"EOQualifierVariable".equals(valueMap.get("class"))
- || !valueMap.containsKey("_key")) {
+ if (!"EOQualifierVariable".equals(valueMap.get("class")) || !valueMap.containsKey("_key")) {
return;
}
String name = (String) valueMap.get("_key");
String className = null;
- // we don't know whether its obj path or db path, so the expression can blow
- // ... in fact we can't support DB Path as the key is different from external
+ // we don't know whether its obj path or db path, so the expression
+ // can blow
+ // ... in fact we can't support DB Path as the key is different from
+ // external
// name,
// so we will use Object type for all DB path...
try {
@@ -185,16 +183,13 @@ public class EOQuery<T> extends SelectQu
if (lastObject instanceof ObjAttribute) {
className = ((ObjAttribute) lastObject).getType();
- }
- else if (lastObject instanceof ObjRelationship) {
- ObjEntity target = (ObjEntity) ((ObjRelationship) lastObject)
- .getTargetEntity();
+ } else if (lastObject instanceof ObjRelationship) {
+ ObjEntity target = ((ObjRelationship) lastObject).getTargetEntity();
if (target != null) {
className = target.getClassName();
}
}
- }
- catch (ExpressionException ex) {
+ } catch (ExpressionException ex) {
className = "java.lang.Object";
}
@@ -217,10 +212,11 @@ public class EOQuery<T> extends SelectQu
}
/**
- * Creates the Expression equivalent of the EOFetchSpecification represented by the
- * Map.
+ * Creates the Expression equivalent of the EOFetchSpecification represented
+ * by the Map.
*
- * @param qualifierMap - FetchSpecification to translate
+ * @param qualifierMap
+ * - FetchSpecification to translate
* @return Expression equivalent to FetchSpecification
*/
public synchronized Expression makeQualifier(Map<String, ?> qualifierMap) {
@@ -228,19 +224,18 @@ public class EOQuery<T> extends SelectQu
return null;
}
- return EOFetchSpecificationParser.makeQualifier(
- (EOObjEntity) getRoot(),
- qualifierMap);
+ return EOFetchSpecificationParser.makeQualifier((EOObjEntity) getRoot(), qualifierMap);
}
/**
- * EOFetchSpecificationParser parses EOFetchSpecifications from a WebObjects-style
- * EOModel. It recursively builds Cayenne Expression objects and assembles them into
- * the final aggregate Expression.
+ * EOFetchSpecificationParser parses EOFetchSpecifications from a
+ * WebObjects-style EOModel. It recursively builds Cayenne Expression
+ * objects and assembles them into the final aggregate Expression.
*/
static class EOFetchSpecificationParser {
- // Xcode/EOModeler expressions have a colon at the end of the selector name
+ // Xcode/EOModeler expressions have a colon at the end of the selector
+ // name
// (just like standard Objective-C syntax). WOLips does not. Add both
// sets to the hash map to handle both types of models.
@@ -259,10 +254,11 @@ public class EOQuery<T> extends SelectQu
private static HashMap<String, Integer> selectorToExpressionBridge;
/**
- * selectorToExpressionBridge is just a mapping of EOModeler's selector types to
- * Cayenne Expression types.
+ * selectorToExpressionBridge is just a mapping of EOModeler's selector
+ * types to Cayenne Expression types.
*
- * @return HashMap of Expression types, keyed by the corresponding selector name
+ * @return HashMap of Expression types, keyed by the corresponding
+ * selector name
*/
static synchronized HashMap<String, Integer> selectorToExpressionBridge() {
// Initialize selectorToExpressionBridge if needed.
@@ -273,53 +269,38 @@ public class EOQuery<T> extends SelectQu
selectorToExpressionBridge.put(IS_EQUAL_TO + OBJ_C, Expression.EQUAL_TO);
selectorToExpressionBridge.put(IS_NOT_EQUAL_TO, Expression.NOT_EQUAL_TO);
- selectorToExpressionBridge.put(
- IS_NOT_EQUAL_TO + OBJ_C,
- Expression.NOT_EQUAL_TO);
+ selectorToExpressionBridge.put(IS_NOT_EQUAL_TO + OBJ_C, Expression.NOT_EQUAL_TO);
selectorToExpressionBridge.put(IS_LIKE, Expression.LIKE);
selectorToExpressionBridge.put(IS_LIKE + OBJ_C, Expression.LIKE);
- selectorToExpressionBridge.put(
- CASE_INSENSITIVE_LIKE,
- Expression.LIKE_IGNORE_CASE);
- selectorToExpressionBridge.put(
- CASE_INSENSITIVE_LIKE + OBJ_C,
- Expression.LIKE_IGNORE_CASE);
+ selectorToExpressionBridge.put(CASE_INSENSITIVE_LIKE, Expression.LIKE_IGNORE_CASE);
+ selectorToExpressionBridge.put(CASE_INSENSITIVE_LIKE + OBJ_C, Expression.LIKE_IGNORE_CASE);
selectorToExpressionBridge.put(IS_LESS_THAN, Expression.LESS_THAN);
- selectorToExpressionBridge
- .put(IS_LESS_THAN + OBJ_C, Expression.LESS_THAN);
+ selectorToExpressionBridge.put(IS_LESS_THAN + OBJ_C, Expression.LESS_THAN);
- selectorToExpressionBridge.put(
- IS_LESS_THAN_OR_EQUAL_TO,
- Expression.LESS_THAN_EQUAL_TO);
- selectorToExpressionBridge.put(
- IS_LESS_THAN_OR_EQUAL_TO + OBJ_C,
- Expression.LESS_THAN_EQUAL_TO);
+ selectorToExpressionBridge.put(IS_LESS_THAN_OR_EQUAL_TO, Expression.LESS_THAN_EQUAL_TO);
+ selectorToExpressionBridge.put(IS_LESS_THAN_OR_EQUAL_TO + OBJ_C, Expression.LESS_THAN_EQUAL_TO);
selectorToExpressionBridge.put(IS_GREATER_THAN, Expression.GREATER_THAN);
- selectorToExpressionBridge.put(
- IS_GREATER_THAN + OBJ_C,
- Expression.GREATER_THAN);
-
- selectorToExpressionBridge.put(
- IS_GREATER_THAN_OR_EQUAL_TO,
- Expression.GREATER_THAN_EQUAL_TO);
- selectorToExpressionBridge.put(
- IS_GREATER_THAN_OR_EQUAL_TO + OBJ_C,
- Expression.GREATER_THAN_EQUAL_TO);
+ selectorToExpressionBridge.put(IS_GREATER_THAN + OBJ_C, Expression.GREATER_THAN);
+
+ selectorToExpressionBridge.put(IS_GREATER_THAN_OR_EQUAL_TO, Expression.GREATER_THAN_EQUAL_TO);
+ selectorToExpressionBridge.put(IS_GREATER_THAN_OR_EQUAL_TO + OBJ_C, Expression.GREATER_THAN_EQUAL_TO);
}
return selectorToExpressionBridge;
}
/**
- * isAggregate determines whether a qualifier is "aggregate" -- has children -- or
- * "simple".
+ * isAggregate determines whether a qualifier is "aggregate" -- has
+ * children -- or "simple".
*
- * @param qualifier - a Map containing the qualifier settings
- * @return boolean indicating whether the qualifier is "aggregate" qualifier
+ * @param qualifier
+ * - a Map containing the qualifier settings
+ * @return boolean indicating whether the qualifier is "aggregate"
+ * qualifier
*/
static boolean isAggregate(Map qualifier) {
boolean result = true;
@@ -337,11 +318,12 @@ public class EOQuery<T> extends SelectQu
}
/**
- * expressionTypeForQualifier looks at a qualifier containing the EOModeler
- * FetchSpecification and returns the equivalent Cayenne Expression type for its
- * selector.
+ * expressionTypeForQualifier looks at a qualifier containing the
+ * EOModeler FetchSpecification and returns the equivalent Cayenne
+ * Expression type for its selector.
*
- * @param qualifierMap - a Map containing the qualifier settings to examine.
+ * @param qualifierMap
+ * - a Map containing the qualifier settings to examine.
* @return int Expression type
*/
static int expressionTypeForQualifier(Map qualifierMap) {
@@ -352,9 +334,11 @@ public class EOQuery<T> extends SelectQu
/**
* expressionTypeForSelector looks at a selector from an EOModeler
- * FetchSpecification and returns the equivalent Cayenne Expression type.
+ * FetchSpecification and returns the equivalent Cayenne Expression
+ * type.
*
- * @param selector - a String containing the selector name.
+ * @param selector
+ * - a String containing the selector name.
* @return int Expression type
*/
static int expressionTypeForSelector(String selector) {
@@ -363,10 +347,12 @@ public class EOQuery<T> extends SelectQu
}
/**
- * aggregateExpressionClassForQualifier looks at a qualifer and returns the
- * aggregate type: one of Expression.AND, Expression.OR, or Expression.NOT
+ * aggregateExpressionClassForQualifier looks at a qualifer and returns
+ * the aggregate type: one of Expression.AND, Expression.OR, or
+ * Expression.NOT
*
- * @param qualifierMap - containing the qualifier to examine
+ * @param qualifierMap
+ * - containing the qualifier to examine
* @return int aggregate Expression type
*/
static int aggregateExpressionClassForQualifier(Map qualifierMap) {
@@ -374,11 +360,9 @@ public class EOQuery<T> extends SelectQu
if (qualifierClass != null) {
if (qualifierClass.equalsIgnoreCase("EOAndQualifier")) {
return Expression.AND;
- }
- else if (qualifierClass.equalsIgnoreCase("EOOrQualifier")) {
+ } else if (qualifierClass.equalsIgnoreCase("EOOrQualifier")) {
return Expression.OR;
- }
- else if (qualifierClass.equalsIgnoreCase("EONotQualifier")) {
+ } else if (qualifierClass.equalsIgnoreCase("EONotQualifier")) {
return Expression.NOT;
}
}
@@ -387,11 +371,12 @@ public class EOQuery<T> extends SelectQu
}
/**
- * makeQualifier recursively builds an Expression for each condition in the
- * qualifierMap and assembles from them the complex Expression to represent the
- * entire EOFetchSpecification.
+ * makeQualifier recursively builds an Expression for each condition in
+ * the qualifierMap and assembles from them the complex Expression to
+ * represent the entire EOFetchSpecification.
*
- * @param qualifierMap - Map representation of EOFetchSpecification
+ * @param qualifierMap
+ * - Map representation of EOFetchSpecification
* @return Expression translation of the EOFetchSpecification
*/
static Expression makeQualifier(EOObjEntity entity, Map qualifierMap) {
@@ -402,15 +387,16 @@ public class EOQuery<T> extends SelectQu
// NOT
if (aggregateClass == Expression.NOT) {
- // NOT qualifiers only have one child, keyed with "qualifier"
+ // NOT qualifiers only have one child, keyed with
+ // "qualifier"
Map child = (Map) qualifierMap.get("qualifier");
// build the child expression
Expression childExp = makeQualifier(entity, child);
- return childExp.notExp(); // add the "not" clause and return the
+ return childExp.notExp(); // add the "not" clause and return
+ // the
// result
- }
- else {
+ } else {
// AND, OR qualifiers can have multiple children, keyed with
// "qualifiers"
// get the list of children
@@ -424,8 +410,7 @@ public class EOQuery<T> extends SelectQu
childExpressions.add(childExp);
}
// join the child expressions and return the result
- return ExpressionFactory
- .joinExp(aggregateClass, childExpressions);
+ return ExpressionFactory.joinExp(aggregateClass, childExpressions);
}
}
@@ -437,7 +422,8 @@ public class EOQuery<T> extends SelectQu
// the key or key path we're comparing
String key = null;
- // the key, keyPath, value, or parameterized value against which we're
+ // the key, keyPath, value, or parameterized value against which
+ // we're
// comparing the key
Object comparisonValue = null;
@@ -446,11 +432,11 @@ public class EOQuery<T> extends SelectQu
key = (String) qualifierMap.get("leftValue");
comparisonValue = qualifierMap.get("rightValue");
- // FIXME: I think EOKeyComparisonQualifier sytle Expressions are not
+ // FIXME: I think EOKeyComparisonQualifier sytle Expressions are
+ // not
// supported...
return null;
- }
- else if ("EOKeyValueQualifier".equals(qualifierClass)) {
+ } else if ("EOKeyValueQualifier".equals(qualifierClass)) {
// Comparing key with a value or parameterized value
key = (String) qualifierMap.get("key");
Object value = qualifierMap.get("value");
@@ -461,36 +447,33 @@ public class EOQuery<T> extends SelectQu
// qualifier class
// or java type
- if ("EOQualifierVariable".equals(objClass)
- && valueMap.containsKey("_key")) {
+ if ("EOQualifierVariable".equals(objClass) && valueMap.containsKey("_key")) {
// make a parameterized expression
String paramName = valueMap.get("_key");
comparisonValue = new ExpressionParameter(paramName);
- }
- else {
+ } else {
Object queryVal = valueMap.get("value");
if ("NSNumber".equals(objClass)) {
// comparison to NSNumber -- cast
comparisonValue = queryVal;
- }
- else if ("EONull".equals(objClass)) {
+ } else if ("EONull".equals(objClass)) {
// comparison to null
comparisonValue = null;
- }
- else { // Could there be other types? boolean, date, etc.???
- // no cast
+ } else { // Could there be other types? boolean, date,
+ // etc.???
+ // no cast
comparisonValue = queryVal;
}
}
- }
- else if (value instanceof String) {
+ } else if (value instanceof String) {
// value expression
comparisonValue = value;
} // end if (value instanceof Map) else...
}
- // check whether the key is an object path; if at least one component is not,
+ // check whether the key is an object path; if at least one
+ // component is not,
// switch to db path..
Expression keyExp = Expression.fromString(key);
@@ -505,14 +488,12 @@ public class EOQuery<T> extends SelectQu
}
try {
- Expression exp = ExpressionFactory
- .expressionOfType(expressionTypeForQualifier(qualifierMap));
+ Expression exp = ExpressionFactory.expressionOfType(expressionTypeForQualifier(qualifierMap));
exp.setOperand(0, keyExp);
exp.setOperand(1, comparisonValue);
return exp;
- }
- catch (ExpressionException e) {
+ } catch (ExpressionException e) {
return null;
}
}
Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateAttributeAction.java Sun Aug 4 18:04:14 2013
@@ -48,8 +48,6 @@ import org.apache.cayenne.util.NamedObje
*/
public class CreateAttributeAction extends CayenneAction {
-
-
public static String getActionName() {
return "Create Attribute";
}
@@ -76,54 +74,36 @@ public class CreateAttributeAction exten
if (getProjectController().getCurrentEmbeddable() != null) {
Embeddable embeddable = mediator.getCurrentEmbeddable();
- EmbeddableAttribute attr = (EmbeddableAttribute) NamedObjectFactory
- .createObject(EmbeddableAttribute.class, embeddable);
+ EmbeddableAttribute attr = (EmbeddableAttribute) NamedObjectFactory.createObject(EmbeddableAttribute.class,
+ embeddable);
createEmbAttribute(embeddable, attr);
application.getUndoManager().addEdit(
- new CreateEmbAttributeUndoableEdit(
- embeddable,
- new EmbeddableAttribute[] {
- attr
- }));
+ new CreateEmbAttributeUndoableEdit(embeddable, new EmbeddableAttribute[] { attr }));
}
if (getProjectController().getCurrentObjEntity() != null) {
ObjEntity objEntity = mediator.getCurrentObjEntity();
- ObjAttribute attr = (ObjAttribute) NamedObjectFactory.createObject(
- ObjAttribute.class,
- objEntity);
-
- createObjAttribute(mediator
- .getCurrentDataMap(), objEntity, attr);
+ ObjAttribute attr = NamedObjectFactory.createObject(ObjAttribute.class, objEntity);
+
+ createObjAttribute(mediator.getCurrentDataMap(), objEntity, attr);
application.getUndoManager().addEdit(
- new CreateAttributeUndoableEdit(
- (DataChannelDescriptor)mediator.getProject().getRootNode(),
- mediator.getCurrentDataMap(),
- objEntity,
- attr));
- }
- else if (getProjectController().getCurrentDbEntity() != null) {
+ new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(),
+ mediator.getCurrentDataMap(), objEntity, attr));
+ } else if (getProjectController().getCurrentDbEntity() != null) {
DbEntity dbEntity = getProjectController().getCurrentDbEntity();
- DbAttribute attr = (DbAttribute) NamedObjectFactory.createObject(
- DbAttribute.class,
- dbEntity);
-
- createDbAttribute(
- mediator
- .getCurrentDataMap(), dbEntity, attr);
+ DbAttribute attr = NamedObjectFactory.createObject(DbAttribute.class, dbEntity);
+
+ createDbAttribute(mediator.getCurrentDataMap(), dbEntity, attr);
application.getUndoManager().addEdit(
- new CreateAttributeUndoableEdit(
- (DataChannelDescriptor)mediator.getProject().getRootNode(),
- mediator.getCurrentDataMap(),
- dbEntity,
- attr));
+ new CreateAttributeUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(),
+ mediator.getCurrentDataMap(), dbEntity, attr));
}
}
@@ -133,32 +113,18 @@ public class CreateAttributeAction exten
fireEmbeddableAttributeEvent(this, mediator, embeddable, attr);
}
- static void fireEmbeddableAttributeEvent(
- Object src,
- ProjectController mediator,
- Embeddable embeddable,
+ static void fireEmbeddableAttributeEvent(Object src, ProjectController mediator, Embeddable embeddable,
EmbeddableAttribute attr) {
- mediator.fireEmbeddableAttributeEvent(new EmbeddableAttributeEvent(
- src,
- attr,
- embeddable,
- MapEvent.ADD));
-
- EmbeddableAttributeDisplayEvent e = new EmbeddableAttributeDisplayEvent(
- src,
- embeddable,
- attr,
- mediator.getCurrentDataMap(),
- (DataChannelDescriptor)mediator.getProject().getRootNode());
+ mediator.fireEmbeddableAttributeEvent(new EmbeddableAttributeEvent(src, attr, embeddable, MapEvent.ADD));
+
+ EmbeddableAttributeDisplayEvent e = new EmbeddableAttributeDisplayEvent(src, embeddable, attr,
+ mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireEmbeddableAttributeDisplayEvent(e);
}
- public void createObjAttribute(
- DataMap map,
- ObjEntity objEntity,
- ObjAttribute attr) {
+ public void createObjAttribute(DataMap map, ObjEntity objEntity, ObjAttribute attr) {
ProjectController mediator = getProjectController();
objEntity.addAttribute(attr);
@@ -168,35 +134,19 @@ public class CreateAttributeAction exten
/**
* Fires events when an obj attribute was added
*/
- static void fireObjAttributeEvent(
- Object src,
- ProjectController mediator,
- DataMap map,
- ObjEntity objEntity,
+ static void fireObjAttributeEvent(Object src, ProjectController mediator, DataMap map, ObjEntity objEntity,
ObjAttribute attr) {
- mediator.fireObjAttributeEvent(new AttributeEvent(
- src,
- attr,
- objEntity,
- MapEvent.ADD));
-
- DataChannelDescriptor domain = (DataChannelDescriptor)mediator.getProject().getRootNode();
-
- AttributeDisplayEvent ade = new AttributeDisplayEvent(
- src,
- attr,
- objEntity,
- map,
- domain);
+ mediator.fireObjAttributeEvent(new AttributeEvent(src, attr, objEntity, MapEvent.ADD));
+
+ DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
+
+ AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, objEntity, map, domain);
mediator.fireObjAttributeDisplayEvent(ade);
}
- public void createDbAttribute(
- DataMap map,
- DbEntity dbEntity,
- DbAttribute attr) {
+ public void createDbAttribute(DataMap map, DbEntity dbEntity, DbAttribute attr) {
dbEntity.addAttribute(attr);
ProjectController mediator = getProjectController();
fireDbAttributeEvent(this, mediator, map, dbEntity, attr);
@@ -205,24 +155,12 @@ public class CreateAttributeAction exten
/**
* Fires events when a db attribute was added
*/
- static void fireDbAttributeEvent(
- Object src,
- ProjectController mediator,
- DataMap map,
- DbEntity dbEntity,
+ static void fireDbAttributeEvent(Object src, ProjectController mediator, DataMap map, DbEntity dbEntity,
DbAttribute attr) {
- mediator.fireDbAttributeEvent(new AttributeEvent(
- src,
- attr,
- dbEntity,
- MapEvent.ADD));
-
- AttributeDisplayEvent ade = new AttributeDisplayEvent(
- src,
- attr,
- dbEntity,
- map,
- (DataChannelDescriptor)mediator.getProject().getRootNode());
+ mediator.fireDbAttributeEvent(new AttributeEvent(src, attr, dbEntity, MapEvent.ADD));
+
+ AttributeDisplayEvent ade = new AttributeDisplayEvent(src, attr, dbEntity, map,
+ (DataChannelDescriptor) mediator.getProject().getRootNode());
mediator.fireDbAttributeDisplayEvent(ade);
}
@@ -236,10 +174,10 @@ public class CreateAttributeAction exten
return false;
}
- if(object instanceof Attribute){
- return ((Attribute)object).getParent() != null && ((Attribute)object).getParent() instanceof Entity;
+ if (object instanceof Attribute) {
+ return ((Attribute) object).getParent() != null && ((Attribute) object).getParent() instanceof Entity;
}
-
+
return false;
}
}
Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/codegen/GeneratorController.java Sun Aug 4 18:04:14 2013
@@ -30,9 +30,8 @@ import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
-import org.apache.cayenne.gen.ClassGenerationAction;
import org.apache.cayenne.gen.ArtifactsGenerationMode;
-import org.apache.cayenne.map.Attribute;
+import org.apache.cayenne.gen.ClassGenerationAction;
import org.apache.cayenne.map.Embeddable;
import org.apache.cayenne.map.EmbeddableAttribute;
import org.apache.cayenne.map.EmbeddedAttribute;
@@ -82,10 +81,8 @@ public abstract class GeneratorControlle
initOutputFolder();
- JTextField outputFolder = ((GeneratorControllerPanel) getView())
- .getOutputFolder();
- JButton outputSelect = ((GeneratorControllerPanel) getView())
- .getSelectOutputFolder();
+ JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder();
+ JButton outputSelect = ((GeneratorControllerPanel) getView()).getSelectOutputFolder();
outputFolder.setText(getOutputPath());
bindingBuilder.bindToAction(outputSelect, "selectOutputFolderAction()");
@@ -101,9 +98,9 @@ public abstract class GeneratorControlle
protected abstract DataMapDefaults createDefaults();
/**
- * Creates an appropriate subclass of {@link ClassGenerationAction}, returning it in
- * an unconfigured state. Configuration is performed by {@link #createGenerator()}
- * method.
+ * Creates an appropriate subclass of {@link ClassGenerationAction},
+ * returning it in an unconfigured state. Configuration is performed by
+ * {@link #createGenerator()} method.
*/
protected abstract ClassGenerationAction newGenerator();
@@ -116,30 +113,25 @@ public abstract class GeneratorControlle
// no destination folder
if (outputDir == null) {
- JOptionPane.showMessageDialog(
- this.getView(),
- "Select directory for source files.");
+ JOptionPane.showMessageDialog(this.getView(), "Select directory for source files.");
return null;
}
// no such folder
if (!outputDir.exists() && !outputDir.mkdirs()) {
- JOptionPane.showMessageDialog(this.getView(), "Can't create directory "
- + outputDir
+ JOptionPane.showMessageDialog(this.getView(), "Can't create directory " + outputDir
+ ". Select a different one.");
return null;
}
// not a directory
if (!outputDir.isDirectory()) {
- JOptionPane.showMessageDialog(this.getView(), outputDir
- + " is not a valid directory.");
+ JOptionPane.showMessageDialog(this.getView(), outputDir + " is not a valid directory.");
return null;
}
// remove generic entities...
- Collection<ObjEntity> entities = new ArrayList<ObjEntity>(getParentController()
- .getSelectedEntities());
+ Collection<ObjEntity> entities = new ArrayList<ObjEntity>(getParentController().getSelectedEntities());
Iterator<ObjEntity> it = entities.iterator();
while (it.hasNext()) {
if (it.next().isGeneric()) {
@@ -154,22 +146,16 @@ public abstract class GeneratorControlle
generator.addEmbeddables(getParentController().getSelectedEmbeddables());
generator.addQueries(getParentController().getDataMap().getQueries());
- Preferences preferences = application.getPreferencesNode(
- GeneralPreferences.class,
- "");
+ Preferences preferences = application.getPreferencesNode(GeneralPreferences.class, "");
if (preferences != null) {
- generator.setEncoding(preferences.get(
- GeneralPreferences.ENCODING_PREFERENCE,
- null));
+ generator.setEncoding(preferences.get(GeneralPreferences.ENCODING_PREFERENCE, null));
}
generator.setDestDir(outputDir);
generator.setMakePairs(true);
- String superPackage = ((GeneratorControllerPanel) getView())
- .getSuperclassPackage()
- .getText();
+ String superPackage = ((GeneratorControllerPanel) getView()).getSuperclassPackage().getText();
if (!Util.isEmptyString(superPackage)) {
generator.setSuperPkg(superPackage);
}
@@ -177,9 +163,7 @@ public abstract class GeneratorControlle
return generator;
}
- public void validateEmbeddable(
- ValidationResult validationBuffer,
- Embeddable embeddable) {
+ public void validateEmbeddable(ValidationResult validationBuffer, Embeddable embeddable) {
ValidationFailure embeddableFailure = validateEmbeddable(embeddable);
if (embeddableFailure != null) {
validationBuffer.addFailure(embeddableFailure);
@@ -198,33 +182,25 @@ public abstract class GeneratorControlle
private ValidationFailure validateEmbeddableAttribute(EmbeddableAttribute attribute) {
String name = attribute.getEmbeddable().getClassName();
- ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.name",
+ ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name",
attribute.getName());
if (emptyName != null) {
return emptyName;
}
- ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(
- name,
- "attribute.name",
+ ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name",
attribute.getName());
if (badName != null) {
return badName;
}
- ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.type",
+ ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type",
attribute.getType());
if (emptyType != null) {
return emptyType;
}
- ValidationFailure badType = BeanValidationFailure.validateJavaClassName(
- name,
- "attribute.type",
+ ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type",
attribute.getType());
if (badType != null) {
return badType;
@@ -237,17 +213,13 @@ public abstract class GeneratorControlle
String name = embeddable.getClassName();
- ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(
- name,
- "className",
+ ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "className",
embeddable.getClassName());
if (emptyClass != null) {
return emptyClass;
}
- ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(
- name,
- "className",
+ ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name, "className",
embeddable.getClassName());
if (badClass != null) {
return badClass;
@@ -256,19 +228,15 @@ public abstract class GeneratorControlle
return null;
}
- public void validateEntity(
- ValidationResult validationBuffer,
- ObjEntity entity,
- boolean clientValidation) {
+ public void validateEntity(ValidationResult validationBuffer, ObjEntity entity, boolean clientValidation) {
- ValidationFailure entityFailure = validateEntity(clientValidation ? entity
- .getClientEntity() : entity);
+ ValidationFailure entityFailure = validateEntity(clientValidation ? entity.getClientEntity() : entity);
if (entityFailure != null) {
validationBuffer.addFailure(entityFailure);
return;
}
- for (Attribute attribute : entity.getAttributes()) {
+ for (ObjAttribute attribute : entity.getAttributes()) {
if (attribute instanceof EmbeddedAttribute) {
EmbeddedAttribute embeddedAttribute = (EmbeddedAttribute) attribute;
for (ObjAttribute subAttribute : embeddedAttribute.getAttributes()) {
@@ -278,10 +246,9 @@ public abstract class GeneratorControlle
return;
}
}
- }
- else {
+ } else {
- ValidationFailure failure = validateAttribute((ObjAttribute) attribute);
+ ValidationFailure failure = validateAttribute(attribute);
if (failure != null) {
validationBuffer.addFailure(failure);
return;
@@ -306,26 +273,20 @@ public abstract class GeneratorControlle
return new SimpleValidationFailure(name, "Generic class");
}
- ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(
- name,
- "className",
- entity.getClassName());
+ ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "className", entity.getClassName());
if (emptyClass != null) {
return emptyClass;
}
- ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(
- name,
- "className",
+ ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name, "className",
entity.getClassName());
if (badClass != null) {
return badClass;
}
if (entity.getSuperClassName() != null) {
- ValidationFailure badSuperClass = BeanValidationFailure
- .validateJavaClassName(name, "superClassName", entity
- .getSuperClassName());
+ ValidationFailure badSuperClass = BeanValidationFailure.validateJavaClassName(name, "superClassName",
+ entity.getSuperClassName());
if (badSuperClass != null) {
return badSuperClass;
}
@@ -338,33 +299,25 @@ public abstract class GeneratorControlle
String name = attribute.getEntity().getName();
- ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.name",
+ ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name",
attribute.getName());
if (emptyName != null) {
return emptyName;
}
- ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(
- name,
- "attribute.name",
+ ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name",
attribute.getName());
if (badName != null) {
return badName;
}
- ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.type",
+ ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type",
attribute.getType());
if (emptyType != null) {
return emptyType;
}
- ValidationFailure badType = BeanValidationFailure.validateJavaClassName(
- name,
- "attribute.type",
+ ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type",
attribute.getType());
if (badType != null) {
return badType;
@@ -385,49 +338,35 @@ public abstract class GeneratorControlle
int beginIndex = attributes[0].length();
String attr = attribute.getName().substring(beginIndex + 1);
- ValidationFailure emptyEmbeddedName = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.name",
+ ValidationFailure emptyEmbeddedName = BeanValidationFailure.validateNotEmpty(name, "attribute.name",
nameEmbeddedAttribute);
if (emptyEmbeddedName != null) {
return emptyEmbeddedName;
}
- ValidationFailure badEmbeddedName = CodeValidationUtil.validateJavaIdentifier(
- name,
- "attribute.name",
+ ValidationFailure badEmbeddedName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name",
nameEmbeddedAttribute);
if (badEmbeddedName != null) {
return badEmbeddedName;
}
- ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.name",
- attr);
+ ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "attribute.name", attr);
if (emptyName != null) {
return emptyName;
}
- ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(
- name,
- "attribute.name",
- attr);
+ ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "attribute.name", attr);
if (badName != null) {
return badName;
}
- ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(
- name,
- "attribute.type",
+ ValidationFailure emptyType = BeanValidationFailure.validateNotEmpty(name, "attribute.type",
attribute.getType());
if (emptyType != null) {
return emptyType;
}
- ValidationFailure badType = BeanValidationFailure.validateJavaClassName(
- name,
- "attribute.type",
+ ValidationFailure badType = BeanValidationFailure.validateJavaClassName(name, "attribute.type",
attribute.getType());
if (badType != null) {
return badType;
@@ -436,23 +375,17 @@ public abstract class GeneratorControlle
return null;
}
- protected ValidationFailure validateRelationship(
- ObjRelationship relationship,
- boolean clientValidation) {
+ protected ValidationFailure validateRelationship(ObjRelationship relationship, boolean clientValidation) {
String name = relationship.getSourceEntity().getName();
- ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(
- name,
- "relationship.name",
+ ValidationFailure emptyName = BeanValidationFailure.validateNotEmpty(name, "relationship.name",
relationship.getName());
if (emptyName != null) {
return emptyName;
}
- ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(
- name,
- "relationship.name",
+ ValidationFailure badName = CodeValidationUtil.validateJavaIdentifier(name, "relationship.name",
relationship.getName());
if (badName != null) {
return badName;
@@ -468,24 +401,16 @@ public abstract class GeneratorControlle
if (targetEntity == null) {
- return new BeanValidationFailure(
- name,
- "relationship.targetEntity",
- "No target entity");
- }
- else if (!targetEntity.isGeneric()) {
- ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(
- name,
- "relationship.targetEntity.className",
- targetEntity.getClassName());
+ return new BeanValidationFailure(name, "relationship.targetEntity", "No target entity");
+ } else if (!targetEntity.isGeneric()) {
+ ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name,
+ "relationship.targetEntity.className", targetEntity.getClassName());
if (emptyClass != null) {
return emptyClass;
}
- ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(
- name,
- "relationship.targetEntity.className",
- targetEntity.getClassName());
+ ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name,
+ "relationship.targetEntity.className", targetEntity.getClassName());
if (badClass != null) {
return badClass;
}
@@ -499,22 +424,15 @@ public abstract class GeneratorControlle
* Returns a predicate for default entity selection in a given mode.
*/
public Predicate getDefaultClassFilter() {
- final ObjEntity selectedEntity = Application
- .getInstance()
- .getFrameController()
- .getProjectController()
+ final ObjEntity selectedEntity = Application.getInstance().getFrameController().getProjectController()
.getCurrentObjEntity();
- final Embeddable selectedEmbeddable = Application
- .getInstance()
- .getFrameController()
- .getProjectController()
+ final Embeddable selectedEmbeddable = Application.getInstance().getFrameController().getProjectController()
.getCurrentEmbeddable();
// select a single entity
if (selectedEntity != null) {
- final boolean hasProblem = getParentController().getProblem(
- selectedEntity.getName()) != null;
+ final boolean hasProblem = getParentController().getProblem(selectedEntity.getName()) != null;
return new Predicate() {
@@ -525,8 +443,7 @@ public abstract class GeneratorControlle
}
// select a single embeddable
else if (selectedEmbeddable != null) {
- final boolean hasProblem = getParentController().getProblem(
- selectedEmbeddable.getClassName()) != null;
+ final boolean hasProblem = getParentController().getProblem(selectedEmbeddable.getClassName()) != null;
return new Predicate() {
@@ -542,13 +459,11 @@ public abstract class GeneratorControlle
public boolean evaluate(Object object) {
if (object instanceof ObjEntity) {
- return getParentController().getProblem(
- ((ObjEntity) object).getName()) == null;
+ return getParentController().getProblem(((ObjEntity) object).getName()) == null;
}
if (object instanceof Embeddable) {
- return getParentController().getProblem(
- ((Embeddable) object).getClassName()) == null;
+ return getParentController().getProblem(((Embeddable) object).getClassName()) == null;
}
return false;
@@ -567,13 +482,12 @@ public abstract class GeneratorControlle
}
/**
- * An action method that pops up a file chooser dialog to pick the generation
- * directory.
+ * An action method that pops up a file chooser dialog to pick the
+ * generation directory.
*/
public void selectOutputFolderAction() {
- JTextField outputFolder = ((GeneratorControllerPanel) getView())
- .getOutputFolder();
+ JTextField outputFolder = ((GeneratorControllerPanel) getView()).getOutputFolder();
String currentDir = outputFolder.getText();
@@ -584,12 +498,8 @@ public abstract class GeneratorControlle
// guess start directory
if (!Util.isEmptyString(currentDir)) {
chooser.setCurrentDirectory(new File(currentDir));
- }
- else {
- FSPath lastDir = Application
- .getInstance()
- .getFrameController()
- .getLastDirectory();
+ } else {
+ FSPath lastDir = Application.getInstance().getFrameController().getLastDirectory();
lastDir.updateChooser(chooser);
}
@@ -610,23 +520,16 @@ public abstract class GeneratorControlle
if (preferences.getOutputPath() == null) {
if (System.getProperty("cayenne.cgen.destdir") != null) {
setOutputPath(System.getProperty("cayenne.cgen.destdir"));
- }
- else {
+ } else {
// init default directory..
- FSPath lastPath = Application
- .getInstance()
- .getFrameController()
- .getLastDirectory();
+ FSPath lastPath = Application.getInstance().getFrameController().getLastDirectory();
path = checkDefaultMavenResourceDir(lastPath, "test");
- if (path != null
- || (path = checkDefaultMavenResourceDir(lastPath, "main")) != null) {
+ if (path != null || (path = checkDefaultMavenResourceDir(lastPath, "main")) != null) {
setOutputPath(path);
- }
- else {
- File lastDir = (lastPath != null) ? lastPath
- .getExistingDirectory(false) : null;
+ } else {
+ File lastDir = (lastPath != null) ? lastPath.getExistingDirectory(false) : null;
setOutputPath(lastDir != null ? lastDir.getAbsolutePath() : null);
}
}
@@ -640,8 +543,7 @@ public abstract class GeneratorControlle
if (idx < 0) {
return null;
}
- return path.substring(0, idx)
- + buildFilePath("src", dirType, "java")
+ return path.substring(0, idx) + buildFilePath("src", dirType, "java")
+ path.substring(idx + resourcePath.length());
}
Modified: cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/validator/DuplicatedAttributesDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/validator/DuplicatedAttributesDialog.java?rev=1510286&r1=1510285&r2=1510286&view=diff
==============================================================================
--- cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/validator/DuplicatedAttributesDialog.java (original)
+++ cayenne/main/trunk/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/validator/DuplicatedAttributesDialog.java Sun Aug 4 18:04:14 2013
@@ -175,8 +175,7 @@ public class DuplicatedAttributesDialog
for (ObjAttribute attribute : attributes) {
DuplicatedAttributeInfo attributeInfo = new DuplicatedAttributeInfo(attribute.getName(),
- attribute.getType(), ((ObjAttribute) superEntity.getAttribute(attribute.getName())).getType(),
- DELETE_ACTION);
+ attribute.getType(), superEntity.getAttribute(attribute.getName()).getType(), DELETE_ACTION);
duplicatedAttributes.add(attributeInfo);
}