Java Code Examples for org.jooq.Record#getValue()

The following examples show how to use org.jooq.Record#getValue() . 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: Application.java    From hellokoding-courses with MIT License 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    String user = System.getProperty("jdbc.user");
    String password = System.getProperty("jdbc.password");
    String url = System.getProperty("jdbc.url");
    String driver = System.getProperty("jdbc.driver");

    Class.forName(driver).newInstance();
    try (Connection connection = DriverManager.getConnection(url, user, password)) {
        DSLContext dslContext = DSL.using(connection, SQLDialect.MYSQL);
        Result<Record> result = dslContext.select().from(AUTHOR).fetch();

        for (Record r : result) {
            Integer id = r.getValue(AUTHOR.ID);
            String firstName = r.getValue(AUTHOR.FIRST_NAME);
            String lastName = r.getValue(AUTHOR.LAST_NAME);

            System.out.println("ID: " + id + " first name: " + firstName + " last name: " + lastName);
        }
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 2
Source File: CMSCrawler.java    From oneops with Apache License 2.0 6 votes vote down vote up
private List<Environment> getOneopsEnvironments(Connection conn) {
    List<Environment> envs = new ArrayList<>();
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    log.info("Fetching all environments..");
    Result<Record> envRecords = create.select().from(CM_CI)
            .join(MD_CLASSES).on(CM_CI.CLASS_ID.eq(MD_CLASSES.CLASS_ID))
            .join(NS_NAMESPACES).on(CM_CI.NS_ID.eq(NS_NAMESPACES.NS_ID))
            .where(MD_CLASSES.CLASS_NAME.eq("manifest.Environment"))
            .fetch(); //all the env cis
    log.info("Got all environments");
    for (Record r : envRecords) {
        long envId = r.getValue(CM_CI.CI_ID);
        //now query attributes for this env
        Environment env = new Environment();
        env.setName(r.getValue(CM_CI.CI_NAME));
        env.setId(r.getValue(CM_CI.CI_ID));
        env.setPath(r.getValue(NS_NAMESPACES.NS_PATH));
        env.setNsId(r.getValue(NS_NAMESPACES.NS_ID));
        envs.add(env);
    }
    return envs;
}
 
Example 3
Source File: CMSCrawler.java    From oneops with Apache License 2.0 6 votes vote down vote up
private List<String> getActiveClouds(Platform platform, Connection conn) {
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    List<String> clouds = new ArrayList<>();
    Result<Record> consumesRecords = create.select().from(CM_CI_RELATIONS)
            .join(MD_RELATIONS).on(MD_RELATIONS.RELATION_ID.eq(CM_CI_RELATIONS.RELATION_ID))
            .join(CM_CI_RELATION_ATTRIBUTES).on(CM_CI_RELATION_ATTRIBUTES.CI_RELATION_ID.eq(CM_CI_RELATIONS.CI_RELATION_ID))
            .where(CM_CI_RELATIONS.FROM_CI_ID.eq(platform.getId()))
            .and(CM_CI_RELATION_ATTRIBUTES.DF_ATTRIBUTE_VALUE.eq("active"))
            .fetch();
    for (Record r : consumesRecords) {
        String comments = r.getValue(CM_CI_RELATIONS.COMMENTS);
        String cloudName = comments.split(":")[1];
        cloudName = cloudName.split("\"")[1];
        clouds.add(cloudName);
    }
    return clouds;
}
 
Example 4
Source File: CMSCrawler.java    From oneops with Apache License 2.0 5 votes vote down vote up
private void crawlClouds(Connection conn) {

        DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);

        log.info("Fetching all clouds..");
        Result<Record> cloudRecords = create.select().from(CM_CI)
                .join(MD_CLASSES).on(CM_CI.CLASS_ID.eq(MD_CLASSES.CLASS_ID))
                .join(NS_NAMESPACES).on(CM_CI.NS_ID.eq(NS_NAMESPACES.NS_ID))
                .where(MD_CLASSES.CLASS_NAME.eq("account.Cloud"))
                .fetch(); //all the env cis
        log.info("Got all clouds ");


        for (Record r : cloudRecords) {
            if (shutDownRequested) {
                log.info("Shutdown requested, exiting !");
                break;
            }

            long cloudId = r.getValue(CM_CI.CI_ID);
            String cloudName = r.getValue(CM_CI.CI_NAME);
            String cloudNS = r.getValue(NS_NAMESPACES.NS_PATH);
            if (syncClouds) {
                syncCloudVariables(cloudId, cloudName, cloudNS, conn);
            }
        }
    }
 
