Java Code Examples for org.eclipse.emf.ecore.EAttribute#getEAnnotation()

The following examples show how to use org.eclipse.emf.ecore.EAttribute#getEAnnotation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends IdEObject> List<T> query(EAttribute attribute, Object value) throws BimserverLockConflictException, BimserverDatabaseException {
	List<T> result = new ArrayList<>();
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + attribute.getEContainingClass().getName() + "_" + attribute.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		List<byte[]> duplicates = database.getKeyValueStore().getDuplicates(indexTableName, queryBytes, this);
		for (byte[] indexValue : duplicates) {
			ByteBuffer buffer = ByteBuffer.wrap(indexValue);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			result.add((T) get(oid, OldQuery.getDefault()));
		}
	}
	return result;
}
 
Example 2
Source File: QueryNamesAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ObjectIdentifier getOidOfGuidAlternative(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
		valueBuffer.putInt(pid);
		valueBuffer.putInt(-rid);
		valueBuffer.put(queryBytes);
		byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array());
		if (firstDuplicate != null) {
			ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			
			return new ObjectIdentifier(oid, (short)oid);
		}
	} else {
		throw new BimserverDatabaseException("Name queries are not implemented yet");
	}
	return null;
}
 
Example 3
Source File: QueryClassificationsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ObjectIdentifier getOid(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
		valueBuffer.putInt(pid);
		valueBuffer.putInt(-rid);
		valueBuffer.put(queryBytes);
		byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array());
		if (firstDuplicate != null) {
			ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			
			return new ObjectIdentifier(oid, (short)oid);
		}
	} else {
		throw new UnsupportedOperationException(eClass.getName() + "." + attribute.getName() + " does not have a singleindex");
	}
	return null;
}
 
Example 4
Source File: QueryGuidsAndTypesStackFrame.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
public ObjectIdentifier getOidOfGuidAlternative(EClass eClass, EAttribute attribute, Object value, DatabaseInterface databaseInterface, int pid, int rid) throws BimserverDatabaseException {
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + eClass.getName() + "_" + attribute.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
		valueBuffer.putInt(pid);
		valueBuffer.putInt(-rid);
		valueBuffer.put(queryBytes);
		byte[] firstDuplicate = databaseInterface.get(indexTableName, valueBuffer.array());
		if (firstDuplicate != null) {
			ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			
			return new ObjectIdentifier(oid, (short)oid);
		}
	} else {
		throw new UnsupportedOperationException("Attribute " + attribute.getName() + " does not have the \"singleindex\" annotation");
	}
	return null;
}
 
Example 5
Source File: DatabaseSession.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <T extends IdEObject> T querySingle(EAttribute attribute, Object value, int pid, int rid) throws BimserverLockConflictException, BimserverDatabaseException {
	if (attribute.getEAnnotation("singleindex") != null) {
		String indexTableName = attribute.getEContainingClass().getEPackage().getName() + "_" + attribute.getEContainingClass().getName() + "_" + attribute.getName();
		byte[] queryBytes = null;
		if (value instanceof String) {
			queryBytes = ((String)value).getBytes(Charsets.UTF_8);
		} else if (value instanceof Integer) {
			queryBytes = BinUtils.intToByteArray((Integer)value);
		} else {
			throw new BimserverDatabaseException("Unsupported type " + value);
		}
		boolean perRecordVersioning = perRecordVersioning(attribute.getEContainingClass());
		if (!perRecordVersioning) {
			ByteBuffer valueBuffer = ByteBuffer.allocate(queryBytes.length + 8);
			valueBuffer.putInt(pid);
			valueBuffer.putInt(-rid);
			valueBuffer.put(queryBytes);
			queryBytes = valueBuffer.array();
		}
		byte[] firstDuplicate = database.getKeyValueStore().get(indexTableName, queryBytes, this);
		if (firstDuplicate != null) {
			ByteBuffer buffer = ByteBuffer.wrap(firstDuplicate);
			buffer.getInt(); // pid
			long oid = buffer.getLong();
			return (T) get(oid, OldQuery.getDefault());
		}
	} else {
		throw new UnsupportedOperationException(attribute.getContainerClass().getName() + "." + attribute.getName() + " does not have a \"singleindex\"");
	}
	return null;
}