Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split SchemaRuleNotFoundException to more specific exceptions, introd…
…uce hierarchy of exceptions for duplicate schema rules. Provide tests for expected user messages.
- Loading branch information
1 parent
aa6ca0d
commit 12c003f
Showing
18 changed files
with
663 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../main/java/org/neo4j/kernel/api/exceptions/schema/DuplicateEntitySchemaRuleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,71 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.EntityType; | |||
import org.neo4j.kernel.api.TokenNameLookup; | |||
|
|||
import static java.lang.String.format; | |||
|
|||
public class DuplicateEntitySchemaRuleException extends DuplicateSchemaRuleException | |||
{ | |||
private static final String DUPLICATE_NODE_RULE_MESSAGE_TEMPLATE = | |||
"Multiple %s found for label '%s' and property '%s'."; | |||
private static final String DUPLICATED_RELATIONSHIP_RULE_MESSAGE_TEMPLATE = | |||
"Multiple %s found for relationship type '%s' and property '%s'."; | |||
|
|||
private EntityType entityType; | |||
|
|||
public DuplicateEntitySchemaRuleException( EntityType entityType, int entityId, int propertyKeyId ) | |||
{ | |||
this( entityType, entityId, propertyKeyId, false ); | |||
} | |||
|
|||
public DuplicateEntitySchemaRuleException( EntityType entityType, int ruleEntityId, int propertyKeyId, | |||
boolean unique ) | |||
{ | |||
super( getMessageTemplate( entityType ), ruleEntityId, propertyKeyId, | |||
unique ? UNIQUE_CONSTRAINT_PREFIX : CONSTRAINT_PREFIX ); | |||
this.entityType = entityType; | |||
} | |||
|
|||
|
|||
@Override | |||
public String getUserMessage( TokenNameLookup tokenNameLookup ) | |||
{ | |||
String entityName = EntityType.NODE == entityType ? tokenNameLookup.labelGetName( ruleEntityId ) : | |||
tokenNameLookup.relationshipTypeGetName( ruleEntityId ); | |||
return format( messageTemplate, messagePrefix, entityName, | |||
tokenNameLookup.propertyKeyGetName( propertyKeyId ) ); | |||
} | |||
|
|||
private static String getMessageTemplate( EntityType entityType ) | |||
{ | |||
switch ( entityType ) | |||
{ | |||
case NODE: | |||
return DUPLICATE_NODE_RULE_MESSAGE_TEMPLATE; | |||
case RELATIONSHIP: | |||
return DUPLICATED_RELATIONSHIP_RULE_MESSAGE_TEMPLATE; | |||
default: | |||
throw new IllegalArgumentException( "Schema rules for specified entityType not supported." ); | |||
} | |||
} | |||
} |
48 changes: 48 additions & 0 deletions
48
...c/main/java/org/neo4j/kernel/api/exceptions/schema/DuplicateIndexSchemaRuleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.TokenNameLookup; | |||
|
|||
import static java.lang.String.format; | |||
|
|||
public class DuplicateIndexSchemaRuleException extends DuplicateSchemaRuleException | |||
{ | |||
private static final String UNIQUE_INDEX_PREFIX = "uniqueness indexes"; | |||
private static final String INDEX_PREFIX = "indexes"; | |||
|
|||
private static final String DUPLICATE_INDEX_RULE_MESSAGE_TEMPLATE = | |||
"Multiple %s found for label '%s' and property '%s'."; | |||
|
|||
public DuplicateIndexSchemaRuleException( int ruleEntityId, int propertyKeyId, | |||
boolean unique ) | |||
{ | |||
super( DUPLICATE_INDEX_RULE_MESSAGE_TEMPLATE, ruleEntityId, propertyKeyId, | |||
unique ? UNIQUE_INDEX_PREFIX : INDEX_PREFIX ); | |||
} | |||
|
|||
@Override | |||
public String getUserMessage( TokenNameLookup tokenNameLookup ) | |||
{ | |||
return format( messageTemplate, messagePrefix, | |||
tokenNameLookup.labelGetName( ruleEntityId ), | |||
tokenNameLookup.propertyKeyGetName( propertyKeyId ) ); | |||
} | |||
} |
34 changes: 34 additions & 0 deletions
34
...el/src/main/java/org/neo4j/kernel/api/exceptions/schema/DuplicateSchemaRuleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.exceptions.Status; | |||
|
|||
public abstract class DuplicateSchemaRuleException extends SchemaRuleException | |||
{ | |||
protected static final String UNIQUE_CONSTRAINT_PREFIX = "uniqueness constraints"; | |||
protected static final String CONSTRAINT_PREFIX = "constraints"; | |||
|
|||
protected DuplicateSchemaRuleException( String messageTemplate, int ruleEntityId, int propertyKeyId, String | |||
messagePrefix ) | |||
{ | |||
super( Status.Schema.DuplicateSchemaRule, messageTemplate, ruleEntityId, propertyKeyId, messagePrefix ); | |||
} | |||
} |
66 changes: 66 additions & 0 deletions
66
...c/main/java/org/neo4j/kernel/api/exceptions/schema/EntitySchemaRuleNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,66 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.EntityType; | |||
import org.neo4j.kernel.api.TokenNameLookup; | |||
|
|||
public class EntitySchemaRuleNotFoundException extends SchemaRuleNotFoundException | |||
{ | |||
private static final String NODE_RULE_NOT_FOUND_MESSAGE_TEMPLATE = | |||
"%s for label '%s' and property '%s' not found."; | |||
private static final String RELATIONSHIP_RULE_NOT_FOUND_MESSAGE_TEMPLATE = | |||
"%s for relationship type '%s' and property '%s' not found."; | |||
private EntityType entityType; | |||
|
|||
public EntitySchemaRuleNotFoundException( EntityType entityType, int labelId, int propertyKeyId ) | |||
{ | |||
this( entityType, labelId, propertyKeyId, false ); | |||
} | |||
|
|||
public EntitySchemaRuleNotFoundException( EntityType entityType, int entityId, int propertyKeyId, boolean unique ) | |||
{ | |||
super( getMessageTemplate( entityType ), entityId, propertyKeyId, | |||
unique ? UNIQUE_CONSTRAINT_PREFIX : CONSTRAINT_PREFIX ); | |||
this.entityType = entityType; | |||
} | |||
|
|||
@Override | |||
public String getUserMessage( TokenNameLookup tokenNameLookup ) | |||
{ | |||
String entityName = EntityType.NODE == entityType ? tokenNameLookup.labelGetName( ruleEntityId ) : | |||
tokenNameLookup.relationshipTypeGetName( ruleEntityId ); | |||
return String.format( messageTemplate, messagePrefix, entityName, | |||
tokenNameLookup.propertyKeyGetName( propertyKeyId ) ); | |||
} | |||
|
|||
private static String getMessageTemplate( EntityType entityType ) | |||
{ | |||
switch ( entityType ) | |||
{ | |||
case NODE: | |||
return NODE_RULE_NOT_FOUND_MESSAGE_TEMPLATE; | |||
case RELATIONSHIP: | |||
return RELATIONSHIP_RULE_NOT_FOUND_MESSAGE_TEMPLATE; | |||
default: | |||
throw new IllegalArgumentException( "Schema rules for specified entityType not supported." ); | |||
} | |||
} | |||
} |
49 changes: 49 additions & 0 deletions
49
...rc/main/java/org/neo4j/kernel/api/exceptions/schema/IndexSchemaRuleNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.TokenNameLookup; | |||
|
|||
public class IndexSchemaRuleNotFoundException extends SchemaRuleNotFoundException | |||
{ | |||
private static final String UNIQUE_INDEX_PREFIX = "Uniqueness index"; | |||
private static final String INDEX_PREFIX = "Index"; | |||
private static final String INDEX_RULE_NOT_FOUND_MESSAGE_TEMPLATE = | |||
"%s for label '%s' and property '%s' not found."; | |||
|
|||
public IndexSchemaRuleNotFoundException( int labelId, int propertyKeyId ) | |||
{ | |||
this( labelId, propertyKeyId, false ); | |||
} | |||
|
|||
public IndexSchemaRuleNotFoundException( int labelId, int propertyKeyId, boolean unique ) | |||
{ | |||
super( INDEX_RULE_NOT_FOUND_MESSAGE_TEMPLATE, labelId, propertyKeyId, | |||
unique ? UNIQUE_INDEX_PREFIX : INDEX_PREFIX ); | |||
} | |||
|
|||
@Override | |||
public String getUserMessage( TokenNameLookup tokenNameLookup ) | |||
{ | |||
return String.format( messageTemplate, messagePrefix, | |||
tokenNameLookup.labelGetName( ruleEntityId ), | |||
tokenNameLookup.propertyKeyGetName( propertyKeyId ) ); | |||
} | |||
} |
43 changes: 43 additions & 0 deletions
43
...nity/kernel/src/main/java/org/neo4j/kernel/api/exceptions/schema/SchemaRuleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,43 @@ | |||
/* | |||
* Copyright (c) 2002-2015 "Neo Technology," | |||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | |||
* | |||
* This file is part of Neo4j. | |||
* | |||
* Neo4j is free software: you can redistribute it and/or modify | |||
* it under the terms of the GNU General Public License as published by | |||
* the Free Software Foundation, either version 3 of the License, or | |||
* (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
* GNU General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | |||
package org.neo4j.kernel.api.exceptions.schema; | |||
|
|||
import org.neo4j.kernel.api.exceptions.Status; | |||
|
|||
import static java.lang.String.format; | |||
|
|||
public class SchemaRuleException extends SchemaKernelException | |||
{ | |||
|
|||
protected final int ruleEntityId; | |||
protected final int propertyKeyId; | |||
protected final String messageTemplate; | |||
protected final String messagePrefix; | |||
|
|||
protected SchemaRuleException( Status status, String messageTemplate, int ruleEntityId, int propertyKeyId, | |||
String messagePrefix) | |||
{ | |||
super( status, format( messageTemplate, messagePrefix, ruleEntityId, propertyKeyId ) ); | |||
this.ruleEntityId = ruleEntityId; | |||
this.propertyKeyId = propertyKeyId; | |||
this.messageTemplate = messageTemplate; | |||
this.messagePrefix = messagePrefix; | |||
} | |||
} |
Oops, something went wrong.