Example 5
Source File: CMSCrawler.java    From oneops with Apache License 2.0 5 votes vote down vote up
private void init(Connection conn) {
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    Result<Record> coresAttributes = create.select().from(MD_CLASS_ATTRIBUTES)
    .join(MD_CLASSES).on(MD_CLASS_ATTRIBUTES.CLASS_ID.eq(MD_CLASSES.CLASS_ID))
    .where(MD_CLASSES.CLASS_NAME.like("bom%Compute"))
    .and(MD_CLASS_ATTRIBUTES.ATTRIBUTE_NAME.eq("cores")).fetch();

    for (Record coresAttribute : coresAttributes) {
        coresAttributeIds.add(coresAttribute.getValue(MD_CLASS_ATTRIBUTES.ATTRIBUTE_ID));
    }

    //create = DSL.using(conn, SQLDialect.POSTGRES);
    Result<Record> computeClasses = create.select().from(MD_CLASSES)
            .where(MD_CLASSES.CLASS_NAME.like("bom%Compute")).fetch();
    for (Record computeClass : computeClasses) {
        computeClassIds.add(computeClass.get(MD_CLASSES.CLASS_ID));
    }
    log.info("cached compute class ids: " + computeClassIds);
    log.info("cached compute cores attribute ids: " + coresAttributeIds);
    populateBaseOrganizationClassAttribMappingsCache(conn);

    //cache relation attribute ids
    Result<Record> relationsAttributes = create.select().from(MD_RELATION_ATTRIBUTES).join(MD_RELATIONS)
            .on(MD_RELATION_ATTRIBUTES.RELATION_ID.eq(MD_RELATIONS.RELATION_ID))
            .fetch();
    for (Record relationAttribute : relationsAttributes) {
        if (relationAttribute.getValue(MD_RELATIONS.RELATION_NAME)
                .equalsIgnoreCase("manifest.ComposedOf")
                && relationAttribute.getValue(MD_RELATION_ATTRIBUTES.ATTRIBUTE_NAME).equalsIgnoreCase("enabled")) {
            //cache the "enabled" attribute id of platform
            platformEnabledAttributeId = relationAttribute.getValue(MD_RELATION_ATTRIBUTES.ATTRIBUTE_ID);
        }
        //Here cache more attribute ids as needed for different cases
    }
}
 
Example 6
Source File: CMSCrawler.java    From oneops with Apache License 2.0 5 votes vote down vote up
private void populateEnv(Environment env, Connection conn) {
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    Result<Record> envAttributes = create.select().from(CM_CI_ATTRIBUTES)
            .join(MD_CLASS_ATTRIBUTES).on(CM_CI_ATTRIBUTES.ATTRIBUTE_ID.eq(MD_CLASS_ATTRIBUTES.ATTRIBUTE_ID))
            .where(CM_CI_ATTRIBUTES.CI_ID.eq(env.getId()))
            .fetch();
    for (Record attrib : envAttributes) {
        String attributeName = attrib.getValue(MD_CLASS_ATTRIBUTES.ATTRIBUTE_NAME);
        if (attributeName.equalsIgnoreCase("profile")) {
            env.setProfile(attrib.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));
        }
        //add other attributes as and when needed
    }
    //now query all the platforms for this env
    Result<Record> platformRels = create.select().from(CM_CI_RELATIONS)
            .join(MD_RELATIONS).on(MD_RELATIONS.RELATION_ID.eq(CM_CI_RELATIONS.RELATION_ID))
            .join(CM_CI).on(CM_CI.CI_ID.eq(CM_CI_RELATIONS.TO_CI_ID))
            .where(MD_RELATIONS.RELATION_NAME.eq("manifest.ComposedOf"))
            .and(CM_CI_RELATIONS.FROM_CI_ID.eq(env.getId()))
            .fetch();
    int totalCores = 0;
    for (Record platformRel : platformRels) {
        long platformId = platformRel.getValue(CM_CI_RELATIONS.TO_CI_ID);
        Platform platform = new Platform();
        platform.setId(platformId);
        platform.setName(platformRel.getValue(CM_CI.CI_NAME));
        platform.setPath(env.getPath() + "/" + env.getName() + "/bom/" + platform.getName() + "/1");
        populatePlatform(conn, platform, platformRel.getValue(CM_CI_RELATIONS.CI_RELATION_ID));
        platform.setActiveClouds(getActiveClouds(platform, conn));
        platform.setCloudsMap(getCloudsDataForPlatform(conn, platformId));
        
        //now calculate total cores of the env - including all platforms
        totalCores += platform.getTotalCores();
        env.addPlatform(platform);
    }
    env.setTotalCores(totalCores);
}
 
Example 7
Source File: TPanel.java    From plugins with GNU General Public License v3.0 4 votes vote down vote up
private void populateSelector()
{
	if (!databaseManager.checkTableExists("TMORPH_SETS"))
	{
		databaseManager.getDsl().createTable(TMORPH_SETS)
			.column(TMORPH_SETS.SET_NAME, SQLDataType.VARCHAR(255).nullable(false))
			.column(TMORPH_SETS.HELMET, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.CAPE, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.AMULET, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.WEAPON, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.TORSO, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.SHIELD, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.LEGS, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.HANDS, SQLDataType.INTEGER.nullable(false))
			.column(TMORPH_SETS.BOOTS, SQLDataType.INTEGER.nullable(false))
			.execute();
	}

	Result<TmorphSetsRecord> recs = databaseManager.getDsl().selectFrom(TMORPH_SETS).fetch();
	setMap.clear();
	selector.removeAllItems();
	selector.addItem("Select your set...");
	selector.setSelectedIndex(0);

	for (Record record : recs)
	{
		TmorphSet tmo = new TmorphSet();
		String name = record.getValue(TMORPH_SETS.SET_NAME);
		tmo.setName(name);
		tmo.setHelmet(record.getValue(TMORPH_SETS.HELMET));
		tmo.setCape(record.getValue(TMORPH_SETS.CAPE));
		tmo.setAmulet(record.getValue(TMORPH_SETS.AMULET));
		tmo.setWeapon(record.getValue(TMORPH_SETS.WEAPON));
		tmo.setTorso(record.getValue(TMORPH_SETS.TORSO));
		tmo.setShield(record.getValue(TMORPH_SETS.SHIELD));
		tmo.setLegs(record.getValue(TMORPH_SETS.LEGS));
		tmo.setHands(record.getValue(TMORPH_SETS.HANDS));
		tmo.setBoots(record.getValue(TMORPH_SETS.BOOTS));
		setMap.put(name, tmo);
		selector.addItem(name);
	}
}
 
Example 8
Source File: CMSCrawler.java    From oneops with Apache License 2.0 4 votes vote down vote up
private void populatePlatform(Connection conn, Platform platform, long composedOfRelationId) {
    DSLContext create = DSL.using(conn, SQLDialect.POSTGRES);
    Result<Record> computes = create.select().from(CM_CI)
            .join(NS_NAMESPACES).on(NS_NAMESPACES.NS_ID.eq(CM_CI.NS_ID))
            .join(CM_CI_ATTRIBUTES).on(CM_CI_ATTRIBUTES.CI_ID.eq(CM_CI.CI_ID))
            .where(NS_NAMESPACES.NS_PATH.eq(platform.getPath())
            .and(CM_CI.CLASS_ID.in(computeClassIds))
            .and(CM_CI_ATTRIBUTES.ATTRIBUTE_ID.in(coresAttributeIds)))
            .fetch();

    platform.setTotalComputes(computes.size());
    int totalCores = 0;
    if (platform.getTotalComputes() > 0) {
        for (Record compute : computes) {
            totalCores += Integer.parseInt(compute.get(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));
        }
    }
    platform.setTotalCores(totalCores);

    //Now query platform ci attributes and set to the object
    Result<Record> platformAttributes = create.select().from(CM_CI_ATTRIBUTES)
            .join(MD_CLASS_ATTRIBUTES).on(MD_CLASS_ATTRIBUTES.ATTRIBUTE_ID.eq(CM_CI_ATTRIBUTES.ATTRIBUTE_ID))
            .where(CM_CI_ATTRIBUTES.CI_ID.eq(platform.getId()))
            .fetch();

    for (Record attribute : platformAttributes) {
        String attributeName = attribute.getValue(MD_CLASS_ATTRIBUTES.ATTRIBUTE_NAME);
        if (attributeName.equalsIgnoreCase("source")) {
            platform.setSource(attribute.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));
        } else if (attributeName.equalsIgnoreCase("pack")) {
            platform.setPack(attribute.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE));
        } else if (attributeName.equalsIgnoreCase("autorepair")) {
          platform.setAutoRepairEnabled(new Boolean(attribute.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE)));
        } else if (attributeName.equalsIgnoreCase("autoreplace")) {
            platform.setAutoReplaceEnabled(new Boolean(attribute.getValue(CM_CI_ATTRIBUTES.DF_ATTRIBUTE_VALUE)));
        }
    }
    //Now set the enable/disable status
    //select * from cm_ci_relation_attributes where ci_relation_id=composedOfRelationId
    Result<Record> composedOfRelationAttributes = create.select().from(CM_CI_RELATION_ATTRIBUTES)
            .where(CM_CI_RELATION_ATTRIBUTES.CI_RELATION_ID.eq(composedOfRelationId))
            .fetch();
    for (Record relAttribute : composedOfRelationAttributes) {
        if (relAttribute.getValue(CM_CI_RELATION_ATTRIBUTES.ATTRIBUTE_ID) == platformEnabledAttributeId) {
            boolean enabled = Boolean.valueOf(relAttribute.getValue(CM_CI_RELATION_ATTRIBUTES.DF_ATTRIBUTE_VALUE));
            if (enabled) {
                platform.setEnable("enable");//this could have been a boolean, but model has dependency on nubu
            } else {
                platform.setEnable("disable");
            }
        }
    }
}
 
Example 9
Source File: RecordGetter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public P get(Record target) throws Exception {
	return (P) target.getValue(index);
}
 
Example 10
Source File: JooqKeySourceGetter.java    From SimpleFlatMapper with MIT License 4 votes vote down vote up
@Override
public Object getValue(JooqFieldKey key, Record source) {
    return source.getValue(key.getIndex());
}