Skip to content

Instantly share code, notes, and snippets.

@hugith
Last active Aug 29, 2015
Embed
What would you like to do?
<db-relationship name="product" source="fd_product_link" target="fd_product" toMany="false">
<db-attribute-pair source="product_id" target="id"/>
</db-relationship>
08:43:25.619 [main] INFO strimillinn.core.QueryTest - Fetching all ProductLinks
08:43:25.756 [main] INFO org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader - Loading XML configuration resource from file:/Users/hugi/Documents/workspace/strimillinn-core/target/classes/cayenne-strimillinn.xml
08:43:25.761 [main] INFO org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader - Loading XML DataMap resource from file:/Users/hugi/Documents/workspace/strimillinn-core/target/classes/datamap.map.xml
08:43:25.799 [main] INFO org.apache.cayenne.configuration.XMLDataChannelDescriptorLoader - loading user name and password.
08:43:25.818 [main] INFO org.apache.cayenne.configuration.server.DataDomainProvider - setting DataNode 'Strimillinn' as default, used by all unlinked DataMaps
08:43:25.890 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - Opening connection: jdbc:mysql://revoked:3306/strimillinn?useUnicode=true&characterEncoding=utf8
Login: revoked
Password: *******
08:43:26.727 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - +++ Connecting: SUCCESS.
08:43:26.812 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - Detected and installed adapter: org.apache.cayenne.dba.mysql.MySQLAdapter
08:43:26.813 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - --- transaction started.
08:43:26.889 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - SELECT t0.creation_date, t0.modification_date, t0.text, t0.units, t0.product_id, t0.shop_id, t0.id FROM strimillinn.fd_product_link t0
08:43:26.981 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === returned 106 rows. - took 97 ms.
08:43:26.983 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - SELECT t0.creation_date, t0.modification_date, t0.name, t0.number, t0.id FROM strimillinn.fd_product t0
08:43:27.129 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - === returned 193 rows. - took 148 ms.
08:43:27.195 [main] INFO org.apache.cayenne.log.CommonsJdbcEventLogger - +++ transaction committed.
08:43:27.215 [main] INFO strimillinn.core.QueryTest - Fetching products
08:43:27.215 [main] INFO strimillinn.core.QueryTest - Product: null
08:43:27.215 [main] INFO strimillinn.core.QueryTest - Product: null
08:43:27.215 [main] INFO strimillinn.core.QueryTest - Product: null
[etc...]
package strimillinn.core;
import java.util.List;
import org.apache.cayenne.query.SelectQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import strimillinn.core.model.ProductLink;
public class QueryTest {
private static final Logger logger = LoggerFactory.getLogger( QueryTest.class );
public static void main( String[] args ) {
SelectQuery<ProductLink> query = SelectQuery.query( ProductLink.class );
query.addPrefetch( ProductLink.PRODUCT_KEY );
logger.info( "Fetching all ProductLinks" );
List<ProductLink> links = StrimillinnCore.newContext().select( query );
logger.info( "Fetching products" );
for( ProductLink link : links ) {
logger.info( "Product: " + link.product() );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment