com.j256.ormlite.dao.ForeignCollection Java Examples

The following examples show how to use com.j256.ormlite.dao.ForeignCollection. 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: Tag.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, String> getAttributesWithNamesWithoutChecking() {
    Map<String, String> attributesWithNames = new LinkedHashMap<>();
    ForeignCollection<Attribute> attributes = getAttributes();
    try {
        for (Attribute attribute : attributes) {
            attributesWithNames.put(attribute.getName(), attribute.getValue());
        }
        return attributesWithNames;
    } catch (NullPointerException e) {
        return new HashMap<>();
    }

}
 
Example #2
Source File: RxBaseDaoImpl.java    From AndroidStarter with Apache License 2.0 5 votes vote down vote up
@Override
public <FT> Observable<ForeignCollection<FT>> rxGetEmptyForeignCollection(final String fieldName) {
    final Func0<Observable<ForeignCollection<FT>>> loFunc = () -> {
        try {
            return Observable.just(getEmptyForeignCollection(fieldName));
        } catch (SQLException e) {
            return Observable.error(e);
        }
    };
    return Observable.defer(loFunc);
}
 
Example #3
Source File: SpatialReferenceSystemDao.java    From geopackage-core-java with MIT License 5 votes vote down vote up
/**
 * Delete the Spatial Reference System, cascading
 * 
 * @param srs
 *            spatial reference system
 * @return deleted count
 * @throws SQLException
 *             upon deletion failure
 */
public int deleteCascade(SpatialReferenceSystem srs) throws SQLException {
	int count = 0;

	if (srs != null) {

		// Delete Contents
		ForeignCollection<Contents> contentsCollection = srs.getContents();
		if (!contentsCollection.isEmpty()) {
			ContentsDao dao = getContentsDao();
			dao.deleteCascade(contentsCollection);
		}

		// Delete Geometry Columns
		GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao();
		if (geometryColumnsDao.isTableExists()) {
			ForeignCollection<GeometryColumns> geometryColumnsCollection = srs
					.getGeometryColumns();
			if (!geometryColumnsCollection.isEmpty()) {
				geometryColumnsDao.delete(geometryColumnsCollection);
			}
		}

		// Delete Tile Matrix Set
		TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao();
		if (tileMatrixSetDao.isTableExists()) {
			ForeignCollection<TileMatrixSet> tileMatrixSetCollection = srs
					.getTileMatrixSet();
			if (!tileMatrixSetCollection.isEmpty()) {
				tileMatrixSetDao.delete(tileMatrixSetCollection);
			}
		}

		// Delete
		count = delete(srs);
	}
	return count;
}
 
Example #4
Source File: OrmliteReflection.java    From poetry with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the generic type argument: the type that is held by the specified ForeignCollection Field
 *
 * @param field a {@link Field} that holds the type {@link com.j256.ormlite.dao.ForeignCollection}
 * @throws RuntimeException when the Field is not a ForeignCollection
 * @return the class
 */
public static Class<?> getForeignCollectionParameterType(Field field)
{
    if (!field.getType().equals(ForeignCollection.class))
    {
        throw new RuntimeException(field.getDeclaringClass().getName() + " declares the field \"" + field.getName() + "\" which is not a ForeignCollection but is annotated by ForeignCollectionField");
    }

    Type type = field.getGenericType();
    ParameterizedType parameterized_type = (ParameterizedType)type;
    Type child_type = parameterized_type.getActualTypeArguments()[0];

    return (Class<?>)child_type; // TODO: check conversion?
}
 
Example #5
Source File: Tag.java    From mae-annotation with GNU General Public License v3.0 5 votes vote down vote up
public Map<String, String> getAttributesWithNames() {
    Map<String, String> attributesWithNames = new LinkedHashMap<>();
    ForeignCollection<Attribute> attributes = getAttributes();
    if (attributes != null) {
        for (Attribute attribute : attributes) {
            String value = attribute.getValue();
            if (value.length() > 0) {
                attributesWithNames.put(attribute.getName(), value);
            }
        }
    }
    return attributesWithNames;

}
 
