private NucleusException noMetaDataException(String member, String fullClassName) { return new NucleusFatalUserException( "No meta-data for member named " + member + " on class " + fullClassName + ". Are you sure you provided the correct member name in your query?"); }
public static NucleusException wrapIllegalArgumentException(IllegalArgumentException e) { // Bad input, so mark fatal to let user know not to retry. return new NucleusFatalUserException("Illegal argument", e); }
if (!f.isDirectory()) throw new NucleusFatalUserException("Invalid binarystream spool directory:" + spool); if (!f.isDirectory()) throw new NucleusFatalUserException("Invalid binarystream spool directory:" + spool); throw new NucleusFatalUserException("Cannot get binary stream spool directory");
private void storeParentStringField(String value) { Key key = null; if (value != null) { try { key = KeyFactory.stringToKey(value); } catch (IllegalArgumentException iae) { throw new NucleusFatalUserException("Attempt was made to set parent to " + value + " but this cannot be converted into a Key."); } } storeParentKeyPK(key); }
private static Object intOrLongToInternalKey( String kind, Class<?> pkType, AbstractMemberMetaData pkMemberMetaData, Class<?> cls, Object val) { Object result = null; Key keyWithId = KeyFactory.createKey(kind, ((Number) val).longValue()); if (pkType.equals(String.class)) { if (pkMemberMetaData.hasExtension(DatastoreManager.ENCODED_PK)) { result = KeyFactory.keyToString(keyWithId); } else { throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is an unencoded String. However, the provided value is of type " + val.getClass().getName() + "."); } } else if (pkType.equals(Long.class) || pkType.equals(long.class)) { result = keyWithId.getId(); } else if (pkType.equals(Key.class)) { result = keyWithId; } return result; }
private String getPrefixFromMatchesExpression(Object matchesExprObj) { if (matchesExprObj instanceof Character) { matchesExprObj = matchesExprObj.toString(); } if (!(matchesExprObj instanceof String)) { throw new NucleusFatalUserException( "Prefix matching only supported on strings (received a " + matchesExprObj.getClass().getName() + ")."); } String matchesExpr = (String) matchesExprObj; String wildcardExpr = (getStoreManager().getApiAdapter().getName().equalsIgnoreCase("JPA")) ? "%" : ".*"; int wildcardIndex = matchesExpr.indexOf(wildcardExpr); if (wildcardIndex == -1 || wildcardIndex != matchesExpr.length() - wildcardExpr.length()) { throw new UnsupportedDatastoreFeatureException( "Wildcard must appear at the end of the expression string (only prefix matches are supported)"); } return matchesExpr.substring(0, wildcardIndex); }
static StorageVersion fromStoreManager(StoreManager storeMgr) { String val = storeMgr.getStringProperty(STORAGE_VERSION_PROPERTY); // if the user hasn't specific a specific storage version we'll use the default if (val == null) { return DEFAULT; } try { return StorageVersion.valueOf(val); } catch (IllegalArgumentException iae) { throw new NucleusFatalUserException( String.format("'%s' is an unknwon value for %s. Legal values are %s.", val, STORAGE_VERSION_PROPERTY, Arrays.toString(StorageVersion.values()))); } } }
private void processPotentialBatchGet(QueryData qd, Collection value, AbstractClassMetaData acmd, Query.FilterOperator op) { if (!op.equals(Query.FilterOperator.EQUAL)) { throw new NucleusFatalUserException( "Batch lookup by primary key is only supported with the equality operator."); } // If it turns out there aren't any other filters or sorts we'll fulfill // the query using a batch get qd.batchGetKeys = Utils.newLinkedHashSet(); for (Object obj : value) { qd.batchGetKeys.add(internalPkToKey(acmd, obj)); } }
static Object idToInternalKey( String kind, AbstractMemberMetaData pkMemberMetaData, Class<?> cls, Object val, ExecutionContext ec, boolean allowSubclasses) { Object result = null; Class<?> pkType = pkMemberMetaData.getType(); if (val instanceof String) { result = stringToInternalKey(kind, pkType, pkMemberMetaData, cls, val); } else if (val instanceof Long || val instanceof Integer || long.class.isInstance(val)) { result = intOrLongToInternalKey(kind, pkType, pkMemberMetaData, cls, val); } else if (val instanceof Key) { result = keyToInternalKey(kind, pkType, pkMemberMetaData, cls, (Key) val, ec, allowSubclasses); } if (result == null && val != null) { // missed a case somewhere throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + " identified by " + val + ". This is not a valid representation of a primary key for an instance of " + cls.getName() + "."); } return result; }
private void storeParentKeyPK(Key key) { if (key != null && parentAlreadySet) { throw new NucleusFatalUserException(PARENT_ALREADY_SET); throw new NucleusFatalUserException( "Attempt was made to modify the parent of an object of type " + getObjectProvider().getClassMetaData().getFullClassName() + " identified by " if (!insert) { throw new NucleusFatalUserException("You can only rely on this class to properly handle " + "parent pks if you instantiated the class without providing a datastore " + "entity to the constructor."); throw new NucleusFatalUserException(PARENT_ALREADY_SET);
Object result = null; if (!keyKindIsValid(kind, pkMemberMetaData, cls, key, ec, allowSubclasses)) { throw new NucleusFatalUserException( "Received a request to find an object of kind " + kind + " but the provided " + "identifier is a Key for kind " + key.getKind()); throw new NucleusFatalUserException( "Received a request to find an object of kind " + kind + " but the provided " + "identifier is is an incomplete Key"); throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is an unencoded String, which means instances of this type " throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is a Long, which means instances of this type " throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is a Long. However, the encoded string "
void storePKIdField(int fieldNumber, Object value) { AbstractMemberMetaData mmd = getMetaData(fieldNumber); if (!mmd.getType().equals(Long.class)) { throw new NucleusFatalUserException( "Field with \"" + DatastoreManager.PK_ID + "\" extension must be of type Long"); } Key key = null; if (value != null) { key = KeyFactory.createKey(datastoreEntity.getKind(), (Long) value); } storeKeyPK(key); }
decodedKey = KeyFactory.stringToKey((String) val); if (!decodedKey.isComplete()) { throw new NucleusFatalUserException( "Received a request to find an object of kind " + kind + " but the provided " + "identifier is the String representation of an incomplete Key for kind " throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + " identified by the String " + val + ", but the primary key of " + cls.getName() + " is of type Long."); throw new NucleusFatalUserException( "Received a request to find an object of kind " + kind + " but the provided " + "identifier is the String representation of a Key for kind " } else { if (decodedKey.getParent() != null) { throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is an unencoded String, which means instances of this type " throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is an unencoded String. However, the encoded string " throw new NucleusFatalUserException( "Received a request to find an object of type " + cls.getName() + ". The primary " + "key for this type is a Long, which means instances of this type " throw new NucleusFatalUserException(
@Override public int size(ObjectProvider op) { if (storeMgr.storageVersionAtLeast(StorageVersion.READ_OWNED_CHILD_KEYS_FROM_PARENTS) && !indexedList) { if (MetaDataUtils.isOwnedRelation(ownerMemberMetaData, storeMgr)) { // Ordered list can only be done via parent key currently return getSizeUsingParentKeyInChildren(op); } else { throw new NucleusFatalUserException("Dont currently support ordered lists that are unowned"); } } return super.size(op); }
private void verifyRelatedKeyIsOfProperType( AbstractMemberMetaData ammd, Key key, AbstractClassMetaData acmd) { String keyKind = key.getKind(); String fieldKind = getIdentifierFactory().newDatastoreContainerIdentifier(acmd).getIdentifierName(); if (!keyKind.equals(fieldKind)) { throw new org.datanucleus.exceptions.NucleusFatalUserException(query.getSingleStringQuery() + ": Field " + ammd.getFullFieldName() + " maps to kind " + fieldKind + " but" + " parameter value contains Key of kind " + keyKind ); } }
private void storePKNameField(int fieldNumber, String value) { // TODO(maxr) make sure the pk is an encoded string AbstractMemberMetaData mmd = getMetaData(fieldNumber); if (!mmd.getType().equals(String.class)) { throw new NucleusFatalUserException( "Field with \"" + DatastoreManager.PK_ID + "\" extension must be of type String"); } Key key = null; if (value != null) { key = KeyFactory.createKey(datastoreEntity.getParent(), datastoreEntity.getKind(), value); } storeKeyPK(key); }
throw new NucleusFatalUserException(GAE_LOCALISER.msg("AppEngine.OwnedChildCannotChangeParent", key, datastoreEntity.getKey()));
private AbstractMemberMetaData getMemberMetaDataForTuples(AbstractClassMetaData acmd, List<String> tuples) { AbstractMemberMetaData ammd = acmd.getMetaDataForMember(tuples.get(0)); if (ammd == null || tuples.size() == 1) { return ammd; } // more than one tuple, so it must be embedded data String parentFullClassName = acmd.getFullClassName(); for (String tuple : tuples.subList(1, tuples.size())) { EmbeddedMetaData emd = ammd.getEmbeddedMetaData(); if (emd == null) { throw new NucleusFatalUserException( query.getSingleStringQuery() + ": Can only reference properties of a sub-object if " + "the sub-object is embedded."); } DatastoreTable parentTable = getStoreManager().getDatastoreClass(parentFullClassName, getClassLoaderResolver()); parentFullClassName = ammd.getTypeName(); AbstractMemberMetaData parentField = (AbstractMemberMetaData) emd.getParent(); EmbeddedMapping embeddedMapping = (EmbeddedMapping) parentTable.getMappingForFullFieldName(parentField.getFullFieldName()); ammd = findMemberMetaDataWithName(tuple, embeddedMapping); if (ammd == null) { break; } } return ammd; }
private void storeKeyPK(Key key) { if (key != null && !datastoreEntity.getKind().equals(key.getKind())) { throw new NucleusFatalUserException( "Attempt was made to set the primary key of an entity with kind " + datastoreEntity.getKind() + " to a key with kind " + key.getKind()); if (!keyAlreadySet) { throw new NucleusFatalUserException( "Attempt was made to modify the primary key of an object of type " + getObjectProvider().getClassMetaData().getFullClassName() + " identified by " if (keyAlreadySet) { throw new NucleusFatalUserException(PARENT_ALREADY_SET);
private DatastoreServiceConfig createDatastoreServiceConfigPrototype( PersistenceConfiguration persistenceConfiguration, String... timeoutProps) { DatastoreServiceConfig datastoreServiceConfig = DatastoreServiceConfig.Builder.withDefaults(); for (String timeoutProp : timeoutProps) { int defaultDeadline = persistenceConfiguration.getIntProperty(timeoutProp); if (defaultDeadline > 0) { datastoreServiceConfig.deadline(defaultDeadline / 1000d); } } String defaultReadConsistencyStr = persistenceConfiguration.getStringProperty( DATASTORE_READ_CONSISTENCY_PROPERTY); if (defaultReadConsistencyStr != null) { try { datastoreServiceConfig.readPolicy(new ReadPolicy(Consistency.valueOf(defaultReadConsistencyStr))); } catch (IllegalArgumentException iae) { throw new NucleusFatalUserException( "Illegal value for " + DATASTORE_READ_CONSISTENCY_PROPERTY + ". Valid values are " + Arrays.toString(Consistency.values())); } } return datastoreServiceConfig; }