Example #6
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
public void setContacts(Collection<Contact> contacts) {
    if (contacts instanceof ForeignCollection) {
        this.contacts = (ForeignCollection) contacts;
    } else {
        this.nonDaoContacts = contacts;
    }
}
 
Example #7
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
@Override
public void setAddresses(Collection<AddressItem> addresses) {
    if (addresses instanceof ForeignCollection) {
        this.addresses = (ForeignCollection) addresses;
    } else {
        this.nonDaoAddresses = addresses;
    }
}
 
Example #8
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
public void setContacts(Collection<Contact> contacts) {
    if (contacts instanceof ForeignCollection) {
        this.contacts = (ForeignCollection) contacts;
    } else {
        this.nonDaoContacts = contacts;
    }
}
 
Example #9
Source File: AddressBook.java    From AndroidDatabaseLibraryComparison with MIT License 5 votes vote down vote up
@Override
public void setAddresses(Collection<AddressItem> addresses) {
    if (addresses instanceof ForeignCollection) {
        this.addresses = (ForeignCollection) addresses;
    } else {
        this.nonDaoAddresses = addresses;
    }
}
 
Example #10
Source File: AttributeType.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public void setAttributes(ForeignCollection<Attribute> attributes) {
    this.attributes = attributes;
}
 
Example #11
Source File: LinkTag.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<Argument> getArguments() {
    return arguments;
}
 
Example #12
Source File: Tag.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<Attribute> getAttributes() {
    return attributes;
}
 
Example #13
Source File: DialogOccupant.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public void setMessageCollection(ForeignCollection<Message> messageCollection) {
    this.messageCollection = messageCollection;
}
 
Example #14
Source File: DialogOccupant.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public ForeignCollection<Message> getMessageCollection() {
    return messageCollection;
}
 
Example #15
Source File: DialogOccupant.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public void setMessages(ForeignCollection<Message> message) {
    this.messageCollection = message;
}
 
Example #16
Source File: DialogOccupant.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public ForeignCollection<Message> getMessages() {
    return messageCollection;
}
 
Example #17
Source File: DialogOccupant.java    From q-municate-android with Apache License 2.0 4 votes vote down vote up
public DialogOccupant(Dialog dialog, QMUser user, ForeignCollection<Message> messageCollection) {
    this.dialog = dialog;
    this.user = user;
    this.messageCollection = messageCollection;
}
 
Example #18
Source File: ArgumentType.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<Argument> getArguments() {
    return arguments;
}
 
Example #19
Source File: AttributeType.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<Attribute> getAttributes() {
    return attributes;
}
 
Example #20
Source File: ExtentTag.java    From mae-annotation with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<CharIndex> getSpans() {
    return spans;
}
 
Example #21
Source File: ForeignCollectionMain.java    From ormlite-jdbc with ISC License 4 votes vote down vote up
private void readWriteData() throws Exception {
	// create an instance of Account
	String name = "Buzz Lightyear";
	Account account = new Account(name);

	// persist the account object to the database
	accountDao.create(account);

	// create an associated Order for the Account
	// Buzz bought 2 of item #21312 for a price of $12.32
	int quantity1 = 2;
	int itemNumber1 = 21312;
	float price1 = 12.32F;
	Order order1 = new Order(account, itemNumber1, price1, quantity1);
	orderDao.create(order1);

	// create another Order for the Account
	// Buzz also bought 1 of item #785 for a price of $7.98
	int quantity2 = 1;
	int itemNumber2 = 785;
	float price2 = 7.98F;
	Order order2 = new Order(account, itemNumber2, price2, quantity2);
	orderDao.create(order2);

	Account accountResult = accountDao.queryForId(account.getId());
	ForeignCollection<Order> orders = accountResult.getOrders();

	// sanity checks
	CloseableIterator<Order> iterator = orders.closeableIterator();
	try {
		assertTrue(iterator.hasNext());
		Order order = iterator.next();
		assertEquals(itemNumber1, order.getItemNumber());
		assertSame(accountResult, order.getAccount());
		assertTrue(iterator.hasNext());
		order = iterator.next();
		assertEquals(itemNumber2, order.getItemNumber());
		assertFalse(iterator.hasNext());
	} finally {
		// must always close our iterators otherwise connections to the database are held open
		iterator.close();
	}

	// create another Order for the Account
	// Buzz also bought 1 of item #785 for a price of $7.98
	int quantity3 = 50;
	int itemNumber3 = 78315;
	float price3 = 72.98F;
	Order order3 = new Order(account, itemNumber3, price3, quantity3);

	// now let's add this order via the foreign collection
	orders.add(order3);
	// now there are 3 of them in there
	assertEquals(3, orders.size());

	List<Order> orderList = orderDao.queryForAll();
	// and 3 in the database
	assertEquals(3, orderList.size());
}
 
Example #22
Source File: Account.java    From ormlite-jdbc with ISC License 4 votes vote down vote up
public ForeignCollection<Order> getOrders() {
	return orders;
}
 
Example #23
Source File: ContentsDao.java    From geopackage-core-java with MIT License 4 votes vote down vote up
/**
 * Delete the Contents, cascading
 * 
 * @param contents
 *            contents
 * @return deleted count
 * @throws SQLException
 *             upon deletion error
 */
public int deleteCascade(Contents contents) throws SQLException {
	int count = 0;

	if (contents != null) {

		ContentsDataType dataType = contents.getDataType();

		if (dataType != null) {

			switch (dataType) {
			case FEATURES:

				// Delete Geometry Columns
				GeometryColumnsDao geometryColumnsDao = getGeometryColumnsDao();
				if (geometryColumnsDao.isTableExists()) {
					GeometryColumns geometryColumns = contents
							.getGeometryColumns();
					if (geometryColumns != null) {
						geometryColumnsDao.delete(geometryColumns);
					}
				}

				break;

			case TILES:
			case GRIDDED_COVERAGE:

				// Delete Tile Matrix collection
				TileMatrixDao tileMatrixDao = getTileMatrixDao();
				if (tileMatrixDao.isTableExists()) {
					ForeignCollection<TileMatrix> tileMatrixCollection = contents
							.getTileMatrix();
					if (!tileMatrixCollection.isEmpty()) {
						tileMatrixDao.delete(tileMatrixCollection);
					}
				}

				// Delete Tile Matrix Set
				TileMatrixSetDao tileMatrixSetDao = getTileMatrixSetDao();
				if (tileMatrixSetDao.isTableExists()) {
					TileMatrixSet tileMatrixSet = contents
							.getTileMatrixSet();
					if (tileMatrixSet != null) {
						tileMatrixSetDao.delete(tileMatrixSet);
					}
				}

				break;

			case ATTRIBUTES:

				dropTable(contents.getTableName());

				break;

			}

		} else {
			dropTable(contents.getTableName());
		}

		count = delete(contents);
	}

	return count;
}
 
Example #24
Source File: Library.java    From tutorials with MIT License 4 votes vote down vote up
public ForeignCollection<Book> getBooks() {
    return books;
}
 
Example #25
Source File: DBServerVisibleSecret.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
public void setGroupSecrets(ForeignCollection<DBGroupSecret> groupSecrets) {
  this.groupSecrets = groupSecrets;
}
 
Example #26
Source File: DBServerVisibleSecret.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
public ForeignCollection<DBGroupSecret> getGroupSecrets() {
  return groupSecrets;
}
 
Example #27
Source File: Library.java    From tutorials with MIT License 4 votes vote down vote up
public void setBooks(ForeignCollection<Book> books) {
    this.books = books;
}
 
Example #28
Source File: DBGroup.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the groupSecrets
 */
public ForeignCollection<DBGroupSecret> getGroupSecrets() {
  return groupSecrets;
}
 
Example #29
Source File: Message.java    From android-orm-benchmark with Apache License 2.0 4 votes vote down vote up
public ForeignCollection<User> getReaders() {
    return mReaders;
}
 
Example #30
Source File: DBGroup.java    From passopolis-server with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return the acls
 */
public ForeignCollection<DBAcl> getAcls() {
  return acls;
}